Clover icon

Magnolia REST Integration Tests 2.1.5

  1. Project Clover database Tue Jan 28 2020 16:43:22 CET
  2. Package info.magnolia.integrationtests.rest.delivery.jcr.v2

File JcrDeliveryEndpointTest.java

 

Code metrics

0
31
31
1
483
393
31
1
1
31
1
11.4% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
JcrDeliveryEndpointTest 47 31 11.4% 31 62
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /**
2    * This file Copyright (c) 2018 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.integrationtests.rest.delivery.jcr.v2;
35   
36    import static io.restassured.RestAssured.given;
37    import static org.hamcrest.Matchers.*;
38    import static org.hamcrest.core.IsNot.not;
39   
40    import org.junit.Test;
41   
42    /**
43    * In order to show JSON output, simply append "log().body()" after "then()"<br/>
44    * For example: get("/x").then().log().body()...
45    * @see <a href="https://github.com/rest-assured/rest-assured/wiki/Usage#user-content-response-logging">Response Logging</a>
46    */
 
47    public class JcrDeliveryEndpointTest extends AbstractJcrDeliveryEndpointTest {
48   
 
49  0 toggle @Test
50    public void withoutBypassAcls() {
51  0 given().when()
52    .get("withoutBypassAcls/v1/travel")
53    .then()
54    .statusCode(404);
55    }
56   
 
57  0 toggle @Test
58    public void withoutSystemProperties() {
59  0 given().when()
60    .get("withoutSystemProperties/v1/travel")
61    .then()
62    .statusCode(200)
63    .body(
64    "", allOf(hasKey("title"), not(hasKey("mgnl:lastModified")))
65    );
66    }
67   
 
68  0 toggle @Test
69    public void readNode() {
70  0 given().when()
71    .get("default/v1/travel")
72    .then()
73    .statusCode(200)
74    .body(
75    "", allOf(hasKey("title"), hasKey("mgnl:lastModified"))
76    );
77    }
78   
 
79  0 toggle @Test
80    public void readNodesFromUnregisteredWorkspace() {
81  0 given().when()
82    .get("users/v1/travel")
83    .then()
84    .statusCode(404);
85    }
86   
 
87  0 toggle @Test
88    public void readNodeWithConfiguredRootPath() {
89  0 given().when()
90    .get("rootPathConfigured/v1/about")
91    .then()
92    .statusCode(200)
93    .body("@name", equalTo("about"));
94    }
95   
 
96  0 toggle @Test
97    public void readNodeWithStrictMode() {
98  0 given().when()
99    .get("strict/v1/travel")
100    .then()
101    .statusCode(200)
102    .body(
103    "@nodes.size()", equalTo(1),
104    "", hasKey("about")
105    );
106    }
107   
 
108  0 toggle @Test
109    public void readNodeWithConfiguredNodeTypes() {
110  0 given().when()
111    .get("areas/v1/travel")
112    .then()
113    .statusCode(404);
114    }
115   
 
116  0 toggle @Test
117    public void readNodeWithConfiguredChildNodeTypes() {
118  0 given().when()
119    .get("childNodeTypesConfigured/v1/travel")
120    .then()
121    .statusCode(200)
122    .body(
123    "about.@name", equalTo("about")
124    );
125    }
126   
 
127  0 toggle @Test
128    public void readNodeWithFolderAsConfiguredNodeTypeReturnFolder() {
129  0 given().when()
130    .get("folderAsNodeTypesConfigured/v1/folderTests")
131    .then()
132    .statusCode(200)
133    .body(
134    "@name", equalTo("folderTests")
135    );
136    }
137   
 
138  0 toggle @Test
139    public void readNodeWithDepth0() {
140  0 given().when()
141    .get("default/v1/travel")
142    .then()
143    .statusCode(200)
144    .body(
145    "@name", equalTo("travel"),
146    "@nodes", empty()
147    );
148    }
149   
 
150  0 toggle @Test
151    public void readNodeWithDepth1() {
152  0 given().when()
153    .get("depth1/v1/travel")
154    .then()
155    .statusCode(200)
156    .body(
157    "@name", equalTo("travel"),
158    "@nodes", not(empty()),
159    "main.@nodes", empty(),
160    "main", not(hasKey("0")),
161    "footer.@nodes", empty()
162    );
163    }
164   
 
165  0 toggle @Test
166    public void readNodeWithDepth2() {
167  0 given().when()
168    .get("depth2/v1/travel")
169    .then()
170    .statusCode(200)
171    .body(
172    "@name", equalTo("travel"),
173    "@nodes", not(empty()),
174    "main.@nodes", not(empty()),
175    "main", hasKey("0"),
176    "footer.@nodes", empty()
177    );
178    }
179   
 
180  0 toggle @Test
181    public void dateTimeShouldBeISO8601() {
182  0 given().when()
183    .get("default/v1/travel")
184    .then()
185    .statusCode(200)
186    .body(
187    "'mgnl:created'", equalTo("2018-01-01T10:26:43.630+07:00"),
188    "'mgnl:lastModified'", equalTo("2018-12-01T13:47:21.051+07:00")
189    );
190    }
191   
192    /*
193    * ====================== Get children ====================
194    */
195   
196   
 
197    toggle @Test
198    public void getChildrenOfRoot() {
199    given().when()
200    .urlEncodingEnabled(false) // encode "@" for restassured framework
201    .get("getChildrenOfRoot/v1/@nodes")
202    .then()
203    .statusCode(200)
204    .body(
205    "@name", hasItem("travel"),
206    "about.@name", hasItem("about")
207    );
208    }
209   
 
210    toggle @Test
211    public void getChildrenUnderPathParam() {
212    given().when()
213    .urlEncodingEnabled(false) // encode "@" for restassured framework
214    .get("getChildrenOfRoot/v1/travel/@nodes")
215    .then()
216    .statusCode(200)
217    .body(
218    "@name", hasItem("about"),
219    "company.@name", hasItem("company")
220    );
221    }
222   
 
223    toggle @Test
224    public void getChildrenUnderConfiguredRootPath() {
225    given().when()
226    .urlEncodingEnabled(false) // encode "@" for restassured framework
227    .get("getChildrenUnderConfiguredRootPath/v1/@nodes")
228    .then()
229    .statusCode(200)
230    .body(
231    "@name", hasItem("about"),
232    "company.@name", hasItem("company")
233    );
234    }
235   
 
236    toggle @Test
237    public void getChildrenUnderConfiguredRootPathAndPathParam() {
238    given().when()
239    .urlEncodingEnabled(false) // encode "@" for restassured framework
240    .get("getChildrenUnderConfiguredRootPath/v1/about/@nodes")
241    .then()
242    .statusCode(200)
243    .body(
244    "@name", hasItem("company")
245    );
246    }
247   
248    /*
249    * ====================== Querying nodes ====================
250    */
251   
 
252  0 toggle @Test
253    public void queryNodes() {
254  0 given().when()
255    .get("default/v1")
256    .then()
257    .statusCode(200)
258    .body(
259    "results.@name", containsInAnyOrder("company", "about", "travel")
260    );
261    }
262   
 
263  0 toggle @Test
264    public void queryNodesWithConfiguredRootPath() {
265  0 given().when()
266    .get("rootPathConfiguredForQuery/v1")
267    .then()
268    .statusCode(200)
269    .body(
270    "results.@name", containsInAnyOrder("about", "company")
271    );
272    }
273   
 
274  0 toggle @Test
275    public void queryNodesWithStrictMode() {
276  0 given().when()
277    .get("strict/v1")
278    .then()
279    .statusCode(200)
280    .root("results")
281    .body(
282    "@name", containsInAnyOrder("about", "company", "travel"),
283    "[0].@nodes", empty(),
284    "[1].@nodes.size()", equalTo(1),
285    "[1]", hasKey("company"),
286    "[2].@nodes.size()", equalTo(1),
287    "[2]", hasKey("about")
288    );
289    }
290   
 
291  0 toggle @Test
292    public void queryNodesWithConfiguredNodeTypes() {
293  0 given().when()
294    .get("pages/v1")
295    .then()
296    .statusCode(200)
297    .body(
298    "results.@name", containsInAnyOrder("about", "company", "travel")
299    );
300    }
301   
 
302  0 toggle @Test
303    public void queryNodesWithConfiguredNodeTypesAndChildNodeTypes() {
304  0 given().when()
305    .get("pagesAndMore/v1")
306    .then()
307    .statusCode(200)
308    .body("results.size()", equalTo(3))
309    .body("results.@name", containsInAnyOrder("about", "company", "travel"))
310    .body("results.@nodes", not(empty()))
311    .body("results", everyItem(allOf(hasKey("main"), hasKey("footer"))));
312    }
313   
 
314  0 toggle @Test
315    public void queryNodesWithFolderAsConfiguredNodeTypeReturnFolder() {
316  0 given().when()
317    .get("folderAsNodeTypesConfigured/v1")
318    .then()
319    .statusCode(200)
320    .body("results.@name", containsInAnyOrder("folderTests", "folder1", "folder2"))
321    .body("results.@name", not(containsInAnyOrder("node1")))
322    .body("results.@id", not(containsInAnyOrder("cafebabe-cafe-babe-cafe-babecafebabe")));
323    }
324   
 
325  0 toggle @Test
326    public void offset() {
327  0 given().param("orderBy", "@name") // sorting to have fixed paging
328    .param("offset", 1)
329    .when()
330    .get("pages/v1")
331    .then()
332    .statusCode(200)
333    .body(
334    "results.@name", containsInAnyOrder("company", "travel")
335    );
336    }
337   
 
338  0 toggle @Test
339    public void limit() {
340  0 given().param("limit", 2)
341    .when()
342    .get("pages/v1")
343    .then()
344    .statusCode(200)
345    .body("results.size()", equalTo(2));
346    }
347   
 
348  0 toggle @Test
349    public void offsetAndLimit() {
350  0 given().param("orderBy", "@name") // sorting to have fixed paging
351    .param("offset", 1)
352    .param("limit", 2)
353    .when()
354    .get("pages/v1")
355    .then()
356    .statusCode(200)
357    .body(
358    "results.@name", containsInAnyOrder("company", "travel")
359    );
360    }
361   
 
362  0 toggle @Test
363    public void orderByName() {
364  0 given().param("orderBy", "@name desc")
365    .when()
366    .get("pages/v1")
367    .then()
368    .statusCode(200)
369    .body(
370    "results.@name", contains("travel", "company", "about")
371    );
372    }
373   
 
374  0 toggle @Test
375    public void orderByTwoProperties() {
376  0 given().param("orderBy", "@name desc,mgnl:created desc")
377    .when()
378    .get("areas/v1")
379    .then()
380    .statusCode(200)
381    .body(
382    "results.@path", contains(
383    "/travel/about/company/main",
384    "/travel/main",
385    "/travel/about/main",
386    "/travel/about/company/footer",
387    "/travel/footer",
388    "/travel/about/footer"
389    ));
390    }
391   
 
392  0 toggle @Test
393    public void orderByTwoPropertiesWithDefaultDirections() {
394  0 given().param("orderBy", "@name asc,mgnl:lastModified")
395    .when()
396    .get("areas/v1")
397    .then()
398    .statusCode(200)
399    .body(
400    "results.@path", contains(
401    "/travel/footer",
402    "/travel/about/footer",
403    "/travel/about/company/footer",
404    "/travel/about/main",
405    "/travel/main",
406    "/travel/about/company/main"
407    ));
408    }
409   
 
410  0 toggle @Test
411    public void fullTextSearch() {
412  0 given().param("q", "travel")
413    .when()
414    .get("pages/v1")
415    .then()
416    .statusCode(200)
417    .body(
418    "results.@name", contains("travel")
419    );
420    }
421   
 
422  0 toggle @Test
423    public void fullTextSearchAnNonexistentString() {
424  0 given().param("q", "something")
425    .when()
426    .get("pages/v1")
427    .then()
428    .statusCode(200)
429    .body("results.size()", equalTo(0));
430    }
431   
432    /*
433    * ====================== Filtering by property ====================
434    */
435   
 
436  0 toggle @Test
437    public void filterByTitle() {
438  0 given().param("title", "Travel Home")
439    .when()
440    .get("pages/v1")
441    .then()
442    .statusCode(200)
443    .body(
444    "results.@name", contains("travel")
445    );
446    }
447   
 
448  0 toggle @Test
449    public void filterByName() {
450  0 given().param("@name", "about")
451    .when()
452    .get("pages/v1")
453    .then()
454    .statusCode(200)
455    .body(
456    "results.@name", contains("about")
457    );
458    }
459   
 
460  0 toggle @Test
461    public void filterByAncestor() {
462  0 given().param("@ancestor", "/travel")
463    .when()
464    .get("pages/v1")
465    .then()
466    .statusCode(200)
467    .body(
468    "results.@name", containsInAnyOrder("about", "company")
469    );
470    }
471   
 
472  0 toggle @Test
473    public void filterByMultiValueProperty() {
474  0 given().param("title", "Travel Home|Our Company")
475    .when()
476    .get("pages/v1")
477    .then()
478    .statusCode(200)
479    .body(
480    "results.@name", containsInAnyOrder("company", "travel")
481    );
482    }
483    }