KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > CreateDestinationsOnStartupViaXBeanTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 package org.apache.activemq.broker;
18
19 import org.apache.activemq.EmbeddedBrokerTestSupport;
20 import org.apache.activemq.command.ActiveMQDestination;
21 import org.apache.activemq.command.ActiveMQQueue;
22 import org.apache.activemq.command.ActiveMQTopic;
23 import org.apache.activemq.xbean.XBeanBrokerFactory;
24
25 import java.net.URI JavaDoc;
26 import java.util.Set JavaDoc;
27
28 /**
29  *
30  * @version $Revision: 426366 $
31  */

32 public class CreateDestinationsOnStartupViaXBeanTest extends EmbeddedBrokerTestSupport {
33
34     public void testNewDestinationsAreCreatedOnStartup() throws Exception JavaDoc {
35         assertQueueCreated("FOO.BAR", true);
36         assertQueueCreated("FOO.DoesNotExist", false);
37         
38         assertTopicCreated("SOME.TOPIC", true);
39         assertTopicCreated("FOO.DoesNotExist", false);
40     }
41
42     protected void assertQueueCreated(String JavaDoc name, boolean expected) throws Exception JavaDoc {
43         assertDestinationCreated(new ActiveMQQueue(name), expected);
44     }
45     
46     protected void assertTopicCreated(String JavaDoc name, boolean expected) throws Exception JavaDoc {
47         assertDestinationCreated(new ActiveMQTopic(name), expected);
48     }
49
50     protected void assertDestinationCreated(ActiveMQDestination destination, boolean expected) throws Exception JavaDoc {
51         Set JavaDoc answer = broker.getBroker().getDestinations(destination);
52         int size = expected ? 1 : 0;
53         assertEquals("Could not find destination: " + destination + ". Size of found destinations: " + answer, size, answer.size());
54     }
55     
56     protected BrokerService createBroker() throws Exception JavaDoc {
57         XBeanBrokerFactory factory = new XBeanBrokerFactory();
58         BrokerService answer = factory.createBroker(new URI JavaDoc(getBrokerConfigUri()));
59         
60         // lets disable persistence as we are a test
61
answer.setPersistent(false);
62         
63         return answer;
64     }
65
66     protected String JavaDoc getBrokerConfigUri() {
67         return "org/apache/activemq/broker/destinations-on-start.xml";
68     }
69 }
70
Popular Tags