| 1 |
|
package org.europa.together.application; |
| 2 |
|
|
| 3 |
|
import java.io.File; |
| 4 |
|
import java.io.IOException; |
| 5 |
|
import org.europa.together.JUnit5Preperator; |
| 6 |
|
import org.europa.together.business.Logger; |
| 7 |
|
import org.europa.together.domain.LogLevel; |
| 8 |
|
import org.europa.together.service.LoggingService; |
| 9 |
|
import org.europa.together.utils.Constraints; |
| 10 |
|
import org.junit.jupiter.api.AfterAll; |
| 11 |
|
import org.junit.jupiter.api.AfterEach; |
| 12 |
|
import static org.junit.jupiter.api.Assertions.*; |
| 13 |
|
import org.junit.jupiter.api.Assumptions; |
| 14 |
|
import org.junit.jupiter.api.BeforeAll; |
| 15 |
|
import org.junit.jupiter.api.BeforeEach; |
| 16 |
|
import org.junit.jupiter.api.Test; |
| 17 |
|
import org.junit.jupiter.api.extension.ExtendWith; |
| 18 |
|
import org.springframework.test.context.ContextConfiguration; |
| 19 |
|
import org.springframework.test.context.junit.jupiter.SpringExtension; |
| 20 |
|
|
| 21 |
|
@SuppressWarnings("unchecked") |
| 22 |
|
@ExtendWith({SpringExtension.class, JUnit5Preperator.class}) |
| 23 |
|
@ContextConfiguration(locations = {"/applicationContext.xml"}) |
| |
|
| 100% |
Uncovered Elements: 0 (62) |
Complexity: 16 |
Complexity Density: 0.35 |
|
| 24 |
|
public class LogbackLoggerTest { |
| 25 |
|
|
| 26 |
|
private static final Logger LOGGER = new LogbackLogger(LogbackLoggerTest.class); |
| 27 |
|
|
| 28 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 29 |
1 |
@BeforeAll... |
| 30 |
|
static void setUp() { |
| 31 |
1 |
Assumptions.assumeTrue(true, "Assumtion failed."); |
| 32 |
|
|
| 33 |
1 |
LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG); |
| 34 |
|
} |
| 35 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 36 |
1 |
@AfterAll... |
| 37 |
|
static void tearDown() { |
| 38 |
|
} |
| 39 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 40 |
12 |
@BeforeEach... |
| 41 |
|
void testCaseInitialization() { |
| 42 |
|
} |
| 43 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 44 |
12 |
@AfterEach... |
| 45 |
|
void testCaseTermination() { |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 49 |
1 |
@Test... |
| 50 |
|
void constructor() { |
| 51 |
1 |
LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG); |
| 52 |
|
|
| 53 |
1 |
Logger test_01 = new LogbackLogger(Logger.class); |
| 54 |
1 |
assertNotNull(test_01); |
| 55 |
|
} |
| 56 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
| 57 |
1 |
@Test... |
| 58 |
|
void fallbackConstructor() throws IOException { |
| 59 |
1 |
LOGGER.log("TEST CASE: fallbackConstructor", LogLevel.DEBUG); |
| 60 |
|
|
| 61 |
1 |
LoggingService service = new LoggingService(); |
| 62 |
1 |
service.createLogConfiguration(); |
| 63 |
|
|
| 64 |
1 |
File config = new File(Constraints.SYSTEM_APP_DIR + "/logback.xml"); |
| 65 |
1 |
assertTrue(config.exists()); |
| 66 |
1 |
Logger test_02 = new LogbackLogger(Logger.class); |
| 67 |
1 |
assertNotNull(test_02); |
| 68 |
|
|
| 69 |
|
|
| 70 |
1 |
config.delete(); |
| 71 |
1 |
assertFalse(config.exists()); |
| 72 |
|
} |
| 73 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 74 |
1 |
@Test... |
| 75 |
|
void getLoggerName() { |
| 76 |
1 |
LOGGER.log("TEST CASE: getLoggerName", LogLevel.DEBUG); |
| 77 |
1 |
String loggerName = "org.europa.together.application.LogbackLogger"; |
| 78 |
1 |
Logger logger = new LogbackLogger(LogbackLogger.class); |
| 79 |
1 |
logger.log("log", LogLevel.WARN); |
| 80 |
|
|
| 81 |
1 |
assertEquals(loggerName, logger.getLoggerName()); |
| 82 |
|
} |
| 83 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 84 |
1 |
@Test... |
| 85 |
|
void getLogLevel() { |
| 86 |
1 |
LOGGER.log("TEST CASE: getLogLevel", LogLevel.DEBUG); |
| 87 |
1 |
assertNotNull(LOGGER.getConfiguredLogLevel()); |
| 88 |
|
} |
| 89 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 90 |
1 |
@Test... |
| 91 |
|
void failLog() throws Exception { |
| 92 |
1 |
LOGGER.log("TEST CASE: faiLog", LogLevel.DEBUG); |
| 93 |
|
|
| 94 |
1 |
Logger logger = new LogbackLogger(Logger.class); |
| 95 |
1 |
assertThrows(Exception.class, () -> { |
| 96 |
1 |
logger.log("console logging test: trace", null); |
| 97 |
|
}); |
| 98 |
|
} |
| 99 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 100 |
1 |
@Test... |
| 101 |
|
void logTrace() { |
| 102 |
1 |
LOGGER.log("TEST CASE: logTrace", LogLevel.DEBUG); |
| 103 |
|
|
| 104 |
1 |
Logger logger = new LogbackLogger(Logger.class); |
| 105 |
1 |
assertEquals(LogLevel.TRACE, logger.log("console logging test: trace", LogLevel.TRACE)); |
| 106 |
|
} |
| 107 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 108 |
1 |
@Test... |
| 109 |
|
void logDebug() { |
| 110 |
1 |
LOGGER.log("TEST CASE: logDebug", LogLevel.DEBUG); |
| 111 |
|
|
| 112 |
1 |
Logger logger = new LogbackLogger(Logger.class); |
| 113 |
1 |
assertEquals(LogLevel.DEBUG, logger.log("console logging test: debug", LogLevel.DEBUG)); |
| 114 |
|
} |
| 115 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 116 |
1 |
@Test... |
| 117 |
|
void logInfo() { |
| 118 |
1 |
LOGGER.log("TEST CASE: logInfo", LogLevel.DEBUG); |
| 119 |
|
|
| 120 |
1 |
Logger logger = new LogbackLogger(Logger.class); |
| 121 |
1 |
assertEquals(LogLevel.INFO, logger.log("console logging test: info", LogLevel.INFO)); |
| 122 |
|
} |
| 123 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 124 |
1 |
@Test... |
| 125 |
|
void logWarn() { |
| 126 |
1 |
LOGGER.log("TEST CASE: logWarn", LogLevel.DEBUG); |
| 127 |
|
|
| 128 |
1 |
Logger logger = new LogbackLogger(Logger.class); |
| 129 |
1 |
assertEquals(LogLevel.WARN, logger.log("console logging test: warn", LogLevel.WARN)); |
| 130 |
|
} |
| 131 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 132 |
1 |
@Test... |
| 133 |
|
void logError() { |
| 134 |
1 |
LOGGER.log("TEST CASE: logError", LogLevel.DEBUG); |
| 135 |
|
|
| 136 |
1 |
Logger logger = new LogbackLogger(Logger.class); |
| 137 |
1 |
assertEquals(LogLevel.ERROR, logger.log("console logging test: error", LogLevel.ERROR)); |
| 138 |
|
} |
| 139 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 140 |
1 |
@Test... |
| 141 |
|
void catchException() { |
| 142 |
1 |
LOGGER.log("TEST CASE: catchException", LogLevel.DEBUG); |
| 143 |
|
|
| 144 |
1 |
Logger logger = new LogbackLogger(Logger.class); |
| 145 |
1 |
assertEquals("Logging exception test.", |
| 146 |
|
logger.catchException(new Exception("Logging exception test."))); |
| 147 |
|
} |
| 148 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 149 |
1 |
@Test... |
| 150 |
|
void catchNullpointerException() { |
| 151 |
1 |
LOGGER.log("TEST CASE: catchNullpointerException", LogLevel.DEBUG); |
| 152 |
|
|
| 153 |
1 |
Logger logger = new LogbackLogger(Logger.class); |
| 154 |
1 |
assertEquals("Logging exception test.", |
| 155 |
|
logger.catchException(new NullPointerException("Logging exception test."))); |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
} |