1. Project Clover database Wed Jan 17 2024 23:40:18 CST
  2. Package org.europa.together.service

File ConfigurationServiceTest.java

 

Code metrics

2
26
7
1
114
94
14
0.54
3.71
7
2

Classes

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