1 |
|
package org.europa.together.service; |
2 |
|
|
3 |
|
import static com.google.code.beanmatchers.BeanMatchers.*; |
4 |
|
import java.io.File; |
5 |
|
import org.europa.together.JUnit5Preperator; |
6 |
|
import org.europa.together.application.LogbackLogger; |
7 |
|
import org.europa.together.business.Logger; |
8 |
|
import org.europa.together.domain.ByteOrderMark; |
9 |
|
import org.europa.together.domain.LogLevel; |
10 |
|
import org.europa.together.utils.Constraints; |
11 |
|
import org.europa.together.utils.FileUtils; |
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"}) |
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 9 |
Complexity Density: 0.5 |
|
29 |
|
public class LoggingServiceTest { |
30 |
|
|
31 |
|
private static final Logger LOGGER |
32 |
|
= new LogbackLogger(LoggingServiceTest.class); |
33 |
|
private final String configFile |
34 |
|
= Constraints.SYSTEM_APP_DIR + "/"; |
35 |
|
|
36 |
|
@Autowired |
37 |
|
private LoggingService loggingSevice; |
38 |
|
|
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
40 |
1 |
@BeforeAll... |
41 |
|
static void setUp() { |
42 |
1 |
Assumptions.assumeTrue(true); |
43 |
|
|
44 |
1 |
LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG); |
45 |
|
} |
46 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
47 |
1 |
@AfterAll... |
48 |
|
static void tearDown() { |
49 |
|
} |
50 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
51 |
5 |
@BeforeEach... |
52 |
|
void testCaseInitialization() { |
53 |
|
} |
54 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
55 |
5 |
@AfterEach... |
56 |
|
void testCaseTermination() throws Exception { |
57 |
|
} |
58 |
|
|
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
60 |
1 |
@Test... |
61 |
|
void constructor() { |
62 |
1 |
LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG); |
63 |
1 |
assertThat(LoggingService.class, hasValidBeanConstructor()); |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
66 |
1 |
@Test... |
67 |
|
void readLogConfig() throws Exception { |
68 |
1 |
LOGGER.log("TEST CASE: readLogConfig", LogLevel.DEBUG); |
69 |
1 |
assertNotNull(loggingSevice.readLogConfiguration( |
70 |
|
Constraints.SYSTEM_APP_DIR + "/target/test-classes/logback-test.xml")); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
void failReadLogConfig() throws Exception { |
75 |
1 |
LOGGER.log("TEST CASE: failReadLogConfig", LogLevel.DEBUG); |
76 |
1 |
assertThrows(Exception.class, () -> { |
77 |
1 |
loggingSevice.readLogConfiguration(null); |
78 |
|
}); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
81 |
1 |
@Test... |
82 |
|
void writeLogConfig() throws Exception { |
83 |
1 |
LOGGER.log("TEST CASE: writeLogConfig", LogLevel.DEBUG); |
84 |
|
|
85 |
1 |
String input = FileUtils.readFileStream(new File( |
86 |
|
Constraints.SYSTEM_APP_DIR + "/target/test-classes/logback-test.xml"), |
87 |
|
ByteOrderMark.UTF_8); |
88 |
1 |
String output = Constraints.SYSTEM_APP_DIR + "/target/logback.xml"; |
89 |
|
|
90 |
1 |
loggingSevice.writeLogConfiguration(input, output); |
91 |
1 |
assertTrue(new File(output).exists()); |
92 |
|
} |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
94 |
1 |
@Test... |
95 |
|
void failWriteLogConfig() throws Exception { |
96 |
1 |
LOGGER.log("TEST CASE: failWriteLogConfig", LogLevel.DEBUG); |
97 |
|
|
98 |
1 |
String input = FileUtils.readFileStream(new File( |
99 |
|
Constraints.SYSTEM_APP_DIR + "/target/test-classes/org/europa/together/xml/test_non_wellformed_01.xml"), |
100 |
|
ByteOrderMark.UTF_8); |
101 |
|
|
102 |
1 |
assertThrows(Exception.class, () -> { |
103 |
1 |
loggingSevice.writeLogConfiguration(input, null); |
104 |
|
}); |
105 |
|
} |
106 |
|
} |