activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [6/8] activemq-artemis git commit: ARTEMIS-1511 Update tests to use StompTest Client + Fix issues
Date Mon, 13 Nov 2017 22:02:45 GMT
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a5c443af/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v12/StompV12Test.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v12/StompV12Test.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v12/StompV12Test.java
index 06f3b16..23a93d4 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v12/StompV12Test.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v12/StompV12Test.java
@@ -24,15 +24,18 @@ import javax.jms.MessageListener;
 import javax.jms.MessageProducer;
 import javax.jms.TextMessage;
 import java.io.IOException;
+import java.net.URI;
 import java.nio.channels.ClosedChannelException;
 import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.UUID;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.core.protocol.stomp.Stomp;
-import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
 import org.apache.activemq.artemis.tests.integration.stomp.StompTestBase;
@@ -45,6 +48,7 @@ import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runners.Parameterized;
 
 /**
  * Testing Stomp version 1.2 functionalities
@@ -56,11 +60,22 @@ public class StompV12Test extends StompTestBase {
 
    private StompClientConnectionV12 conn;
 
+   private URI v10Uri;
+
+   private URI v11Uri;
+
+   @Parameterized.Parameters(name = "{0}")
+   public static Collection<Object[]> data() {
+      return Arrays.asList(new Object[][]{{"ws+v12.stomp"}, {"tcp+v12.stomp"}});
+   }
+
    @Override
    @Before
    public void setUp() throws Exception {
       super.setUp();
-      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      v10Uri = new URI(uri.toString().replace("v12", "v10"));
+      v11Uri = new URI(uri.toString().replace("v12", "v11"));
+      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection(uri);
    }
 
    @Override
@@ -74,13 +89,14 @@ public class StompV12Test extends StompTestBase {
          }
       } finally {
          super.tearDown();
+         conn.closeTransport();
       }
    }
 
    @Test
    public void testConnection() throws Exception {
       server.getActiveMQServer().getConfiguration().setSecurityEnabled(true);
-      StompClientConnection connection = StompClientConnectionFactory.createClientConnection("1.0",
hostname, port);
+      StompClientConnection connection = StompClientConnectionFactory.createClientConnection(v10Uri);
 
       connection.connect(defUser, defPass);
 
@@ -90,7 +106,7 @@ public class StompV12Test extends StompTestBase {
 
       connection.disconnect();
 
-      connection = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
+      connection = StompClientConnectionFactory.createClientConnection(uri);
 
       connection.connect(defUser, defPass);
 
@@ -100,14 +116,14 @@ public class StompV12Test extends StompTestBase {
 
       connection.disconnect();
 
-      connection = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
+      connection = StompClientConnectionFactory.createClientConnection(uri);
 
       connection.connect();
 
       Assert.assertFalse(connection.isConnected());
 
       //new way of connection
-      StompClientConnectionV11 conn = (StompClientConnectionV11) StompClientConnectionFactory.createClientConnection("1.1",
hostname, port);
+      StompClientConnectionV11 conn = (StompClientConnectionV11) StompClientConnectionFactory.createClientConnection(v11Uri);
       conn.connect1(defUser, defPass);
 
       Assert.assertTrue(conn.isConnected());
@@ -117,7 +133,7 @@ public class StompV12Test extends StompTestBase {
 
    @Test
    public void testConnectionAsInSpec() throws Exception {
-      StompClientConnection conn = StompClientConnectionFactory.createClientConnection("1.0",
hostname, port);
+      StompClientConnection conn = StompClientConnectionFactory.createClientConnection(v10Uri);
 
       ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT);
       frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
@@ -133,7 +149,7 @@ public class StompV12Test extends StompTestBase {
       conn.disconnect();
 
       //need 1.2 client
-      conn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
+      conn = StompClientConnectionFactory.createClientConnection(uri);
 
       frame = conn.createFrame(Stomp.Commands.STOMP);
       frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
@@ -151,7 +167,7 @@ public class StompV12Test extends StompTestBase {
 
    @Test
    public void testNegotiation() throws Exception {
-      StompClientConnection conn = StompClientConnectionFactory.createClientConnection("1.0",
hostname, port);
+      StompClientConnection conn = StompClientConnectionFactory.createClientConnection(v10Uri);
       // case 1 accept-version absent. It is a 1.0 connect
       ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT);
       frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
@@ -168,7 +184,7 @@ public class StompV12Test extends StompTestBase {
       conn.disconnect();
 
       // case 2 accept-version=1.0, result: 1.0
-      conn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
+      conn = StompClientConnectionFactory.createClientConnection(v11Uri);
       frame = conn.createFrame(Stomp.Commands.CONNECT);
       frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0");
       frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
@@ -185,7 +201,7 @@ public class StompV12Test extends StompTestBase {
       conn.disconnect();
 
       // case 3 accept-version=1.1, result: 1.1
-      conn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
+      conn = StompClientConnectionFactory.createClientConnection(v11Uri);
       frame = conn.createFrame(Stomp.Commands.CONNECT);
       frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.1");
       frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
@@ -202,7 +218,7 @@ public class StompV12Test extends StompTestBase {
       conn.disconnect();
 
       // case 4 accept-version=1.0,1.1,1.3, result 1.2
-      conn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
+      conn = StompClientConnectionFactory.createClientConnection(v11Uri);
       frame = conn.createFrame(Stomp.Commands.CONNECT);
       frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.3");
       frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
@@ -219,7 +235,7 @@ public class StompV12Test extends StompTestBase {
       conn.disconnect();
 
       // case 5 accept-version=1.3, result error
-      conn = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
+      conn = StompClientConnectionFactory.createClientConnection(v11Uri);
       frame = conn.createFrame(Stomp.Commands.CONNECT);
       frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.3");
       frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
@@ -230,6 +246,8 @@ public class StompV12Test extends StompTestBase {
 
       Assert.assertEquals(Stomp.Responses.ERROR, reply.getCommand());
 
+      conn.disconnect();
+
       System.out.println("Got error frame " + reply);
 
    }
@@ -245,7 +263,7 @@ public class StompV12Test extends StompTestBase {
       send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World 2!", true);
 
       //subscribe
-      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
       newConn.connect(defUser, defPass);
       subscribe(newConn, "a-sub");
 
@@ -281,7 +299,7 @@ public class StompV12Test extends StompTestBase {
       send(conn, getQueuePrefix() + getQueueName(), "application/xml", "Hello World 1!");
 
       //subscribe
-      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.1",
hostname, port);
+      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(v11Uri);
       newConn.connect(defUser, defPass);
       subscribe(newConn, "a-sub");
 
@@ -315,7 +333,7 @@ public class StompV12Test extends StompTestBase {
       conn.sendFrame(frame);
 
       //subscribe
-      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
       newConn.connect(defUser, defPass);
       subscribe(newConn, "a-sub");
 
@@ -376,7 +394,7 @@ public class StompV12Test extends StompTestBase {
       conn.sendFrame(frame);
 
       //subscribe
-      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
       newConn.connect(defUser, defPass);
       subscribe(newConn, "a-sub", null, null, true);
 
@@ -434,7 +452,7 @@ public class StompV12Test extends StompTestBase {
       conn.sendFrame(frame);
 
       //subscribe
-      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
       newConn.connect(defUser, defPass);
       subscribe(newConn, "a-sub");
 
@@ -481,7 +499,7 @@ public class StompV12Test extends StompTestBase {
       conn.sendFrame(frame);
 
       //subscribe
-      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
       newConn.connect(defUser, defPass);
 
       subscribe(newConn, "a-sub");
@@ -540,7 +558,7 @@ public class StompV12Test extends StompTestBase {
 
    @Test
    public void testHeartBeat() throws Exception {
-      StompClientConnection conn = StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
       //no heart beat at all if heat-beat absent
       ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT)
                                    .addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1")
@@ -558,7 +576,7 @@ public class StompV12Test extends StompTestBase {
       conn.disconnect();
 
       //no heart beat for (0,0)
-      conn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
+      conn = StompClientConnectionFactory.createClientConnection(uri);
       frame = conn.createFrame(Stomp.Commands.CONNECT)
                   .addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1")
                   .addHeader(Stomp.Headers.Connect.LOGIN, this.defUser)
@@ -579,7 +597,7 @@ public class StompV12Test extends StompTestBase {
       conn.disconnect();
 
       //heart-beat (1,0), should receive a min client ping accepted by server
-      conn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
+      conn = StompClientConnectionFactory.createClientConnection(uri);
       frame = conn.createFrame(Stomp.Commands.CONNECT)
                   .addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1")
                   .addHeader(Stomp.Headers.Connect.LOGIN, this.defUser)
@@ -605,7 +623,7 @@ public class StompV12Test extends StompTestBase {
       }
 
       //heart-beat (1,0), start a ping, then send a message, should be ok.
-      conn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
+      conn = StompClientConnectionFactory.createClientConnection(uri);
       frame = conn.createFrame(Stomp.Commands.CONNECT)
                   .addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1")
                   .addHeader(Stomp.Headers.Connect.LOGIN, this.defUser)
@@ -650,7 +668,7 @@ public class StompV12Test extends StompTestBase {
       conn.disconnect();
 
       //heart-beat (500,1000)
-      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection(uri);
       frame = conn.createFrame(Stomp.Commands.CONNECT)
                   .addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1")
                   .addHeader(Stomp.Headers.Connect.LOGIN, this.defUser)
@@ -703,7 +721,7 @@ public class StompV12Test extends StompTestBase {
          }
 
          // subscribe
-         newConn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
+         newConn = StompClientConnectionFactory.createClientConnection(uri);
          newConn.connect(defUser, defPass);
          subscribe(newConn, "a-sub");
 
@@ -738,7 +756,7 @@ public class StompV12Test extends StompTestBase {
       }
 
       //subscribe
-      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.1",
hostname, port);
+      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(v11Uri);
       try {
          ClientStompFrame frame = newConn.createFrame(Stomp.Commands.CONNECT)
                                          .addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1")
@@ -795,7 +813,7 @@ public class StompV12Test extends StompTestBase {
          }
 
          // subscribe
-         newConn = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
+         newConn = StompClientConnectionFactory.createClientConnection(uri);
          frame = newConn.createFrame(Stomp.Commands.CONNECT)
                         .addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1")
                         .addHeader(Stomp.Headers.Connect.LOGIN, this.defUser)
@@ -1250,7 +1268,7 @@ public class StompV12Test extends StompTestBase {
 
       this.subscribeTopic(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO, null);
 
-      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection("1.1",
hostname, port);
+      StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(v11Uri);
       newConn.connect(defUser, defPass, "myclientid2");
 
       this.subscribeTopic(newConn, "sub2", Stomp.Headers.Subscribe.AckModeValues.AUTO, null);
@@ -1284,7 +1302,7 @@ public class StompV12Test extends StompTestBase {
 
       send(conn, getQueuePrefix() + getQueueName(), null, "Hello World");
 
-      StompClientConnection connV12_2 = StompClientConnectionFactory.createClientConnection("1.1",
hostname, port);
+      StompClientConnection connV12_2 = StompClientConnectionFactory.createClientConnection(v11Uri);
       connV12_2.connect(defUser, defPass);
 
       this.subscribe(connV12_2, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
@@ -1423,9 +1441,8 @@ public class StompV12Test extends StompTestBase {
 
       this.subscribe(conn, "sub1", "client", getName());
 
-      this.subscribe(conn, "sub1", "client", getName());
+      ClientStompFrame frame = this.subscribe(conn, "sub1", "client", getName());
 
-      ClientStompFrame frame = conn.receiveFrame();
       Assert.assertTrue(frame.getCommand().equals(Stomp.Responses.ERROR));
 
       waitDisconnect(conn);
@@ -1451,7 +1468,7 @@ public class StompV12Test extends StompTestBase {
       sendJmsMessage(getName(), topic);
 
       conn.destroy();
-      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection(uri);
       conn.connect(defUser, defPass, CLIENT_ID);
 
       this.subscribeTopic(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO, getName());
@@ -1476,7 +1493,7 @@ public class StompV12Test extends StompTestBase {
 
       conn.disconnect();
       conn.destroy();
-      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection(uri);
       conn.connect(defUser, defPass, CLIENT_ID);
 
       this.unsubscribe(conn, getName(), null, false, true);
@@ -2131,7 +2148,7 @@ public class StompV12Test extends StompTestBase {
       sendJmsMessage("second message");
 
       //reconnect
-      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection(uri);
       conn.connect(defUser, defPass);
 
       frame = conn.receiveFrame(1000);
@@ -2172,10 +2189,10 @@ public class StompV12Test extends StompTestBase {
 
       if (sendDisconnect) {
          conn.disconnect();
-         conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+         conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection(uri);
       } else {
          conn.destroy();
-         conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+         conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection(uri);
       }
 
       // message should be received since message was not acknowledged
@@ -2190,7 +2207,7 @@ public class StompV12Test extends StompTestBase {
 
       // now let's make sure we don't see the message again
       conn.destroy();
-      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection("1.2",
hostname, port);
+      conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection(uri);
       conn.connect(defUser, defPass);
 
       this.subscribe(conn, "sub1", null, null, true);


Mime
View raw message