1 |
|
package org.europa.together.application; |
2 |
|
|
3 |
|
import java.sql.Timestamp; |
4 |
|
import java.time.LocalDateTime; |
5 |
|
import java.time.ZoneOffset; |
6 |
|
import java.util.Date; |
7 |
|
import java.util.HashMap; |
8 |
|
import java.util.List; |
9 |
|
import java.util.Map; |
10 |
|
import org.europa.together.JUnit5Preperator; |
11 |
|
import org.europa.together.business.DatabaseActions; |
12 |
|
import org.europa.together.business.Logger; |
13 |
|
import org.europa.together.business.PaginationTestDAO; |
14 |
|
import org.europa.together.domain.JpaPagination; |
15 |
|
import org.europa.together.domain.LogLevel; |
16 |
|
import org.europa.together.domain.PaginationTestDO; |
17 |
|
import org.junit.jupiter.api.AfterAll; |
18 |
|
import org.junit.jupiter.api.AfterEach; |
19 |
|
import static org.junit.jupiter.api.Assertions.*; |
20 |
|
import org.junit.jupiter.api.Assumptions; |
21 |
|
import org.junit.jupiter.api.BeforeAll; |
22 |
|
import org.junit.jupiter.api.BeforeEach; |
23 |
|
import org.junit.jupiter.api.Test; |
24 |
|
import org.junit.jupiter.api.extension.ExtendWith; |
25 |
|
import org.springframework.beans.factory.annotation.Autowired; |
26 |
|
import org.springframework.test.context.ContextConfiguration; |
27 |
|
import org.springframework.test.context.junit.jupiter.SpringExtension; |
28 |
|
|
29 |
|
@SuppressWarnings("unchecked") |
30 |
|
@ExtendWith(SpringExtension.class) |
31 |
|
@ExtendWith({JUnit5Preperator.class}) |
32 |
|
@ContextConfiguration(locations = {"/applicationContext.xml"}) |
|
|
| 100% |
Uncovered Elements: 0 (182) |
Complexity: 20 |
Complexity Density: 0.12 |
|
33 |
|
public class DaoPaginationTest { |
34 |
|
|
35 |
|
private static final Logger LOGGER = new LogbackLogger(DaoPaginationTest.class); |
36 |
|
|
37 |
|
private static final String FLUSH_TABLE |
38 |
|
= "TRUNCATE TABLE " + PaginationTestDO.TABLE_NAME + ";"; |
39 |
|
private static final String FILE |
40 |
|
= "org/europa/together/sql/pagination-test.sql"; |
41 |
|
|
42 |
|
@Autowired |
43 |
|
private PaginationTestDAO paginationTestDAO; |
44 |
|
|
45 |
|
private static DatabaseActions jdbcActions = new JdbcActions(); |
46 |
|
|
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
48 |
1 |
@BeforeAll... |
49 |
|
static void setUp() { |
50 |
1 |
Assumptions.assumeTrue(jdbcActions.connect("test"), "JDBC DBMS Connection failed."); |
51 |
1 |
jdbcActions.executeSqlFromClasspath(FILE); |
52 |
|
|
53 |
1 |
LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG); |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
1 |
@AfterAll... |
57 |
|
static void tearDown() throws Exception { |
58 |
1 |
jdbcActions.executeQuery(FLUSH_TABLE); |
59 |
|
} |
60 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
61 |
16 |
@BeforeEach... |
62 |
|
void testCaseInitialization() { |
63 |
|
} |
64 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
65 |
16 |
@AfterEach... |
66 |
|
void testCaseTermination() throws Exception { |
67 |
|
} |
68 |
|
|
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
70 |
1 |
@Test... |
71 |
|
void emptyListAll() throws Exception { |
72 |
1 |
LOGGER.log("TEST CASE: emptyListAllAsc", LogLevel.DEBUG); |
73 |
|
|
74 |
1 |
jdbcActions.executeQuery(FLUSH_TABLE); |
75 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
76 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
77 |
|
|
78 |
|
|
79 |
1 |
jdbcActions.executeSqlFromClasspath(FILE); |
80 |
|
|
81 |
1 |
assertNotNull(result); |
82 |
1 |
assertEquals(0, result.size()); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
85 |
1 |
@Test... |
86 |
|
void listAllAsc() throws Exception { |
87 |
1 |
LOGGER.log("TEST CASE: listAllAsc", LogLevel.DEBUG); |
88 |
|
|
89 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
90 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
91 |
|
|
92 |
1 |
assertEquals(101, result.size()); |
93 |
1 |
assertEquals("88888888-0000-4444-4444-cccccccccc", result.get(0).getUuid()); |
94 |
1 |
assertEquals("88888888-0100-4444-4444-cccccccccc", result.get(result.size() - 1).getUuid()); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
97 |
1 |
@Test... |
98 |
|
void listAllDesc() throws Exception { |
99 |
1 |
LOGGER.log("TEST CASE: listAllDesc", LogLevel.DEBUG); |
100 |
|
|
101 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
102 |
1 |
pivotElement.setSorting(JpaPagination.ORDER_DESC); |
103 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
104 |
|
|
105 |
1 |
assertEquals(101, result.size()); |
106 |
1 |
assertEquals("88888888-0100-4444-4444-cccccccccc", result.get(0).getUuid()); |
107 |
1 |
assertEquals("88888888-0000-4444-4444-cccccccccc", result.get(result.size() - 1).getUuid()); |
108 |
|
} |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
110 |
1 |
@Test... |
111 |
|
void limitAsc() throws Exception { |
112 |
1 |
LOGGER.log("TEST CASE: limitAsc", LogLevel.DEBUG); |
113 |
|
|
114 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
115 |
1 |
pivotElement.setPageSize(35); |
116 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
117 |
|
|
118 |
1 |
assertEquals(35, result.size()); |
119 |
1 |
assertEquals("88888888-0000-4444-4444-cccccccccc", result.get(0).getUuid()); |
120 |
1 |
assertEquals("88888888-0034-4444-4444-cccccccccc", result.get(result.size() - 1).getUuid()); |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
123 |
1 |
@Test... |
124 |
|
void limitDesc() throws Exception { |
125 |
1 |
LOGGER.log("TEST CASE: limitDesc", LogLevel.DEBUG); |
126 |
|
|
127 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
128 |
1 |
pivotElement.setPageSize(3); |
129 |
1 |
pivotElement.setSorting(JpaPagination.ORDER_DESC); |
130 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
131 |
|
|
132 |
1 |
assertEquals(3, result.size()); |
133 |
1 |
assertEquals("88888888-0100-4444-4444-cccccccccc", result.get(0).getUuid()); |
134 |
1 |
assertEquals("88888888-0098-4444-4444-cccccccccc", result.get(result.size() - 1).getUuid()); |
135 |
|
} |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
137 |
1 |
@Test... |
138 |
|
void pageAhead() throws Exception { |
139 |
1 |
LOGGER.log("TEST CASE: pageAhead", LogLevel.DEBUG); |
140 |
|
|
141 |
|
|
142 |
1 |
String primareyKey = "88888888-0027-4444-4444-cccccccccc"; |
143 |
|
|
144 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
145 |
1 |
pivotElement.setPageSize(5); |
146 |
1 |
pivotElement.setPageBreak(primareyKey); |
147 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
148 |
|
|
149 |
1 |
assertEquals(5, result.size()); |
150 |
1 |
assertEquals(primareyKey, result.get(0).getUuid()); |
151 |
1 |
assertEquals("88888888-0031-4444-4444-cccccccccc", result.get(4).getUuid()); |
152 |
|
} |
153 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
154 |
1 |
@Test... |
155 |
|
void pageBackwards() throws Exception { |
156 |
1 |
LOGGER.log("TEST CASE: pageBackwards", LogLevel.DEBUG); |
157 |
|
|
158 |
|
|
159 |
1 |
String primareyKey = "88888888-0027-4444-4444-cccccccccc"; |
160 |
|
|
161 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
162 |
1 |
pivotElement.setPageSize(5); |
163 |
1 |
pivotElement.setPageBreak(primareyKey); |
164 |
1 |
pivotElement.setPaging(JpaPagination.PAGING_BACKWARD); |
165 |
1 |
pivotElement.setSorting(JpaPagination.ORDER_DESC); |
166 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
167 |
|
|
168 |
1 |
assertEquals(5, result.size()); |
169 |
1 |
assertEquals(primareyKey, result.get(0).getUuid()); |
170 |
1 |
assertEquals("88888888-0023-4444-4444-cccccccccc", result.get(4).getUuid()); |
171 |
|
} |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
173 |
1 |
@Test... |
174 |
|
void fetchEndOfList() throws Exception { |
175 |
1 |
LOGGER.log("TEST CASE: fetchEndOfList", LogLevel.DEBUG); |
176 |
|
|
177 |
|
|
178 |
1 |
String primareyKey = "88888888-0081-4444-4444-cccccccccc"; |
179 |
|
|
180 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
181 |
1 |
pivotElement.setPageSize(27); |
182 |
1 |
pivotElement.setPageBreak(primareyKey); |
183 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
184 |
|
|
185 |
1 |
assertEquals(20, result.size()); |
186 |
1 |
assertEquals(primareyKey, result.get(0).getUuid()); |
187 |
1 |
assertEquals("88888888-0100-4444-4444-cccccccccc", result.get(19).getUuid()); |
188 |
|
} |
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
190 |
1 |
@Test... |
191 |
|
void fetchLessResultsThanAPage() throws Exception { |
192 |
1 |
LOGGER.log("TEST CASE: fetchLessResultsThanAPage", LogLevel.DEBUG); |
193 |
|
|
194 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
195 |
1 |
pivotElement.setPageSize(150); |
196 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
197 |
|
|
198 |
1 |
assertEquals(101, result.size()); |
199 |
1 |
assertEquals("88888888-0000-4444-4444-cccccccccc", result.get(0).getUuid()); |
200 |
1 |
assertEquals("88888888-0100-4444-4444-cccccccccc", result.get(100).getUuid()); |
201 |
|
} |
202 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
203 |
1 |
@Test... |
204 |
|
void simpleResultFilterWhitoutPagination() throws Exception { |
205 |
1 |
LOGGER.log("TEST CASE: simpleResultFilterWhitoutPagination", LogLevel.DEBUG); |
206 |
|
|
207 |
1 |
Map<String, String> filters = new HashMap<>(); |
208 |
1 |
filters.put("modulName", "default"); |
209 |
|
|
210 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
211 |
1 |
pivotElement.setFilterStringCriteria(filters); |
212 |
|
|
213 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
214 |
|
|
215 |
1 |
assertEquals(26, result.size()); |
216 |
1 |
assertEquals("88888888-0050-4444-4444-cccccccccc", result.get(0).getUuid()); |
217 |
1 |
assertEquals("88888888-0075-4444-4444-cccccccccc", result.get(25).getUuid()); |
218 |
|
} |
219 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
220 |
1 |
@Test... |
221 |
|
void complexResultFilterWithPagination() throws Exception { |
222 |
1 |
LOGGER.log("TEST CASE: complexResultFilterWithPagination", LogLevel.DEBUG); |
223 |
|
|
224 |
1 |
Map<String, String> stringFilters = new HashMap<>(); |
225 |
1 |
stringFilters.put("modulName", "default"); |
226 |
|
|
227 |
1 |
Map<String, Boolean> boolFilters = new HashMap<>(); |
228 |
1 |
boolFilters.put("deprecated", true); |
229 |
|
|
230 |
1 |
Map<String, Integer> intFilters = new HashMap<>(); |
231 |
1 |
intFilters.put("intNumber", 3); |
232 |
|
|
233 |
1 |
Map<String, Float> floatFilters = new HashMap<>(); |
234 |
1 |
floatFilters.put("floatNumber", 6.3f); |
235 |
|
|
236 |
1 |
Timestamp selctedDate = Timestamp.from(LocalDateTime |
237 |
|
.parse("1984-04-01T12:00:01.0") |
238 |
|
.toInstant(ZoneOffset.UTC) |
239 |
|
); |
240 |
|
|
241 |
1 |
Map<String, Date> dateFilters = new HashMap<>(); |
242 |
1 |
dateFilters.put("dateValue", selctedDate); |
243 |
|
|
244 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
245 |
1 |
pivotElement.setFilterStringCriteria(stringFilters); |
246 |
1 |
pivotElement.setFilterBooleanCriteria(boolFilters); |
247 |
1 |
pivotElement.setFilterIntegerCriteria(intFilters); |
248 |
1 |
pivotElement.setFilterFloatCriteria(floatFilters); |
249 |
1 |
pivotElement.setFilterDateCriteria(dateFilters); |
250 |
1 |
pivotElement.setPageSize(10); |
251 |
1 |
pivotElement.setPageBreak("88888888-0060-4444-4444-cccccccccc"); |
252 |
|
|
253 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
254 |
|
|
255 |
1 |
assertEquals(1, result.size()); |
256 |
1 |
assertEquals("88888888-0063-4444-4444-cccccccccc", result.get(0).getUuid()); |
257 |
|
} |
258 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
259 |
1 |
@Test... |
260 |
|
void simpleResultStringEqualFilterWithPagination() throws Exception { |
261 |
1 |
LOGGER.log("TEST CASE: simpleResultStringEqualFilterWithPagination", LogLevel.DEBUG); |
262 |
|
|
263 |
1 |
Map<String, String> filters = new HashMap<>(); |
264 |
1 |
filters.put("modulName", "default"); |
265 |
|
|
266 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
267 |
1 |
pivotElement.setFilterStringCriteria(filters); |
268 |
1 |
pivotElement.setPageSize(8); |
269 |
1 |
pivotElement.setPageBreak("88888888-0057-4444-4444-cccccccccc"); |
270 |
|
|
271 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
272 |
|
|
273 |
1 |
assertEquals(8, result.size()); |
274 |
1 |
assertEquals("88888888-0057-4444-4444-cccccccccc", result.get(0).getUuid()); |
275 |
1 |
assertEquals("88888888-0064-4444-4444-cccccccccc", result.get(7).getUuid()); |
276 |
|
} |
277 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
278 |
1 |
@Test... |
279 |
|
void simpleResultBooleanEqualFilterWithPagination() throws Exception { |
280 |
1 |
LOGGER.log("TEST CASE: simpleResultBooleanEqualFilterWithPagination", LogLevel.DEBUG); |
281 |
|
|
282 |
1 |
Map<String, Boolean> filters = new HashMap<>(); |
283 |
1 |
filters.put("deprecated", true); |
284 |
|
|
285 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
286 |
1 |
pivotElement.setFilterBooleanCriteria(filters); |
287 |
1 |
pivotElement.setPageSize(8); |
288 |
1 |
pivotElement.setPageBreak("88888888-0057-4444-4444-cccccccccc"); |
289 |
|
|
290 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
291 |
|
|
292 |
1 |
assertEquals(8, result.size()); |
293 |
1 |
assertEquals("88888888-0057-4444-4444-cccccccccc", result.get(0).getUuid()); |
294 |
1 |
assertEquals("88888888-0064-4444-4444-cccccccccc", result.get(7).getUuid()); |
295 |
|
} |
296 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
297 |
1 |
@Test... |
298 |
|
void simpleResultIntegerEqualFilterWithPagination() throws Exception { |
299 |
1 |
LOGGER.log("TEST CASE: simpleResultIntegerEqualFilterWithPagination", LogLevel.DEBUG); |
300 |
|
|
301 |
1 |
Map<String, Integer> filters = new HashMap<>(); |
302 |
1 |
filters.put("intNumber", 1); |
303 |
|
|
304 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
305 |
1 |
pivotElement.setFilterIntegerCriteria(filters); |
306 |
1 |
pivotElement.setPageSize(8); |
307 |
1 |
pivotElement.setPageBreak("88888888-0057-4444-4444-cccccccccc"); |
308 |
|
|
309 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
310 |
|
|
311 |
1 |
assertEquals(2, result.size()); |
312 |
1 |
assertEquals("88888888-0061-4444-4444-cccccccccc", result.get(0).getUuid()); |
313 |
1 |
assertEquals("88888888-0091-4444-4444-cccccccccc", result.get(1).getUuid()); |
314 |
|
} |
315 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
316 |
1 |
@Test... |
317 |
|
void simpleResultFloatEqualFilterWithPagination() throws Exception { |
318 |
1 |
LOGGER.log("TEST CASE: simpleResultFloatEqualFilterWithPagination", LogLevel.DEBUG); |
319 |
|
|
320 |
1 |
Map<String, Float> filters = new HashMap<>(); |
321 |
1 |
filters.put("floatNumber", 6.8f); |
322 |
|
|
323 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
324 |
1 |
pivotElement.setFilterFloatCriteria(filters); |
325 |
1 |
pivotElement.setPageSize(8); |
326 |
1 |
pivotElement.setPageBreak("88888888-0057-4444-4444-cccccccccc"); |
327 |
|
|
328 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
329 |
|
|
330 |
1 |
assertEquals(1, result.size()); |
331 |
1 |
assertEquals("88888888-0068-4444-4444-cccccccccc", result.get(0).getUuid()); |
332 |
|
} |
333 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
334 |
1 |
@Test... |
335 |
|
void simpleResultDateEqualFilterWithPagination() throws Exception { |
336 |
1 |
LOGGER.log("TEST CASE: simpleResultDateEqualFilterWithPagination", LogLevel.DEBUG); |
337 |
|
|
338 |
1 |
Timestamp selctedDate = Timestamp.from(LocalDateTime |
339 |
|
.parse("1984-04-01T12:00:01.0") |
340 |
|
.toInstant(ZoneOffset.UTC) |
341 |
|
); |
342 |
1 |
Map<String, Date> filters = new HashMap<>(); |
343 |
1 |
filters.put("dateValue", selctedDate); |
344 |
|
|
345 |
1 |
JpaPagination pivotElement = new JpaPagination("uuid"); |
346 |
1 |
pivotElement.setFilterDateCriteria(filters); |
347 |
1 |
pivotElement.setPageSize(8); |
348 |
1 |
pivotElement.setPageBreak("88888888-0057-4444-4444-cccccccccc"); |
349 |
|
|
350 |
1 |
List<PaginationTestDO> result = paginationTestDAO.listAllElements(pivotElement); |
351 |
|
|
352 |
1 |
assertEquals(8, result.size()); |
353 |
1 |
assertEquals("88888888-0057-4444-4444-cccccccccc", result.get(0).getUuid()); |
354 |
1 |
assertEquals("88888888-0064-4444-4444-cccccccccc", result.get(7).getUuid()); |
355 |
|
} |
356 |
|
} |