KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > xbean > XBeanConfigTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.xbean;
19
20 import java.net.URI JavaDoc;
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 /**
42  *
43  * @version $Revision: 1.1 $
44  */

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 JavaDoc {
55
56         // Validate the system properties are being evaluated in xbean.
57
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 JavaDoc {
87         System.setProperty("brokername", "testbroker");
88         brokerService = createBroker();
89         broker = brokerService.getBroker();
90
91         // started automatically
92
//brokerService.start();
93

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 JavaDoc e) {
105             e.printStackTrace();
106             fail(e.getMessage());
107         }
108
109         assertNotNull("No broker created!");
110     }
111
112     protected void tearDown() throws Exception JavaDoc {
113         if (brokerService != null) {
114             brokerService.stop();
115         }
116     }
117
118     protected BrokerService createBroker() throws Exception JavaDoc {
119         String JavaDoc 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 JavaDoc("xbean:"+uri));
122     }
123
124 }
125
Popular Tags