1 /*** 2 * 3 * Copyright 2004 Protique Ltd 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 **/ 18 package org.codehaus.activemq.usecases; 19 20 import org.codehaus.activemq.ActiveMQConnectionFactory; 21 import org.codehaus.activemq.JmsTopicSendReceiveWithTwoConnectionsTest; 22 import org.codehaus.activemq.spring.SpringBrokerContainerFactory; 23 import org.springframework.core.io.ClassPathResource; 24 25 import javax.jms.Connection; 26 import javax.jms.JMSException; 27 28 /*** 29 * @version $Revision: 1.7 $ 30 */ 31 public class TwoBrokerTopicSendReceiveTest extends JmsTopicSendReceiveWithTwoConnectionsTest { 32 33 protected ActiveMQConnectionFactory sendFactory; 34 protected ActiveMQConnectionFactory receiveFactory; 35 36 protected void setUp() throws Exception { 37 sendFactory = createSenderConnectionFactory(); 38 receiveFactory = createReceiverConnectionFactory(); 39 super.setUp(); 40 } 41 42 protected ActiveMQConnectionFactory createReceiverConnectionFactory() throws JMSException { 43 return createConnectionFactory("org/codehaus/activemq/usecases/receiver.xml", "receiver", "vm://receiver"); 44 } 45 46 protected ActiveMQConnectionFactory createSenderConnectionFactory() throws JMSException { 47 return createConnectionFactory("org/codehaus/activemq/usecases/sender.xml", "sender", "vm://sender"); 48 } 49 50 protected void tearDown() throws Exception { 51 super.tearDown(); 52 sendFactory.stop(); 53 receiveFactory.stop(); 54 } 55 56 protected Connection createReceiveConnection() throws JMSException { 57 return receiveFactory.createConnection(); 58 } 59 60 protected Connection createSendConnection() throws JMSException { 61 return sendFactory.createConnection(); 62 } 63 64 protected ActiveMQConnectionFactory createConnectionFactory(String config, String brokerName, String connectUrl) throws JMSException { 65 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectUrl); 66 factory.setBrokerName(brokerName); 67 factory.setUseEmbeddedBroker(true); 68 factory.setBrokerContainerFactory(new SpringBrokerContainerFactory(new ClassPathResource(config))); 69 return factory; 70 } 71 }