/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.qpid.jms.destinations;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import javax.jms.Session;
import javax.jms.TemporaryQueue;

import org.apache.qpid.jms.support.AmqpTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Test functionality of Temporary Queues.
 */
public class JmsTemporaryQueueTest extends AmqpTestSupport {

    protected static final Logger LOG = LoggerFactory.getLogger(JmsTemporaryQueueTest.class);

    @Test(timeout = 60000)
    public void testCreateTemporaryQueue() throws Exception {
        connection = createAmqpConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        assertNotNull(session);
        TemporaryQueue queue = session.createTemporaryQueue();
        session.createConsumer(queue);

        assertEquals(1, brokerService.getAdminView().getTemporaryQueues().length);
    }
}

@@ -931,16 +931,262 @@
 otNull;%0A
+import static org.junit.Assert.fail;%0A%0Aimport javax.jms.Connection;%0Aimport javax.jms.IllegalStateException;%0Aimport javax.jms.InvalidDestinationException;%0Aimport javax.jms.Message;%0Aimport javax.jms.MessageConsumer;%0Aimport javax.jms.MessageProducer;
 %0Aimport 
@@ -2050,11 +2050,2636 @@
 );%0A    %7D
+%0A%0A    @Test(timeout = 60000)%0A    public void testConsumeFromTemporaryQueueCreatedOnAnotherConnection() throws Exception %7B%0A        connection = createAmqpConnection();%0A        connection.start();%0A%0A        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);%0A        TemporaryQueue tempQueue = session.createTemporaryQueue();%0A        session.createConsumer(tempQueue);%0A%0A        Connection connection2 = createAmqpConnection();%0A        try %7B%0A            Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);%0A            try %7B%0A                session2.createConsumer(tempQueue);%0A                fail(%22should not be able to consumer from temporary queue from another connection%22);%0A            %7D catch (InvalidDestinationException ide) %7B%0A                // expected%0A            %7D%0A        %7D finally %7B%0A            connection2.close();%0A        %7D%0A    %7D%0A%0A    @Test(timeout = 60000)%0A    public void testCantSendToTemporaryQueueFromClosedConnection() throws Exception %7B%0A        connection = createAmqpConnection();%0A        connection.start();%0A%0A        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);%0A        TemporaryQueue tempQueue = session.createTemporaryQueue();%0A%0A        Connection connection2 = createAmqpConnection();%0A        try %7B%0A            Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);%0A            Message msg = session2.createMessage();%0A            MessageProducer producer = session2.createProducer(tempQueue);%0A%0A            // Close the original connection%0A            connection.close();%0A%0A            try %7B%0A                producer.send(msg);%0A                fail(%22should not be able to send to temporary queue from closed connection%22);%0A            %7D catch (IllegalStateException ide) %7B%0A                // expected%0A            %7D%0A        %7D finally %7B%0A            connection2.close();%0A        %7D%0A    %7D%0A%0A    @Test(timeout = 60000)%0A    public void testCantDeleteTemporaryQueueWithConsumers() throws Exception %7B%0A        connection = createAmqpConnection();%0A        connection.start();%0A%0A        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);%0A        TemporaryQueue tempQueue = session.createTemporaryQueue();%0A        MessageConsumer consumer = session.createConsumer(tempQueue);%0A%0A        try %7B%0A            tempQueue.delete();%0A            fail(%22should not be able to delete temporary queue with active consumers%22);%0A        %7D catch (IllegalStateException ide) %7B%0A            // expected%0A        %7D%0A%0A        consumer.close();%0A%0A        // Now it should be allowed%0A        tempQueue.delete();%0A    %7D
 %0A%7D%0A

add more TemporaryQueue tests