KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

56     protected void setUp() throws Exception JavaDoc {
57         ;
58         File JavaDoc journalFile = new File JavaDoc(JOURNAL_ROOT);
59         recursiveDelete(journalFile);
60         // Create broker from resource
61
System.out.print("Creating broker... ");
62         broker = createBroker("org/apache/activemq/usecases/activemq.xml");
63         log.info("Success");
64         super.setUp();
65
66     }
67
68
69
70      /*
71      * Stops the Broker
72      * @see junit.framework.TestCase#tearDown()
73      */

74     protected void tearDown() throws Exception JavaDoc {
75          log.info("Closing Broker");
76             if (broker != null) {
77                broker.stop();
78             }
79          log.info("Broker closed...");
80
81
82     }
83
84
85     /*
86      * clean up the journal
87      */

88
89     protected static void recursiveDelete(File JavaDoc file) {
90         if( file.isDirectory() ) {
91             File JavaDoc[] files = file.listFiles();
92             for (int i = 0; i < files.length; i++) {
93                 recursiveDelete(files[i]);
94             }
95         }
96         file.delete();
97     }
98
99     protected BrokerService createBroker(String JavaDoc resource) throws Exception JavaDoc {
100         return createBroker(new ClassPathResource(resource));
101     }
102
103     protected BrokerService createBroker(Resource resource) throws Exception JavaDoc {
104         BrokerFactoryBean factory = new BrokerFactoryBean(resource);
105         factory.afterPropertiesSet();
106
107         BrokerService broker = factory.getBroker();
108
109         //assertTrue("Should have a broker!", broker != null);
110

111
112         return broker;
113     }
114 }
115
Popular Tags