/*
 * Copyright (c) 2007-2014, Kaazing Corporation. All rights reserved.
 */
package org.kaazing.qpid.amqp_1_0.jms;

import static javax.jms.Session.AUTO_ACKNOWLEDGE;
import static javax.jms.Session.CLIENT_ACKNOWLEDGE;
import static javax.jms.Session.DUPS_OK_ACKNOWLEDGE;

import org.apache.qpid.amqp_1_0.jms.Connection;
import org.apache.qpid.amqp_1_0.jms.ConnectionFactory;
import org.apache.qpid.amqp_1_0.jms.Session;
import org.apache.qpid.amqp_1_0.jms.impl.ConnectionFactoryImpl;
import org.junit.Rule;
import org.junit.Test;
import org.kaazing.robot.junit.annotation.Robotic;
import org.kaazing.robot.junit.rules.RobotRule;

public class QueueConsumerIT {

    @Rule
    public RobotRule robot = new RobotRule().setScriptRoot("org/kaazing/robot/scripts/amqp_1_0/jms/queue/consumer");

    @Robotic(script = "create")
    @Test(timeout = 1000)
    public void shouldCreateAutoAcknowledgeConsumer() throws Exception {
        ConnectionFactory factory = new ConnectionFactoryImpl("localhost", 5672, null, null, "clientID");
        Connection connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, AUTO_ACKNOWLEDGE);
        session.createConsumer(session.createQueue("queue-A"));
        robot.join();
    }

    @Robotic(script = "create")
    @Test(timeout = 1000)
    public void shouldCreateClientAcknowledgeConsumer() throws Exception {
        ConnectionFactory factory = new ConnectionFactoryImpl("localhost", 5672, null, null, "clientID");
        Connection connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, CLIENT_ACKNOWLEDGE);
        session.createConsumer(session.createQueue("queue-A"));
        robot.join();
    }

    @Robotic(script = "create")
    @Test(timeout = 1000)
    public void shouldCreateDupsOkayAcknowledgeConsumer() throws Exception {
        ConnectionFactory factory = new ConnectionFactoryImpl("localhost", 5672, null, null, "clientID");
        Connection connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, DUPS_OK_ACKNOWLEDGE);
        session.createConsumer(session.createQueue("queue-A"));
        robot.join();
    }
}

@@ -369,16 +369,69 @@
 actory;%0A
+import org.apache.qpid.amqp_1_0.jms.MessageConsumer;%0A
 import o
@@ -858,32 +858,43 @@
 script = %22create
+.then.close
 %22)%0A    @Test(tim
@@ -1249,32 +1249,59 @@
 WLEDGE);%0A       
+ MessageConsumer consumer =
  session.createC
@@ -1326,39 +1326,126 @@
 eateQueue(%22queue
+://queue
 -A%22));%0A
+        consumer.close();%0A        session.close();%0A        connection.close();%0A
         robot.jo
@@ -1478,32 +1478,43 @@
 script = %22create
+.then.close
 %22)%0A    @Test(tim
@@ -1873,32 +1873,59 @@
 WLEDGE);%0A       
+ MessageConsumer consumer =
  session.createC
@@ -1950,39 +1950,126 @@
 eateQueue(%22queue
+://queue
 -A%22));%0A
+        consumer.close();%0A        session.close();%0A        connection.close();%0A
         robot.jo
@@ -2110,16 +2110,27 @@
  %22create
+.then.close
 %22)%0A    @
@@ -2500,32 +2500,59 @@
 WLEDGE);%0A       
+ MessageConsumer consumer =
  session.createC
@@ -2581,28 +2581,115 @@
 Queue(%22queue
--A%22)
+://queue-A%22));%0A        consumer.close();%0A        session.close();%0A        connection.close(
 );%0A        r

Add close behavior to queue consumer test.