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 ReferenceResolverTest.java

 

Code metrics

0
10
10
1
200
129
10
1
1
10
1

Classes

Class Line # Actions
ReferenceResolverTest 47 10 0% 10 20
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 ReferenceResolverTest extends AbstractJcrDeliveryEndpointTest {
48   
 
49  0 toggle @Test
50    public void uuidToNode() {
51  0 given().when()
52    .get("uuidToNode/v1/travel")
53    .then()
54    .statusCode(200)
55    .body(
56    "@name", equalTo("travel"),
57    "editor.@name", equalTo("john")
58    );
59    }
60   
 
61  0 toggle @Test
62    public void uuidToListOfNodes() {
63  0 given().when()
64    .get("uuidToListOfNodes/v1/travel")
65    .then()
66    .statusCode(200)
67    .body("@name", equalTo("travel"))
68    .root("contributors")
69    .body(
70    "size()", equalTo(2),
71    "[0].@name", equalTo("john"),
72    "[1].@name", equalTo("jane")
73    );
74    }
75   
76    /**
77    * Self reference: A -> A
78    */
 
79  0 toggle @Test
80    public void resolvedNodeWhichIsRequestedNodeShouldNotContainItselfAgain() {
81  0 given().when()
82    .get("selfReference/v1/travel")
83    .then()
84    .statusCode(200)
85    .body(
86    "@name", equalTo("travel"),
87    "promotionPage", equalTo("084d8dcd-7c80-4f46-8a9a-860ea891971b")
88    )
89    .root("promotionPage")
90    .body(not(contains("@name")));
91    }
92   
93    /**
94    * Cyclical reference: A -> B -> A
95    */
 
96  0 toggle @Test
97    public void cyclicalReference() {
98  0 given().when()
99    .get("cyclicalReference/v1/admin/john")
100    .then()
101    .statusCode(200)
102    .body("@name", equalTo("john"))
103    .root("partner")
104    .body(
105    "@name", equalTo("jane"),
106    /**
107    * "partner" property will not be resolved again
108    * because reference resolver doesn't resolve more deeply after the first time.
109    */
110    "partner", equalTo("795d8ace-6aa4-4d30-961d-6b86006a4e1f")
111    );
112    }
113   
114    /**
115    * Rererence to child: A -> B and B is child of A
116    */
 
117  0 toggle @Test
118    public void resolvedNodeWhichIsChildOfRequestedNodeShouldBeReturned() {
119  0 given().when()
120    .get("referenceToChild/v1/travel")
121    .then()
122    .statusCode(200)
123    .body("@name", equalTo("travel"))
124    .body("advertisementPage.@name", equalTo("about"));
125    }
126   
127    /**
128    * Reference to parent: A -> B and B is parent of A
129    */
 
130  0 toggle @Test
131    public void resolvedNodeWhichIsParentOfRequestedNodeShouldNotContainRequestedNodeAgain() {
132  0 given().when()
133    .get("referenceToParent/v1/travel/about")
134    .then()
135    .statusCode(200)
136    .body("@name", equalTo("about"))
137    .root("relatedPage")
138    .body(
139    "@name", equalTo("travel"),
140    // "relatedPage" property will not be resolved again.
141    "about.relatedPage", equalTo("084d8dcd-7c80-4f46-8a9a-860ea891971b")
142    );
143    }
144   
145    /**
146    * Reference to duplicated contents
147    */
 
148  0 toggle @Test
149    public void duplicatedReference() {
150  0 given().when()
151    .get("duplicatedReference/v1/travel")
152    .then()
153    .statusCode(200)
154    .body("@name", equalTo("travel"))
155    .root("authors")
156    .body(
157    "size()", equalTo(2),
158    "[0].@name", equalTo("john"),
159    "[1].@name", equalTo("john")
160    );
161    }
162   
 
163  0 toggle @Test
164    public void resolvedNodeContainsLink() {
165  0 given().when()
166    .get("referenceNodeWithLink/v1/travel/about")
167    .then()
168    .statusCode(200)
169    .body("@name", equalTo("about"))
170    .root("relatedPage")
171    .body(
172    "@name", equalTo("travel"),
173    "@link", equalTo("http://localhost:8080/magnolia/travel.html")
174    );
175    }
176   
 
177  0 toggle @Test
178    public void resolvedAsLink() {
179  0 given().when()
180    .get("referenceWithLink/v1/travel/about")
181    .then()
182    .statusCode(200)
183    .body("@name", equalTo("about"),
184    "relatedPage" , equalTo("http://localhost:8080/magnolia/travel.html"));
185    }
186   
 
187  0 toggle @Test
188    public void resolvedNodeNotContainsLink() {
189  0 given().when()
190    .get("referenceNodeWithoutLink/v1/travel/about")
191    .then()
192    .statusCode(200)
193    .body("@name", equalTo("about"),
194    "relatedPage", not(hasKey("@link")))
195    .root("relatedPage")
196    .body(
197    "@name", equalTo("travel")
198    );
199    }
200    }