KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > usecases > PublishOnTopicConsumerMessageUsingActivemqXMLTest


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.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 JavaDoc;
26
27 /**
28  *
29  * Test Publish/Consume topic using the release activemq.xml configuration file
30  *
31  * @version $Revision: 1.2 $
32  */

33 public class PublishOnTopicConsumerMessageUsingActivemqXMLTest extends PublishOnTopicConsumedMessageTest {
34     protected static final String JavaDoc JOURNAL_ROOT = "../data/";
35     BrokerService broker;
36
37
38
39      /**
40      * Use the transportConnector uri configured on the activemq.xml
41      *
42      * @return ActiveMQConnectionFactory
43      * @throws Exception
44      */

45     protected ActiveMQConnectionFactory createConnectionFactory() throws Exception JavaDoc {
46         return new ActiveMQConnectionFactory("tcp://localhost:61616");
47     }
48
49
50     /**
51      * Sets up a test where the producer and consumer have their own connection.
52      *
53      * @see junit.framework.TestCase#setUp()
54      */

55     protected void setUp() throws Exception JavaDoc {
56         ;
57         File JavaDoc journalFile = new File JavaDoc(JOURNAL_ROOT);
58         recursiveDelete(journalFile);
59         // Create broker from resource
60
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      /*
70      * Stops the Broker
71      * @see junit.framework.TestCase#tearDown()
72      */

73     protected void tearDown() throws Exception JavaDoc {
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     /*
88      * clean up the journal
89      */

90
91     protected static void recursiveDelete(File JavaDoc file) {
92         if( file.isDirectory() ) {
93             File JavaDoc[] 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 JavaDoc resource) throws Exception JavaDoc {
102         return createBroker(new ClassPathResource(resource));
103     }
104
105     protected BrokerService createBroker(Resource resource) throws Exception JavaDoc {
106         BrokerFactoryBean factory = new BrokerFactoryBean(resource);
107         factory.afterPropertiesSet();
108
109         BrokerService broker = factory.getBroker();
110
111         //assertTrue("Should have a broker!", broker != null);
112

113
114         return broker;
115     }
116 }
117
Popular Tags