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 info.magnolia.resourceloader.dummy.DummyResourceOrigin.Differentiator.qux; |
37 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
38 |
|
import static org.hamcrest.core.Is.is; |
39 |
|
|
40 |
|
import info.magnolia.context.SystemContext; |
41 |
|
import info.magnolia.jcr.util.NodeTypes; |
42 |
|
import info.magnolia.resourceloader.ResourceOrigin; |
43 |
|
import info.magnolia.resourceloader.dummy.DummyResourceOrigin; |
44 |
|
import info.magnolia.resourceloader.jcr.JcrResourceOrigin; |
45 |
|
import info.magnolia.resourceloader.jcr.JcrResourceOriginFactory; |
46 |
|
import info.magnolia.resourceloader.layered.LayeredResourceOrigin; |
47 |
|
import info.magnolia.resourceloader.layered.LayeredResourceOriginFactory; |
48 |
|
import info.magnolia.test.mock.MockContext; |
49 |
|
import info.magnolia.test.mock.jcr.MockSession; |
50 |
|
|
51 |
|
import javax.jcr.Node; |
52 |
|
|
53 |
|
import org.junit.Before; |
54 |
|
import org.junit.Test; |
55 |
|
|
56 |
|
import com.google.inject.util.Providers; |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (35) |
Complexity: 5 |
Complexity Density: 0.17 |
|
58 |
|
public class IsJcrOnlyResourceRuleTest { |
59 |
|
|
60 |
|
private IsJcrOnlyResourceRule isJcrOnlyResourceRule; |
61 |
|
|
62 |
|
private JcrResourceOrigin jcrResourceOrigin; |
63 |
|
private IsJcrOnlyResourceRuleDefinition ruleDefinition; |
64 |
|
private LayeredResourceOrigin layeredResourceOrigin; |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
66 |
4 |
@Before... |
67 |
|
public void setUp() throws Exception { |
68 |
4 |
final MockSession session = new MockSession("resources"); |
69 |
4 |
final MockContext ctx = new MockContext(); |
70 |
4 |
ctx.addSession("resources", session); |
71 |
|
|
72 |
4 |
final Node folderA = session.getRootNode().addNode("a", NodeTypes.Folder.NAME); |
73 |
4 |
folderA.addNode("foo.txt", NodeTypes.Content.NAME); |
74 |
4 |
folderA.addNode("qux.txt", NodeTypes.Content.NAME); |
75 |
|
|
76 |
4 |
session.getRootNode().addNode("b", NodeTypes.Folder.NAME).addNode("bar.txt", NodeTypes.Content.NAME); |
77 |
|
|
78 |
4 |
DummyResourceOrigin dummyResourceOrigin = new DummyResourceOrigin(qux, "/a", "/a/foo.txt", "/c", "/c/baz.txt"); |
79 |
4 |
this.jcrResourceOrigin = new JcrResourceOriginFactory(Providers.<SystemContext>of(ctx)).create("jcr"); |
80 |
4 |
this.layeredResourceOrigin = new LayeredResourceOriginFactory().create("layered", new ResourceOrigin[]{ |
81 |
|
dummyResourceOrigin, |
82 |
|
jcrResourceOrigin, |
83 |
|
}); |
84 |
|
|
85 |
4 |
this.ruleDefinition = new IsJcrOnlyResourceRuleDefinition(); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void nonLayeredJcrResourcePassesRule() throws Exception { |
90 |
|
|
91 |
1 |
isJcrOnlyResourceRule = new IsJcrOnlyResourceRule(jcrResourceOrigin, ruleDefinition); |
92 |
|
|
93 |
|
|
94 |
1 |
boolean barIsPassing = isJcrOnlyResourceRule.isAvailableForItem("/b/bar.txt"); |
95 |
1 |
boolean fooIsPassing = isJcrOnlyResourceRule.isAvailableForItem("/a/foo.txt"); |
96 |
|
|
97 |
|
|
98 |
1 |
assertThat(barIsPassing, is(true)); |
99 |
1 |
assertThat(fooIsPassing, is(true)); |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
102 |
1 |
@Test... |
103 |
|
public void jcrOnlyResourceFromLayeredOriginPassesRule() throws Exception { |
104 |
|
|
105 |
1 |
isJcrOnlyResourceRule = new IsJcrOnlyResourceRule(layeredResourceOrigin, ruleDefinition); |
106 |
|
|
107 |
|
|
108 |
1 |
boolean barIsPassing = isJcrOnlyResourceRule.isAvailableForItem("/b/bar.txt"); |
109 |
|
|
110 |
|
|
111 |
1 |
assertThat(barIsPassing, is(true)); |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
114 |
1 |
@Test... |
115 |
|
public void overriddenResourceDoesNotPassRule() throws Exception { |
116 |
|
|
117 |
1 |
isJcrOnlyResourceRule = new IsJcrOnlyResourceRule(layeredResourceOrigin, ruleDefinition); |
118 |
|
|
119 |
|
|
120 |
1 |
boolean fooIsPassing = isJcrOnlyResourceRule.isAvailableForItem("/a/foo.txt"); |
121 |
|
|
122 |
|
|
123 |
1 |
assertThat(fooIsPassing, is(false)); |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
126 |
1 |
@Test... |
127 |
|
public void turningNegationOnInDefinitionInvertsResult() throws Exception { |
128 |
|
|
129 |
1 |
isJcrOnlyResourceRule = new IsJcrOnlyResourceRule(layeredResourceOrigin, ruleDefinition); |
130 |
1 |
final IsJcrOnlyResourceRuleDefinition negatedRuleDefinition = new IsJcrOnlyResourceRuleDefinition(); |
131 |
1 |
negatedRuleDefinition.setNegateResult(true); |
132 |
|
|
133 |
1 |
final IsJcrOnlyResourceRule negatedRule = new IsJcrOnlyResourceRule(layeredResourceOrigin, negatedRuleDefinition); |
134 |
|
|
135 |
|
|
136 |
1 |
boolean barIsPassingStraightRule = isJcrOnlyResourceRule.isAvailableForItem("/b/bar.txt"); |
137 |
1 |
boolean barIsPassingNegatedRule = negatedRule.isAvailableForItem("/b/bar.txt"); |
138 |
|
|
139 |
|
|
140 |
1 |
assertThat(barIsPassingStraightRule, is(true)); |
141 |
1 |
assertThat(barIsPassingNegatedRule, is(false)); |
142 |
|
} |
143 |
|
} |