KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > jndi > ActiveMQInitialContextFactoryTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.jndi;
19
20 import org.apache.activemq.command.ActiveMQQueue;
21 import org.apache.activemq.command.ActiveMQTopic;
22
23
24 import javax.naming.*;
25
26 /**
27  * @version $Revision: 1.4 $
28  */

29 public class ActiveMQInitialContextFactoryTest extends JNDITestSupport {
30
31     public void testConnectionFactoriesArePresent() throws NamingException {
32         String JavaDoc lookupName = getConnectionFactoryLookupName();
33         assertConnectionFactoryPresent(lookupName);
34     }
35
36     public void testDestinationsArePresent() throws NamingException {
37
38         //Retrieving destinations context is not yet implemented on the broker. For this test, a jndi file properties will be used.
39

40         InitialContext context = new InitialContext();
41
42         //make sure context is not null
43
assertTrue("Created context", context != null);
44
45         Object JavaDoc topicDestination = context.lookup("MyTopic");
46
47         // check if MyTopic is an ActiveMQTopic
48
assertTrue("Should have found a topic but found: " + topicDestination, topicDestination instanceof ActiveMQTopic);
49
50         Object JavaDoc queueDestination = context.lookup("MyQueue");
51
52         // check if MyQueue is an ActiveMQueue
53
assertTrue("Should have found a queue but found: " + queueDestination,queueDestination instanceof ActiveMQQueue);
54
55     }
56
57     public void testDynamicallyGrowing() throws Exception JavaDoc {
58         Object JavaDoc answer = context.lookup("dynamicQueues/FOO.BAR");
59         assertTrue("Should have found a queue but found: " + answer, answer instanceof ActiveMQQueue);
60
61         ActiveMQQueue queue = (ActiveMQQueue) answer;
62         assertEquals("queue name", "FOO.BAR", queue.getPhysicalName());
63
64          answer = context.lookup("dynamicTopics/A.B.C");
65         assertTrue("Should have found a topic but found: " + answer, answer instanceof ActiveMQTopic);
66
67         ActiveMQTopic topic = (ActiveMQTopic) answer;
68         assertEquals("topic name", "A.B.C", topic.getPhysicalName());
69
70     }
71
72
73     protected String JavaDoc getConnectionFactoryLookupName() {
74         return "ConnectionFactory";
75     }
76 }
77
Popular Tags