1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.resources.setup; |
35 |
|
|
36 |
|
import static info.magnolia.test.hamcrest.NodeMatchers.hasNode; |
37 |
|
import static org.junit.Assert.assertThat; |
38 |
|
import static org.mockito.Mockito.*; |
39 |
|
|
40 |
|
import info.magnolia.module.InstallContext; |
41 |
|
import info.magnolia.module.resources.ResourcesModule; |
42 |
|
import info.magnolia.test.mock.jcr.MockSession; |
43 |
|
|
44 |
|
import org.junit.Before; |
45 |
|
import org.junit.Test; |
46 |
|
|
47 |
|
|
48 |
|
@link |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
50 |
|
public class InstallBinaryResourcesTaskTest { |
51 |
|
|
52 |
|
private static final String resourcePath = "templating-kit/img/magnolia-logoTest"; |
53 |
|
private static final String imageNameWithJCRInvalidChars = "templating-kit/img/imagename@with invalid%chars"; |
54 |
|
private InstallBinaryResourcesTask task; |
55 |
|
private InstallContext installContext; |
56 |
|
private MockSession session; |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
58 |
3 |
@Before... |
59 |
|
public void setUp() throws Exception { |
60 |
3 |
installContext = mock(InstallContext.class); |
61 |
3 |
session = new MockSession(ResourcesModule.DEFAULT_WORKSPACE); |
62 |
3 |
when(installContext.getJCRSession(ResourcesModule.DEFAULT_WORKSPACE)).thenReturn(session); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
65 |
1 |
@Test... |
66 |
|
public void testExecuteDontStripExtensions() throws Exception { |
67 |
|
|
68 |
1 |
boolean stripExtension = false; |
69 |
1 |
task = new TestInstallBinaryResourcesTask(null, null, "/templating-kit/img/*.*", false, stripExtension); |
70 |
|
|
71 |
|
|
72 |
1 |
task.execute(installContext); |
73 |
|
|
74 |
|
|
75 |
1 |
assertThat(session.getRootNode(), hasNode(resourcePath + ".png")); |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
78 |
1 |
@Test... |
79 |
|
public void testExecuteStripExtensions() throws Exception { |
80 |
|
|
81 |
1 |
task = new TestInstallBinaryResourcesTask("/templating-kit/img/*.*"); |
82 |
|
|
83 |
|
|
84 |
1 |
task.execute(installContext); |
85 |
|
|
86 |
|
|
87 |
1 |
assertThat(session.getRootNode(), hasNode(resourcePath)); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
90 |
1 |
@Test... |
91 |
|
public void testInvalidJcrCharsAreReplaced() throws Exception { |
92 |
|
|
93 |
1 |
task = new TestInstallBinaryResourcesTask("/templating-kit/img/imagename@with invalid%chars.png"); |
94 |
|
|
95 |
|
|
96 |
1 |
task.execute(installContext); |
97 |
|
|
98 |
|
|
99 |
1 |
assertThat(session.getRootNode(), hasNode("templating-kit/img/imagename-with-invalid-chars")); |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 1 |
|
102 |
|
private class TestInstallBinaryResourcesTask extends InstallBinaryResourcesTask { |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
2 |
public TestInstallBinaryResourcesTask(String pattern) {... |
105 |
2 |
super(pattern); |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
1 |
public TestInstallBinaryResourcesTask(String taskName, String taskDescription, String pattern, boolean preserveResourcesParameters, boolean stripExtension) {... |
109 |
1 |
super(taskName, taskDescription, pattern, preserveResourcesParameters, stripExtension); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
3 |
@Override... |
113 |
|
protected String[] findResources() { |
114 |
3 |
return new String[] { resourcePath + ".png" , imageNameWithJCRInvalidChars + ".png"}; |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
|
} |