diff --git a/src/test/java/HttpEventCollectorUnitTest.java b/src/test/java/HttpEventCollectorUnitTest.java index 2961934b..94bf1d73 100644 --- a/src/test/java/HttpEventCollectorUnitTest.java +++ b/src/test/java/HttpEventCollectorUnitTest.java @@ -23,7 +23,9 @@ import com.splunk.logging.HttpEventCollectorErrorHandler; import com.splunk.logging.HttpEventCollectorEventInfo; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestRule; import sun.rmi.runtime.Log; import java.io.ByteArrayInputStream; @@ -34,6 +36,10 @@ import java.util.logging.Logger; public class HttpEventCollectorUnitTest { + + @Rule + public TestRule watcher = new SplunkTestWatcher(); + @Test public void log4j_simple() throws Exception { HashMap userInputs = new HashMap(); diff --git a/src/test/java/HttpEventCollector_JavaLoggingTest.java b/src/test/java/HttpEventCollector_JavaLoggingTest.java index 32127d78..2f9204c9 100644 --- a/src/test/java/HttpEventCollector_JavaLoggingTest.java +++ b/src/test/java/HttpEventCollector_JavaLoggingTest.java @@ -23,7 +23,9 @@ import org.apache.commons.lang3.StringUtils; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestRule; import java.util.logging.Logger; @@ -33,6 +35,9 @@ public final class HttpEventCollector_JavaLoggingTest { List> errors = new ArrayList>(); List logEx = new ArrayList(); + @Rule + public TestRule watcher = new SplunkTestWatcher(); + /** * sending a message via httplogging using java.logging to splunk */ @@ -430,7 +435,6 @@ public void eventsIsIndexedInOrderOfSent() throws Exception { TestUtil.verifyEventsSentInOrder(prefix, totalEventsCount, indexName); TestUtil.deleteHttpEventCollectorToken(httpEventCollectorName); - System.out.println("====================== Test pass========================="); } /** diff --git a/src/test/java/HttpEventCollector_Log4j2Test.java b/src/test/java/HttpEventCollector_Log4j2Test.java index b049f812..1d18387b 100644 --- a/src/test/java/HttpEventCollector_Log4j2Test.java +++ b/src/test/java/HttpEventCollector_Log4j2Test.java @@ -25,14 +25,19 @@ import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.core.LoggerContext; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; import org.apache.logging.log4j.Logger; +import org.junit.rules.TestRule; public final class HttpEventCollector_Log4j2Test { private String httpEventCollectorName = "Log4j2Test"; List> errors = new ArrayList>(); List logEx = new ArrayList<>(); + @Rule + public TestRule watcher = new SplunkTestWatcher(); + /** * sending a message via httplogging using log4j2 to splunk */ @@ -62,7 +67,6 @@ public void canSendEventUsingLog4j2() throws Exception, IOException, Interrupted TestUtil.verifyEventsSentToSplunk(msgs); TestUtil.deleteHttpEventCollectorToken(httpEventCollectorName); - System.out.println("====================== Test pass========================="); } @@ -100,7 +104,6 @@ public void canSendEventUsingLog4j2WithOptions() throws Exception, IOException, TestUtil.verifyEventsSentToSplunk(msgs); TestUtil.deleteHttpEventCollectorToken(httpEventCollectorName); - System.out.println("====================== Test pass========================="); } /** @@ -368,7 +371,6 @@ public void eventsIsIndexedInOrderOfSent() throws Exception { TestUtil.verifyEventsSentInOrder(prefix,totalEventsCount,indexName); TestUtil.deleteHttpEventCollectorToken(httpEventCollectorName); - System.out.println("====================== Test pass========================="); } /** diff --git a/src/test/java/HttpEventCollector_LogbackTest.java b/src/test/java/HttpEventCollector_LogbackTest.java index 3fa2c20e..53010dc9 100644 --- a/src/test/java/HttpEventCollector_LogbackTest.java +++ b/src/test/java/HttpEventCollector_LogbackTest.java @@ -23,7 +23,9 @@ import org.apache.commons.lang3.StringUtils; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestRule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,6 +35,9 @@ public final class HttpEventCollector_LogbackTest { List> errors = new ArrayList>(); List logEx = new ArrayList(); + @Rule + public TestRule watcher = new SplunkTestWatcher(); + /** * sending a message via httplogging using logback to splunk */ @@ -361,7 +366,6 @@ public void eventsIsIndexedInOrderOfSent() throws Exception { TestUtil.verifyEventsSentInOrder(prefix, totalEventsCount, indexName); TestUtil.deleteHttpEventCollectorToken(httpEventCollectorName); - System.out.println("====================== Test pass========================="); } /** diff --git a/src/test/java/HttpEventCollector_Test.java b/src/test/java/HttpEventCollector_Test.java index 35a32920..a324eeb6 100644 --- a/src/test/java/HttpEventCollector_Test.java +++ b/src/test/java/HttpEventCollector_Test.java @@ -20,6 +20,7 @@ import com.splunk.logging.HttpEventCollectorErrorHandler; import com.splunk.logging.HttpEventCollectorEventInfo; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; import java.io.*; @@ -30,6 +31,7 @@ import java.lang.reflect.*; import com.splunk.*; +import org.junit.rules.TestRule; import org.slf4j.*; public class HttpEventCollector_Test { @@ -90,6 +92,9 @@ private static String setupHttpEventCollector(boolean batching) throws Exceptio return token; } + @Rule + public TestRule watcher = new SplunkTestWatcher(); + @Test public void LogToSplunkViaDifferentLoggers() throws Exception { LogToSplunk(false); diff --git a/src/test/java/HttpLoggerStressTest.java b/src/test/java/HttpLoggerStressTest.java index 3f21ea03..9da9e609 100644 --- a/src/test/java/HttpLoggerStressTest.java +++ b/src/test/java/HttpLoggerStressTest.java @@ -2,6 +2,7 @@ import org.apache.logging.log4j.Logger; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; import java.io.*; @@ -12,6 +13,7 @@ import java.lang.reflect.*; import com.splunk.*; +import org.junit.rules.TestRule; public class HttpLoggerStressTest { private static class DataSender implements Runnable { @@ -105,6 +107,9 @@ private static void setupHttpEventCollector() throws Exception { TestUtil.resetLog4j2Configuration("log4j2_template.xml", "log4j2.xml", userInputs); } + @Rule + public TestRule watcher = new SplunkTestWatcher(); + @Test public void canSendEventUsingJavaLogging() throws Exception { long startTime = System.currentTimeMillis()/1000; diff --git a/src/test/java/JULFunctionalTest.java b/src/test/java/JULFunctionalTest.java index 54de6b02..ddd739cd 100644 --- a/src/test/java/JULFunctionalTest.java +++ b/src/test/java/JULFunctionalTest.java @@ -14,7 +14,9 @@ * under the License. */ import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestRule; import java.io.BufferedReader; import java.io.IOException; @@ -26,6 +28,9 @@ public class JULFunctionalTest { + @Rule + public TestRule watcher = new SplunkTestWatcher(); + /** * Try writing a message via TCP to java.util.logging to validate the example configuration. */ diff --git a/src/test/java/Log4jFunctionalTest.java b/src/test/java/Log4jFunctionalTest.java index 5f4c899b..3a4a15fa 100644 --- a/src/test/java/Log4jFunctionalTest.java +++ b/src/test/java/Log4jFunctionalTest.java @@ -16,10 +16,15 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestRule; public class Log4jFunctionalTest { + @Rule + public TestRule watcher = new SplunkTestWatcher(); + /** * Try writing a message via TCP to log4j 2 to validate the example configuration. */ diff --git a/src/test/java/LogbackFunctionalTest.java b/src/test/java/LogbackFunctionalTest.java index 193364ed..5554846e 100644 --- a/src/test/java/LogbackFunctionalTest.java +++ b/src/test/java/LogbackFunctionalTest.java @@ -14,12 +14,17 @@ * under the License. */ import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestRule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class LogbackFunctionalTest { + @Rule + public TestRule watcher = new SplunkTestWatcher(); + /** * Try writing a message via TCP to logback to validate the example configuration. */ diff --git a/src/test/java/SplunkCimLogEventUnitTest.java b/src/test/java/SplunkCimLogEventUnitTest.java index 35407ec8..48344715 100644 --- a/src/test/java/SplunkCimLogEventUnitTest.java +++ b/src/test/java/SplunkCimLogEventUnitTest.java @@ -16,7 +16,9 @@ import com.splunk.logging.SplunkCimLogEvent; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestRule; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -25,6 +27,10 @@ * Check that SplunkCimLogEvent produces what we expect it to. */ public class SplunkCimLogEventUnitTest { + + @Rule + public TestRule watcher = new SplunkTestWatcher(); + @Test public void addFieldWithCharValue() { SplunkCimLogEvent event = new SplunkCimLogEvent("name", "event-id"); diff --git a/src/test/java/SplunkTestWatcher.java b/src/test/java/SplunkTestWatcher.java new file mode 100644 index 00000000..8fb29890 --- /dev/null +++ b/src/test/java/SplunkTestWatcher.java @@ -0,0 +1,21 @@ +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +public class SplunkTestWatcher extends TestWatcher { + + @Override + protected void starting(Description description) { + System.out.println("Starting test: " + description.getMethodName()); + } + + @Override + protected void succeeded(Description description) { + System.out.println("====================== Test pass========================="); + } + + @Override + protected void finished(Description description) { + // GitHub pipeline is not including output from last test failure + System.out.flush(); + } +}