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

File LoggingServiceTest.java

 

Code metrics

0
18
9
1
106
86
9
0.5
2
9
1

Classes

Class Line # Actions
LoggingServiceTest 29 18 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 5 tests. .

Source view

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"})
 
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    //<editor-fold defaultstate="collapsed" desc="Test Preparation">
 
40  1 toggle @BeforeAll
41    static void setUp() {
42  1 Assumptions.assumeTrue(true);
43   
44  1 LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG);
45    }
46   
 
47  1 toggle @AfterAll
48    static void tearDown() {
49    }
50   
 
51  5 toggle @BeforeEach
52    void testCaseInitialization() {
53    }
54   
 
55  5 toggle @AfterEach
56    void testCaseTermination() throws Exception {
57    }
58    //</editor-fold>
59   
 
60  1 toggle @Test
61    void constructor() {
62  1 LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG);
63  1 assertThat(LoggingService.class, hasValidBeanConstructor());
64    }
65   
 
66  1 toggle @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   
 
73  1 toggle @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   
 
81  1 toggle @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   
 
94  1 toggle @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    }