Put common setup code in the utils classes
[lttng-ust-java-tests.git] / lttng-ust-java-tests-log4j / src / test / java / org / lttng / ust / agent / utils / Log4jTestUtils.java
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.0238 seconds and 4 git commands to generate.