Package org.activemq.service

Source Code of org.activemq.service.BrokerTestSupport

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

import junit.framework.TestCase;
import org.activemq.broker.Broker;
import org.activemq.broker.impl.DefaultBroker;
import org.activemq.filter.Filter;
import org.activemq.filter.FilterFactory;
import org.activemq.filter.FilterFactoryImpl;
import org.activemq.message.ActiveMQDestination;
import org.activemq.message.ActiveMQMessage;
import org.activemq.message.ActiveMQQueue;
import org.activemq.message.ActiveMQTopic;
import org.activemq.message.ConsumerInfo;
import org.activemq.util.IdGenerator;

import javax.jms.JMSException;

/**
* Useful base class for Broker related test cases
*
* @version $Revision: 1.1.1.1 $
*/
public abstract class BrokerTestSupport extends TestCase {

    private static final String BROKER_NAME = "TEST_BROKER";

    protected Broker broker;
    protected FilterFactory filterFactory = new FilterFactoryImpl();
    protected IdGenerator idGenerator = new IdGenerator();

    protected boolean isTopic() {
        return true;
    }

    protected ActiveMQMessage createMessage(String subject) {
        ActiveMQMessage message = new ActiveMQMessage();
        message.setJMSMessageID(idGenerator.generateId());
        message.setJMSDestination(createDestination(subject));
        return message;
    }

    protected Filter createFilter(String subject, String selector) throws JMSException {
        return filterFactory.createFilter(createDestination(subject), selector);
    }

    protected ActiveMQDestination createDestination(String subject) {
        if (isTopic()) {
            return new ActiveMQTopic(subject);
        }
        else {
            return new ActiveMQQueue(subject);
        }
    }

    protected Broker createStore() {
        return new DefaultBroker(BROKER_NAME);
    }

    protected ConsumerInfo createConsumer(String subject) {
        return createConsumer(subject, null);
    }

    protected ConsumerInfo createConsumer(String subject, String selector) {
        ConsumerInfo info = new ConsumerInfo();
        info.setConsumerId(idGenerator.generateId());
        info.setDestination(createDestination(subject));
        info.setSelector(selector);
        return info;
    }

    protected void setUp() throws Exception {
        broker = new DefaultBroker(BROKER_NAME);
        broker.start();
    }

    protected void tearDown() throws Exception {
        broker.stop();
    }
}
TOP

Related Classes of org.activemq.service.BrokerTestSupport

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.