/**
*
* Copyright 2004 Protique Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.codehaus.activemq.usecases;
import junit.framework.TestCase;
import org.codehaus.activemq.ActiveMQConnectionFactory;
import org.codehaus.activemq.broker.BrokerContainer;
import org.codehaus.activemq.broker.impl.BrokerContainerImpl;
import org.codehaus.activemq.store.vm.VMPersistenceAdapter;
import javax.jms.Connection;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.Topic;
/**
* @author Peter Henning
* @version $Revision: 1.2 $
*/
public class CreateTemporaryQueueBeforeStartTest extends TestCase {
protected String bindAddress = "tcp://localhost:61623";
private Connection connection;
private BrokerContainer broker = new BrokerContainerImpl("localhost", new VMPersistenceAdapter());
public void testCreateTemporaryQueue() throws Exception {
connection = createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createTemporaryQueue();
assertTrue("No queue created!", queue != null);
Topic topic = session.createTemporaryTopic();
assertTrue("No topic created!", topic != null);
}
public void testTryToReproduceNullPointerBug() throws Exception {
String url = bindAddress;
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
QueueConnection queueConnection = factory.createQueueConnection();
this.connection = queueConnection;
QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(null); //Unidentified
Queue receiverQueue = session.createTemporaryQueue();
QueueReceiver receiver = session.createReceiver(receiverQueue);
queueConnection.start();
}
protected Connection createConnection() throws Exception {
ActiveMQConnectionFactory factory = createConnectionFactory();
return factory.createConnection();
}
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
return new ActiveMQConnectionFactory(broker, "tcp://localhost:61623");
}
protected void setUp() throws Exception {
broker.addConnector(bindAddress);
broker.start();
super.setUp();
}
protected void tearDown() throws Exception {
if (connection != null) {
connection.close();
}
broker.stop();
super.tearDown();
}
}