Add tests for "lttng list" when using the legacy agent
[lttng-ust-java-tests.git] / lttng-ust-java-tests-log4j / src / test / java / org / lttng / ust / agent / integration / events / Log4jLegacyApiIT.java
index e6b9a7903c40e010a7dd74e686ec43b9332ce058..50e824e9a7305a650c04dde6133c17dcec2ac1da 100644 (file)
@@ -22,9 +22,10 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
 
 import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.log4j.Level;
@@ -37,11 +38,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;
 
 /**
@@ -58,6 +57,7 @@ public class Log4jLegacyApiIT {
     private static final String EVENT_NAME_B = "EventB";
 
     private ILttngSession session;
+    private LTTngAgent agent;
 
     private Logger loggerA;
     private Logger loggerB;
@@ -66,20 +66,16 @@ public class Log4jLegacyApiIT {
      * Class setup
      */
     @BeforeClass
-    public static void classSetup() {
-        /* Skip tests if we can't find the JNI library or lttng-tools */
-        assumeTrue(Log4jTestUtils.checkForLog4jLibrary());
-        assumeTrue(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();
     }
 
     /**
@@ -88,7 +84,7 @@ public class Log4jLegacyApiIT {
     @Before
     public void setup() {
         loggerA = Logger.getLogger(EVENT_NAME_A);
-        LTTngAgent.getLTTngAgent();
+        agent = LTTngAgent.getLTTngAgent();
         loggerB = Logger.getLogger(EVENT_NAME_B);
 
         loggerA.setLevel(Level.ALL);
@@ -104,7 +100,7 @@ public class Log4jLegacyApiIT {
     public void tearDown() {
         session.close();
 
-        LTTngAgent.dispose();
+        agent.dispose();
 
         loggerA = null;
         loggerB = null;
@@ -172,6 +168,20 @@ public class Log4jLegacyApiIT {
         assertEquals(10, handler.getEventCount());
     }
 
+    /**
+     * Test that the "lttng list" commands lists the expected events.
+     */
+    @Test
+    public void testListEvents() {
+        List<String> enabledEvents = session.listEvents();
+        List<String> expectedEvents = Arrays.asList(EVENT_NAME_A, EVENT_NAME_B);
+
+        Collections.sort(enabledEvents);
+        Collections.sort(expectedEvents);
+
+        assertEquals(expectedEvents, enabledEvents);
+    }
+
     /**
      * Get the singleton Log4j Handler currently managed by the LTTngAgent. It
      * is not public, so we need reflection to access it.
@@ -184,7 +194,7 @@ public class Log4jLegacyApiIT {
             log4jAppenderField.setAccessible(true);
             return (ILttngHandler) log4jAppenderField.get(LTTngAgent.getLTTngAgent());
         } catch (ReflectiveOperationException | SecurityException e) {
-            fail();
+            fail(e.getMessage());
             return null;
         }
     }
This page took 0.023919 seconds and 4 git commands to generate.