1 /***
2 *
3 * Copyright 2004 Protique Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * 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 **/
18 package org.codehaus.activemq;
19
20 import org.codehaus.activemq.util.IndentPrinter;
21
22 import javax.jms.Connection;
23 import javax.jms.JMSException;
24 import javax.jms.MessageConsumer;
25 import javax.jms.Session;
26 import javax.jms.Topic;
27
28 /***
29 * @version $Revision: 1.14 $
30 */
31 public class JmsTopicSendReceiveTest extends JmsSendReceiveTestSupport {
32 protected Connection connection;
33
34 protected void setUp() throws Exception {
35 super.setUp();
36
37 connectionFactory = createConnectionFactory();
38 connection = createConnection();
39 if (durable) {
40 connection.setClientID(getClass().getName());
41 }
42
43 System.out.println("Created connection: " + connection);
44
45 session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
46
47 System.out.println("Created session: " + session);
48 producer = session.createProducer(null);
49
50 System.out.println("Created producer: " + producer);
51
52 if (topic) {
53 destination = session.createTopic(getSubject());
54 }
55 else {
56 destination = session.createQueue(getSubject());
57 }
58
59 System.out.println("Created destination: " + destination + " of type: " + destination.getClass());
60
61 consumer = createConsumer();
62 consumer.setMessageListener(this);
63 connection.start();
64
65 System.out.println("Created connection: " + connection);
66 }
67
68 protected MessageConsumer createConsumer() throws JMSException {
69 if (durable) {
70 System.out.println("Creating durable consumer");
71 return session.createDurableSubscriber((Topic) destination, getName());
72 }
73 return session.createConsumer(destination);
74 }
75
76 protected void tearDown() throws Exception {
77 System.out.println("Dumping stats...");
78 connectionFactory.getFactoryStats().dump(new IndentPrinter());
79
80 System.out.println("Closing down connection");
81
82 /*** TODO we should be able to shut down properly */
83 session.close();
84 connection.close();
85 }
86
87 }