KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.TestCase;
21
22 import org.apache.activemq.ActiveMQConnectionFactory;
23
24 import javax.naming.InitialContext JavaDoc;
25 import javax.naming.Context JavaDoc;
26 import java.util.Properties JavaDoc;
27
28 /**
29  * @version $Revision: 1.3 $
30  */

31 public class InitialContextTest extends TestCase {
32     
33     private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
34             .getLog(InitialContextTest.class);
35     
36     public void testInitialContext() throws Exception JavaDoc {
37         InitialContext JavaDoc context = new InitialContext JavaDoc();
38         assertTrue("Created context", context != null);
39
40         ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
41
42         assertTrue("Should have created a ConnectionFactory", connectionFactory != null);
43
44         log.info("Created with brokerURL: " + connectionFactory.getBrokerURL());
45
46     }
47
48     public void testUsingStandardJNDIKeys() throws Exception JavaDoc {
49         Properties JavaDoc properties = new Properties JavaDoc();
50         properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
51         String JavaDoc expected = "tcp://localhost:65432";
52         properties.put(Context.PROVIDER_URL, expected);
53
54         InitialContext JavaDoc context = new InitialContext JavaDoc(properties);
55         assertTrue("Created context", context != null);
56
57         ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
58
59         assertTrue("Should have created a ConnectionFactory", connectionFactory != null);
60
61         assertEquals("the brokerURL should match", expected, connectionFactory.getBrokerURL());
62     }
63     
64     
65     
66     public void testConnectionFactoryPolicyConfig() throws Exception JavaDoc {
67         
68         Properties JavaDoc properties = new Properties JavaDoc();
69         properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
70         properties.put(Context.PROVIDER_URL, "tcp://localhost:65432");
71         properties.put("prefetchPolicy.queuePrefetch", "777");
72         properties.put("redeliveryPolicy.maximumRedeliveries", "15");
73         properties.put("redeliveryPolicy.backOffMultiplier", "32");
74
75         InitialContext JavaDoc context = new InitialContext JavaDoc(properties);
76         assertTrue("Created context", context != null);
77
78         ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
79
80         assertTrue("Should have created a ConnectionFactory", connectionFactory != null);
81
82         assertEquals(777, connectionFactory.getPrefetchPolicy().getQueuePrefetch());
83         assertEquals(15, connectionFactory.getRedeliveryPolicy().getMaximumRedeliveries());
84         assertEquals(32, connectionFactory.getRedeliveryPolicy().getBackOffMultiplier());
85     }
86 }
87
Popular Tags