1. Project Clover database Mon Dec 22 2025 14:59:38 CST
  2. Package org.europa.together.application

File DaoPaginationTest.java

 

Code metrics

0
161
20
1
352
264
20
0.12
8.05
20
1

Classes

Class Line # Actions
DaoPaginationTest 31 161 0% 20 0
1.0100%
 

Contributing tests

This file is covered by 16 tests. .

Source view

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