add some intitial tests for JmsInitialContextFactory around queues and topics
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/68d402ef Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/68d402ef Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/68d402ef Branch: refs/heads/master Commit: 68d402ef13ceeb837015514ec28b26c9de885f3a Parents: 342e97d Author: Robert Gemmell <[email protected]> Authored: Tue Jan 20 15:45:28 2015 +0000 Committer: Robert Gemmell <[email protected]> Committed: Tue Jan 20 16:04:36 2015 +0000 ---------------------------------------------------------------------- .../jms/jndi/JmsInitialContextFactoryTest.java | 158 +++++++++++++++++++ 1 file changed, 158 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/68d402ef/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java new file mode 100644 index 0000000..64a0925 --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.qpid.jms.jndi; + +import static org.junit.Assert.*; + +import java.util.Hashtable; + +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.OperationNotSupportedException; + +import org.apache.qpid.jms.JmsQueue; +import org.apache.qpid.jms.JmsTopic; +import org.apache.qpid.jms.test.QpidJmsTestCase; +import org.junit.Test; + +public class JmsInitialContextFactoryTest extends QpidJmsTestCase { + + private JmsInitialContextFactory factory; + private Context context; + + private Context createInitialContext(final Hashtable<Object, Object> environment) throws NamingException { + factory = new JmsInitialContextFactory(); + context = factory.getInitialContext(environment); + assertNotNull("No context created", context); + + return context; + } + + @Test + public void testQueueBinding() throws Exception { + String lookupName = "myLookupName"; + String actualName = "myQueueName"; + + Hashtable<Object, Object> env = new Hashtable<Object, Object>(); + env.put("queue." + lookupName, actualName); + + Context ctx = createInitialContext(env); + Object o = ctx.lookup(lookupName); + + assertNotNull("No object returned", o); + assertEquals("Unexpected class type for returned object", JmsQueue.class, o.getClass()); + assertEquals("Unexpected name for returned object", ((JmsQueue) o).getQueueName(), actualName); + } + + @Test + public void testDynamicQueueLookup() throws Exception { + String actualName = "myQueueName"; + String lookupName = "dynamicQueues/" + actualName; + + Context ctx = createInitialContext(new Hashtable<Object, Object>()); + Object o = ctx.lookup(lookupName); + + assertNotNull("No object returned", o); + assertEquals("Unexpected class type for returned object", JmsQueue.class, o.getClass()); + assertEquals("Unexpected name for returned object", ((JmsQueue) o).getQueueName(), actualName); + } + + @Test + public void testTopicBinding() throws Exception { + String lookupName = "myLookupName"; + String actualName = "myTopicName"; + + Hashtable<Object, Object> env = new Hashtable<Object, Object>(); + env.put("topic." + lookupName, actualName); + + Context ctx = createInitialContext(env); + Object o = ctx.lookup(lookupName); + + assertNotNull("No object returned", o); + assertEquals("Unexpected class type for returned object", JmsTopic.class, o.getClass()); + assertEquals("Unexpected name for returned object", ((JmsTopic) o).getTopicName(), actualName); + } + + @Test + public void testDynamicTopicLookup() throws Exception { + String actualName = "myTopicName"; + String lookupName = "dynamicTopics/" + actualName; + + Context ctx = createInitialContext(new Hashtable<Object, Object>()); + Object o = ctx.lookup(lookupName); + + assertNotNull("No object returned", o); + assertEquals("Unexpected class type for returned object", JmsTopic.class, o.getClass()); + assertEquals("Unexpected name for returned object", ((JmsTopic) o).getTopicName(), actualName); + } + + @Test + public void testQueueBindingWithSlashInLookupName() throws Exception { + String lookupName = "myLookup/Name"; + String actualName = "myQueueName"; + + Hashtable<Object, Object> env = new Hashtable<Object, Object>(); + env.put("queue." + lookupName, actualName); + + Context ctx = createInitialContext(env); + Object o = ctx.lookup(lookupName); + + assertNotNull("No object returned", o); + assertEquals("Unexpected class type for returned object", JmsQueue.class, o.getClass()); + assertEquals("Unexpected name for returned object", ((JmsQueue) o).getQueueName(), actualName); + } + + @Test + public void testTopicBindingWithMulupleSlashesInLookupName() throws Exception { + String lookupName = "my/Lookup/Name"; + String actualName = "myTopicName"; + + Hashtable<Object, Object> env = new Hashtable<Object, Object>(); + env.put("topic." + lookupName, actualName); + + Context ctx = createInitialContext(env); + Object o = ctx.lookup(lookupName); + + assertNotNull("No object returned", o); + assertEquals("Unexpected class type for returned object", JmsTopic.class, o.getClass()); + assertEquals("Unexpected name for returned object", ((JmsTopic) o).getTopicName(), actualName); + } + + @Test(expected = OperationNotSupportedException.class) + public void testContextPreventsUnbind() throws Exception { + Hashtable<Object, Object> env = new Hashtable<Object, Object>(); + Context ctx = createInitialContext(env); + + ctx.unbind("lookupName"); + } + + @Test(expected = OperationNotSupportedException.class) + public void testContextPreventsRebind() throws Exception { + Hashtable<Object, Object> env = new Hashtable<Object, Object>(); + Context ctx = createInitialContext(env); + + ctx.rebind("lookupName", new Object()); + } + + @Test(expected = OperationNotSupportedException.class) + public void testContextPreventsRename() throws Exception { + Hashtable<Object, Object> env = new Hashtable<Object, Object>(); + Context ctx = createInitialContext(env); + + ctx.rename("lookupName", ""); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
