1 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 ; 25 import javax.naming.Context ; 26 import java.util.Properties ; 27 28 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 { 37 InitialContext context = new InitialContext (); 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 { 49 Properties properties = new Properties (); 50 properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); 51 String expected = "tcp://localhost:65432"; 52 properties.put(Context.PROVIDER_URL, expected); 53 54 InitialContext context = new InitialContext (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 { 67 68 Properties properties = new Properties (); 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 context = new InitialContext (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 |