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.rest.delivery.jcr.v1; |
35 |
|
|
36 |
|
import static info.magnolia.rest.RestTestAccessManager.ANONYMOUS; |
37 |
|
import static info.magnolia.test.hamcrest.NodeMatchers.*; |
38 |
|
import static java.util.Collections.singletonList; |
39 |
|
import static org.hamcrest.CoreMatchers.allOf; |
40 |
|
import static org.hamcrest.core.IsNot.not; |
41 |
|
import static org.junit.Assert.*; |
42 |
|
import static org.mockito.Mockito.*; |
43 |
|
|
44 |
|
import info.magnolia.cms.security.User; |
45 |
|
import info.magnolia.cms.util.ClasspathResourcesUtil; |
46 |
|
import info.magnolia.context.DefaultRepositoryStrategy; |
47 |
|
import info.magnolia.context.MgnlContext; |
48 |
|
import info.magnolia.context.UserContext; |
49 |
|
import info.magnolia.jcr.util.NodeTypes; |
50 |
|
import info.magnolia.jcr.util.PropertiesImportExport; |
51 |
|
import info.magnolia.objectfactory.Components; |
52 |
|
import info.magnolia.repository.RepositoryConstants; |
53 |
|
import info.magnolia.test.ComponentsTestUtil; |
54 |
|
import info.magnolia.test.RepositoryTestCase; |
55 |
|
import info.magnolia.test.mock.MockWebContext; |
56 |
|
|
57 |
|
import java.io.InputStream; |
58 |
|
import java.util.Arrays; |
59 |
|
import java.util.HashMap; |
60 |
|
import java.util.LinkedHashMap; |
61 |
|
import java.util.Map; |
62 |
|
|
63 |
|
import javax.jcr.Node; |
64 |
|
import javax.jcr.NodeIterator; |
65 |
|
import javax.jcr.PathNotFoundException; |
66 |
|
import javax.jcr.RepositoryException; |
67 |
|
import javax.jcr.Session; |
68 |
|
import javax.ws.rs.NotFoundException; |
69 |
|
import javax.ws.rs.core.MultivaluedHashMap; |
70 |
|
import javax.ws.rs.core.MultivaluedMap; |
71 |
|
import javax.ws.rs.core.UriInfo; |
72 |
|
|
73 |
|
import org.junit.Before; |
74 |
|
import org.junit.Test; |
75 |
|
import org.mockito.internal.util.reflection.Whitebox; |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (222) |
Complexity: 29 |
Complexity Density: 0.15 |
|
77 |
|
public class JcrDeliveryEndpointTest extends RepositoryTestCase { |
78 |
|
|
79 |
|
private Session session; |
80 |
|
private JcrDeliveryEndpoint endpoint; |
81 |
|
private ConfiguredJcrDeliveryEndpointDefinition endpointDefinition; |
82 |
|
private WorkspaceParameters websiteParameters; |
83 |
|
private MultivaluedMap<String, String> queryParameters; |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
|
85 |
26 |
@Before... |
86 |
|
public void setUp() throws Exception { |
87 |
26 |
super.setUp(); |
88 |
26 |
session = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE); |
89 |
26 |
new PropertiesImportExport().createNodes(session.getRootNode(), getClass().getClassLoader().getResourceAsStream("travel-test-data.properties")); |
90 |
26 |
session.save(); |
91 |
|
|
92 |
26 |
Map<String, WorkspaceParameters> paramsByWorkspace = new LinkedHashMap<>(); |
93 |
26 |
websiteParameters = new WorkspaceParameters(); |
94 |
26 |
paramsByWorkspace.put(RepositoryConstants.WEBSITE, websiteParameters); |
95 |
26 |
paramsByWorkspace.put(RepositoryConstants.CONFIG, new WorkspaceParameters()); |
96 |
26 |
endpointDefinition = new ConfiguredJcrDeliveryEndpointDefinition(); |
97 |
26 |
endpointDefinition.setParams(paramsByWorkspace); |
98 |
26 |
endpoint = new JcrDeliveryEndpoint(endpointDefinition, MgnlContext::getInstance); |
99 |
|
|
100 |
26 |
UriInfo uriInfo = mock(UriInfo.class); |
101 |
26 |
queryParameters = new MultivaluedHashMap<>(); |
102 |
26 |
when(uriInfo.getQueryParameters()).thenReturn(queryParameters); |
103 |
26 |
Whitebox.setInternalState(endpoint, "uriInfo", uriInfo); |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
26 |
@Override... |
107 |
|
protected InputStream getJackrabbitRepositoryConfigFileStream() throws Exception { |
108 |
26 |
return ClasspathResourcesUtil.getResource("jackrabbit-memory-search.xml").openStream(); |
109 |
|
} |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
111 |
1 |
@Test... |
112 |
|
public void readNodeWithDefaultParameters() throws Exception { |
113 |
|
|
114 |
1 |
Node node = endpoint.readNode(RepositoryConstants.WEBSITE, "/travel/about"); |
115 |
|
|
116 |
|
|
117 |
1 |
assertNotNull(node); |
118 |
1 |
assertEquals("about", node.getName()); |
119 |
1 |
assertThat(node, hasProperty("title")); |
120 |
1 |
assertThat(node, hasProperty(NodeTypes.LastModified.NAME)); |
121 |
1 |
assertThat(node, not(hasNode("footer"))); |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
124 |
1 |
@Test... |
125 |
|
public void readNodeWithConfiguredRootPath() throws Exception { |
126 |
|
|
127 |
1 |
websiteParameters.setRootPath("/travel"); |
128 |
|
|
129 |
|
|
130 |
1 |
Node node = endpoint.readNode(RepositoryConstants.WEBSITE, "about"); |
131 |
|
|
132 |
|
|
133 |
1 |
assertNotNull(node); |
134 |
1 |
assertEquals("about", node.getName()); |
135 |
1 |
assertThat(node, hasProperty("title")); |
136 |
1 |
assertThat(node, hasProperty(NodeTypes.LastModified.NAME)); |
137 |
|
} |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
139 |
1 |
@Test... |
140 |
|
public void readNodeWithConfiguredChildNodeTypes() throws Exception { |
141 |
|
|
142 |
1 |
websiteParameters.setDepth(1); |
143 |
1 |
websiteParameters.setChildNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
144 |
|
|
145 |
|
|
146 |
1 |
Node node = endpoint.readNode(RepositoryConstants.WEBSITE, "/travel/about"); |
147 |
|
|
148 |
|
|
149 |
1 |
assertNotNull(node); |
150 |
1 |
assertEquals("about", node.getName()); |
151 |
1 |
assertThat(node, hasProperty("title")); |
152 |
1 |
assertThat(node, hasProperty(NodeTypes.LastModified.NAME)); |
153 |
1 |
assertThat(node, not(hasNode("footer"))); |
154 |
1 |
assertThat(node, hasNode("company")); |
155 |
|
} |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
157 |
1 |
@Test... |
158 |
|
public void readNodeWithDepth0() throws Exception { |
159 |
|
|
160 |
1 |
websiteParameters.setDepth(0); |
161 |
1 |
websiteParameters.setChildNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
162 |
|
|
163 |
|
|
164 |
1 |
Node node = endpoint.readNode(RepositoryConstants.WEBSITE, "/travel"); |
165 |
|
|
166 |
|
|
167 |
1 |
assertNotNull(node); |
168 |
1 |
assertEquals("travel", node.getName()); |
169 |
1 |
assertThat(node, hasProperty("title")); |
170 |
1 |
assertThat(node, not(hasNode("about"))); |
171 |
|
} |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
173 |
1 |
@Test... |
174 |
|
public void readNodeWithDepth1() throws Exception { |
175 |
|
|
176 |
1 |
websiteParameters.setDepth(1); |
177 |
1 |
websiteParameters.setChildNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
178 |
|
|
179 |
|
|
180 |
1 |
Node node = endpoint.readNode(RepositoryConstants.WEBSITE, "/travel"); |
181 |
|
|
182 |
|
|
183 |
1 |
assertNotNull(node); |
184 |
1 |
assertEquals("travel", node.getName()); |
185 |
1 |
assertThat(node, hasProperty("title")); |
186 |
1 |
assertThat(node, hasNode("about")); |
187 |
1 |
Node about = node.getNode("about"); |
188 |
1 |
assertThat(about, not(hasNode("company"))); |
189 |
|
} |
190 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
191 |
1 |
@Test... |
192 |
|
public void readNodeWithDepth2() throws Exception { |
193 |
|
|
194 |
1 |
websiteParameters.setDepth(2); |
195 |
1 |
websiteParameters.setChildNodeTypes(Arrays.asList(NodeTypes.Page.NAME, NodeTypes.Area.NAME)); |
196 |
|
|
197 |
|
|
198 |
1 |
Node node = endpoint.readNode(RepositoryConstants.WEBSITE, "/travel"); |
199 |
|
|
200 |
|
|
201 |
1 |
assertNotNull(node); |
202 |
1 |
assertEquals("travel", node.getName()); |
203 |
1 |
assertThat(node, hasProperty("title")); |
204 |
1 |
assertThat(node, hasNode("about")); |
205 |
1 |
Node about = node.getNode("about"); |
206 |
1 |
assertThat(about, hasNode("company")); |
207 |
1 |
Node company = about.getNode("company"); |
208 |
1 |
assertThat(company, not(hasNode("main"))); |
209 |
|
} |
210 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
211 |
1 |
@Test... |
212 |
|
public void processedNodeExcludingSpecialPropertiesDoesNotHaveSpecialProperties() throws Exception { |
213 |
|
|
214 |
1 |
websiteParameters.setDepth(1); |
215 |
1 |
websiteParameters.setIncludeSystemProperties(false); |
216 |
1 |
websiteParameters.setChildNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
217 |
|
|
218 |
|
|
219 |
1 |
Node node = endpoint.readNode(RepositoryConstants.WEBSITE, "/travel/about"); |
220 |
|
|
221 |
|
|
222 |
1 |
assertThat(node, hasProperty("title")); |
223 |
1 |
assertThat(node, not(hasProperty(NodeTypes.LastModified.NAME))); |
224 |
1 |
assertThat(node, hasNode("company")); |
225 |
1 |
Node company = node.getNode("company"); |
226 |
1 |
assertThat(company, hasProperty("title")); |
227 |
1 |
assertThat(company, not(hasProperty(NodeTypes.LastModified.NAME))); |
228 |
|
} |
229 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
230 |
1 |
@Test... |
231 |
|
public void processedNodeIncludingSpecialPropertiesHasSpecialProperties() throws Exception { |
232 |
|
|
233 |
1 |
websiteParameters.setDepth(1); |
234 |
1 |
websiteParameters.setIncludeSystemProperties(true); |
235 |
1 |
websiteParameters.setChildNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
236 |
|
|
237 |
|
|
238 |
1 |
Node node = endpoint.readNode(RepositoryConstants.WEBSITE, "/travel/about"); |
239 |
|
|
240 |
|
|
241 |
1 |
assertThat(node, hasProperty("title")); |
242 |
1 |
assertThat(node, hasProperty(NodeTypes.LastModified.NAME)); |
243 |
1 |
assertThat(node, hasNode("company")); |
244 |
1 |
Node company = node.getNode("company"); |
245 |
1 |
assertThat(node, hasProperty("title")); |
246 |
1 |
assertThat(company, hasProperty(NodeTypes.LastModified.NAME)); |
247 |
|
} |
248 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
249 |
1 |
@Test(expected = NotFoundException.class)... |
250 |
|
public void nodeIsFilteredByNodeType() throws Exception { |
251 |
|
|
252 |
1 |
websiteParameters.setNodeTypes(Arrays.asList(NodeTypes.Area.NAME)); |
253 |
|
|
254 |
|
|
255 |
1 |
endpoint.readNode(RepositoryConstants.WEBSITE, "/travel/about"); |
256 |
|
} |
257 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
258 |
1 |
@Test(expected = NotFoundException.class)... |
259 |
|
public void readNodesFromUnregisteredWorkspace() throws Exception { |
260 |
1 |
endpoint.readNode(RepositoryConstants.USERS, "anything"); |
261 |
|
} |
262 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
263 |
1 |
@Test... |
264 |
|
public void queryNodesFromWebsiteWorkspace() throws Exception { |
265 |
|
|
266 |
1 |
websiteParameters.setNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
267 |
|
|
268 |
|
|
269 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.WEBSITE, "", "", 0L, 10L).getResults(); |
270 |
|
|
271 |
|
|
272 |
1 |
assertNotNull(nodeIterator); |
273 |
1 |
assertEquals(3, nodeIterator.getSize()); |
274 |
1 |
assertEquals("about", nodeIterator.nextNode().getName()); |
275 |
1 |
assertEquals("company", nodeIterator.nextNode().getName()); |
276 |
1 |
assertEquals("travel", nodeIterator.nextNode().getName()); |
277 |
|
} |
278 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
279 |
1 |
@Test... |
280 |
|
public void queryNodesWithConfiguredNodeTypes() throws Exception { |
281 |
|
|
282 |
1 |
websiteParameters.setDepth(1); |
283 |
1 |
websiteParameters.setNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
284 |
|
|
285 |
|
|
286 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.WEBSITE, "", "", 0L, 10L).getResults(); |
287 |
|
|
288 |
|
|
289 |
1 |
assertNotNull(nodeIterator); |
290 |
1 |
assertEquals(3, nodeIterator.getSize()); |
291 |
1 |
Node about = nodeIterator.nextNode(); |
292 |
1 |
assertEquals("about", about.getName()); |
293 |
1 |
assertThat(about, not(hasNode("company"))); |
294 |
1 |
assertThat(about, hasNode("footer")); |
295 |
|
} |
296 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
297 |
1 |
@Test... |
298 |
|
public void queryNodesWithoutConfiguredNodeTypes() throws Exception { |
299 |
|
|
300 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.WEBSITE, "", "", 0L, 10L).getResults(); |
301 |
|
|
302 |
|
|
303 |
1 |
assertNotNull(nodeIterator); |
304 |
1 |
assertEquals(0, nodeIterator.getSize()); |
305 |
|
} |
306 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
307 |
1 |
@Test... |
308 |
|
public void queryNodesWithConfiguredNodeTypesAndChildNodeTypes() throws Exception { |
309 |
|
|
310 |
1 |
websiteParameters.setDepth(1); |
311 |
1 |
websiteParameters.setNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
312 |
1 |
websiteParameters.setChildNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
313 |
|
|
314 |
|
|
315 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.WEBSITE, "", "", 0L, 10L).getResults(); |
316 |
|
|
317 |
|
|
318 |
1 |
assertNotNull(nodeIterator); |
319 |
1 |
assertEquals(3, nodeIterator.getSize()); |
320 |
1 |
Node about = nodeIterator.nextNode(); |
321 |
1 |
assertEquals("about", about.getName()); |
322 |
1 |
assertThat(about, hasNode("company")); |
323 |
1 |
assertThat(about, not(hasNode("footer"))); |
324 |
|
} |
325 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
326 |
1 |
@Test... |
327 |
|
public void queryNodesWithoutSameTypeParent() throws Exception { |
328 |
|
|
329 |
1 |
websiteParameters.setNodeTypes(Arrays.asList(NodeTypes.Component.NAME)); |
330 |
|
|
331 |
|
|
332 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.WEBSITE, "", "", 0L, 10L).getResults(); |
333 |
|
|
334 |
|
|
335 |
1 |
assertNotNull(nodeIterator); |
336 |
1 |
assertEquals(1, nodeIterator.getSize()); |
337 |
1 |
assertEquals("00", nodeIterator.nextNode().getName()); |
338 |
|
} |
339 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
340 |
1 |
@Test... |
341 |
|
public void queryNodesWithOrderByName() throws Exception { |
342 |
|
|
343 |
1 |
websiteParameters.setNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
344 |
|
|
345 |
|
|
346 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.WEBSITE, "", "@name desc", 0L, 10L).getResults(); |
347 |
|
|
348 |
|
|
349 |
1 |
assertNotNull(nodeIterator); |
350 |
1 |
assertEquals(3, nodeIterator.getSize()); |
351 |
1 |
assertEquals("travel", nodeIterator.nextNode().getName()); |
352 |
1 |
assertEquals("company", nodeIterator.nextNode().getName()); |
353 |
1 |
assertEquals("about", nodeIterator.nextNode().getName()); |
354 |
|
} |
355 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
356 |
1 |
@Test... |
357 |
|
public void queryNodesWithNonExistingNodeTypes() throws Exception { |
358 |
|
|
359 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.WEBSITE, "", "", 0L, 10L).getResults(); |
360 |
|
|
361 |
|
|
362 |
1 |
assertNotNull(nodeIterator); |
363 |
1 |
assertEquals(0, nodeIterator.getSize()); |
364 |
|
} |
365 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
366 |
1 |
@Test... |
367 |
|
public void queryNodesFromEmptyWorkspace() throws Exception { |
368 |
|
|
369 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.CONFIG, "", "", 0L, 10L).getResults(); |
370 |
|
|
371 |
|
|
372 |
1 |
assertNotNull(nodeIterator); |
373 |
1 |
assertEquals(0, nodeIterator.getSize()); |
374 |
|
} |
375 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
376 |
1 |
@Test(expected = NotFoundException.class)... |
377 |
|
public void queryNodesFromUnregisteredWorkspace() throws Exception { |
378 |
1 |
endpoint.queryNodes(RepositoryConstants.USERS, "", "", 0L, 10L); |
379 |
|
} |
380 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
381 |
1 |
@Test... |
382 |
|
public void queryNodesWithFullTextSearch() throws Exception { |
383 |
|
|
384 |
1 |
websiteParameters.setNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
385 |
|
|
386 |
|
|
387 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.WEBSITE, "travel", "", 0L, 10L).getResults(); |
388 |
|
|
389 |
|
|
390 |
1 |
assertNotNull(nodeIterator); |
391 |
1 |
assertEquals(1, nodeIterator.getSize()); |
392 |
1 |
assertEquals("travel", nodeIterator.nextNode().getName()); |
393 |
|
} |
394 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
395 |
1 |
@Test... |
396 |
|
public void filterNodesByTitle() throws Exception { |
397 |
|
|
398 |
1 |
websiteParameters.setNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
399 |
1 |
queryParameters.put("title", Arrays.asList("Travel Home")); |
400 |
|
|
401 |
|
|
402 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.WEBSITE, "", "", 0L, 10L).getResults(); |
403 |
|
|
404 |
|
|
405 |
1 |
assertNotNull(nodeIterator); |
406 |
1 |
assertEquals(1, nodeIterator.getSize()); |
407 |
1 |
assertEquals("travel", nodeIterator.nextNode().getName()); |
408 |
|
} |
409 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
410 |
1 |
@Test... |
411 |
|
public void queryNodesFromWebsiteWorkspaceBypassingAclsWithAnonymous() throws Exception { |
412 |
|
|
413 |
1 |
websiteParameters.setNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
414 |
1 |
websiteParameters.setBypassWorkspaceAcls(true); |
415 |
1 |
setUpContextForAnonymous(); |
416 |
|
|
417 |
|
|
418 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.WEBSITE, "", "", 0L, 10L).getResults(); |
419 |
|
|
420 |
|
|
421 |
1 |
assertNotNull(nodeIterator); |
422 |
1 |
assertEquals(3, nodeIterator.getSize()); |
423 |
1 |
assertEquals("about", nodeIterator.nextNode().getName()); |
424 |
1 |
assertEquals("company", nodeIterator.nextNode().getName()); |
425 |
1 |
assertEquals("travel", nodeIterator.nextNode().getName()); |
426 |
|
} |
427 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
428 |
1 |
@Test... |
429 |
|
public void queryNodesFromWebsiteWorkspaceCannotBypassingAclsWithAnonymous() throws Exception { |
430 |
|
|
431 |
1 |
setUpContextForAnonymous(); |
432 |
|
|
433 |
|
|
434 |
1 |
NodeIterator nodeIterator = endpoint.queryNodes(RepositoryConstants.WEBSITE, "", "", 0L, 10L).getResults(); |
435 |
|
|
436 |
|
|
437 |
1 |
assertNotNull(nodeIterator); |
438 |
1 |
assertEquals(0, nodeIterator.getSize()); |
439 |
|
} |
440 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
441 |
1 |
@Test... |
442 |
|
public void readNodeWithDefaultParametersBypassingAclsWithAnonymous() throws Exception { |
443 |
|
|
444 |
1 |
websiteParameters.setNodeTypes(Arrays.asList(NodeTypes.Page.NAME)); |
445 |
1 |
websiteParameters.setBypassWorkspaceAcls(true); |
446 |
1 |
setUpContextForAnonymous(); |
447 |
|
|
448 |
|
|
449 |
1 |
Node node = endpoint.readNode(RepositoryConstants.WEBSITE, "/travel/about"); |
450 |
|
|
451 |
|
|
452 |
1 |
assertNotNull(node); |
453 |
1 |
assertEquals("about", node.getName()); |
454 |
1 |
assertThat(node, hasProperty("title")); |
455 |
1 |
assertThat(node, hasProperty(NodeTypes.LastModified.NAME)); |
456 |
1 |
assertThat(node, not(hasNode("footer"))); |
457 |
|
} |
458 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
459 |
1 |
@Test(expected = PathNotFoundException.class)... |
460 |
|
public void readNodeWithDefaultParametersCannotBypassingAclsWithAnonymous() throws Exception { |
461 |
|
|
462 |
1 |
setUpContextForAnonymous(); |
463 |
|
|
464 |
|
|
465 |
1 |
endpoint.readNode(RepositoryConstants.WEBSITE, "/travel/about"); |
466 |
|
} |
467 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
468 |
1 |
@Test... |
469 |
|
public void endpointServesSameWorkspaceFromDifferentParams() throws Exception { |
470 |
|
|
471 |
1 |
WorkspaceParameters websitePages = new WorkspaceParameters(); |
472 |
1 |
websitePages.setWorkspace(RepositoryConstants.WEBSITE); |
473 |
1 |
websitePages.setNodeTypes(singletonList(NodeTypes.Page.NAME)); |
474 |
1 |
websitePages.setRootPath("/travel"); |
475 |
|
|
476 |
1 |
WorkspaceParameters websiteAreas = new WorkspaceParameters(); |
477 |
1 |
websiteAreas.setWorkspace(RepositoryConstants.WEBSITE); |
478 |
1 |
websiteAreas.setNodeTypes(singletonList(NodeTypes.Area.NAME)); |
479 |
1 |
websiteAreas.setRootPath("/"); |
480 |
|
|
481 |
1 |
Map<String, WorkspaceParameters> params = new HashMap<>(); |
482 |
1 |
params.put("pages", websitePages); |
483 |
1 |
params.put("areas", websiteAreas); |
484 |
1 |
endpointDefinition.setParams(params); |
485 |
1 |
endpoint = new JcrDeliveryEndpoint(endpointDefinition, MgnlContext::getInstance); |
486 |
|
|
487 |
|
|
488 |
1 |
assertThat(endpoint.readNode("pages", "about"), allOf( |
489 |
|
nodeName("about"), |
490 |
|
hasProperty("title", "About") |
491 |
|
)); |
492 |
|
|
493 |
|
|
494 |
|
|
495 |
|
|
496 |
1 |
assertThat(endpoint.readNode("areas", "travel/about/company/main"), allOf( |
497 |
|
nodeName("main"), |
498 |
|
hasProperty("name", "Main") |
499 |
|
)); |
500 |
|
|
501 |
|
|
502 |
|
} |
503 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
504 |
4 |
private void setUpContextForAnonymous() throws RepositoryException {... |
505 |
4 |
MockWebContext context = new MockWebContext(); |
506 |
4 |
ComponentsTestUtil.setInstance(UserContext.class, mock(UserContext.class)); |
507 |
4 |
DefaultRepositoryStrategy defaultRepositoryStrategy = Components.newInstance(DefaultRepositoryStrategy.class); |
508 |
4 |
context.setRepositoryStrategy(defaultRepositoryStrategy); |
509 |
|
|
510 |
|
|
511 |
4 |
User user = mock(User.class); |
512 |
4 |
when(user.getName()).thenReturn(ANONYMOUS); |
513 |
4 |
context.setUser(user); |
514 |
|
|
515 |
4 |
MgnlContext.setInstance(context); |
516 |
|
} |
517 |
|
} |