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

File ConfigurationServiceTest.java

 

Code metrics

2
26
7
1
113
93
14
0.54
3.71
7
2

Classes

Class Line # Actions
ConfigurationServiceTest 29 26 0% 14 5
0.8571428785.7%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    package org.europa.together.service;
2   
3    import static com.google.code.beanmatchers.BeanMatchers.*;
4    import java.util.List;
5    import org.europa.together.JUnit5Preperator;
6    import org.europa.together.application.LogbackLogger;
7    import org.europa.together.business.ConfigurationDAO;
8    import org.europa.together.business.DatabaseActions;
9    import org.europa.together.business.Logger;
10    import org.europa.together.domain.ConfigurationDO;
11    import org.europa.together.domain.LogLevel;
12    import static org.hamcrest.MatcherAssert.*;
13    import static org.junit.jupiter.api.Assertions.*;
14    import org.junit.jupiter.api.AfterAll;
15    import org.junit.jupiter.api.AfterEach;
16    import org.junit.jupiter.api.Assumptions;
17    import org.junit.jupiter.api.BeforeAll;
18    import org.junit.jupiter.api.BeforeEach;
19    import org.junit.jupiter.api.Test;
20    import org.junit.jupiter.api.extension.ExtendWith;
21    import org.springframework.beans.factory.annotation.Autowired;
22    import org.springframework.test.context.ContextConfiguration;
23    import org.springframework.test.context.junit.jupiter.SpringExtension;
24   
25    @SuppressWarnings("unchecked")
26    @ExtendWith({JUnit5Preperator.class})
27    @ExtendWith(SpringExtension.class)
28    @ContextConfiguration(locations = {"/applicationContext.xml"})
 
29    public class ConfigurationServiceTest {
30   
31    private static final Logger LOGGER
32    = new LogbackLogger(ConfigurationServiceTest.class);
33    public static DatabaseActions CONNECTION
34    = JUnit5Preperator.JDBC_CONNECTION;
35    private static final String SQL_FILE
36    = "org/europa/together/sql/configuration-test.sql";
37   
38    @Autowired
39    private ConfigurationDAO configurationDAO;
40   
41    @Autowired
42    private ConfigurationService configurationService;
43   
44    //<editor-fold defaultstate="collapsed" desc="Test Preparation">
 
45  1 toggle @BeforeAll
46    static void setUp() {
47  1 Assumptions.assumeTrue(JUnit5Preperator.isConnected(), "JDBC DBMS Connection failed.");
48   
49  1 LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG);
50    }
51   
 
52  1 toggle @AfterAll
53    static void tearDown() {
54    }
55   
 
56  3 toggle @BeforeEach
57    void testCaseInitialization() {
58  3 CONNECTION.executeSqlFromClasspath(SQL_FILE);
59    }
60   
 
61  3 toggle @AfterEach
62    void testCaseTermination() throws Exception {
63  3 LOGGER.log("CleanUp Test Suite.", LogLevel.DEBUG);
64  3 try {
65  3 CONNECTION.executeQuery("TRUNCATE TABLE APP_CONFIG;");
66    } catch (Exception ex) {
67  0 LOGGER.catchException(ex);
68    }
69    }
70    //</editor-fold>
71   
 
72  1 toggle @Test
73    void constructor() {
74  1 LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG);
75  1 assertThat(ConfigurationService.class, hasValidBeanConstructor());
76    }
77   
 
78  1 toggle @Test
79    void filterMandatoryFieldsOfConfigSet() {
80  1 LOGGER.log("TEST CASE: filterMandatoryFieldsOfConfigSet", LogLevel.DEBUG);
81  1 List<ConfigurationDO> entryList = configurationService.filterMandatoryFieldsOfConfigSet("Module_A", "1.0", "Set_1");
82   
83  1 assertEquals(1, entryList.size());
84    }
85   
 
86  1 toggle @Test
87    void resetModuleToDefault() {
88  1 LOGGER.log("TEST CASE: resetModuleToDefault", LogLevel.DEBUG);
89  1 try {
90  1 configurationService.resetModuleToDefault("Module_A");
91   
92  1 List<ConfigurationDO> entryList = configurationDAO.getAllModuleEntries("Module_A");
93  1 LOGGER.log("Number of fetched entries: " + entryList.size(), LogLevel.DEBUG);
94   
95  1 boolean test = false;
96  1 for (ConfigurationDO entry : entryList) {
97  10 LOGGER.log(entry.toString(), LogLevel.DEBUG);
98   
99  10 if (entry.getValue().equals("X") || entry.getValue().equals("Y")
100    || entry.getValue().equals("a") || entry.getValue().equals("b") || entry.getValue().equals("c")) {
101  10 test = true;
102    } else {
103  0 test = false;
104  0 break;
105    }
106    }
107  1 assertTrue(test);
108   
109    } catch (Exception ex) {
110  0 LOGGER.catchException(ex);
111    }
112    }
113    }