From: Alexandre Montplaisir Date: Thu, 19 May 2016 21:53:54 +0000 (-0400) Subject: Add test for invalid context names X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=390fca17dbff49e7030ed4f86c91fa277fa8af78;p=lttng-ust-java-tests.git Add test for invalid context names Signed-off-by: Alexandre Montplaisir --- 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 8455374..10327b0 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 @@ -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); + } + } }