1 18 package org.apache.activemq.usecases; 19 20 import org.apache.activemq.broker.BrokerService; 21 import org.apache.activemq.xbean.BrokerFactoryBean; 22 import org.apache.activemq.ActiveMQConnectionFactory; 23 import org.springframework.core.io.ClassPathResource; 24 import org.springframework.core.io.Resource; 25 import java.io.File ; 26 27 33 public class PublishOnTopicConsumerMessageUsingActivemqXMLTest extends PublishOnTopicConsumedMessageTest { 34 protected static final String JOURNAL_ROOT = "../data/"; 35 BrokerService broker; 36 37 38 39 45 protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { 46 return new ActiveMQConnectionFactory("tcp://localhost:61616"); 47 } 48 49 50 55 protected void setUp() throws Exception { 56 ; 57 File journalFile = new File (JOURNAL_ROOT); 58 recursiveDelete(journalFile); 59 System.out.print("Creating broker... "); 61 broker = createBroker("org/apache/activemq/usecases/activemq.xml"); 62 log.info("Success"); 63 super.setUp(); 64 65 } 66 67 68 69 73 protected void tearDown() throws Exception { 74 log.info("Closing Broker"); 75 if (broker != null) { 76 broker.stop(); 77 } 78 log.info("Broker closed..."); 79 80 81 } 82 83 84 85 86 87 90 91 protected static void recursiveDelete(File file) { 92 if( file.isDirectory() ) { 93 File [] files = file.listFiles(); 94 for (int i = 0; i < files.length; i++) { 95 recursiveDelete(files[i]); 96 } 97 } 98 file.delete(); 99 } 100 101 protected BrokerService createBroker(String resource) throws Exception { 102 return createBroker(new ClassPathResource(resource)); 103 } 104 105 protected BrokerService createBroker(Resource resource) throws Exception { 106 BrokerFactoryBean factory = new BrokerFactoryBean(resource); 107 factory.afterPropertiesSet(); 108 109 BrokerService broker = factory.getBroker(); 110 111 113 114 return broker; 115 } 116 } 117 | Popular Tags |