/**
*
* Copyright 2004 Protique Ltd
*
* Licensed 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.codehaus.activemq.jndi;
import junit.framework.TestCase;
import org.codehaus.activemq.ActiveMQConnectionFactory;
import javax.naming.InitialContext;
import java.util.Properties;
/**
* @version $Revision: 1.2 $
*/
public class InitialContextTest extends TestCase {
public void testInitialContext() throws Exception {
InitialContext context = new InitialContext();
assertTrue("Created context", context != null);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
assertTrue("Should have created a ConnectionFactory", connectionFactory != null);
System.out.println("Created with brokerURL: " + connectionFactory.getBrokerURL());
}
public void testProgrammableInitialContext() throws Exception {
Properties properties = new Properties();
properties.put("java.naming.factory.initial", "org.codehaus.activemq.jndi.ActiveMQInitialContextFactory");
String expected = "tcp://localhost:65432";
properties.put("brokerURL", expected);
InitialContext context = new InitialContext(properties);
assertTrue("Created context", context != null);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
assertTrue("Should have created a ConnectionFactory", connectionFactory != null);
assertEquals("the brokerURL should match", expected, connectionFactory.getBrokerURL());
}
}