From 6564693ea592bc3faff467a1158765499d20a6ac Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Mon, 27 Feb 2017 06:47:30 +0100 Subject: [PATCH] BAEL-41 - Renaming tests --- .../log4j2/tests/CustomLoggingTest.java | 34 ++++++++++++------- log4j2/src/test/resources/log4j2.xml | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/CustomLoggingTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/CustomLoggingTest.java index 1562b67068..333b4f5e78 100644 --- a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/CustomLoggingTest.java +++ b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/CustomLoggingTest.java @@ -31,78 +31,85 @@ public class CustomLoggingTest { } @Test - public void givenLoggerWithDefaultConfig_shouldLogToConsole() throws Exception { + public void givenLoggerWithDefaultConfig_whenLogToConsole_thanOK() throws Exception { Logger logger = LogManager.getLogger(getClass()); Exception e = new RuntimeException("This is only a test!"); + logger.info("This is a simple message at INFO level. " + "It will be hidden."); logger.error("This is a simple message at ERROR level. " + "This is the minimum visible level.", e); } @Test - public void givenLoggerWithConsoleConfig_shouldLogToConsoleInColors() throws Exception { + public void givenLoggerWithConsoleConfig_whenLogToConsoleInColors_thanOK() throws Exception { Logger logger = LogManager.getLogger("CONSOLE_PATTERN_APPENDER_MARKER"); + Exception e = new RuntimeException("This is only a test!"); + logger.trace("This is a colored message at TRACE level."); logger.debug("This is a colored message at DEBUG level. " + "This is the minimum visible level."); logger.info("This is a colored message at INFO level."); logger.warn("This is a colored message at WARN level."); - Exception e = new RuntimeException("This is only a test!"); logger.error("This is a colored message at ERROR level.", e); logger.fatal("This is a colored message at FATAL level."); } @Test - public void givenLoggerWithConsoleConfig_shouldFilterByMarker() throws Exception { + public void givenLoggerWithConsoleConfig_whenFilterByMarker_thanOK() throws Exception { Logger logger = LogManager.getLogger("CONSOLE_PATTERN_APPENDER_MARKER"); Marker appError = MarkerManager.getMarker("APP_ERROR"); - logger.error(appError, "This marker message at ERROR level should be hidden."); Marker connectionTrace = MarkerManager.getMarker("CONN_TRACE"); + + logger.error(appError, "This marker message at ERROR level should be hidden."); logger.trace(connectionTrace, "This is a marker message at TRACE level."); } @Test - public void givenLoggerWithConsoleConfig_shouldFilterByThreadContext() throws Exception { + public void givenLoggerWithConsoleConfig_whenFilterByThreadContext_thanOK() throws Exception { Logger logger = LogManager.getLogger("CONSOLE_PATTERN_APPENDER_THREAD_CONTEXT"); ThreadContext.put("userId", "1000"); logger.info("This is a log-visible user login. Maybe from an admin account?"); ThreadContext.put("userId", "1001"); logger.info("This is a log-invisible user login."); - } @Test - public void givenLoggerWithAsyncConfig_shouldLogToJsonFile() throws Exception { + public void givenLoggerWithAsyncConfig_whenLogToJsonFile_thanOK() throws Exception { Logger logger = LogManager.getLogger("ASYNC_JSON_FILE_APPENDER"); + final int count = 88; for (int i = 0; i < count; i++) { logger.info("This is async JSON message #{} at INFO level.", count); } + long logEventsCount = Files.lines(Paths.get("target/logfile.json")) .count(); assertTrue(logEventsCount > 0 && logEventsCount <= count); } @Test - public void givenLoggerWithFailoverConfig_shouldLog() throws Exception { + public void givenLoggerWithFailoverConfig_whenLog_thanOK() throws Exception { Logger logger = LogManager.getLogger("FAIL_OVER_SYSLOG_APPENDER"); + Exception e = new RuntimeException("This is only a test!"); + logger.trace("This is a syslog message at TRACE level."); logger.debug("This is a syslog message at DEBUG level."); logger.info("This is a syslog message at INFO level. This is the minimum visible level."); logger.warn("This is a syslog message at WARN level."); - Exception e = new RuntimeException("This is only a test!"); logger.error("This is a syslog message at ERROR level.", e); logger.fatal("This is a syslog message at FATAL level."); } @Test - public void givenLoggerWithJdbcConfig_shouldLogToDataSource() throws Exception { + public void givenLoggerWithJdbcConfig_whenLogToDataSource_thanOK() throws Exception { Logger logger = LogManager.getLogger("JDBC_APPENDER"); + final int count = 88; for (int i = 0; i < count; i++) { logger.info("This is JDBC message #{} at INFO level.", count); } Connection connection = ConnectionFactory.getConnection(); ResultSet resultSet = connection.createStatement() - .executeQuery("SELECT COUNT(*) AS ROW_COUNT FROM logs"); + .executeQuery("SELECT COUNT(*) AS ROW_COUNT FROM logs"); + int logCount = 0; if (resultSet.next()) { logCount = resultSet.getInt("ROW_COUNT"); @@ -111,8 +118,9 @@ public class CustomLoggingTest { } @Test - public void givenLoggerWithRollingFileConfig_shouldLogToXMLFile() throws Exception { + public void givenLoggerWithRollingFileConfig_whenLogToXMLFile_thanOK() throws Exception { Logger logger = LogManager.getLogger("XML_ROLLING_FILE_APPENDER"); + final int count = 88; for (int i = 0; i < count; i++) { logger.info("This is rolling file XML message #{} at INFO level.", i); diff --git a/log4j2/src/test/resources/log4j2.xml b/log4j2/src/test/resources/log4j2.xml index 83c1184f1f..b0640b16eb 100644 --- a/log4j2/src/test/resources/log4j2.xml +++ b/log4j2/src/test/resources/log4j2.xml @@ -19,7 +19,7 @@ - +