Put common setup code in the utils classes
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 18 Feb 2016 23:09:46 +0000 (18:09 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 18 Feb 2016 23:45:14 +0000 (18:45 -0500)
We now have a large amount of test classes, it's a bit simpler
to put the common, API-specific @BeforeClass and @AfterClass
code in the utils classes.

At the same time we can give slightly more information in case
of failure of these checks.

Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
18 files changed:
lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextIT.java
lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextOrderingIT.java
lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulEnabledEventsIT.java
lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java
lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulListEventsIT.java
lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulMultiSessionIT.java
lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerIT.java
lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerOrderingIT.java
lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/utils/JulTestUtils.java
lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextIT.java
lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextOrderingIT.java
lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jEnabledEventsIT.java
lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java
lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jListEventsIT.java
lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jMultiSessionIT.java
lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerIT.java
lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerOrderingIT.java
lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/utils/Log4jTestUtils.java

index a6b3f68fd582fb413a5e2ae6f6c3e82829d86f72..844acef936dac65458f47e2b684233b883bb3c95 100644 (file)
@@ -18,8 +18,6 @@
 
 package org.lttng.ust.agent.integration.context;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 import java.util.logging.Handler;
 import java.util.logging.Level;
@@ -30,10 +28,8 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.jul.LttngLogHandler;
 import org.lttng.ust.agent.utils.JulTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Enabled app contexts test for the LTTng-UST JUL log handler.
@@ -49,11 +45,7 @@ public class JulAppContextIT extends AppContextITBase {
      */
     @BeforeClass
     public static void julClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(JulTestUtils.checkForJulLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.JUL));
-
-        LttngToolsHelper.destroyAllSessions();
+        JulTestUtils.testClassSetup();
     }
 
     /**
@@ -61,7 +53,7 @@ public class JulAppContextIT extends AppContextITBase {
      */
     @AfterClass
     public static void julClassCleanup() {
-        LttngToolsHelper.deleteAllTraces();
+        JulTestUtils.testClassCleanup();
     }
 
     /**
index 5fbea4cd178ed5d44985f1d3508a6bf77f7fbfa5..530efab60f79eb0dd6d6126fecb9035ee5a2df20 100644 (file)
@@ -18,7 +18,6 @@
 
 package org.lttng.ust.agent.integration.context;
 
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
@@ -27,12 +26,11 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.jul.LttngLogHandler;
 import org.lttng.ust.agent.utils.JulTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Implementation of {@link AppContextOrderingITBase} for the JUL API.
@@ -46,11 +44,15 @@ public class JulAppContextOrderingIT extends AppContextOrderingITBase {
      */
     @BeforeClass
     public static void julClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(JulTestUtils.checkForJulLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.JUL));
+        JulTestUtils.testClassSetup();
+    }
 
-        LttngToolsHelper.destroyAllSessions();
+    /**
+     * Class cleanup
+     */
+    @AfterClass
+    public static void julClassCleanup() {
+        JulTestUtils.testClassCleanup();
     }
 
     /**
index f5aaaac76de1e2a66cbb1a5ba7db76ba6f541347..0226f7d55eb193cf4536866e5b132cee4f32c9f8 100644 (file)
@@ -18,8 +18,6 @@
 
 package org.lttng.ust.agent.integration.events;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 import java.util.logging.Handler;
 import java.util.logging.Level;
@@ -30,10 +28,8 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.jul.LttngLogHandler;
 import org.lttng.ust.agent.utils.JulTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Enabled events test for the LTTng-UST JUL log handler.
@@ -52,11 +48,7 @@ public class JulEnabledEventsIT extends EnabledEventsITBase {
      */
     @BeforeClass
     public static void julClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(JulTestUtils.checkForJulLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.JUL));
-
-        LttngToolsHelper.destroyAllSessions();
+        JulTestUtils.testClassSetup();
     }
 
     /**
@@ -64,7 +56,7 @@ public class JulEnabledEventsIT extends EnabledEventsITBase {
      */
     @AfterClass
     public static void julClassCleanup() {
-        LttngToolsHelper.deleteAllTraces();
+        JulTestUtils.testClassCleanup();
     }
 
     /**
index 88ed2abaea1da7129c2ccb74b8cb6a45d8dcc102..f7c130a325a9eae5917187c720f31571c6af61a1 100644 (file)
@@ -36,11 +36,9 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.lttng.tools.ILttngSession;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.ILttngHandler;
 import org.lttng.ust.agent.LTTngAgent;
 import org.lttng.ust.agent.utils.JulTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 import org.lttng.ust.agent.utils.TestPrintRunner;
 
 /**
@@ -65,11 +63,7 @@ public class JulLegacyApiIT {
      */
     @BeforeClass
     public static void julClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(JulTestUtils.checkForJulLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.JUL));
-
-        LttngToolsHelper.destroyAllSessions();
+        JulTestUtils.testClassSetup();
     }
 
     /**
@@ -77,7 +71,7 @@ public class JulLegacyApiIT {
      */
     @AfterClass
     public static void julClassCleanup() {
-        LttngToolsHelper.deleteAllTraces();
+        JulTestUtils.testClassCleanup();
     }
 
     /**
index 3a4cef60c62d8ae778c455996088e626fd445a0c..0c97d37ae86f91d1bfc01f679727370f916805cb 100644 (file)
 
 package org.lttng.ust.agent.integration.events;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 import java.util.logging.Handler;
 import java.util.logging.Logger;
 
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.lttng.tools.ILttngSession.Domain;
 import org.lttng.tools.ILttngSession;
-import org.lttng.tools.LttngToolsHelper;
-import org.lttng.ust.agent.integration.events.ListEventsITBase;
 import org.lttng.ust.agent.jul.LttngLogHandler;
 import org.lttng.ust.agent.utils.JulTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Test suite for the list events command for the JUL domain
@@ -44,15 +39,19 @@ public class JulListEventsIT extends ListEventsITBase {
     private Handler[] handlers;
 
     /**
-     * Test class setup
+     * Class setup
      */
     @BeforeClass
-    public static void testClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(JulTestUtils.checkForJulLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.JUL));
+    public static void julClassSetup() {
+        JulTestUtils.testClassSetup();
+    }
 
-        LttngToolsHelper.destroyAllSessions();
+    /**
+     * Class cleanup
+     */
+    @AfterClass
+    public static void julClassCleanup() {
+        JulTestUtils.testClassCleanup();
     }
 
     /**
index 4f34b1ba7093b7d0656468b86a4baeeae3de82da..0c860bbd8ace4f2e9e48b8588235d4194345c2a4 100644 (file)
@@ -18,8 +18,6 @@
 
 package org.lttng.ust.agent.integration.events;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 import java.util.logging.Handler;
 import java.util.logging.Level;
@@ -30,11 +28,8 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
-import org.lttng.ust.agent.integration.events.MultiSessionITBase;
 import org.lttng.ust.agent.jul.LttngLogHandler;
 import org.lttng.ust.agent.utils.JulTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * JUL tests for multiple concurrent tracing sessions
@@ -53,11 +48,7 @@ public class JulMultiSessionIT extends MultiSessionITBase {
      */
     @BeforeClass
     public static void julClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(JulTestUtils.checkForJulLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.JUL));
-
-        LttngToolsHelper.destroyAllSessions();
+        JulTestUtils.testClassSetup();
     }
 
     /**
@@ -65,7 +56,7 @@ public class JulMultiSessionIT extends MultiSessionITBase {
      */
     @AfterClass
     public static void julClassCleanup() {
-        LttngToolsHelper.deleteAllTraces();
+        JulTestUtils.testClassCleanup();
     }
 
     /**
index 70390a415995afcc8269e1b7ddee8d0ffd33562c..ace61de1930f1d8fbc37fb72c5eb8dfa208dc5d3 100644 (file)
 
 package org.lttng.ust.agent.integration.filter;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.lttng.tools.ILttngSession;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.ILttngHandler;
 import org.lttng.ust.agent.jul.LttngLogHandler;
 import org.lttng.ust.agent.utils.ILogLevelStrings;
 import org.lttng.ust.agent.utils.JulTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Filter notifications tests using the JUL logging API.
@@ -43,10 +40,15 @@ public class JulFilterListenerIT extends FilterListenerITBase {
      */
     @BeforeClass
     public static void julClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(JulTestUtils.checkForJulLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(ILttngSession.Domain.JUL));
-        LttngToolsHelper.destroyAllSessions();
+        JulTestUtils.testClassSetup();
+    }
+
+    /**
+     * Class cleanup
+     */
+    @AfterClass
+    public static void julClassCleanup() {
+        JulTestUtils.testClassCleanup();
     }
 
     @Override
index 4d599cd180a89554e19a4a9c44b767d1531689b0..e1145c9e6d2230d0a0b8bd99a7919b9e5d3a017d 100644 (file)
@@ -18,7 +18,6 @@
 
 package org.lttng.ust.agent.integration.filter;
 
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
@@ -26,12 +25,11 @@ import java.util.logging.Handler;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.jul.LttngLogHandler;
 import org.lttng.ust.agent.utils.JulTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Implementation of {@link FilterListenerOrderingITBase} for the JUL API.
@@ -46,11 +44,15 @@ public class JulFilterListenerOrderingIT extends FilterListenerOrderingITBase {
      */
     @BeforeClass
     public static void julClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(JulTestUtils.checkForJulLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.JUL));
+        JulTestUtils.testClassSetup();
+    }
 
-        LttngToolsHelper.destroyAllSessions();
+    /**
+     * Class cleanup
+     */
+    @AfterClass
+    public static void julClassCleanup() {
+        JulTestUtils.testClassCleanup();
     }
 
     @Override
index 400881559400087d7eb1eb956452b19532caeb9e..af90383bd45a9599eebc3d01122ecab1e15c19e7 100644 (file)
 
 package org.lttng.ust.agent.utils;
 
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.io.IOException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.lttng.tools.LttngToolsHelper;
+import org.lttng.tools.ILttngSession.Domain;
 import org.lttng.ust.agent.jul.LttngLogHandler;
 
 /**
@@ -32,20 +37,35 @@ public final class JulTestUtils {
     private JulTestUtils() {
     }
 
+    /**
+     * Setup method common to most JUL tests. To be called in a @BeforeClass.
+     */
+    public static void testClassSetup() {
+        /* Make sure we can find the JNI library and lttng-tools */
+        checkForJulLibrary();
+        assertTrue("lttng-tools is not working properly.", LttngUtils.checkForLttngTools(Domain.JUL));
+
+        LttngToolsHelper.destroyAllSessions();
+    }
+
+    /**
+     * Teardown method common to most JUL tests. To be called in a @AfterClass.
+     */
+    public static void testClassCleanup() {
+        LttngToolsHelper.deleteAllTraces();
+    }
+
     /**
      * Check the the JUL native library is available, effectively allowing LTTng
      * JUL handlers to be used.
-     *
-     * @return True if JUL works fine, false if it does not.
      */
-    public static boolean checkForJulLibrary() {
+    private static void checkForJulLibrary() {
         try {
             LttngLogHandler testHandler = new LttngLogHandler();
             testHandler.close();
         } catch (SecurityException | IOException e) {
-            return false;
+            fail(e.getMessage());
         }
-        return true;
     }
 
     /**
index 00e8b37be0b617a1905f1d06e8ec144cf0f2e110..1eea96dedf267b9302b1ce4511bc54a7d9769aec 100644 (file)
@@ -18,8 +18,6 @@
 
 package org.lttng.ust.agent.integration.context;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 
 import org.apache.log4j.Appender;
@@ -30,10 +28,8 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.log4j.LttngLogAppender;
 import org.lttng.ust.agent.utils.Log4jTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Enabled app contexts test for the LTTng-UST JUL log handler.
@@ -48,20 +44,16 @@ public class Log4jAppContextIT extends AppContextITBase {
      * Class setup
      */
     @BeforeClass
-    public static void julClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(Log4jTestUtils.checkForLog4jLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J));
-
-        LttngToolsHelper.destroyAllSessions();
+    public static void log4jClassSetup() {
+        Log4jTestUtils.testClassSetup();
     }
 
     /**
      * Class cleanup
      */
     @AfterClass
-    public static void julClassCleanup() {
-        LttngToolsHelper.deleteAllTraces();
+    public static void log4jClassCleanup() {
+        Log4jTestUtils.testClassCleanup();
     }
 
     /**
index 59b7d1bee6cd2b5276213c4704edfbfd5f05cc60..44a93a829893613b68d99b368cacb82b7d300b3e 100644 (file)
@@ -18,7 +18,6 @@
 
 package org.lttng.ust.agent.integration.context;
 
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
@@ -27,12 +26,11 @@ import org.apache.log4j.Appender;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.log4j.LttngLogAppender;
 import org.lttng.ust.agent.utils.Log4jTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Implementation of {@link AppContextOrderingITBase} for the log4j API.
@@ -46,11 +44,15 @@ public class Log4jAppContextOrderingIT extends AppContextOrderingITBase {
      */
     @BeforeClass
     public static void log4jClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(Log4jTestUtils.checkForLog4jLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J));
+        Log4jTestUtils.testClassSetup();
+    }
 
-        LttngToolsHelper.destroyAllSessions();
+    /**
+     * Class cleanup
+     */
+    @AfterClass
+    public static void log4jClassCleanup() {
+        Log4jTestUtils.testClassCleanup();
     }
 
     /**
index dcca40da005f09f749151cd9701e75a871c55390..2d73217ce7a8764cac057b5965fb6fb7a05a2e8b 100644 (file)
@@ -18,8 +18,6 @@
 
 package org.lttng.ust.agent.integration.events;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 
 import org.apache.log4j.Appender;
@@ -31,10 +29,8 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.log4j.LttngLogAppender;
 import org.lttng.ust.agent.utils.Log4jTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Enabled events test for the LTTng-UST Log4j log handler.
@@ -53,19 +49,15 @@ public class Log4jEnabledEventsIT extends EnabledEventsITBase {
      */
     @BeforeClass
     public static void log4jClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(Log4jTestUtils.checkForLog4jLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J));
-
-        LttngToolsHelper.destroyAllSessions();
+        Log4jTestUtils.testClassSetup();
     }
 
     /**
-     * Class teardown
+     * Class cleanup
      */
     @AfterClass
     public static void log4jClassCleanup() {
-        LttngToolsHelper.deleteAllTraces();
+        Log4jTestUtils.testClassCleanup();
     }
 
     /**
index af46cf4dd5c011d0c1b02b523d6911adc593700e..4cfff7b434ad61e95028b0c59d5b514f37ec1878 100644 (file)
@@ -36,11 +36,9 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.lttng.tools.ILttngSession;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.ILttngHandler;
 import org.lttng.ust.agent.LTTngAgent;
 import org.lttng.ust.agent.utils.Log4jTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 import org.lttng.ust.agent.utils.TestPrintRunner;
 
 /**
@@ -65,20 +63,16 @@ public class Log4jLegacyApiIT {
      * Class setup
      */
     @BeforeClass
-    public static void classSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(Log4jTestUtils.checkForLog4jLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J));
-
-        LttngToolsHelper.destroyAllSessions();
+    public static void log4jClassSetup() {
+        Log4jTestUtils.testClassSetup();
     }
 
     /**
      * Class cleanup
      */
     @AfterClass
-    public static void classCleanup() {
-        LttngToolsHelper.deleteAllTraces();
+    public static void log4jClassCleanup() {
+        Log4jTestUtils.testClassCleanup();
     }
 
     /**
index 885ba4b3c9b04a8198185396ae92f694ab7616dc..c7be8c84affb373f32a7cecade2b874cbdea72c4 100644 (file)
 
 package org.lttng.ust.agent.integration.events;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 
 import org.apache.log4j.Appender;
 import org.apache.log4j.Logger;
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.lttng.tools.ILttngSession.Domain;
 import org.lttng.tools.ILttngSession;
-import org.lttng.tools.LttngToolsHelper;
-import org.lttng.ust.agent.integration.events.ListEventsITBase;
 import org.lttng.ust.agent.log4j.LttngLogAppender;
 import org.lttng.ust.agent.utils.Log4jTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Test suite for the list events command for the log4j domain
@@ -44,15 +39,19 @@ public class Log4jListEventsIT extends ListEventsITBase {
     private Appender[] appenders;
 
     /**
-     * Test class setup
+     * Class setup
      */
     @BeforeClass
-    public static void testClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(Log4jTestUtils.checkForLog4jLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J));
+    public static void log4jClassSetup() {
+        Log4jTestUtils.testClassSetup();
+    }
 
-        LttngToolsHelper.destroyAllSessions();
+    /**
+     * Class cleanup
+     */
+    @AfterClass
+    public static void log4jClassCleanup() {
+        Log4jTestUtils.testClassCleanup();
     }
 
     /**
index 00e71835a7b29846059fe0ab85c439140790a76a..150260a8681711ec0257a772608ef8ccf4a5b22d 100644 (file)
@@ -18,8 +18,6 @@
 
 package org.lttng.ust.agent.integration.events;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 
 import org.apache.log4j.Appender;
@@ -30,11 +28,8 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
-import org.lttng.ust.agent.integration.events.MultiSessionITBase;
 import org.lttng.ust.agent.log4j.LttngLogAppender;
 import org.lttng.ust.agent.utils.Log4jTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Log4j tests for multiple concurrent tracing sessions
@@ -53,19 +48,15 @@ public class Log4jMultiSessionIT extends MultiSessionITBase {
      */
     @BeforeClass
     public static void log4jClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(Log4jTestUtils.checkForLog4jLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J));
-
-        LttngToolsHelper.destroyAllSessions();
+        Log4jTestUtils.testClassSetup();
     }
 
     /**
-     * Class teardown
+     * Class cleanup
      */
     @AfterClass
     public static void log4jClassCleanup() {
-        LttngToolsHelper.deleteAllTraces();
+        Log4jTestUtils.testClassCleanup();
     }
 
        /**
index 364796354b7191d7269d0af5f13b804bd021900a..abe591d30f90497a44d47828012cbbaa50e5f6f4 100644 (file)
 
 package org.lttng.ust.agent.integration.filter;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.lttng.tools.ILttngSession;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.ILttngHandler;
 import org.lttng.ust.agent.log4j.LttngLogAppender;
 import org.lttng.ust.agent.utils.ILogLevelStrings;
 import org.lttng.ust.agent.utils.Log4jTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Filter notifications tests using the log4j logging API.
@@ -43,10 +40,15 @@ public class Log4jFilterListenerIT extends FilterListenerITBase {
      */
     @BeforeClass
     public static void log4jClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(Log4jTestUtils.checkForLog4jLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(ILttngSession.Domain.LOG4J));
-        LttngToolsHelper.destroyAllSessions();
+        Log4jTestUtils.testClassSetup();
+    }
+
+    /**
+     * Class cleanup
+     */
+    @AfterClass
+    public static void log4jClassCleanup() {
+        Log4jTestUtils.testClassCleanup();
     }
 
     @Override
index 0399b71c5aa630cc22a15f23bd3f345187ae08e8..5c700dbe92dcfb80cf974c2846e254758468a53e 100644 (file)
@@ -18,7 +18,6 @@
 
 package org.lttng.ust.agent.integration.filter;
 
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
@@ -26,12 +25,11 @@ import java.io.IOException;
 import org.apache.log4j.Appender;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.lttng.tools.ILttngSession.Domain;
-import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.log4j.LttngLogAppender;
 import org.lttng.ust.agent.utils.Log4jTestUtils;
-import org.lttng.ust.agent.utils.LttngUtils;
 
 /**
  * Implementation of {@link FilterListenerOrderingITBase} for the log4j API.
@@ -45,12 +43,16 @@ public class Log4jFilterListenerOrderingIT extends FilterListenerOrderingITBase
      * Class setup
      */
     @BeforeClass
-    public static void julClassSetup() {
-        /* Make sure we can find the JNI library and lttng-tools */
-        assertTrue(Log4jTestUtils.checkForLog4jLibrary());
-        assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J));
+    public static void log4jClassSetup() {
+        Log4jTestUtils.testClassSetup();
+    }
 
-        LttngToolsHelper.destroyAllSessions();
+    /**
+     * Class cleanup
+     */
+    @AfterClass
+    public static void log4jClassCleanup() {
+        Log4jTestUtils.testClassCleanup();
     }
 
     @Override
index b356dbe21f295a74e9393665aedd81f5c9c81d18..a258e923111ad03a23eb9f7c60039adf625bb08f 100644 (file)
 
 package org.lttng.ust.agent.utils;
 
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.io.IOException;
 
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
+import org.lttng.tools.LttngToolsHelper;
+import org.lttng.tools.ILttngSession.Domain;
 import org.lttng.ust.agent.log4j.LttngLogAppender;
 
 /**
@@ -32,21 +37,35 @@ public final class Log4jTestUtils {
     private Log4jTestUtils() {
     }
 
+    /**
+     * Setup method common to most log4j tests. To be called in a @BeforeClass.
+     */
+    public static void testClassSetup() {
+        /* Make sure we can find the JNI library and lttng-tools */
+        checkForLog4jLibrary();
+        assertTrue("lttng-tools is not working properly.", LttngUtils.checkForLttngTools(Domain.LOG4J));
+
+        LttngToolsHelper.destroyAllSessions();
+    }
+
+    /**
+     * Teardown method common to most log4j tests. To be called in a @AfterClass.
+     */
+    public static void testClassCleanup() {
+        LttngToolsHelper.deleteAllTraces();
+    }
+
     /**
      * Check the the Log4j native library is available, effectively allowing
      * LTTng Log4j appenders to be used.
-     *
-     * @return True if Log4j works fine, false if it does not.
      */
-    public static boolean checkForLog4jLibrary() {
+    private static void checkForLog4jLibrary() {
         try {
             LttngLogAppender testAppender = new LttngLogAppender();
             testAppender.close();
         } catch (SecurityException | IOException e) {
-            e.printStackTrace();
-            return false;
+            fail(e.getMessage());
         }
-        return true;
     }
 
     /**
This page took 0.037776 seconds and 4 git commands to generate.