Package org.activemq.jca

Source Code of org.activemq.jca.JCAContainerTestSupport

/**
*
* 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.activemq.jca;

import junit.framework.TestCase;
import org.activemq.ActiveMQConnectionFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import javax.jms.Connection;
import javax.jms.MessageProducer;
import javax.jms.Session;

/**
* @version $Revision: 1.1.1.1 $
*/
public class JCAContainerTestSupport extends TestCase {
    protected XmlBeanFactory beanFactory;
    protected JCAContainerSupport container;

    // to send some messages
    protected Connection connection;
    protected Session session;
    protected MessageProducer producer;

    protected void setUp() throws Exception {
        beanFactory = createBeanFactory();

        container = (JCAContainerSupport) beanFactory.getBean("activeMQContainer");
        assertTrue("Should have created a JCAContainer", container != null);

        // now lets create the JMS connection
        connection = createConnection();
       
        // start the connection in case we do some consumption on it
        connection.start();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        producer = session.createProducer(null);

    }


    protected void tearDown() throws Exception {
        if (connection != null) {
            connection.close();
        }
        beanFactory.destroySingletons();
    }

    protected String getBrokerURL() {
        return "tcp://localhost:61616";
    }

    protected XmlBeanFactory createBeanFactory() {
        return new XmlBeanFactory(new ClassPathResource("org/activemq/jca/spring.xml"));
    }

    protected Connection createConnection() throws Exception {
        return new ActiveMQConnectionFactory(getBrokerURL()).createConnection();
    }
}
TOP

Related Classes of org.activemq.jca.JCAContainerTestSupport

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.