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

 

Code metrics

0
20
20
1
294
228
20
1
1
20
1

Classes

Class Line # Actions
FilteringOperatorTest 46 20 0% 20 40
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   
39    import org.junit.Test;
40   
41    /**
42    * In order to show JSON output, simply append "log().body()" after "then()"<br/>
43    * For example: get("/x").then().log().body()...
44    * @see <a href="https://github.com/rest-assured/rest-assured/wiki/Usage#user-content-response-logging">Response Logging</a>
45    */
 
46    public class FilteringOperatorTest extends AbstractJcrDeliveryEndpointTest {
47   
 
48  0 toggle @Test
49    public void filterWithEqualityOperator() {
50  0 given().param("views[eq]", 200)
51    .when()
52    .get("pages/v1")
53    .then()
54    .statusCode(200)
55    .body(
56    "results.@name", contains("about")
57    );
58    }
59   
 
60  0 toggle @Test
61    public void filterWithInequalityOperator() {
62  0 given().param("views[ne]", 200)
63    .when()
64    .get("pages/v1")
65    .then()
66    .statusCode(200)
67    .body(
68    "results.@name", containsInAnyOrder("company", "travel")
69    );
70    }
71   
 
72  0 toggle @Test
73    public void filterWithLessThanOperator() {
74  0 given().param("views[lt]", 200)
75    .when()
76    .get("pages/v1")
77    .then()
78    .statusCode(200)
79    .body(
80    "results.@name", contains("travel")
81    );
82    }
83   
 
84  0 toggle @Test
85    public void filterWithLessThanOrEqualToOperator() {
86  0 given().param("views[lte]", 200)
87    .when()
88    .get("pages/v1")
89    .then()
90    .statusCode(200)
91    .body(
92    "results.@name", containsInAnyOrder("about", "travel")
93    );
94    }
95   
 
96  0 toggle @Test
97    public void filterWithGreaterThanOperator() {
98  0 given().param("views[gt]", 200)
99    .when()
100    .get("pages/v1")
101    .then()
102    .statusCode(200)
103    .body(
104    "results.@name", contains("company")
105    );
106    }
107   
 
108  0 toggle @Test
109    public void filterWithGreaterThanOrEqualToOperator() {
110  0 given().param("views[gte]", 200)
111    .when()
112    .get("pages/v1")
113    .then()
114    .statusCode(200)
115    .body(
116    "results.@name", containsInAnyOrder("about", "company")
117    );
118    }
119   
 
120  0 toggle @Test
121    public void filterWithInOperator() {
122  0 given().param("views[in]", "200~300")
123    .when()
124    .get("pages/v1")
125    .then()
126    .statusCode(200)
127    .body(
128    "results.@name", containsInAnyOrder("about", "company")
129    );
130    }
131   
 
132  0 toggle @Test
133    public void filterWithNotInOperator() {
134  0 given().param("views[not-in]", "200~300")
135    .when()
136    .get("pages/v1")
137    .then()
138    .statusCode(200)
139    .body(
140    "results.@name", contains("travel")
141    );
142    }
143   
 
144  0 toggle @Test
145    public void filterWithLikeOperator() {
146  0 given().param("title[like]", "%Home%")
147    .when()
148    .get("pages/v1")
149    .then()
150    .statusCode(200)
151    .body(
152    "results.@name", contains("travel")
153    );
154    }
155   
 
156  0 toggle @Test
157    public void filterByIsoDateTime() {
158  0 given().param("mgnl:created", "2018-02-01T10:26:47.438+07:00")
159    .when()
160    .get("pages/v1")
161    .then()
162    .statusCode(200)
163    .body(
164    "results.@name", contains("about")
165    );
166    }
167   
 
168  0 toggle @Test
169    public void filterByMultipleProperties() {
170  0 given().param("title[like]", "Travel%")
171    .param("views[lt]", 300)
172    .when()
173    .get("pages/v1")
174    .then()
175    .statusCode(200)
176    .body(
177    "results.@name", contains("travel")
178    );
179    }
180   
181    /*
182    * ====================== Filtering by date ====================
183    */
184   
 
185  0 toggle @Test
186    public void inADate() {
187  0 given().param("mgnl:created", "2018-01-01")
188    .when()
189    .get("pages/v1")
190    .then()
191    .statusCode(200)
192    .body(
193    "results.@name", contains("travel")
194    );
195    }
196   
 
197  0 toggle @Test
198    public void differentFromADate() {
199  0 given().param("mgnl:created[ne]", "2018-02-01")
200    .when()
201    .get("pages/v1")
202    .then()
203    .statusCode(200)
204    .body(
205    "results.@name", containsInAnyOrder("company", "travel")
206    );
207    }
208   
 
209  0 toggle @Test
210    public void differentFromARangeOfDates() {
211  0 given().param("mgnl:created[ne]", "2018-01-01~2018-02-01")
212    .when()
213    .get("pages/v1")
214    .then()
215    .statusCode(400)
216    .body(
217    "", hasKey("error"),
218    "error.code", equalTo("badRequest"),
219    "error.message", equalTo("Range is not supported.")
220    );
221    }
222   
 
223  0 toggle @Test
224    public void inARangeOfDates() {
225  0 given().param("mgnl:created[in]", "2018-01-01~2018-02-01")
226    .when()
227    .get("pages/v1")
228    .then()
229    .statusCode(200)
230    .body(
231    "results.@name", containsInAnyOrder("about", "travel")
232    );
233    }
234   
 
235  0 toggle @Test
236    public void notInARangeOfDates() {
237  0 given().param("mgnl:created[not-in]", "2018-01-01~2018-02-01")
238    .when()
239    .get("pages/v1")
240    .then()
241    .statusCode(200)
242    .body(
243    "results.@name", contains("company")
244    );
245    }
246   
 
247  0 toggle @Test
248    public void afterADate() {
249  0 given().param("mgnl:created[gt]", "2018-02-01")
250    .when()
251    .get("pages/v1")
252    .then()
253    .statusCode(200)
254    .body(
255    "results.@name", contains("company")
256    );
257    }
258   
 
259  0 toggle @Test
260    public void noEarlierThanADate() {
261  0 given().param("mgnl:created[gte]", "2018-02-01")
262    .when()
263    .get("pages/v1")
264    .then()
265    .statusCode(200)
266    .body(
267    "results.@name", containsInAnyOrder("about", "company")
268    );
269    }
270   
 
271  0 toggle @Test
272    public void beforeADate() {
273  0 given().param("mgnl:created[lt]", "2018-02-01")
274    .when()
275    .get("pages/v1")
276    .then()
277    .statusCode(200)
278    .body(
279    "results.@name", contains("travel")
280    );
281    }
282   
 
283  0 toggle @Test
284    public void noLaterThanADate() {
285  0 given().param("mgnl:created[lte]", "2018-02-01")
286    .when()
287    .get("pages/v1")
288    .then()
289    .statusCode(200)
290    .body(
291    "results.@name", containsInAnyOrder("about", "travel")
292    );
293    }
294    }