Add tests for localized messages
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 3 Feb 2016 20:58:55 +0000 (15:58 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 4 Feb 2016 04:32:31 +0000 (23:32 -0500)
This does not apply to the log4j (1.2.x) API, but may apply to
future ones.

Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/EnabledEventsITBase.java
lttng-ust-java-tests-jul/src/test/java/org/lttng/ust/agent/integration/events/JulEnabledEventsIT.java
lttng-ust-java-tests-log4j/src/test/java/org/lttng/ust/agent/integration/events/Log4jEnabledEventsIT.java

index 5659493991fbd6495973eea17e83969b3a82c68d..c0de521f82168ad58670a2884e3ee5f8776a2c34 100644 (file)
@@ -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<Integer> 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<String> 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]\""));
+    }
 }
index b0a9738541f485135dda8fdef3738caa486c9afc..72cb283e9cb82834dc0beeffb940d00bd6f2e327 100644 (file)
@@ -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);
+    }
 }
index f331711774f6f34a07456550978758f15ef29298..1642b6a4a024b40610f932f32f7f16f158c2cc0d 100644 (file)
@@ -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 */
+    }
 }
This page took 0.02487 seconds and 4 git commands to generate.