Add test for invalid context names
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 19 May 2016 21:53:54 +0000 (17:53 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 19 May 2016 21:53:54 +0000 (17:53 -0400)
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/context/ContextRegistrationIT.java

index 8455374346af04f6348cd19c72bc9834a325ba89..10327b07657cf1d6634e8319c0933d7f92e6f399 100644 (file)
@@ -19,6 +19,9 @@
 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 java.io.IOException;
@@ -55,14 +58,32 @@ public class ContextRegistrationIT {
      */
     @Test
     public void testRegistration() {
-        final String retrieverName = "test-retriever";
+        final String retrieverName = "test.retriever";
         final IContextInfoRetriever emptyRetriever = (key -> null);
 
-        mgr.registerContextInfoRetriever(retrieverName, emptyRetriever);
+        boolean ret = mgr.registerContextInfoRetriever(retrieverName, emptyRetriever);
+        assertTrue(ret);
 
         IContextInfoRetriever retriever2 = mgr.getContextInfoRetriever(retrieverName);
         assertEquals(emptyRetriever, retriever2);
 
         mgr.unregisterContextInfoRetriever(retrieverName);
     }
+
+    /**
+     * Test registration of retrievers with invalid names.
+     */
+    @Test
+    public void testRegistrationInvalid() {
+        String[] invalidNames = new String[] { "test.rétriever", "with space", "1numberfirst" };
+        for (String retrieverName : invalidNames) {
+            final IContextInfoRetriever emptyRetriever = (key -> null);
+
+            boolean ret = mgr.registerContextInfoRetriever(retrieverName, emptyRetriever);
+            assertFalse(ret);
+
+            IContextInfoRetriever retriever = mgr.getContextInfoRetriever(retrieverName);
+            assertNull(retriever);
+        }
+    }
 }
This page took 0.023722 seconds and 4 git commands to generate.