1 18 19 package org.apache.activemq.broker; 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import junit.framework.TestCase; 25 26 import org.apache.activemq.spring.SpringConsumer; 27 import org.apache.activemq.spring.SpringProducer; 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.springframework.context.support.AbstractApplicationContext; 31 import org.springframework.context.support.ClassPathXmlApplicationContext; 32 33 public class SpringTest extends TestCase { 34 35 private static final Log log = LogFactory.getLog(SpringTest.class); 36 37 protected AbstractApplicationContext context; 38 protected SpringConsumer consumer; 39 protected SpringProducer producer; 40 41 public void testSenderWithSpringXml() throws Exception { 42 assertSenderConfig("org/apache/activemq/broker/spring.xml"); 43 } 44 51 protected void assertSenderConfig(String config) throws Exception { 52 context = new ClassPathXmlApplicationContext(config); 53 54 consumer = (SpringConsumer) context.getBean("consumer"); 55 assertTrue("Found a valid consumer", consumer != null); 56 57 consumer.start(); 58 59 producer = (SpringProducer) context.getBean("producer"); 60 assertTrue("Found a valid producer", producer != null); 61 62 consumer.flushMessages(); 63 producer.start(); 64 65 consumer.waitForMessagesToArrive(producer.getMessageCount()); 67 68 List messages = consumer.flushMessages(); 70 log.info("Consumer has received messages...."); 71 for (Iterator iter = messages.iterator(); iter.hasNext();) { 72 Object message = iter.next(); 73 log.info("Received: " + message); 74 } 75 76 assertEquals("Message count", producer.getMessageCount(), messages.size()); 77 } 78 79 84 protected void tearDown() throws Exception { 85 if (consumer != null) { 86 consumer.stop(); 87 } 88 if (producer != null) { 89 producer.stop(); 90 } 91 92 if (context != null) { 93 context.destroy(); 94 } 95 } 96 97 } 98 | Popular Tags |