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"}) |
|
|
| 85.7% |
Uncovered Elements: 5 (35) |
Complexity: 14 |
Complexity Density: 0.54 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
46 |
1 |
@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 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
53 |
1 |
@AfterAll... |
54 |
|
static void tearDown() { |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
3 |
@BeforeEach... |
58 |
|
void testCaseInitialization() { |
59 |
3 |
CONNECTION.executeSqlFromClasspath(SQL_FILE); |
60 |
|
} |
61 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
62 |
3 |
@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 |
|
|
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
void constructor() { |
75 |
1 |
LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG); |
76 |
1 |
assertThat(ConfigurationService.class, hasValidBeanConstructor()); |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
79 |
1 |
@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 |
|
|
|
|
| 75% |
Uncovered Elements: 4 (16) |
Complexity: 7 |
Complexity Density: 0.5 |
1PASS
|
|
87 |
1 |
@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 |
|
} |