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.usecases;
19
20 import junit.framework.TestCase;
21 import org.codehaus.activemq.ActiveMQConnectionFactory;
22 import org.codehaus.activemq.broker.BrokerContainer;
23 import org.codehaus.activemq.broker.impl.BrokerContainerImpl;
24 import org.codehaus.activemq.store.vm.VMPersistenceAdapter;
25
26 import javax.jms.Connection;
27 import javax.jms.Queue;
28 import javax.jms.QueueConnection;
29 import javax.jms.QueueReceiver;
30 import javax.jms.QueueSender;
31 import javax.jms.QueueSession;
32 import javax.jms.Session;
33 import javax.jms.Topic;
34
35 /***
36 * @author Peter Henning
37 * @version $Revision: 1.2 $
38 */
39 public class CreateTemporaryQueueBeforeStartTest extends TestCase {
40 protected String bindAddress = "tcp://localhost:61623";
41
42 private Connection connection;
43 private BrokerContainer broker = new BrokerContainerImpl("localhost", new VMPersistenceAdapter());
44
45 public void testCreateTemporaryQueue() throws Exception {
46 connection = createConnection();
47
48 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
49 Queue queue = session.createTemporaryQueue();
50 assertTrue("No queue created!", queue != null);
51
52 Topic topic = session.createTemporaryTopic();
53 assertTrue("No topic created!", topic != null);
54 }
55
56 public void testTryToReproduceNullPointerBug() throws Exception {
57 String url = bindAddress;
58 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
59 QueueConnection queueConnection = factory.createQueueConnection();
60 this.connection = queueConnection;
61 QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
62 QueueSender sender = session.createSender(null);
63 Queue receiverQueue = session.createTemporaryQueue();
64 QueueReceiver receiver = session.createReceiver(receiverQueue);
65 queueConnection.start();
66
67 }
68
69 protected Connection createConnection() throws Exception {
70 ActiveMQConnectionFactory factory = createConnectionFactory();
71 return factory.createConnection();
72 }
73
74 protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
75 return new ActiveMQConnectionFactory(broker, "tcp://localhost:61623");
76 }
77
78 protected void setUp() throws Exception {
79 broker.addConnector(bindAddress);
80 broker.start();
81 super.setUp();
82 }
83
84 protected void tearDown() throws Exception {
85 if (connection != null) {
86 connection.close();
87 }
88 broker.stop();
89 super.tearDown();
90 }
91
92
93 }