1 18 package org.apache.activemq.xbean; 19 20 import java.net.URI ; 21 22 import junit.framework.TestCase; 23 24 import org.apache.activemq.broker.Broker; 25 import org.apache.activemq.broker.BrokerFactory; 26 import org.apache.activemq.broker.BrokerService; 27 import org.apache.activemq.broker.ConnectionContext; 28 import org.apache.activemq.broker.region.Topic; 29 import org.apache.activemq.broker.region.policy.DispatchPolicy; 30 import org.apache.activemq.broker.region.policy.LastImageSubscriptionRecoveryPolicy; 31 import org.apache.activemq.broker.region.policy.RoundRobinDispatchPolicy; 32 import org.apache.activemq.broker.region.policy.StrictOrderDispatchPolicy; 33 import org.apache.activemq.broker.region.policy.SubscriptionRecoveryPolicy; 34 import org.apache.activemq.broker.region.policy.TimedSubscriptionRecoveryPolicy; 35 import org.apache.activemq.command.ActiveMQTopic; 36 import org.apache.activemq.command.ConnectionId; 37 import org.apache.activemq.command.ConnectionInfo; 38 import org.apache.commons.logging.Log; 39 import org.apache.commons.logging.LogFactory; 40 41 45 public class XBeanConfigTest extends TestCase { 46 47 protected static final Log log = LogFactory.getLog(XBeanConfigTest.class); 48 49 protected BrokerService brokerService; 50 protected Broker broker; 51 protected ConnectionContext context; 52 protected ConnectionInfo info; 53 54 public void testBrokerConfiguredCorrectly() throws Exception { 55 56 assertEquals("testbroker", brokerService.getBrokerName()); 58 59 Topic topic = (Topic) broker.addDestination(context, new ActiveMQTopic("FOO.BAR")); 60 DispatchPolicy dispatchPolicy = topic.getDispatchPolicy(); 61 assertTrue("dispatchPolicy should be RoundRobinDispatchPolicy: " + dispatchPolicy, dispatchPolicy instanceof RoundRobinDispatchPolicy); 62 63 SubscriptionRecoveryPolicy subscriptionRecoveryPolicy = topic.getSubscriptionRecoveryPolicy(); 64 assertTrue("subscriptionRecoveryPolicy should be LastImageSubscriptionRecoveryPolicy: " + subscriptionRecoveryPolicy, 65 subscriptionRecoveryPolicy instanceof LastImageSubscriptionRecoveryPolicy); 66 67 log.info("destination: " + topic); 68 log.info("dispatchPolicy: " + dispatchPolicy); 69 log.info("subscriptionRecoveryPolicy: " + subscriptionRecoveryPolicy); 70 71 topic = (Topic) broker.addDestination(context, new ActiveMQTopic("ORDERS.BOOKS")); 72 dispatchPolicy = topic.getDispatchPolicy(); 73 assertTrue("dispatchPolicy should be StrictOrderDispatchPolicy: " + dispatchPolicy, dispatchPolicy instanceof StrictOrderDispatchPolicy); 74 75 subscriptionRecoveryPolicy = topic.getSubscriptionRecoveryPolicy(); 76 assertTrue("subscriptionRecoveryPolicy should be TimedSubscriptionRecoveryPolicy: " + subscriptionRecoveryPolicy, 77 subscriptionRecoveryPolicy instanceof TimedSubscriptionRecoveryPolicy); 78 TimedSubscriptionRecoveryPolicy timedSubcriptionPolicy = (TimedSubscriptionRecoveryPolicy) subscriptionRecoveryPolicy; 79 assertEquals("getRecoverDuration()", 60000, timedSubcriptionPolicy.getRecoverDuration()); 80 81 log.info("destination: " + topic); 82 log.info("dispatchPolicy: " + dispatchPolicy); 83 log.info("subscriptionRecoveryPolicy: " + subscriptionRecoveryPolicy); 84 } 85 86 protected void setUp() throws Exception { 87 System.setProperty("brokername", "testbroker"); 88 brokerService = createBroker(); 89 broker = brokerService.getBroker(); 90 91 94 context = new ConnectionContext(); 95 context.setBroker(broker); 96 info = new ConnectionInfo(); 97 info.setClientId("James"); 98 info.setUserName("James"); 99 info.setConnectionId(new ConnectionId("1234")); 100 101 try { 102 broker.addConnection(context, info); 103 } 104 catch (Throwable e) { 105 e.printStackTrace(); 106 fail(e.getMessage()); 107 } 108 109 assertNotNull("No broker created!"); 110 } 111 112 protected void tearDown() throws Exception { 113 if (brokerService != null) { 114 brokerService.stop(); 115 } 116 } 117 118 protected BrokerService createBroker() throws Exception { 119 String uri = "org/apache/activemq/xbean/activemq-policy.xml"; 120 log.info("Loading broker configuration from the classpath with URI: " + uri); 121 return BrokerFactory.createBroker(new URI ("xbean:"+uri)); 122 } 123 124 } 125 | Popular Tags |