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.JCR_OFFSET_DATE_TIME; |
37 |
|
import static org.junit.Assert.assertEquals; |
38 |
|
|
39 |
|
import java.time.ZoneId; |
40 |
|
import java.time.ZonedDateTime; |
41 |
|
|
42 |
|
import org.junit.Test; |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (38) |
Complexity: 12 |
Complexity Density: 0.46 |
|
44 |
|
public class FilteringConditionTest { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
45 |
1 |
@Test... |
46 |
|
public void withStringValue() { |
47 |
|
|
48 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("title", "About"); |
49 |
|
|
50 |
|
|
51 |
1 |
assertEquals("[title] = 'About'", filteringCondition.asSqlString()); |
52 |
|
} |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
54 |
1 |
@Test... |
55 |
|
public void withNumberValue() { |
56 |
|
|
57 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("size", "123"); |
58 |
|
|
59 |
|
|
60 |
1 |
assertEquals("[size] = 123", filteringCondition.asSqlString()); |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
63 |
1 |
@Test... |
64 |
|
public void withFloatingPointNumberValue() { |
65 |
|
|
66 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("price", "99.99"); |
67 |
|
|
68 |
|
|
69 |
1 |
assertEquals("[price] = 99.99", filteringCondition.asSqlString()); |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
72 |
1 |
@Test... |
73 |
|
public void withBooleanValue() { |
74 |
|
|
75 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("available", "true"); |
76 |
|
|
77 |
|
|
78 |
1 |
assertEquals("[available] = 'true'", filteringCondition.asSqlString()); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
81 |
1 |
@Test... |
82 |
|
public void withDateTimeValue() { |
83 |
|
|
84 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("publishedDate", "2015-01-26T23:17:02.000+07:00"); |
85 |
|
|
86 |
|
|
87 |
1 |
assertEquals("[publishedDate] = CAST('2015-01-26T23:17:02.000+07:00' AS DATE)", filteringCondition.asSqlString()); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
90 |
1 |
@Test... |
91 |
|
public void withDateValue() { |
92 |
|
|
93 |
1 |
ZonedDateTime expectedDate = ZonedDateTime.of(2015, 1, 26, 0, 0, 0, 0, ZoneId.systemDefault()); |
94 |
1 |
String expectedDateString = JCR_OFFSET_DATE_TIME.format(expectedDate); |
95 |
|
|
96 |
|
|
97 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("birthday", "2015-01-26"); |
98 |
|
|
99 |
|
|
100 |
1 |
assertEquals("[birthday] = CAST('" + expectedDateString + "' AS DATE)", filteringCondition.asSqlString()); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
103 |
1 |
@Test... |
104 |
|
public void withMultipleNumberValues() { |
105 |
|
|
106 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("size", "100|200"); |
107 |
|
|
108 |
|
|
109 |
1 |
assertEquals("[size] = 100 OR [size] = 200", filteringCondition.asSqlString()); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
112 |
1 |
@Test... |
113 |
|
public void withPathParam() { |
114 |
|
|
115 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("@ancestor", "/travel/about"); |
116 |
|
|
117 |
|
|
118 |
1 |
assertEquals("ISDESCENDANTNODE('/travel/about')", filteringCondition.asSqlString()); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
121 |
1 |
@Test... |
122 |
|
public void withNameParam() { |
123 |
|
|
124 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("@name", "travel"); |
125 |
|
|
126 |
|
|
127 |
1 |
assertEquals("LOWER(NAME(t)) = 'travel'", filteringCondition.asSqlString()); |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
130 |
1 |
@Test... |
131 |
|
public void withNameParamAndValueIsNotActuallyANumber() { |
132 |
|
|
133 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("@name", "00"); |
134 |
|
|
135 |
|
|
136 |
1 |
assertEquals("LOWER(NAME(t)) = '00'", filteringCondition.asSqlString()); |
137 |
|
} |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
139 |
1 |
@Test... |
140 |
|
public void paramNameContainsOperator() { |
141 |
|
|
142 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("price[gte]", "100"); |
143 |
|
|
144 |
|
|
145 |
1 |
assertEquals("[price] >= 100", filteringCondition.asSqlString()); |
146 |
|
} |
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
148 |
1 |
@Test... |
149 |
|
public void paramNameAndOperatorAndMultipleValues() { |
150 |
|
|
151 |
1 |
FilteringCondition filteringCondition = new FilteringCondition("price[ne]", "100|200"); |
152 |
|
|
153 |
|
|
154 |
1 |
assertEquals("[price] != 100 OR [price] != 200", filteringCondition.asSqlString()); |
155 |
|
} |
156 |
|
} |