Package org.codehaus.activemq.jndi

Source Code of org.codehaus.activemq.jndi.ActiveMQInitialContextFactoryTest

/**
*
* 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 javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
import java.util.Hashtable;

/**
* @version $Revision: 1.1 $
*/
public class ActiveMQInitialContextFactoryTest extends TestCase {

    protected Hashtable environment = new Hashtable();
    protected Context context;

    public void testConnectionFactoriesArePresent() throws NamingException {
        Object connectionFactory = context.lookup("ConnectionFactory");

        assertTrue("Should have created a ConnectionFactory but got: " + connectionFactory, connectionFactory instanceof ConnectionFactory);
    }

    public void testDestinationsArePresent() throws NamingException {
        Object destinations = context.lookup("destinations");

        assertTrue("Should have created a destinations context but got: " + destinations, destinations instanceof Context);

        Context destContext = (Context) destinations;
        NamingEnumeration iter = destContext.listBindings("");
        while (iter.hasMore()) {
            Binding binding = (Binding) iter.next();
            System.out.println("Found key: " + binding.getName());
            assertBinding(binding);
        }
    }

    protected void assertBinding(Binding binding) throws NamingException {
        Object object = binding.getObject();
        assertTrue("Should have got a child context but got: " + object, object instanceof Context);

        Context childContext = (Context) object;
        NamingEnumeration iter = childContext.listBindings("");
        while (iter.hasMore()) {
            Binding destinationBinding = (Binding) iter.next();
            System.out.println("Found destination: " + destinationBinding.getName());
            Object destination = destinationBinding.getObject();
            assertTrue("Should have a Destination but got: " + destination, destination instanceof Destination);
        }
    }


    protected void setUp() throws Exception {
        super.setUp();

        environment.put("useEmbeddedBroker", "true");
        environment.put("brokerURL", "vm://localhost");

        InitialContextFactory factory = new ActiveMQInitialContextFactory();
        context = factory.getInitialContext(environment);
        assertTrue("No context created", context != null);
    }
}
TOP

Related Classes of org.codehaus.activemq.jndi.ActiveMQInitialContextFactoryTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.