From: Michael Jeanson Date: Mon, 24 Jan 2022 19:08:49 +0000 (+0000) Subject: Migrate to Junit 5 Jupiter X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=7a4f0255e3d52ad76b194fb2e83bcdc6f641549e;p=lttng-ust-java-tests.git Migrate to Junit 5 Jupiter This is mostly boilerplate stuff to move from Junit 4 to 5. The only exceptions are the TestPrintRunner which was converted to an extension and the parametrized tests that required more involved changes. Signed-off-by: Michael Jeanson --- diff --git a/lttng-tools-java/src/main/java/org/lttng/tools/LttngCommandLineSession.java b/lttng-tools-java/src/main/java/org/lttng/tools/LttngCommandLineSession.java index 3f8793b..d2867dd 100644 --- a/lttng-tools-java/src/main/java/org/lttng/tools/LttngCommandLineSession.java +++ b/lttng-tools-java/src/main/java/org/lttng/tools/LttngCommandLineSession.java @@ -143,6 +143,7 @@ class LttngCommandLineSession implements ILttngSession { .map(e -> e.trim()) .filter(e -> e.startsWith("- ")) .map(e -> e.substring(2)) + .filter(e -> !e.startsWith("org.junit")) .collect(Collectors.toList()); } diff --git a/lttng-tools-java/src/main/java/org/lttng/tools/utils/ShellUtils.java b/lttng-tools-java/src/main/java/org/lttng/tools/utils/ShellUtils.java index 112d5d4..5c45196 100644 --- a/lttng-tools-java/src/main/java/org/lttng/tools/utils/ShellUtils.java +++ b/lttng-tools-java/src/main/java/org/lttng/tools/utils/ShellUtils.java @@ -69,7 +69,7 @@ public final class ShellUtils { Process p = builder.start(); int ret = p.waitFor(); - System.out.println(String.format("(returned from command: %d)", ret)); + System.out.println(String.format("(returned from command: %d)", Integer.valueOf(ret))); return (ret == 0); diff --git a/lttng-ust-java-tests-common/pom.xml b/lttng-ust-java-tests-common/pom.xml index c72cd5c..55edc49 100644 --- a/lttng-ust-java-tests-common/pom.xml +++ b/lttng-ust-java-tests-common/pom.xml @@ -45,8 +45,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter compile diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextITBase.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextITBase.java index f7b3293..acf19bd 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextITBase.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextITBase.java @@ -18,29 +18,29 @@ package org.lttng.ust.agent.integration.context; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.context.ContextInfoManager; -import org.lttng.ust.agent.utils.TestPrintRunner; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Base abstract class to implement all sorts of integration tests verifying the * presence of enabled application contexts in resulting traces. */ -@RunWith(TestPrintRunner.class) +@ExtendWith(TestPrintExtension.class) public abstract class AppContextITBase { protected static final String EVENT_NAME = "EventName"; @@ -65,7 +65,7 @@ public abstract class AppContextITBase { /** * Base test setup */ - @Before + @BeforeEach public void testSetup() { try { cim = ContextInfoManager.getInstance(); @@ -79,7 +79,7 @@ public abstract class AppContextITBase { /** * Base test teardown */ - @After + @AfterEach public void testTeardown() { session.close(); diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextOrderingITBase.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextOrderingITBase.java index d567c18..2ced546 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextOrderingITBase.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextOrderingITBase.java @@ -18,26 +18,26 @@ package org.lttng.ust.agent.integration.context; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.List; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.lttng.tools.ILttngSession; import org.lttng.tools.LttngToolsHelper; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.context.ContextInfoManager; import org.lttng.ust.agent.context.IContextInfoRetriever; -import org.lttng.ust.agent.utils.TestPrintRunner; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * To obtain application contexts in a trace, three steps are required: @@ -51,7 +51,7 @@ import org.lttng.ust.agent.utils.TestPrintRunner; * These three steps however can occur in any order ; this means there are 6 * possible cases. The goal of this class is to test all these cases. */ -@RunWith(TestPrintRunner.class) +@ExtendWith(TestPrintExtension.class) public abstract class AppContextOrderingITBase { protected static final String EVENT_NAME = "EventName"; @@ -72,7 +72,7 @@ public abstract class AppContextOrderingITBase { /** * Base test setup */ - @Before + @BeforeEach public void testSetup() { try { cim = ContextInfoManager.getInstance(); @@ -86,7 +86,7 @@ public abstract class AppContextOrderingITBase { /** * Base test cleanup */ - @After + @AfterEach public void testCleanup() { session.close(); assertTrue(cim.unregisterContextInfoRetriever(RETRIEVER_NAME)); @@ -95,7 +95,7 @@ public abstract class AppContextOrderingITBase { /** * Base class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { LttngToolsHelper.deleteAllTraces(); } diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/EnabledEventsITBase.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/EnabledEventsITBase.java index 7a7ce36..25ebc9e 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/EnabledEventsITBase.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/EnabledEventsITBase.java @@ -18,27 +18,27 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.ILttngHandler; -import org.lttng.ust.agent.utils.TestPrintRunner; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Base abstract class to implement all sorts of integration tests verifying the * presence of enabled events in resulting traces. */ -@RunWith(TestPrintRunner.class) +@ExtendWith(TestPrintExtension.class) public abstract class EnabledEventsITBase { protected static final String EVENT_NAME_A = "EventA"; @@ -67,7 +67,7 @@ public abstract class EnabledEventsITBase { /** * Base test setup */ - @Before + @BeforeEach public void testSetup() { session = ILttngSession.createSession(null, getDomain()); } @@ -75,7 +75,7 @@ public abstract class EnabledEventsITBase { /** * Base test teardown */ - @After + @AfterEach public void testTeardown() { session.close(); diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/ListEventsITBase.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/ListEventsITBase.java index a2fa932..5551db8 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/ListEventsITBase.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/ListEventsITBase.java @@ -18,21 +18,24 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.lttng.tools.ILttngSession; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Base class for the list events command tests */ +@ExtendWith(TestPrintExtension.class) public abstract class ListEventsITBase { protected static final String LOGGER_NAME_1 = "org.lttng.somecomponent"; @@ -44,7 +47,7 @@ public abstract class ListEventsITBase { /** * Common test setup */ - @Before + @BeforeEach public void testSetup() { session = ILttngSession.createSession(null, getDomain()); } @@ -52,7 +55,7 @@ public abstract class ListEventsITBase { /** * Common test teardown */ - @After + @AfterEach public void testTeardown() { session.close(); } diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/LoggerHierachyListITBase.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/LoggerHierachyListITBase.java index 5e1af16..dae031a 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/LoggerHierachyListITBase.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/LoggerHierachyListITBase.java @@ -18,19 +18,22 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runners.Parameterized.Parameters; +import java.util.stream.Stream; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.lttng.tools.ILttngSession; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Base class testing the "lttng list" command when using loggers organized as a @@ -43,16 +46,12 @@ import org.lttng.tools.ILttngSession; * * @author Alexandre Montplaisir */ +@ExtendWith(TestPrintExtension.class) public abstract class LoggerHierachyListITBase { protected static final String PARENT_LOGGER = "org.lttng"; protected static final String CHILD_LOGGER = "org.lttng.mycomponent"; - protected final boolean parentLoggerActive; - protected final boolean parentLoggerHasHandler; - protected final boolean childLoggerActive; - protected final boolean childLoggerHasHandler; - private ILttngSession session; // ------------------------------------------------------------------------ @@ -66,41 +65,6 @@ public abstract class LoggerHierachyListITBase { * except "parentActive" is necessarily true when "hasHandler" is true for a * given logger. * - * @return The test parameters - */ - @Parameters(name = "{index}: parentActive={0}, parentHasHandler={1}, childActive={2}, childHasHandler={3}") - public static Iterable testCases() { - /* - * Kept the whole array for clarity, but some cases are commented out: - * it is impossible to attach an handler if the logger itself is not - * defined! - */ - return Arrays.asList(new Object[][] { - { Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE }, - { Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE }, -// { Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE }, - { Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE }, - - { Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE }, - { Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE }, -// { Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE }, - { Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE }, - -// { Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE }, -// { Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE }, -// { Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE }, -// { Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE }, - - { Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE }, - { Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE }, -// { Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE }, - { Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE }, - }); - } - - /** - * Test constructor - * * @param parentLoggerActive * Parent logger has been instantiated * @param parentLoggerHasHandler @@ -109,15 +73,37 @@ public abstract class LoggerHierachyListITBase { * Child logger has been instantiated * @param childLoggerHasHandler * Child logger has a LTTng handler attached to it + * + * @return The test parameters */ - public LoggerHierachyListITBase(boolean parentLoggerActive, - boolean parentLoggerHasHandler, - boolean childLoggerActive, - boolean childLoggerHasHandler) { - this.parentLoggerActive = parentLoggerActive; - this.parentLoggerHasHandler = parentLoggerHasHandler; - this.childLoggerActive = childLoggerActive; - this.childLoggerHasHandler = childLoggerHasHandler; + protected static Stream provideArguments() { + + /* + * Kept the whole array for clarity, but some cases are commented out: + * it is impossible to attach an handler if the logger itself is not + * defined! + */ + return Stream.of( + Arguments.of( Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE ), + Arguments.of( Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE ), +// Arguments.of( Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE ), + Arguments.of( Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE ), + + Arguments.of( Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE ), + Arguments.of( Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE ), +// Arguments.of( Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE ), + Arguments.of( Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE ), + +// Arguments.of( Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE ), +// Arguments.of( Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE ), +// Arguments.of( Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE ), +// Arguments.of( Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE ), + + Arguments.of( Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE ), + Arguments.of( Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE ), +// Arguments.of( Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE ), + Arguments.of( Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE ) + ); } protected ILttngSession getSession() { @@ -131,7 +117,7 @@ public abstract class LoggerHierachyListITBase { /** * Common test setup */ - @Before + @BeforeEach public void testSetup() { session = ILttngSession.createSession(null, getDomain()); } @@ -139,7 +125,7 @@ public abstract class LoggerHierachyListITBase { /** * Common test teardown */ - @After + @AfterEach public void testTeardown() { session.close(); } @@ -150,7 +136,10 @@ public abstract class LoggerHierachyListITBase { protected abstract ILttngSession.Domain getDomain(); - protected abstract void activateLoggers() throws IOException; + protected abstract void activateLoggers(boolean parentLoggerActive, + boolean parentLoggerHasHandler, + boolean childLoggerActive, + boolean childLoggerHasHandler) throws IOException; // ------------------------------------------------------------------------ // Common tests @@ -159,12 +148,29 @@ public abstract class LoggerHierachyListITBase { /** * Test the output of the "lttng list" command. * + * @param parentLoggerActive + * Parent logger has been instantiated + * @param parentLoggerHasHandler + * Parent logger has a LTTng handler attached to it + * @param childLoggerActive + * Child logger has been instantiated + * @param childLoggerHasHandler + * Child logger has a LTTng handler attached to it + * * @throws IOException * Fails the test */ - @Test - public void testList() throws IOException { - activateLoggers(); + @ParameterizedTest + @MethodSource("provideArguments") + public void testList(boolean parentLoggerActive, + boolean parentLoggerHasHandler, + boolean childLoggerActive, + boolean childLoggerHasHandler) throws IOException { + + activateLoggers(parentLoggerActive, + parentLoggerHasHandler, + childLoggerActive, + childLoggerHasHandler); List enabledEvents = session.listEvents(); List expectedEvents = new ArrayList<>(); diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/MultiSessionITBase.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/MultiSessionITBase.java index bc75961..930b5f9 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/MultiSessionITBase.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/MultiSessionITBase.java @@ -18,25 +18,25 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.ILttngHandler; -import org.lttng.ust.agent.utils.TestPrintRunner; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Base abstract class for tests with multiple concurrent tracing sessions */ -@RunWith(TestPrintRunner.class) +@ExtendWith(TestPrintExtension.class) public abstract class MultiSessionITBase { protected static final String EVENT_NAME_A = "EventA"; @@ -63,7 +63,7 @@ public abstract class MultiSessionITBase { /** * Base test setup */ - @Before + @BeforeEach public void testSetup() { session1 = ILttngSession.createSession(null, getDomain()); session2 = ILttngSession.createSession(null, getDomain()); @@ -73,7 +73,7 @@ public abstract class MultiSessionITBase { /** * Base test teardown */ - @After + @AfterEach public void testTeardown() { session1.close(); session2.close(); diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/filter/FilterListenerITBase.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/filter/FilterListenerITBase.java index dddcaee..7712b46 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/filter/FilterListenerITBase.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/filter/FilterListenerITBase.java @@ -18,7 +18,7 @@ package org.lttng.ust.agent.integration.filter; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.Collections; @@ -27,10 +27,10 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.filter.FilterChangeNotifier; @@ -40,14 +40,14 @@ import org.lttng.ust.agent.session.LogLevelSelector; import org.lttng.ust.agent.session.LogLevelSelector.LogLevelType; import org.lttng.ust.agent.utils.EventRuleFactory; import org.lttng.ust.agent.utils.ILogLevelStrings; -import org.lttng.ust.agent.utils.TestPrintRunner; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Base test class for {@link IFilterChangeListener} tests. * * @author Alexandre Montplaisir */ -@RunWith(TestPrintRunner.class) +@ExtendWith(TestPrintExtension.class) public abstract class FilterListenerITBase { private static final String EVENT_NAME_A = "eventA"; @@ -68,7 +68,7 @@ public abstract class FilterListenerITBase { * @throws SecurityException * @throws IOException */ - @Before + @BeforeEach public void setup() throws SecurityException, IOException { handler = getLogHandler(); listener = new TestFilterListener(); @@ -81,7 +81,7 @@ public abstract class FilterListenerITBase { /** * Test teardown */ - @After + @AfterEach public void teardown() { session.close(); FilterChangeNotifier.getInstance().unregisterListener(listener); diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/filter/FilterListenerOrderingITBase.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/filter/FilterListenerOrderingITBase.java index c226d45..4e344e0 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/filter/FilterListenerOrderingITBase.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/filter/FilterListenerOrderingITBase.java @@ -18,20 +18,22 @@ package org.lttng.ust.agent.integration.filter; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.AfterEach; import org.lttng.tools.ILttngSession; import org.lttng.ust.agent.filter.FilterChangeNotifier; import org.lttng.ust.agent.integration.filter.FilterListenerITBase.TestFilterListener; import org.lttng.ust.agent.session.EventRule; import org.lttng.ust.agent.utils.EventRuleFactory; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * For the filter change notifications to work, several setup steps are @@ -65,6 +67,7 @@ import org.lttng.ust.agent.utils.EventRuleFactory; * possibilities. *

*/ +@ExtendWith(TestPrintExtension.class) @SuppressWarnings("javadoc") public abstract class FilterListenerOrderingITBase { @@ -77,7 +80,7 @@ public abstract class FilterListenerOrderingITBase { /** * Base class cleanup */ - @After + @AfterEach public void baseTeardown() { /* * Deregister the listener (should always be done after all the other diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/utils/TestPrintExtension.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/utils/TestPrintExtension.java new file mode 100644 index 0000000..772d1ed --- /dev/null +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/utils/TestPrintExtension.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2022, EfficiOS Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.lttng.ust.agent.utils; + +import java.util.Optional; + +import org.junit.jupiter.api.extension.AfterTestExecutionCallback; +import org.junit.jupiter.api.extension.BeforeTestExecutionCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.ExtensionContext.Namespace; +import org.junit.jupiter.api.extension.ExtensionContext.Store; +import org.junit.jupiter.api.extension.TestWatcher; + +/** + * Test extension that will print the name of the test being run to stdout. + */ +public class TestPrintExtension implements BeforeTestExecutionCallback, AfterTestExecutionCallback, TestWatcher { + + private static final String START_TIME = "start time"; + + + @Override + public void beforeTestExecution(ExtensionContext context) throws Exception { + System.out.println("\nStarted " + context.getDisplayName() + "\n"); + getStore(context).put(START_TIME, Long.valueOf(System.currentTimeMillis())); + } + + @Override + public void afterTestExecution(ExtensionContext context) throws Exception { + long startTime = getStore(context).remove(START_TIME, long.class).longValue(); + long duration = System.currentTimeMillis() - startTime; + + System.out.println("\nEnded " + context.getDisplayName() + " in " + duration + " ms\n"); + } + + @Override + public void testDisabled(ExtensionContext context, Optional reason) { + System.out.println("\nSKIPPING TEST: " + context.getDisplayName() + "\n"); + } + + private Store getStore(ExtensionContext context) { + return context.getStore(Namespace.create(getClass(), context.getRequiredTestMethod())); + } +} \ No newline at end of file diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/utils/TestPrintRunner.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/utils/TestPrintRunner.java deleted file mode 100644 index 1285984..0000000 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/utils/TestPrintRunner.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.lttng.ust.agent.utils; - -import org.junit.runner.Description; -import org.junit.runner.notification.Failure; -import org.junit.runner.notification.RunListener; -import org.junit.runner.notification.RunNotifier; -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.InitializationError; - -/** - * Test runner that will print the name of the test being run to stdout. - * - * Thanks to http://stackoverflow.com/a/27070843/4227853 for the tips. - * - * @author Alexandre Montplaisir - */ -public class TestPrintRunner extends BlockJUnit4ClassRunner { - - /** - * Constructor - * - * @param klass - * @throws InitializationError - */ - public TestPrintRunner(Class klass) throws InitializationError { - super(klass); - } - - @Override - public void run(RunNotifier notifier) { - RunListener listener = new TestPrintListener(); - - notifier.addListener(listener); - super.run(notifier); - notifier.removeListener(listener); - } - - /** - * Listener that will print the class and test name to stdout. - */ - public static class TestPrintListener extends RunListener { - - @Override - public void testStarted(Description description) { - System.out.println("Running " + getTestName(description)); - } - - @Override - public void testAssumptionFailure(Failure failure) { - System.out.println("SKIPPING TEST: " + getTestName(failure.getDescription())); - System.out.println(failure.getMessage()); - } - - /** - * Get the className#methodName from a Description. - */ - private static String getTestName(Description description) { - return description.getClassName() + '#' + description.getMethodName(); - } - } - -} diff --git a/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/context/ContextRegistrationIT.java b/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/context/ContextRegistrationIT.java index 10327b0..6174d94 100644 --- a/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/context/ContextRegistrationIT.java +++ b/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/context/ContextRegistrationIT.java @@ -18,25 +18,25 @@ package org.lttng.ust.agent.context; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.lttng.ust.agent.utils.TestPrintRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.BeforeEach; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Generic tests related to the context retrieval mechanisms. * * @author Alexandre Montplaisir */ -@RunWith(TestPrintRunner.class) +@ExtendWith(TestPrintExtension.class) public class ContextRegistrationIT { private ContextInfoManager mgr; @@ -44,7 +44,7 @@ public class ContextRegistrationIT { /** * Test setup */ - @Before + @BeforeEach public void testSetup() { try { mgr = ContextInfoManager.getInstance(); diff --git a/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/integration/client/TcpClientIT.java b/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/integration/client/TcpClientIT.java index 8f3750b..0c0af7d 100644 --- a/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/integration/client/TcpClientIT.java +++ b/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/integration/client/TcpClientIT.java @@ -18,21 +18,21 @@ package org.lttng.ust.agent.integration.client; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession; import org.lttng.tools.LttngToolsHelper; import org.lttng.ust.agent.ILttngAgent; @@ -42,7 +42,7 @@ import org.lttng.ust.agent.session.LogLevelSelector; import org.lttng.ust.agent.session.LogLevelSelector.LogLevelType; import org.lttng.ust.agent.utils.EventRuleFactory; import org.lttng.ust.agent.utils.ILogLevelStrings; -import org.lttng.ust.agent.utils.TestPrintRunner; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Tests for the TCP client only, without using an agent. @@ -53,7 +53,7 @@ import org.lttng.ust.agent.utils.TestPrintRunner; * * @author Alexandre Montplaisir */ -@RunWith(TestPrintRunner.class) +@ExtendWith(TestPrintExtension.class) public class TcpClientIT { // ------------------------------------------------------------------------ @@ -86,7 +86,7 @@ public class TcpClientIT { /** * Class setup */ - @BeforeClass + @BeforeAll public static void setupClass() { LttngToolsHelper.destroyAllSessions(); @@ -113,13 +113,13 @@ public class TcpClientIT { clientThread = new Thread(client); clientThread.start(); - assertTrue("Timed out waiting for a sessiond", client.waitForConnection(5)); + assertTrue(client.waitForConnection(5), "Timed out waiting for a sessiond"); } /** * Class teardown */ - @AfterClass + @AfterAll public static void teardownClass() { if (client != null) { client.close(); @@ -135,7 +135,7 @@ public class TcpClientIT { /** * Test setup */ - @Before + @BeforeEach public void setup() { session = ILttngSession.createSession(null, SESSION_DOMAIN); clientListener.clearAllCommands(); @@ -144,7 +144,7 @@ public class TcpClientIT { /** * Test teardown */ - @After + @AfterEach public void teardown() { session.close(); } diff --git a/lttng-ust-java-tests-jul/.classpath b/lttng-ust-java-tests-jul/.classpath index 2d5eac0..3b348b7 100644 --- a/lttng-ust-java-tests-jul/.classpath +++ b/lttng-ust-java-tests-jul/.classpath @@ -24,6 +24,6 @@ - + diff --git a/lttng-ust-java-tests-jul/pom.xml b/lttng-ust-java-tests-jul/pom.xml index b33a1a7..3a23540 100644 --- a/lttng-ust-java-tests-jul/pom.xml +++ b/lttng-ust-java-tests-jul/pom.xml @@ -51,8 +51,9 @@ lttng-ust-java-tests-common
- junit - junit + org.junit.jupiter + junit-jupiter + test diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/JulHandlerBenchmarkBase.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/JulHandlerBenchmarkBase.java index 201ff83..45324a2 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/JulHandlerBenchmarkBase.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/JulHandlerBenchmarkBase.java @@ -24,14 +24,17 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Base abstract class for JUL benchmarks. Sub-classes can setup parameters to * test different types of log handlers. */ +@ExtendWith(TestPrintExtension.class) public abstract class JulHandlerBenchmarkBase { // ------------------------------------------------------------------------ @@ -61,7 +64,7 @@ public abstract class JulHandlerBenchmarkBase { /** * Base test setup */ - @Before + @BeforeEach public void setup() { /* Set up the logger */ logger = Logger.getLogger("Test logger"); @@ -74,7 +77,7 @@ public abstract class JulHandlerBenchmarkBase { /** * Base test teardown */ - @After + @AfterEach public void teardown() { if (handler != null) { logger.removeHandler(handler); diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/DummyHandlerBenchmark.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/DummyHandlerBenchmark.java index 44a5290..c3b8953 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/DummyHandlerBenchmark.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/DummyHandlerBenchmark.java @@ -21,7 +21,7 @@ package org.lttng.ust.agent.benchmarks.jul.handler.builtin; import java.util.logging.Handler; import java.util.logging.LogRecord; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; /** @@ -33,7 +33,7 @@ public class DummyHandlerBenchmark extends JulHandlerBenchmarkBase { /** * Test setup */ - @Before + @BeforeEach public void testSetup() { handler = new DummyHandler(); } diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/FileHandlerBenchmark.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/FileHandlerBenchmark.java index af4ab7c..5437754 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/FileHandlerBenchmark.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/FileHandlerBenchmark.java @@ -24,8 +24,8 @@ import java.nio.file.Path; import java.util.logging.FileHandler; import java.util.logging.SimpleFormatter; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; /** @@ -43,7 +43,7 @@ public class FileHandlerBenchmark extends JulHandlerBenchmarkBase { * @throws IOException * If there is problem setting up the handler */ - @Before + @BeforeEach public void testSetup() throws SecurityException, IOException { outputFile = Files.createTempFile(this.getClass().getSimpleName(), null); @@ -57,7 +57,7 @@ public class FileHandlerBenchmark extends JulHandlerBenchmarkBase { * @throws IOException * If we could not delete the test file */ - @After + @AfterEach public void testTeardown() throws IOException { Files.deleteIfExists(outputFile); } diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/NoLoggerBenchmark.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/NoLoggerBenchmark.java index ffa5726..fc16618 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/NoLoggerBenchmark.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/NoLoggerBenchmark.java @@ -18,8 +18,8 @@ package org.lttng.ust.agent.benchmarks.jul.handler.builtin; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; /** @@ -32,7 +32,7 @@ public class NoLoggerBenchmark extends JulHandlerBenchmarkBase { * Override the super class's setup() to avoid creating a Logger. */ @Override - @Before + @BeforeEach public void setup() { logger = null; handler = null; @@ -42,7 +42,7 @@ public class NoLoggerBenchmark extends JulHandlerBenchmarkBase { * Override the super class's teardown() */ @Override - @After + @AfterEach public void teardown() { } } diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java index d0e514c..df7eca3 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java @@ -18,12 +18,12 @@ package org.lttng.ust.agent.benchmarks.jul.handler.lttng; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; @@ -42,7 +42,7 @@ public class LttngJulHandlerTracingDisabledBenchmark extends JulHandlerBenchmark * * @throws IOException */ - @Before + @BeforeEach public void testSetup() throws IOException { handler = new LttngLogHandler(); @@ -54,7 +54,7 @@ public class LttngJulHandlerTracingDisabledBenchmark extends JulHandlerBenchmark /** * Test cleanup */ - @After + @AfterEach public void testTeardown() { assertTrue(session.stop()); session.close(); diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java index c594de4..bdddeda 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java @@ -18,12 +18,12 @@ package org.lttng.ust.agent.benchmarks.jul.handler.lttng; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; @@ -41,7 +41,7 @@ public class LttngJulHandlerTracingEnabledBenchmark extends JulHandlerBenchmarkB * * @throws IOException */ - @Before + @BeforeEach public void testSetup() throws IOException { handler = new LttngLogHandler(); @@ -53,7 +53,7 @@ public class LttngJulHandlerTracingEnabledBenchmark extends JulHandlerBenchmarkB /** * Test cleanup */ - @After + @AfterEach public void testTeardown() { assertTrue(session.stop()); session.close(); diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java index 49a7c83..17c67e0 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java @@ -18,10 +18,10 @@ package org.lttng.ust.agent.benchmarks.jul.handler.lttng.old; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.LTTngAgent; @@ -40,7 +40,7 @@ public class OldLttngJulHandlerTracingDisabledBenchmark extends JulHandlerBenchm /** * Test setup */ - @Before + @BeforeEach public void testSetup() { agent = LTTngAgent.getLTTngAgent(); @@ -52,7 +52,7 @@ public class OldLttngJulHandlerTracingDisabledBenchmark extends JulHandlerBenchm /** * Test cleanup */ - @After + @AfterEach public void testTeardown() { assertTrue(session.stop()); session.close(); diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java index e18efdc..a9985c4 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java @@ -18,13 +18,13 @@ package org.lttng.ust.agent.benchmarks.jul.handler.lttng.old; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.lang.reflect.Field; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.LTTngAgent; @@ -46,7 +46,7 @@ public class OldLttngJulHandlerTracingEnabledBenchmark extends JulHandlerBenchma /** * Test setup */ - @Before + @BeforeEach public void testSetup() { agent = LTTngAgent.getLTTngAgent(); @@ -78,7 +78,7 @@ public class OldLttngJulHandlerTracingEnabledBenchmark extends JulHandlerBenchma /** * Test cleanup */ - @After + @AfterEach public void testTeardown() { assertTrue(session.stop()); session.close(); diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextIT.java index 56e8d56..b5735f2 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextIT.java @@ -23,10 +23,10 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; @@ -43,7 +43,7 @@ public class JulAppContextIT extends AppContextITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void julClassSetup() { JulTestUtils.testClassSetup(); } @@ -51,7 +51,7 @@ public class JulAppContextIT extends AppContextITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { JulTestUtils.testClassCleanup(); } @@ -62,7 +62,7 @@ public class JulAppContextIT extends AppContextITBase { * @throws SecurityException * @throws IOException */ - @Before + @BeforeEach public void julSetup() throws SecurityException, IOException { logger = Logger.getLogger(EVENT_NAME); logger.setLevel(Level.ALL); @@ -74,7 +74,7 @@ public class JulAppContextIT extends AppContextITBase { /** * Test teardown */ - @After + @AfterEach public void julTeardown() { logger.removeHandler((Handler) logHandler); logger = null; diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextOrderingIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextOrderingIT.java index 530efab..1b488a4 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextOrderingIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/context/JulAppContextOrderingIT.java @@ -18,16 +18,16 @@ package org.lttng.ust.agent.integration.context; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; @@ -42,7 +42,7 @@ public class JulAppContextOrderingIT extends AppContextOrderingITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void julClassSetup() { JulTestUtils.testClassSetup(); } @@ -50,7 +50,7 @@ public class JulAppContextOrderingIT extends AppContextOrderingITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { JulTestUtils.testClassCleanup(); } @@ -58,7 +58,7 @@ public class JulAppContextOrderingIT extends AppContextOrderingITBase { /** * Test teardown */ - @After + @AfterEach public void julTeardown() { logger.removeHandler((Handler) logHandler); logger = null; diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulEnabledEventsIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulEnabledEventsIT.java index 0cfe860..02c1c74 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulEnabledEventsIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulEnabledEventsIT.java @@ -23,10 +23,10 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; @@ -46,7 +46,7 @@ public class JulEnabledEventsIT extends EnabledEventsITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void julClassSetup() { JulTestUtils.testClassSetup(); } @@ -54,7 +54,7 @@ public class JulEnabledEventsIT extends EnabledEventsITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { JulTestUtils.testClassCleanup(); } @@ -65,7 +65,7 @@ public class JulEnabledEventsIT extends EnabledEventsITBase { * @throws SecurityException * @throws IOException */ - @Before + @BeforeEach public void julSetup() throws SecurityException, IOException { loggerA = Logger.getLogger(EVENT_NAME_A); loggerB = Logger.getLogger(EVENT_NAME_B); @@ -89,7 +89,7 @@ public class JulEnabledEventsIT extends EnabledEventsITBase { /** * Test teardown */ - @After + @AfterEach public void julTeardown() { loggerA.removeHandler((Handler) handlerA); loggerB.removeHandler((Handler) handlerB); diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java index 97ba4b6..7b993f3 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiIT.java @@ -18,10 +18,10 @@ package org.lttng.ust.agent.integration.events; -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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.lang.reflect.Field; import java.util.Arrays; @@ -31,23 +31,23 @@ import java.util.logging.Level; import java.util.logging.LogManager; import java.util.logging.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; 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.TestPrintRunner; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Enabled events test for the LTTng-UST JUL log handler, using the legacy API. */ -@RunWith(TestPrintRunner.class) +@ExtendWith(TestPrintExtension.class) @SuppressWarnings("deprecation") public class JulLegacyApiIT { @@ -65,7 +65,7 @@ public class JulLegacyApiIT { /** * Class setup */ - @BeforeClass + @BeforeAll public static void julClassSetup() { JulTestUtils.testClassSetup(); } @@ -73,7 +73,7 @@ public class JulLegacyApiIT { /** * Class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { JulTestUtils.testClassCleanup(); } @@ -81,7 +81,7 @@ public class JulLegacyApiIT { /** * Test setup */ - @Before + @BeforeEach public void setup() { /* Clear the JUL logger configuration */ LogManager.getLogManager().reset(); @@ -100,7 +100,7 @@ public class JulLegacyApiIT { /** * Test cleanup */ - @After + @AfterEach public void tearDown() { session.close(); diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiLoggerHierarchyListIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiLoggerHierarchyListIT.java index a9ecf8c..ed8a08d 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiLoggerHierarchyListIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLegacyApiLoggerHierarchyListIT.java @@ -18,7 +18,7 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.ArrayList; @@ -27,13 +27,12 @@ import java.util.List; import java.util.logging.LogManager; import java.util.logging.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.LTTngAgent; import org.lttng.ust.agent.utils.JulTestUtils; @@ -45,36 +44,13 @@ import org.lttng.ust.agent.utils.JulTestUtils; * @author Alexandre Montplaisir */ @SuppressWarnings("deprecation") -@RunWith(Parameterized.class) +//@RunWith(Parameterized.class) public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase { private LTTngAgent agent; private Logger parentLogger; private Logger childLogger; - /** - * Test constructor - * - * @param parentLoggerActive - * Parent logger has been instantiated - * @param parentLoggerHasHandler - * Parent logger has a LTTng handler attached to it - * @param childLoggerActive - * Child logger has been instantiated - * @param childLoggerHasHandler - * Child logger has a LTTng handler attached to it - */ - public JulLegacyApiLoggerHierarchyListIT(boolean parentLoggerActive, - boolean parentLoggerHasHandler, - boolean childLoggerActive, - boolean childLoggerHasHandler) { - /* Set by parameters defined in the base class */ - super(parentLoggerActive, - parentLoggerHasHandler, - childLoggerActive, - childLoggerHasHandler); - } - // ------------------------------------------------------------------------ // Maintenance // ------------------------------------------------------------------------ @@ -82,7 +58,7 @@ public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase /** * Class setup */ - @BeforeClass + @BeforeAll public static void julClassSetup() { JulTestUtils.testClassSetup(); } @@ -90,7 +66,7 @@ public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase /** * Class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { JulTestUtils.testClassCleanup(); } @@ -99,7 +75,7 @@ public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase * Test setup */ @SuppressWarnings("static-method") - @Before + @BeforeEach public void setup() { LogManager.getLogManager().reset(); System.gc(); @@ -108,7 +84,7 @@ public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase /** * Test cleanup */ - @After + @AfterEach public void cleanup() { agent.dispose(); @@ -134,7 +110,10 @@ public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase } @Override - protected void activateLoggers() throws IOException { + protected void activateLoggers(boolean parentLoggerActive, + boolean parentLoggerHasHandler, + boolean childLoggerActive, + boolean childLoggerHasHandler) throws IOException { agent = LTTngAgent.getLTTngAgent(); /* @@ -161,10 +140,19 @@ public class JulLegacyApiLoggerHierarchyListIT extends LoggerHierachyListITBase * the logger exists, it will be visible in "lttng list" because the single * log handler is attached to the root logger. */ + @SuppressWarnings("resource") @Override - @Test - public void testList() throws IOException { - activateLoggers(); + @ParameterizedTest + @MethodSource("provideArguments") + public void testList(boolean parentLoggerActive, + boolean parentLoggerHasHandler, + boolean childLoggerActive, + boolean childLoggerHasHandler) throws IOException { + + activateLoggers(parentLoggerActive, + parentLoggerHasHandler, + childLoggerActive, + childLoggerHasHandler); List enabledEvents = getSession().listEvents(); List expectedEvents = new ArrayList<>(); diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulListEventsIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulListEventsIT.java index dbd5c33..f3e2b1f 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulListEventsIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulListEventsIT.java @@ -23,10 +23,10 @@ import java.util.logging.Handler; import java.util.logging.LogManager; import java.util.logging.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; @@ -42,7 +42,7 @@ public class JulListEventsIT extends ListEventsITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void julClassSetup() { JulTestUtils.testClassSetup(); } @@ -50,7 +50,7 @@ public class JulListEventsIT extends ListEventsITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { JulTestUtils.testClassCleanup(); } @@ -61,7 +61,7 @@ public class JulListEventsIT extends ListEventsITBase { * @throws SecurityException * @throws IOException */ - @Before + @BeforeEach public void julSetup() throws SecurityException, IOException { /* Clear the JUL logger configuration */ LogManager.getLogManager().reset(); @@ -82,7 +82,7 @@ public class JulListEventsIT extends ListEventsITBase { /** * Test teardown. Detach and close all log handlers. */ - @After + @AfterEach public void julTeardown() { for (Logger logger : loggers) { for (Handler handler : handlers) { diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLoggerHierarchyListIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLoggerHierarchyListIT.java index 531309a..0d588bf 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLoggerHierarchyListIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulLoggerHierarchyListIT.java @@ -23,12 +23,10 @@ import java.util.logging.Handler; import java.util.logging.LogManager; import java.util.logging.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; @@ -38,7 +36,6 @@ import org.lttng.ust.agent.utils.JulTestUtils; * * @author Alexandre Montplaisir */ -@RunWith(Parameterized.class) public class JulLoggerHierarchyListIT extends LoggerHierachyListITBase { private Logger parentLogger; @@ -47,29 +44,6 @@ public class JulLoggerHierarchyListIT extends LoggerHierachyListITBase { private Handler parentHandler; private Handler childHandler; - /** - * Test constructor - * - * @param parentLoggerActive - * Parent logger has been instantiated - * @param parentLoggerHasHandler - * Parent logger has a LTTng handler attached to it - * @param childLoggerActive - * Child logger has been instantiated - * @param childLoggerHasHandler - * Child logger has a LTTng handler attached to it - */ - public JulLoggerHierarchyListIT(boolean parentLoggerActive, - boolean parentLoggerHasHandler, - boolean childLoggerActive, - boolean childLoggerHasHandler) { - /* Set by parameters defined in the base class */ - super(parentLoggerActive, - parentLoggerHasHandler, - childLoggerActive, - childLoggerHasHandler); - } - // ------------------------------------------------------------------------ // Maintenance // ------------------------------------------------------------------------ @@ -77,7 +51,7 @@ public class JulLoggerHierarchyListIT extends LoggerHierachyListITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void julClassSetup() { JulTestUtils.testClassSetup(); } @@ -85,7 +59,7 @@ public class JulLoggerHierarchyListIT extends LoggerHierachyListITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { JulTestUtils.testClassCleanup(); } @@ -94,7 +68,7 @@ public class JulLoggerHierarchyListIT extends LoggerHierachyListITBase { * Test setup */ @SuppressWarnings("static-method") - @Before + @BeforeEach public void setup() { /* * Kind of hackish, but it's the only way to ensure that loggers are @@ -109,7 +83,7 @@ public class JulLoggerHierarchyListIT extends LoggerHierachyListITBase { /** * Test cleanup */ - @After + @AfterEach public void cleanup() { if (parentLogger != null) { if (parentHandler != null) { @@ -143,7 +117,10 @@ public class JulLoggerHierarchyListIT extends LoggerHierachyListITBase { } @Override - protected void activateLoggers() throws IOException { + protected void activateLoggers(boolean parentLoggerActive, + boolean parentLoggerHasHandler, + boolean childLoggerActive, + boolean childLoggerHasHandler) throws IOException { if (parentLoggerActive) { parentLogger = Logger.getLogger(PARENT_LOGGER); if (parentLoggerHasHandler) { diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulMultiSessionIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulMultiSessionIT.java index 5ab9bf0..633f8f0 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulMultiSessionIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulMultiSessionIT.java @@ -23,10 +23,10 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; @@ -46,7 +46,7 @@ public class JulMultiSessionIT extends MultiSessionITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void julClassSetup() { JulTestUtils.testClassSetup(); } @@ -54,7 +54,7 @@ public class JulMultiSessionIT extends MultiSessionITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { JulTestUtils.testClassCleanup(); } @@ -65,7 +65,7 @@ public class JulMultiSessionIT extends MultiSessionITBase { * @throws SecurityException * @throws IOException */ - @Before + @BeforeEach public void julSetup() throws SecurityException, IOException { loggerA = Logger.getLogger(EVENT_NAME_A); loggerB = Logger.getLogger(EVENT_NAME_B); @@ -91,7 +91,7 @@ public class JulMultiSessionIT extends MultiSessionITBase { /** * Test teardown */ - @After + @AfterEach public void julTeardown() { loggerA.removeHandler((Handler) handlerA); loggerB.removeHandler((Handler) handlerB); diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerIT.java index ace61de..04f04ec 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerIT.java @@ -20,8 +20,8 @@ package org.lttng.ust.agent.integration.filter; import java.io.IOException; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.lttng.tools.ILttngSession; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.jul.LttngLogHandler; @@ -38,7 +38,7 @@ public class JulFilterListenerIT extends FilterListenerITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void julClassSetup() { JulTestUtils.testClassSetup(); } @@ -46,7 +46,7 @@ public class JulFilterListenerIT extends FilterListenerITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { JulTestUtils.testClassCleanup(); } diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerOrderingIT.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerOrderingIT.java index e1145c9..5964c97 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerOrderingIT.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/filter/JulFilterListenerOrderingIT.java @@ -18,15 +18,15 @@ package org.lttng.ust.agent.integration.filter; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; @@ -42,7 +42,7 @@ public class JulFilterListenerOrderingIT extends FilterListenerOrderingITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void julClassSetup() { JulTestUtils.testClassSetup(); } @@ -50,7 +50,7 @@ public class JulFilterListenerOrderingIT extends FilterListenerOrderingITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void julClassCleanup() { JulTestUtils.testClassCleanup(); } diff --git a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/utils/JulTestUtils.java b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/utils/JulTestUtils.java index af90383..ed54927 100644 --- a/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/utils/JulTestUtils.java +++ b/lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/utils/JulTestUtils.java @@ -18,8 +18,8 @@ package org.lttng.ust.agent.utils; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.logging.Level; @@ -43,7 +43,7 @@ public final class JulTestUtils { 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)); + assertTrue(LttngUtils.checkForLttngTools(Domain.JUL), "lttng-tools is not working properly."); LttngToolsHelper.destroyAllSessions(); } diff --git a/lttng-ust-java-tests-log4j/.classpath b/lttng-ust-java-tests-log4j/.classpath index 3d72c56..73e8bfa 100644 --- a/lttng-ust-java-tests-log4j/.classpath +++ b/lttng-ust-java-tests-log4j/.classpath @@ -24,6 +24,6 @@ - + diff --git a/lttng-ust-java-tests-log4j/pom.xml b/lttng-ust-java-tests-log4j/pom.xml index 016befa..81c31b8 100644 --- a/lttng-ust-java-tests-log4j/pom.xml +++ b/lttng-ust-java-tests-log4j/pom.xml @@ -55,8 +55,9 @@ log4j - junit - junit + org.junit.jupiter + junit-jupiter + test diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextIT.java index 162d13e..c7670ea 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextIT.java @@ -23,10 +23,10 @@ import java.io.IOException; 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.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; @@ -43,7 +43,7 @@ public class Log4jAppContextIT extends AppContextITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4jClassSetup() { Log4jTestUtils.testClassSetup(); } @@ -51,7 +51,7 @@ public class Log4jAppContextIT extends AppContextITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4jClassCleanup() { Log4jTestUtils.testClassCleanup(); } @@ -62,7 +62,7 @@ public class Log4jAppContextIT extends AppContextITBase { * @throws SecurityException * @throws IOException */ - @Before + @BeforeEach public void julSetup() throws SecurityException, IOException { logger = Logger.getLogger(EVENT_NAME); logger.setLevel(Level.ALL); @@ -74,7 +74,7 @@ public class Log4jAppContextIT extends AppContextITBase { /** * Test teardown */ - @After + @AfterEach public void julTeardown() { logger.removeAppender((Appender) logHandler); logger = null; diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextOrderingIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextOrderingIT.java index 44a93a8..02e0cea 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextOrderingIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/context/Log4jAppContextOrderingIT.java @@ -18,16 +18,16 @@ package org.lttng.ust.agent.integration.context; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; @@ -42,7 +42,7 @@ public class Log4jAppContextOrderingIT extends AppContextOrderingITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4jClassSetup() { Log4jTestUtils.testClassSetup(); } @@ -50,7 +50,7 @@ public class Log4jAppContextOrderingIT extends AppContextOrderingITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4jClassCleanup() { Log4jTestUtils.testClassCleanup(); } @@ -58,7 +58,7 @@ public class Log4jAppContextOrderingIT extends AppContextOrderingITBase { /** * Test teardown */ - @After + @AfterEach public void log4jTeardown() { logger.removeAppender((Appender) logHandler); logger = null; diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jEnabledEventsIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jEnabledEventsIT.java index 34bfdf7..579d43c 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jEnabledEventsIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jEnabledEventsIT.java @@ -23,11 +23,11 @@ import java.io.IOException; 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.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; @@ -47,7 +47,7 @@ public class Log4jEnabledEventsIT extends EnabledEventsITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4jClassSetup() { Log4jTestUtils.testClassSetup(); } @@ -55,7 +55,7 @@ public class Log4jEnabledEventsIT extends EnabledEventsITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4jClassCleanup() { Log4jTestUtils.testClassCleanup(); } @@ -66,7 +66,7 @@ public class Log4jEnabledEventsIT extends EnabledEventsITBase { * @throws SecurityException * @throws IOException */ - @Before + @BeforeEach public void log4jSetup() throws SecurityException, IOException { loggerA = Logger.getLogger(EVENT_NAME_A); loggerB = Logger.getLogger(EVENT_NAME_B); @@ -90,7 +90,7 @@ public class Log4jEnabledEventsIT extends EnabledEventsITBase { /** * Test teardown */ - @After + @AfterEach public void log4jTeardown() { loggerA.removeAppender((Appender) handlerA); loggerB.removeAppender((Appender) handlerB); diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java index 2630101..a82857c 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jLegacyApiIT.java @@ -18,10 +18,10 @@ package org.lttng.ust.agent.integration.events; -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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.lang.reflect.Field; import java.util.Arrays; @@ -29,24 +29,24 @@ import java.util.List; import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.lttng.tools.ILttngSession; import org.lttng.tools.ILttngSession.Domain; 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.TestPrintRunner; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Enabled events test for the LTTng-UST Log4j log handler, using the legacy * API. */ -@RunWith(TestPrintRunner.class) +@ExtendWith(TestPrintExtension.class) @SuppressWarnings("deprecation") public class Log4jLegacyApiIT { @@ -64,7 +64,7 @@ public class Log4jLegacyApiIT { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4jClassSetup() { Log4jTestUtils.testClassSetup(); } @@ -72,7 +72,7 @@ public class Log4jLegacyApiIT { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4jClassCleanup() { Log4jTestUtils.testClassCleanup(); } @@ -80,7 +80,7 @@ public class Log4jLegacyApiIT { /** * Test setup */ - @Before + @BeforeEach public void setup() { loggerA = Logger.getLogger(EVENT_NAME_A); agent = LTTngAgent.getLTTngAgent(); @@ -95,7 +95,7 @@ public class Log4jLegacyApiIT { /** * Test cleanup */ - @After + @AfterEach public void tearDown() { session.close(); diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jListEventsIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jListEventsIT.java index 7c1effa..241e47c 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jListEventsIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jListEventsIT.java @@ -23,10 +23,10 @@ import java.io.IOException; import org.apache.log4j.Appender; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; @@ -42,7 +42,7 @@ public class Log4jListEventsIT extends ListEventsITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4jClassSetup() { Log4jTestUtils.testClassSetup(); } @@ -50,7 +50,7 @@ public class Log4jListEventsIT extends ListEventsITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4jClassCleanup() { Log4jTestUtils.testClassCleanup(); } @@ -61,7 +61,7 @@ public class Log4jListEventsIT extends ListEventsITBase { * @throws SecurityException * @throws IOException */ - @Before + @BeforeEach public void log4jSetup() throws SecurityException, IOException { /* Try clearing the log4j logger configuration */ LogManager.resetConfiguration(); @@ -82,7 +82,7 @@ public class Log4jListEventsIT extends ListEventsITBase { /** * Test teardown. Detach and close all log handlers. */ - @After + @AfterEach public void log4jTeardown() { for (Logger logger : loggers) { for (Appender appender : appenders) { diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jMultiSessionIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jMultiSessionIT.java index dc654b0..5040506 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jMultiSessionIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jMultiSessionIT.java @@ -23,10 +23,10 @@ import java.io.IOException; 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.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; @@ -46,7 +46,7 @@ public class Log4jMultiSessionIT extends MultiSessionITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4jClassSetup() { Log4jTestUtils.testClassSetup(); } @@ -54,7 +54,7 @@ public class Log4jMultiSessionIT extends MultiSessionITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4jClassCleanup() { Log4jTestUtils.testClassCleanup(); } @@ -65,7 +65,7 @@ public class Log4jMultiSessionIT extends MultiSessionITBase { * @throws SecurityException * @throws IOException */ - @Before + @BeforeEach public void log4jSetup() throws SecurityException, IOException { // TODO Wipe all existing LTTng sessions? @@ -93,7 +93,7 @@ public class Log4jMultiSessionIT extends MultiSessionITBase { /** * Test teardown */ - @After + @AfterEach public void log4jTeardown() { loggerA.removeAppender((Appender) handlerA); loggerB.removeAppender((Appender) handlerB); diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerIT.java index abe591d..cc55f40 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerIT.java @@ -20,8 +20,8 @@ package org.lttng.ust.agent.integration.filter; import java.io.IOException; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.lttng.tools.ILttngSession; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.log4j.LttngLogAppender; @@ -38,7 +38,7 @@ public class Log4jFilterListenerIT extends FilterListenerITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4jClassSetup() { Log4jTestUtils.testClassSetup(); } @@ -46,7 +46,7 @@ public class Log4jFilterListenerIT extends FilterListenerITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4jClassCleanup() { Log4jTestUtils.testClassCleanup(); } diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerOrderingIT.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerOrderingIT.java index 5c700db..5b3d1d4 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerOrderingIT.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/filter/Log4jFilterListenerOrderingIT.java @@ -18,15 +18,15 @@ package org.lttng.ust.agent.integration.filter; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; @@ -42,7 +42,7 @@ public class Log4jFilterListenerOrderingIT extends FilterListenerOrderingITBase /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4jClassSetup() { Log4jTestUtils.testClassSetup(); } @@ -50,7 +50,7 @@ public class Log4jFilterListenerOrderingIT extends FilterListenerOrderingITBase /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4jClassCleanup() { Log4jTestUtils.testClassCleanup(); } diff --git a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/utils/Log4jTestUtils.java b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/utils/Log4jTestUtils.java index a258e92..fe8f0f2 100644 --- a/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/utils/Log4jTestUtils.java +++ b/lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/utils/Log4jTestUtils.java @@ -18,8 +18,8 @@ package org.lttng.ust.agent.utils; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; @@ -43,7 +43,7 @@ public final class Log4jTestUtils { 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)); + assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J), "lttng-tools is not working properly."); LttngToolsHelper.destroyAllSessions(); } diff --git a/lttng-ust-java-tests-log4j2/.classpath b/lttng-ust-java-tests-log4j2/.classpath index e6f72a7..8f6300a 100644 --- a/lttng-ust-java-tests-log4j2/.classpath +++ b/lttng-ust-java-tests-log4j2/.classpath @@ -24,6 +24,6 @@ - + diff --git a/lttng-ust-java-tests-log4j2/pom.xml b/lttng-ust-java-tests-log4j2/pom.xml index 422ba8c..1eb7d27 100644 --- a/lttng-ust-java-tests-log4j2/pom.xml +++ b/lttng-ust-java-tests-log4j2/pom.xml @@ -59,8 +59,9 @@ log4j-core - junit - junit + org.junit.jupiter + junit-jupiter + test diff --git a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/context/Log4j2AppContextIT.java b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/context/Log4j2AppContextIT.java index f285b89..7a00b4b 100644 --- a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/context/Log4j2AppContextIT.java +++ b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/context/Log4j2AppContextIT.java @@ -21,11 +21,10 @@ package org.lttng.ust.agent.integration.context; import java.io.IOException; import org.apache.logging.log4j.core.Logger; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.utils.Log4j2TestContext; @@ -44,7 +43,7 @@ public class Log4j2AppContextIT extends AppContextITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4j2ClassSetup() { Log4j2TestUtils.testClassSetup(); } @@ -52,7 +51,7 @@ public class Log4j2AppContextIT extends AppContextITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4j2ClassCleanup() { Log4j2TestUtils.testClassCleanup(); } @@ -63,7 +62,8 @@ public class Log4j2AppContextIT extends AppContextITBase { * @throws SecurityException * @throws IOException */ - @Before + @SuppressWarnings("resource") + @BeforeEach public void log4j2Setup() throws SecurityException, IOException { testContext = new Log4j2TestContext("log4j2.Log4j2AppContextIT.xml"); @@ -77,7 +77,7 @@ public class Log4j2AppContextIT extends AppContextITBase { /** * Test teardown */ - @After + @AfterEach public void log4j2Teardown() { testContext.afterTest(); logger = null; diff --git a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/context/Log4j2AppContextOrderingIT.java b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/context/Log4j2AppContextOrderingIT.java index 9189f82..a015f13 100644 --- a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/context/Log4j2AppContextOrderingIT.java +++ b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/context/Log4j2AppContextOrderingIT.java @@ -20,9 +20,9 @@ package org.lttng.ust.agent.integration.context; import org.apache.logging.log4j.core.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.utils.Log4j2TestContext; @@ -39,7 +39,7 @@ public class Log4j2AppContextOrderingIT extends AppContextOrderingITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4j2ClassSetup() { Log4j2TestUtils.testClassSetup(); } @@ -47,7 +47,7 @@ public class Log4j2AppContextOrderingIT extends AppContextOrderingITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4j2ClassCleanup() { Log4j2TestUtils.testClassCleanup(); } @@ -55,7 +55,7 @@ public class Log4j2AppContextOrderingIT extends AppContextOrderingITBase { /** * Test teardown */ - @After + @AfterEach public void log4j2Teardown() { logger = null; logHandler = null; @@ -68,6 +68,7 @@ public class Log4j2AppContextOrderingIT extends AppContextOrderingITBase { return Domain.LOG4J; } + @SuppressWarnings("resource") @Override protected void registerAgent() { testContext = new Log4j2TestContext("log4j2.Log4j2AppContextOrderingIT.xml"); diff --git a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2EnabledEventsIT.java b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2EnabledEventsIT.java index bd5ad3e..1bbf4e4 100644 --- a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2EnabledEventsIT.java +++ b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2EnabledEventsIT.java @@ -19,18 +19,15 @@ package org.lttng.ust.agent.integration.events; import java.io.IOException; -import java.util.Map; -import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.ILttngHandler; -import org.lttng.ust.agent.log4j2.LttngLogAppender; import org.lttng.ust.agent.utils.Log4j2TestContext; import org.lttng.ust.agent.utils.Log4j2TestUtils; @@ -55,7 +52,7 @@ public class Log4j2EnabledEventsIT extends EnabledEventsITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4j2ClassSetup() { Log4j2TestUtils.testClassSetup(); } @@ -63,7 +60,7 @@ public class Log4j2EnabledEventsIT extends EnabledEventsITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4j2ClassCleanup() { Log4j2TestUtils.testClassCleanup(); } @@ -75,7 +72,7 @@ public class Log4j2EnabledEventsIT extends EnabledEventsITBase { * @throws IOException */ @SuppressWarnings("resource") - @Before + @BeforeEach public void log4j2Setup() throws SecurityException, IOException { testContext = new Log4j2TestContext("log4j2.Log4j2EnabledEventsIT.xml"); @@ -95,7 +92,7 @@ public class Log4j2EnabledEventsIT extends EnabledEventsITBase { /** * Test teardown */ - @After + @AfterEach public void log4j2Teardown() { loggerA = null; loggerB = null; diff --git a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2ListEventsIT.java b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2ListEventsIT.java index 92eedec..04676b6 100644 --- a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2ListEventsIT.java +++ b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2ListEventsIT.java @@ -18,48 +18,50 @@ package org.lttng.ust.agent.integration.events; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.apache.logging.log4j.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.extension.ExtendWith; import org.lttng.tools.ILttngSession; import org.lttng.ust.agent.utils.Log4j2TestContext; import org.lttng.ust.agent.utils.Log4j2TestUtils; +import org.lttng.ust.agent.utils.TestPrintExtension; /** * Test suite for the list events command for the log4j domain */ +@ExtendWith(TestPrintExtension.class) public class Log4j2ListEventsIT { protected static final String LOGGER_NAME_1 = "org.lttng.somecomponent"; protected static final String LOGGER_NAME_2 = "org.lttng.mycomponent"; protected static final String LOGGER_NAME_3 = "org.lttng.myothercomponent-àéç"; + @SuppressWarnings("unused") private Logger logger1; + @SuppressWarnings("unused") private Logger logger2; + @SuppressWarnings("unused") private Logger logger3; private ILttngSession session; private Log4j2TestContext testContext; - @Rule - public TestName testName = new TestName(); - /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4j2ClassSetup() { Log4j2TestUtils.testClassSetup(); } @@ -67,19 +69,21 @@ public class Log4j2ListEventsIT { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4j2ClassCleanup() { Log4j2TestUtils.testClassCleanup(); } /** * Create a new session before each test. + * @param testInfo current test information */ - @Before - public void testSetup() { + @SuppressWarnings("resource") + @BeforeEach + public void testSetup(TestInfo testInfo) { session = ILttngSession.createSession("Log4j2ListEventsIT", ILttngSession.Domain.LOG4J); - testContext = new Log4j2TestContext("log4j2." + testName.getMethodName() + ".xml"); + testContext = new Log4j2TestContext("log4j2." + testInfo.getDisplayName().replaceAll("[()]", "") + ".xml"); testContext.beforeTest(); @@ -91,7 +95,7 @@ public class Log4j2ListEventsIT { /** * Close the current session after each test. */ - @After + @AfterEach public void testTeardown() { session.close(); testContext.afterTest(); diff --git a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2MultiSessionIT.java b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2MultiSessionIT.java index e4b29c3..36eb435 100644 --- a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2MultiSessionIT.java +++ b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/events/Log4j2MultiSessionIT.java @@ -21,10 +21,10 @@ package org.lttng.ust.agent.integration.events; import java.io.IOException; import org.apache.logging.log4j.core.Logger; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.utils.Log4j2TestContext; @@ -52,7 +52,7 @@ public class Log4j2MultiSessionIT extends MultiSessionITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4j2ClassSetup() { Log4j2TestUtils.testClassSetup(); } @@ -60,7 +60,7 @@ public class Log4j2MultiSessionIT extends MultiSessionITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4j2ClassCleanup() { Log4j2TestUtils.testClassCleanup(); } @@ -71,7 +71,8 @@ public class Log4j2MultiSessionIT extends MultiSessionITBase { * @throws SecurityException * @throws IOException */ - @Before + @SuppressWarnings("resource") + @BeforeEach public void log4j2Setup() throws SecurityException, IOException { testContext = new Log4j2TestContext("log4j2.Log4j2MultiSessionIT.xml"); @@ -92,7 +93,7 @@ public class Log4j2MultiSessionIT extends MultiSessionITBase { /** * Test teardown */ - @After + @AfterEach public void log4j2Teardown() { loggerA = null; loggerB = null; diff --git a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/filter/Log4j2FilterListenerIT.java b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/filter/Log4j2FilterListenerIT.java index 057e8b0..7e2beb7 100644 --- a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/filter/Log4j2FilterListenerIT.java +++ b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/filter/Log4j2FilterListenerIT.java @@ -20,8 +20,8 @@ package org.lttng.ust.agent.integration.filter; import java.io.IOException; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.lttng.tools.ILttngSession; import org.lttng.ust.agent.ILttngHandler; import org.lttng.ust.agent.log4j2.LttngLogAppender; @@ -38,7 +38,7 @@ public class Log4j2FilterListenerIT extends FilterListenerITBase { /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4j2ClassSetup() { Log4j2TestUtils.testClassSetup(); } @@ -46,7 +46,7 @@ public class Log4j2FilterListenerIT extends FilterListenerITBase { /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4j2ClassCleanup() { Log4j2TestUtils.testClassCleanup(); } diff --git a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/filter/Log4j2FilterListenerOrderingIT.java b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/filter/Log4j2FilterListenerOrderingIT.java index dae9a6b..03e8f9e 100644 --- a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/filter/Log4j2FilterListenerOrderingIT.java +++ b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/integration/filter/Log4j2FilterListenerOrderingIT.java @@ -18,8 +18,8 @@ package org.lttng.ust.agent.integration.filter; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.lttng.tools.ILttngSession.Domain; import org.lttng.ust.agent.utils.Log4j2TestContext; import org.lttng.ust.agent.utils.Log4j2TestUtils; @@ -34,7 +34,7 @@ public class Log4j2FilterListenerOrderingIT extends FilterListenerOrderingITBase /** * Class setup */ - @BeforeClass + @BeforeAll public static void log4j2ClassSetup() { Log4j2TestUtils.testClassSetup(); } @@ -42,7 +42,7 @@ public class Log4j2FilterListenerOrderingIT extends FilterListenerOrderingITBase /** * Class cleanup */ - @AfterClass + @AfterAll public static void log4j2ClassCleanup() { Log4j2TestUtils.testClassCleanup(); } diff --git a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/utils/Log4j2TestContext.java b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/utils/Log4j2TestContext.java index 96b2683..301ff70 100644 --- a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/utils/Log4j2TestContext.java +++ b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/utils/Log4j2TestContext.java @@ -24,12 +24,18 @@ import java.net.URL; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.LoggerContext; +/** + * Log4j 2.x test context utilities. + */ public class Log4j2TestContext { private final URI configFileUri; private LoggerContext loggerContext; + /** + * @param configFile path to the log4j configuration file. + */ public Log4j2TestContext(String configFile) { URL resource = getClass().getClassLoader().getResource(configFile); @@ -45,15 +51,24 @@ public class Log4j2TestContext { } } + /** + * @return the log4j2 logger context. + */ public synchronized LoggerContext getLoggerContext() { return loggerContext; } + /** + * Initialize the log4j2 context before running a test. + */ public synchronized void beforeTest() { loggerContext = (LoggerContext) LogManager.getContext( ClassLoader.getSystemClassLoader(), false, configFileUri); } + /** + * Dispose of the log4j2 context after running a test. + */ public synchronized void afterTest() { loggerContext.stop(); } diff --git a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/utils/Log4j2TestUtils.java b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/utils/Log4j2TestUtils.java index 948e120..33eed8e 100644 --- a/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/utils/Log4j2TestUtils.java +++ b/lttng-ust-java-tests-log4j2/src/test/java/org/lttng/ust/agent/utils/Log4j2TestUtils.java @@ -18,8 +18,8 @@ package org.lttng.ust.agent.utils; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; @@ -44,7 +44,7 @@ public final class Log4j2TestUtils { 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)); + assertTrue(LttngUtils.checkForLttngTools(Domain.LOG4J), "lttng-tools is not working properly."); LttngToolsHelper.destroyAllSessions(); } diff --git a/pom.xml b/pom.xml index e64a7b1..68c634a 100644 --- a/pom.xml +++ b/pom.xml @@ -114,10 +114,11 @@ - junit - junit - 4.13.2 - test + org.junit + junit-bom + 5.8.2 + pom + import