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