From: Alexandre Montplaisir Date: Wed, 3 Feb 2016 20:58:55 +0000 (-0500) Subject: Add tests for localized messages X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3fa81377f13cb170528a66254b91a36c8c5050f6;p=lttng-ust-java-tests.git Add tests for localized messages This does not apply to the log4j (1.2.x) API, but may apply to future ones. Signed-off-by: Alexandre Montplaisir --- 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 5659493..c0de521 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 @@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.util.Arrays; import java.util.List; import org.junit.After; @@ -56,6 +57,11 @@ public abstract class EnabledEventsITBase { protected abstract void sendEventsToLoggers(); + /** + * Send one event using a localized API to logger/handler A. + */ + protected abstract void sendLocalizedEvent(String rawString, Object[] params); + /** * Base test setup */ @@ -261,4 +267,28 @@ public abstract class EnabledEventsITBase { assertEquals(10, handlerB.getEventCount()); assertEquals(10, handlerC.getEventCount()); } + + /** + * Test sending a localized message. + */ + @Test + public void testLocalizedMessage() { + Integer value1 = Integer.valueOf(10); + List value2 = Arrays.asList(Integer.valueOf(1000), Integer.valueOf(1001), Integer.valueOf(1002)); + + assertTrue(session.enableAllEvents()); + assertTrue(session.start()); + + sendLocalizedEvent("Message with a localized value: {0} and some others: {1}", + new Object[] { value1, value2 }); + + assertTrue(session.stop()); + assertEquals(1, handlerA.getEventCount()); + + List output = session.view(); + + assertNotNull(output); + assertEquals(1, output.size()); + assertTrue(output.get(0).contains("msg = \"Message with a localized value: 10 and some others: [1000, 1001, 1002]\"")); + } } 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 b0a9738..72cb283 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 @@ -31,7 +31,6 @@ import org.junit.Before; import org.junit.BeforeClass; import org.lttng.tools.ILttngSession.Domain; import org.lttng.tools.LttngToolsHelper; -import org.lttng.ust.agent.integration.events.EnabledEventsITBase; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.JulTestUtils; import org.lttng.ust.agent.utils.LttngUtils; @@ -122,4 +121,9 @@ public class JulEnabledEventsIT extends EnabledEventsITBase { JulTestUtils.send10EventsTo(loggerC); JulTestUtils.send10EventsTo(loggerD); } + + @Override + protected void sendLocalizedEvent(String rawString, Object[] params) { + loggerA.log(Level.SEVERE, rawString, params); + } } 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 f331711..1642b6a 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 @@ -29,9 +29,9 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Test; import org.lttng.tools.ILttngSession.Domain; import org.lttng.tools.LttngToolsHelper; -import org.lttng.ust.agent.integration.events.EnabledEventsITBase; import org.lttng.ust.agent.log4j.LttngLogAppender; import org.lttng.ust.agent.utils.Log4jTestUtils; import org.lttng.ust.agent.utils.LttngUtils; @@ -122,4 +122,15 @@ public class Log4jEnabledEventsIT extends EnabledEventsITBase { Log4jTestUtils.send10Events(loggerC); Log4jTestUtils.send10Events(loggerD); } + + @Override + protected void sendLocalizedEvent(String rawString, Object[] params) { + throw new UnsupportedOperationException(); + } + + @Override + @Test + public void testLocalizedMessage() { + /* Does not apply to log4j 1.2.x */ + } }