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; |
35 |
|
|
36 |
|
import static info.magnolia.rest.delivery.jcr.FilteringCondition.*; |
37 |
|
import static info.magnolia.test.hamcrest.ExceptionMatcher.instanceOf; |
38 |
|
import static info.magnolia.test.hamcrest.ExecutionMatcher.throwsAnException; |
39 |
|
import static org.hamcrest.CoreMatchers.containsString; |
40 |
|
import static org.junit.Assert.*; |
41 |
|
|
42 |
|
import java.time.LocalDate; |
43 |
|
import java.time.LocalTime; |
44 |
|
import java.time.ZoneId; |
45 |
|
import java.time.ZonedDateTime; |
46 |
|
import java.util.Arrays; |
47 |
|
|
48 |
|
import javax.ws.rs.BadRequestException; |
49 |
|
|
50 |
|
import org.junit.Test; |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (161) |
Complexity: 36 |
Complexity Density: 0.29 |
|
52 |
|
public class FilteringConditionTest { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
53 |
1 |
@Test... |
54 |
|
public void withStringValue() { |
55 |
|
|
56 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("title", "About"); |
57 |
|
|
58 |
|
|
59 |
1 |
assertEquals("[title] = 'About'", filteringCondition.asSqlString()); |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
62 |
1 |
@Test... |
63 |
|
public void withNumberValue() { |
64 |
|
|
65 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("size", "123"); |
66 |
|
|
67 |
|
|
68 |
1 |
assertEquals("[size] = 123", filteringCondition.asSqlString()); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void withFloatingPointNumberValue() { |
73 |
|
|
74 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("price", "99.99"); |
75 |
|
|
76 |
|
|
77 |
1 |
assertEquals("[price] = 99.99", filteringCondition.asSqlString()); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void withBooleanValue() { |
82 |
|
|
83 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("available", "true"); |
84 |
|
|
85 |
|
|
86 |
1 |
assertEquals("[available] = 'true'", filteringCondition.asSqlString()); |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
89 |
1 |
@Test... |
90 |
|
public void withDateTimeValue() { |
91 |
|
|
92 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("publishedDate", "2015-01-26T23:17:02.000+07:00"); |
93 |
|
|
94 |
|
|
95 |
1 |
assertEquals("[publishedDate] = CAST('2015-01-26T23:17:02.000+07:00' AS DATE)", filteringCondition.asSqlString()); |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void withSingleSimpleDateValue() { |
100 |
|
|
101 |
1 |
String dateString = "2018-02-21"; |
102 |
1 |
String startDateTime = convertDateToStartOfIsoDateTime(dateString); |
103 |
1 |
String endDateTime = convertDateToEndOfIsoDateTime(dateString); |
104 |
|
|
105 |
|
|
106 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("birthday", dateString); |
107 |
|
|
108 |
|
|
109 |
1 |
assertEquals("[birthday] >= CAST('" + startDateTime + "' AS DATE) AND [birthday] <= CAST('" + endDateTime + "' AS DATE)", filteringCondition.asSqlString()); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
112 |
1 |
@Test... |
113 |
|
public void withMultipleNumberValues() { |
114 |
|
|
115 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("size", "100|200"); |
116 |
|
|
117 |
|
|
118 |
1 |
assertEquals("[size] = 100 OR [size] = 200", filteringCondition.asSqlString()); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
121 |
1 |
@Test... |
122 |
|
public void withPathParam() { |
123 |
|
|
124 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("@ancestor", "/travel/about"); |
125 |
|
|
126 |
|
|
127 |
1 |
assertEquals("ISDESCENDANTNODE('/travel/about')", filteringCondition.asSqlString()); |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
130 |
1 |
@Test... |
131 |
|
public void withNameParam() { |
132 |
|
|
133 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("@name", "travel"); |
134 |
|
|
135 |
|
|
136 |
1 |
assertEquals("LOWER(LOCALNAME(t)) LIKE 'travel'", filteringCondition.asSqlString()); |
137 |
|
} |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
139 |
1 |
@Test... |
140 |
|
public void withNameParamAndValueIsNotActuallyANumber() { |
141 |
|
|
142 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("@name", "00"); |
143 |
|
|
144 |
|
|
145 |
1 |
assertEquals("LOWER(LOCALNAME(t)) LIKE '00'", filteringCondition.asSqlString()); |
146 |
|
} |
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
148 |
1 |
@Test... |
149 |
|
public void paramNameContainsOperator() { |
150 |
|
|
151 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("price[gte]", "100"); |
152 |
|
|
153 |
|
|
154 |
1 |
assertEquals("[price] >= 100", filteringCondition.asSqlString()); |
155 |
|
} |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
157 |
1 |
@Test... |
158 |
|
public void paramNameAndOperatorAndMultipleValues() { |
159 |
|
|
160 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("price[ne]", "100|200"); |
161 |
|
|
162 |
|
|
163 |
1 |
assertEquals("[price] <> 100 OR [price] <> 200", filteringCondition.asSqlString()); |
164 |
|
} |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
166 |
1 |
@Test... |
167 |
|
public void inARangeOfNumbers() { |
168 |
|
|
169 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("price[in]", "-5~10"); |
170 |
|
|
171 |
|
|
172 |
1 |
assertEquals("[price] >= -5 AND [price] <= 10", filteringCondition.asSqlString()); |
173 |
|
} |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
175 |
1 |
@Test... |
176 |
|
public void inMultipleRangesOfNumbers() { |
177 |
|
|
178 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("price[in]", "-5~10|20~30"); |
179 |
|
|
180 |
|
|
181 |
1 |
assertEquals("[price] >= -5 AND [price] <= 10 OR [price] >= 20 AND [price] <= 30", filteringCondition.asSqlString()); |
182 |
|
} |
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
184 |
1 |
@Test... |
185 |
|
public void inARangeOfDates() { |
186 |
|
|
187 |
1 |
String fromDate = "2015-10-20"; |
188 |
1 |
String fromIsoDateTime = convertDateToStartOfIsoDateTime(fromDate); |
189 |
1 |
String toDate = "2015-10-25"; |
190 |
1 |
String toIsoDateTime = convertDateToEndOfIsoDateTime(toDate); |
191 |
1 |
String expectedResult = String.format("[mgnl:created] >= CAST('%s' AS DATE) AND [mgnl:created] <= CAST('%s' AS DATE)", |
192 |
|
fromIsoDateTime, toIsoDateTime); |
193 |
|
|
194 |
|
|
195 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("mgnl:created[in]", String.format("%s~%s", fromDate, toDate)); |
196 |
|
|
197 |
|
|
198 |
1 |
assertEquals(expectedResult, filteringCondition.asSqlString()); |
199 |
|
} |
200 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
201 |
8 |
private String convertDateToStartOfIsoDateTime(String date) {... |
202 |
8 |
LocalDate localDate = LocalDate.parse(date, DATE_FORMATTER); |
203 |
8 |
ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault()); |
204 |
8 |
return zonedDateTime.format(DATE_TIME_FORMATTER); |
205 |
|
} |
206 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
207 |
8 |
private String convertDateToEndOfIsoDateTime(String date) {... |
208 |
8 |
LocalDate localDate = LocalDate.parse(date, DATE_FORMATTER); |
209 |
8 |
ZonedDateTime zonedDateTime = localDate.atTime(LocalTime.MAX).atZone(ZoneId.systemDefault()); |
210 |
8 |
return zonedDateTime.format(DATE_TIME_FORMATTER); |
211 |
|
} |
212 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
213 |
1 |
@Test... |
214 |
|
public void inMultipleRangesOfDates() { |
215 |
|
|
216 |
1 |
String fromDate1 = "2015-10-20"; |
217 |
1 |
String fromIsoDateTime1 = convertDateToStartOfIsoDateTime(fromDate1); |
218 |
1 |
String toDate1 = "2015-10-25"; |
219 |
1 |
String toIsoDateTime1 = convertDateToEndOfIsoDateTime(toDate1); |
220 |
1 |
String fromDate2 = "2017-10-20"; |
221 |
1 |
String fromIsoDateTime2 = convertDateToStartOfIsoDateTime(fromDate2); |
222 |
1 |
String toDate2 = "2017-10-25"; |
223 |
1 |
String toIsoDateTime2 = convertDateToEndOfIsoDateTime(toDate2); |
224 |
1 |
String expectedResult = String.format("[mgnl:created] >= CAST('%s' AS DATE) AND [mgnl:created] <= CAST('%s' AS DATE) OR [mgnl:created] >= CAST('%s' AS DATE) AND [mgnl:created] <= CAST('%s' AS DATE)", |
225 |
|
fromIsoDateTime1, toIsoDateTime1, fromIsoDateTime2, toIsoDateTime2); |
226 |
|
|
227 |
|
|
228 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("mgnl:created[in]", String.format("%s~%s|%s~%s", fromDate1, toDate1, fromDate2, toDate2)); |
229 |
|
|
230 |
|
|
231 |
1 |
assertEquals(expectedResult, filteringCondition.asSqlString()); |
232 |
|
} |
233 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
234 |
1 |
@Test... |
235 |
|
public void inARangeOfDateTimes() { |
236 |
|
|
237 |
1 |
String fromDate = "2015-12-26T23:17:02.000+01:00"; |
238 |
1 |
String toDate = "2015-12-26T23:17:02.000+01:00"; |
239 |
1 |
String expectedResult = String.format("[mgnl:created] >= CAST('%s' AS DATE) AND [mgnl:created] <= CAST('%s' AS DATE)", fromDate, toDate); |
240 |
|
|
241 |
|
|
242 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("mgnl:created[in]", String.format("%s~%s", fromDate, toDate)); |
243 |
|
|
244 |
|
|
245 |
1 |
assertEquals(expectedResult, filteringCondition.asSqlString()); |
246 |
|
} |
247 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
248 |
1 |
@Test... |
249 |
|
public void inMultipleRangesOfDateTimes() { |
250 |
|
|
251 |
1 |
String fromDate1 = "2015-12-20T23:17:02.000+01:00"; |
252 |
1 |
String toDate1 = "2015-12-25T23:17:02.000+01:00"; |
253 |
1 |
String fromDate2 = "2017-12-20T23:17:02.000+01:00"; |
254 |
1 |
String toDate2 = "2017-12-25T23:17:02.000+01:00"; |
255 |
1 |
String expectedResult = String.format("[mgnl:created] >= CAST('%s' AS DATE) AND [mgnl:created] <= CAST('%s' AS DATE) OR [mgnl:created] >= CAST('%s' AS DATE) AND [mgnl:created] <= CAST('%s' AS DATE)", |
256 |
|
fromDate1, toDate1, fromDate2, toDate2); |
257 |
|
|
258 |
|
|
259 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("mgnl:created[in]", String.format("%s~%s|%s~%s", fromDate1, toDate1, fromDate2, toDate2)); |
260 |
|
|
261 |
|
|
262 |
1 |
assertEquals(expectedResult, filteringCondition.asSqlString()); |
263 |
|
} |
264 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
265 |
1 |
@Test... |
266 |
|
public void notInARangeOfNumbers() { |
267 |
|
|
268 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("price[not-in]", "-5~10"); |
269 |
|
|
270 |
|
|
271 |
1 |
assertEquals("[price] < -5 OR [price] > 10", filteringCondition.asSqlString()); |
272 |
|
} |
273 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
274 |
1 |
@Test... |
275 |
|
public void notInARangeOfDates() { |
276 |
|
|
277 |
1 |
String fromDate = "2015-10-20"; |
278 |
1 |
String fromIsoDateTime = convertDateToStartOfIsoDateTime(fromDate); |
279 |
1 |
String toDate = "2015-10-25"; |
280 |
1 |
String toIsoDateTime = convertDateToEndOfIsoDateTime(toDate); |
281 |
1 |
String expectedResult = String.format("[mgnl:created] < CAST('%s' AS DATE) OR [mgnl:created] > CAST('%s' AS DATE)", |
282 |
|
fromIsoDateTime, toIsoDateTime); |
283 |
|
|
284 |
|
|
285 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("mgnl:created[not-in]", String.format("%s~%s", fromDate, toDate)); |
286 |
|
|
287 |
|
|
288 |
1 |
assertEquals(expectedResult, filteringCondition.asSqlString()); |
289 |
|
} |
290 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
291 |
1 |
@Test... |
292 |
|
public void notInARangeOfDateTimes() { |
293 |
|
|
294 |
1 |
String fromDate1 = "2015-12-20T23:17:02.000+01:00"; |
295 |
1 |
String toDate1 = "2015-12-25T23:17:02.000+01:00"; |
296 |
1 |
String fromDate2 = "2017-12-20T23:17:02.000+01:00"; |
297 |
1 |
String toDate2 = "2017-12-25T23:17:02.000+01:00"; |
298 |
|
|
299 |
1 |
String expectedResult = String.format("[mgnl:created] < CAST('%s' AS DATE) OR [mgnl:created] > CAST('%s' AS DATE)", |
300 |
|
fromDate1, toDate1, fromDate2, toDate2); |
301 |
|
|
302 |
|
|
303 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("mgnl:created[not-in]", String.format("%s~%s", fromDate1, toDate1, fromDate2, toDate2)); |
304 |
|
|
305 |
|
|
306 |
1 |
assertEquals(expectedResult, filteringCondition.asSqlString()); |
307 |
|
} |
308 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
309 |
1 |
@Test... |
310 |
|
public void propertyStringIsEmpty() { |
311 |
1 |
assertThat(() -> new FilteringCondition("", "test"), |
312 |
|
throwsAnException(instanceOf(IllegalArgumentException.class) |
313 |
|
.withMessage(containsString("Property string is invalid.")))); |
314 |
|
} |
315 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
316 |
1 |
@Test... |
317 |
|
public void valueStringIsEmpty() { |
318 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("test[in]", ""); |
319 |
1 |
assertEquals("", filteringCondition.asSqlString()); |
320 |
|
} |
321 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
322 |
1 |
@Test... |
323 |
|
public void treatEscapedValueWithQuotesAsString() { |
324 |
|
|
325 |
1 |
FilteringCondition filteringCondition1 = new FilteringCondition("zipCode[ne]", "\"100\""); |
326 |
1 |
FilteringCondition filteringCondition2 = new FilteringCondition("title[ne]", "\"About\""); |
327 |
|
|
328 |
|
|
329 |
1 |
assertEquals("[zipCode] <> '100'", filteringCondition1.asSqlString()); |
330 |
1 |
assertEquals("[title] <> 'About'", filteringCondition2.asSqlString()); |
331 |
|
} |
332 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
333 |
1 |
@Test... |
334 |
|
public void treatEscapedMultiValuesWithQuotesAsString() { |
335 |
|
|
336 |
1 |
FilteringCondition filteringCondition1 = new FilteringCondition("zipCode[ne]", "\"100\"|\"200\""); |
337 |
1 |
FilteringCondition filteringCondition2 = new FilteringCondition("title[ne]", "\"About\"|\"Company\""); |
338 |
|
|
339 |
|
|
340 |
1 |
assertEquals("[zipCode] <> '100' OR [zipCode] <> '200'", filteringCondition1.asSqlString()); |
341 |
1 |
assertEquals("[title] <> 'About' OR [title] <> 'Company'", filteringCondition2.asSqlString()); |
342 |
|
} |
343 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
344 |
1 |
@Test... |
345 |
|
public void stringContainsSingleQuoteOrQuotesIsNotEscaped() { |
346 |
|
|
347 |
1 |
FilteringCondition filteringCondition1 = new FilteringCondition("price[ne]", "\"abc'abc"); |
348 |
|
|
349 |
|
|
350 |
1 |
assertEquals("[price] <> '\"abc\'abc'", filteringCondition1.asSqlString()); |
351 |
|
} |
352 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
353 |
1 |
@Test... |
354 |
|
public void afterADate() { |
355 |
|
|
356 |
1 |
String date = "2018-02-21"; |
357 |
1 |
String dateToCompare = convertDateToEndOfIsoDateTime(date); |
358 |
|
|
359 |
|
|
360 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("birthday[gt]", date); |
361 |
|
|
362 |
|
|
363 |
1 |
assertEquals("[birthday] > CAST('" + dateToCompare + "' AS DATE)", filteringCondition.asSqlString()); |
364 |
|
} |
365 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
366 |
1 |
@Test... |
367 |
|
public void noEarlierThanADate() { |
368 |
|
|
369 |
1 |
String date = "2018-02-21"; |
370 |
1 |
String dateToCompare = convertDateToStartOfIsoDateTime(date); |
371 |
|
|
372 |
|
|
373 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("birthday[gte]", date); |
374 |
|
|
375 |
|
|
376 |
1 |
assertEquals("[birthday] >= CAST('" + dateToCompare + "' AS DATE)", filteringCondition.asSqlString()); |
377 |
|
} |
378 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
379 |
1 |
@Test... |
380 |
|
public void beforeADate() { |
381 |
|
|
382 |
1 |
String date = "2018-02-21"; |
383 |
1 |
String dateToCompare = convertDateToStartOfIsoDateTime(date); |
384 |
|
|
385 |
|
|
386 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("birthday[lt]", date); |
387 |
|
|
388 |
|
|
389 |
1 |
assertEquals("[birthday] < CAST('" + dateToCompare + "' AS DATE)", filteringCondition.asSqlString()); |
390 |
|
} |
391 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
392 |
1 |
@Test... |
393 |
|
public void noLaterThanADate() { |
394 |
|
|
395 |
1 |
String date = "2018-02-21"; |
396 |
1 |
String dateToCompare = convertDateToEndOfIsoDateTime(date); |
397 |
|
|
398 |
|
|
399 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("birthday[lte]", date); |
400 |
|
|
401 |
|
|
402 |
1 |
assertEquals("[birthday] <= CAST('" + dateToCompare + "' AS DATE)", filteringCondition.asSqlString()); |
403 |
|
} |
404 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
405 |
1 |
@Test... |
406 |
|
public void differentFromADate() { |
407 |
|
|
408 |
1 |
String date = "2018-02-21"; |
409 |
1 |
String startDateTime = convertDateToStartOfIsoDateTime(date); |
410 |
1 |
String endDateTime = convertDateToEndOfIsoDateTime(date); |
411 |
|
|
412 |
|
|
413 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("birthday[ne]", date); |
414 |
|
|
415 |
|
|
416 |
1 |
assertEquals("[birthday] < CAST('" + startDateTime + "' AS DATE) OR [birthday] > CAST('" + endDateTime + "' AS DATE)", filteringCondition.asSqlString()); |
417 |
|
} |
418 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
419 |
1 |
@Test... |
420 |
|
public void rangeIsNotSupportedForSomeOperators() { |
421 |
|
|
422 |
1 |
String fromDate = "2015-10-20"; |
423 |
1 |
String toDate = "2015-10-25"; |
424 |
1 |
String operators[] = { "gt", "gte", "lt", "lte", "eq", "ne" }; |
425 |
|
|
426 |
1 |
Arrays.stream(operators).forEach(operator -> { |
427 |
|
|
428 |
6 |
FilteringCondition filteringCondition = new FilteringCondition(String.format("birthday[%s]", operator), String.format("%s~%s", fromDate, toDate)); |
429 |
|
|
430 |
|
|
431 |
6 |
assertThat(() -> filteringCondition.asSqlString(), |
432 |
|
throwsAnException(instanceOf(BadRequestException.class) |
433 |
|
.withMessage(containsString("Range is not supported.")))); |
434 |
|
}); |
435 |
|
} |
436 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
437 |
1 |
@Test... |
438 |
|
public void invalidRangeThrowsException() { |
439 |
|
|
440 |
1 |
assertThat(() -> new FilteringCondition("birthday[in]", "2018-01-01~"), |
441 |
|
throwsAnException(instanceOf(BadRequestException.class) |
442 |
|
.withMessage(containsString("Value string is invalid.")))); |
443 |
|
} |
444 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
445 |
1 |
@Test... |
446 |
|
public void mixingRangeOfDatesAndDateThrowsException() { |
447 |
|
|
448 |
1 |
assertThat(() -> new FilteringCondition("mgnl:created[in]", "2015-10-20~2015-10-25|2018-03-01"), |
449 |
|
throwsAnException(instanceOf(BadRequestException.class) |
450 |
|
.withMessage(containsString("Value string is invalid.")))); |
451 |
|
} |
452 |
|
} |