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.resources.app.availability; |
35 |
|
|
36 |
|
import static org.hamcrest.Matchers.is; |
37 |
|
import static org.junit.Assert.assertThat; |
38 |
|
import static org.mockito.BDDMockito.given; |
39 |
|
import static org.mockito.Mockito.mock; |
40 |
|
|
41 |
|
import info.magnolia.resourceloader.Resource; |
42 |
|
import info.magnolia.resourceloader.ResourceOrigin; |
43 |
|
import info.magnolia.resourceloader.classpath.ClasspathResourceOrigin; |
44 |
|
import info.magnolia.resourceloader.jcr.JcrResourceOrigin; |
45 |
|
import info.magnolia.resourceloader.layered.LayeredResource; |
46 |
|
|
47 |
|
import org.junit.Before; |
48 |
|
import org.junit.Test; |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.06 |
|
50 |
|
public class IsHotfixableRuleTest { |
51 |
|
|
52 |
|
private static final String NOT_HOTFIXABLE = "/a.txt"; |
53 |
|
private static final String HOTFIXABLE = "/b.txt"; |
54 |
|
|
55 |
|
private IsHotfixableRule rule; |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
|
57 |
2 |
@Before... |
58 |
|
public void setUp() throws Exception { |
59 |
2 |
ResourceOrigin origin = mock(ResourceOrigin.class); |
60 |
2 |
rule = new IsHotfixableRule(origin); |
61 |
|
|
62 |
2 |
LayeredResource hotfixableResourcePath = mock(LayeredResource.class); |
63 |
2 |
LayeredResource notHotfixableResourcePath = mock(LayeredResource.class); |
64 |
|
|
65 |
2 |
Resource jcrResourcePath = mock(Resource.class); |
66 |
2 |
Resource classpathResourcePath = mock(Resource.class); |
67 |
|
|
68 |
2 |
JcrResourceOrigin jcrOrigin = mock(JcrResourceOrigin.class); |
69 |
2 |
ClasspathResourceOrigin classPathOrigin = mock(ClasspathResourceOrigin.class); |
70 |
|
|
71 |
2 |
given(hotfixableResourcePath.getFirst()).willReturn(classpathResourcePath); |
72 |
2 |
given(notHotfixableResourcePath.getFirst()).willReturn(jcrResourcePath); |
73 |
|
|
74 |
2 |
given(jcrResourcePath.getOrigin()).willReturn(jcrOrigin); |
75 |
2 |
given(classpathResourcePath.getOrigin()).willReturn(classPathOrigin); |
76 |
|
|
77 |
2 |
given(jcrOrigin.getName()).willReturn("jcr"); |
78 |
2 |
given(classPathOrigin.getName()).willReturn("classpath"); |
79 |
|
|
80 |
2 |
given(origin.hasPath(HOTFIXABLE)).willReturn(true); |
81 |
2 |
given(origin.hasPath(NOT_HOTFIXABLE)).willReturn(true); |
82 |
|
|
83 |
2 |
given(origin.getByPath(HOTFIXABLE)).willReturn(hotfixableResourcePath); |
84 |
2 |
given(origin.getByPath(NOT_HOTFIXABLE)).willReturn(notHotfixableResourcePath); |
85 |
|
} |
86 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
87 |
|
@Test... |
88 |
|
public void isAvailableOnlyForJcrOrigin() { |
89 |
|
|
90 |
|
|
91 |
|
assertThat(rule.isAvailableForItem(NOT_HOTFIXABLE), is(false)); |
92 |
|
assertThat(rule.isAvailableForItem(HOTFIXABLE), is(true)); |
93 |
|
} |
94 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
95 |
|
@Test... |
96 |
|
public void isNotAvailableForNonResourceItems() { |
97 |
|
|
98 |
|
String wrongInstanceType = ""; |
99 |
|
|
100 |
|
|
101 |
|
boolean isFile = rule.isAvailableForItem(wrongInstanceType); |
102 |
|
|
103 |
|
|
104 |
|
assertThat(isFile, is(false)); |
105 |
|
} |
106 |
|
|
107 |
|
} |