Source code: org/activemq/jndi/ActiveMQInitialContextFactoryTest.java
1 /**
2 *
3 * Copyright 2004 Protique Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package org.activemq.jndi;
19
20 import org.activemq.message.ActiveMQQueue;
21 import org.activemq.message.ActiveMQTopic;
22
23 import javax.naming.Binding;
24 import javax.naming.Context;
25 import javax.naming.NamingEnumeration;
26 import javax.naming.NamingException;
27
28 /**
29 * @version $Revision: 1.1.1.1 $
30 */
31 public class ActiveMQInitialContextFactoryTest extends JNDITestSupport {
32
33 public void testConnectionFactoriesArePresent() throws NamingException {
34 String lookupName = getConnectionFactoryLookupName();
35 assertConnectionFactoryPresent(lookupName);
36 }
37
38 public void testDestinationsArePresent() throws NamingException {
39 Object destinations = context.lookup("destinations");
40
41 assertTrue("Should have created a destinations context but got: " + destinations, destinations instanceof Context);
42
43 Context destContext = (Context) destinations;
44 NamingEnumeration iter = destContext.listBindings("");
45 while (iter.hasMore()) {
46 Binding binding = (Binding) iter.next();
47 System.out.println("Found key: " + binding.getName());
48 assertBinding(binding);
49 }
50 }
51
52 public void testDynamicallyGrowing() throws Exception {
53 Object answer = context.lookup("dynamicQueues/FOO.BAR");
54 assertTrue("Should have found a queue but found: " + answer, answer instanceof ActiveMQQueue);
55
56 ActiveMQQueue queue = (ActiveMQQueue) answer;
57 assertEquals("queue name", "FOO.BAR", queue.getPhysicalName());
58
59 answer = context.lookup("dynamicTopics/A.B.C");
60 assertTrue("Should have found a topic but found: " + answer, answer instanceof ActiveMQTopic);
61
62 ActiveMQTopic topic = (ActiveMQTopic) answer;
63 assertEquals("topic name", "A.B.C", topic.getPhysicalName());
64
65 }
66
67
68 protected String getConnectionFactoryLookupName() {
69 return "ConnectionFactory";
70 }
71 }