[hornetq-commits] JBoss hornetq SVN: r11346 - in branches/STOMP11: tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Sep 13 23:43:57 EDT 2011


Author: gaohoward
Date: 2011-09-13 23:43:57 -0400 (Tue, 13 Sep 2011)
New Revision: 11346

Modified:
   branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompConnection.java
   branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompDecoder.java
   branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/AbstractStompClientConnection.java
   branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/StompClientConnectionV10.java
   branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/StompClientConnectionV11.java
   branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/v11/StompTestV11.java
Log:
test


Modified: branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompConnection.java
===================================================================
--- branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompConnection.java	2011-09-13 15:05:32 UTC (rev 11345)
+++ branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompConnection.java	2011-09-14 03:43:57 UTC (rev 11346)
@@ -442,7 +442,8 @@
       {
          if (!initialized)
          {
-            if (!Stomp.Commands.CONNECT.equals(request.getCommand()))
+            String cmd = request.getCommand();
+            if ( ! (Stomp.Commands.CONNECT.equals(cmd) || Stomp.Commands.STOMP.equals(cmd)))
             {
                throw new HornetQStompException("Connection hasn't been established.");
             }

Modified: branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompDecoder.java
===================================================================
--- branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompDecoder.java	2011-09-13 15:05:32 UTC (rev 11345)
+++ branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompDecoder.java	2011-09-14 03:43:57 UTC (rev 11346)
@@ -104,6 +104,8 @@
 
    public static final byte E = (byte)'E';
 
+   public static final byte T = (byte)'T';
+
    public static final byte M = (byte)'M';
 
    public static final byte S = (byte)'S';
@@ -367,6 +369,16 @@
                   // SEND
                   command = COMMAND_SEND;
                }
+               else if (workingBuffer[offset + 1] == T)
+               {
+                  if (!tryIncrement(offset + COMMAND_STOMP_LENGTH + 1))
+                  {
+                     return null;
+                  }
+
+                  // SEND
+                  command = COMMAND_STOMP;                  
+               }
                else
                {
                   if (!tryIncrement(offset + COMMAND_SUBSCRIBE_LENGTH + 1))

Modified: branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/AbstractStompClientConnection.java
===================================================================
--- branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/AbstractStompClientConnection.java	2011-09-13 15:05:32 UTC (rev 11345)
+++ branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/AbstractStompClientConnection.java	2011-09-14 03:43:57 UTC (rev 11346)
@@ -179,7 +179,6 @@
    public void connect() throws Exception
    {
       connect(null, null);
-      connected = true;
    }
    
    public void connect(String username, String password) throws Exception

Modified: branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/StompClientConnectionV10.java
===================================================================
--- branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/StompClientConnectionV10.java	2011-09-13 15:05:32 UTC (rev 11345)
+++ branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/StompClientConnectionV10.java	2011-09-14 03:43:57 UTC (rev 11346)
@@ -35,9 +35,16 @@
       frame.addHeader(PASSCODE_HEADER, passcode);
       
       ClientStompFrame response = this.sendFrame(frame);
-      System.out.println("Got response : " + response);
       
-      connected = true;
+      if (response.getCommand().equals(CONNECTED_COMMAND))
+      {
+         connected = true;
+      }
+      else
+      {
+         System.out.println("Connection failed with: " + response);
+         connected = false;
+      }
    }
 
    @Override

Modified: branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/StompClientConnectionV11.java
===================================================================
--- branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/StompClientConnectionV11.java	2011-09-13 15:05:32 UTC (rev 11345)
+++ branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/util/StompClientConnectionV11.java	2011-09-14 03:43:57 UTC (rev 11346)
@@ -55,14 +55,17 @@
          this.passcode = passcode;
          this.connected = true;
       }
-      connected = true;
+      else
+      {
+         connected = false;
+      }
    }
 
    public void connect1(String username, String passcode) throws IOException, InterruptedException
    {
       ClientStompFrame frame = factory.newFrame(STOMP_COMMAND);
       frame.addHeader(ACCEPT_HEADER, "1.0,1.1");
-      frame.addHeader(HOST_HEADER, "localhost");
+      frame.addHeader(HOST_HEADER, "127.0.0.1");
       if (username != null)
       {
          frame.addHeader(LOGIN_HEADER, username);
@@ -80,6 +83,11 @@
          this.passcode = passcode;
          this.connected = true;
       }
+      else
+      {
+         System.out.println("Connection failed with frame " + response);
+         connected = false;
+      }
    }
 
    @Override

Modified: branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/v11/StompTestV11.java
===================================================================
--- branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/v11/StompTestV11.java	2011-09-13 15:05:32 UTC (rev 11345)
+++ branches/STOMP11/tests/integration-tests/src/test/java/org/hornetq/tests/integration/stomp/v11/StompTestV11.java	2011-09-14 03:43:57 UTC (rev 11346)
@@ -21,6 +21,7 @@
 import org.hornetq.tests.integration.stomp.util.ClientStompFrame;
 import org.hornetq.tests.integration.stomp.util.StompClientConnection;
 import org.hornetq.tests.integration.stomp.util.StompClientConnectionFactory;
+import org.hornetq.tests.integration.stomp.util.StompClientConnectionV11;
 
 
 public class StompTestV11 extends StompTestBase2
@@ -65,18 +66,25 @@
       assertEquals("1.1", connection.getVersion());
       
       connection.disconnect();
+      
+      connection = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
+      
+      connection.connect();
+      
+      assertFalse(connection.isConnected());
+      
+      //new way of connection
+      StompClientConnectionV11 conn = (StompClientConnectionV11) StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
+      conn.connect1(defUser, defPass);
+      
+      assertTrue(conn.isConnected());
+      
+      conn.disconnect();
    }
    
-   /*
-    * test case:
-    * 1 accept-version absent. It is a 1.0 connect
-    * 2 accept-version=1.0, result: 1.0
-    * 3 accept-version=1.0,1.1,1.2, result 1.1
-    * 4 accept-version="1.2,1.3", result error
-    */
    public void testNegotiation() throws Exception
    {
-      // case 1
+      // case 1 accept-version absent. It is a 1.0 connect
       ClientStompFrame frame = connV11.createFrame("CONNECT");
       //frame.addHeader("accept-version", "1.0,1.1,1.2");
       frame.addHeader("host", "127.0.0.1");
@@ -91,6 +99,72 @@
       assertEquals(null, reply.getHeader("version"));
       
       connV11.disconnect();
+
+      // case 2 accept-version=1.0, result: 1.0
+      connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
+      frame = connV11.createFrame("CONNECT");
+      frame.addHeader("accept-version", "1.0");
+      frame.addHeader("host", "127.0.0.1");
+      frame.addHeader("login", this.defUser);
+      frame.addHeader("passcode", this.defPass);
       
+      reply = connV11.sendFrame(frame);
+      
+      assertEquals("CONNECTED", reply.getCommand());
+      
+      //reply headers: version, session, server
+      assertEquals("1.0", reply.getHeader("version"));
+      
+      connV11.disconnect();
+
+      // case 3 accept-version=1.1, result: 1.1
+      connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
+      frame = connV11.createFrame("CONNECT");
+      frame.addHeader("accept-version", "1.1");
+      frame.addHeader("host", "127.0.0.1");
+      frame.addHeader("login", this.defUser);
+      frame.addHeader("passcode", this.defPass);
+      
+      reply = connV11.sendFrame(frame);
+      
+      assertEquals("CONNECTED", reply.getCommand());
+      
+      //reply headers: version, session, server
+      assertEquals("1.1", reply.getHeader("version"));
+      
+      connV11.disconnect();
+
+      // case 4 accept-version=1.0,1.1,1.2, result 1.1
+      connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
+      frame = connV11.createFrame("CONNECT");
+      frame.addHeader("accept-version", "1.0,1.1,1.2");
+      frame.addHeader("host", "127.0.0.1");
+      frame.addHeader("login", this.defUser);
+      frame.addHeader("passcode", this.defPass);
+      
+      reply = connV11.sendFrame(frame);
+      
+      assertEquals("CONNECTED", reply.getCommand());
+      
+      //reply headers: version, session, server
+      assertEquals("1.1", reply.getHeader("version"));
+      
+      connV11.disconnect();
+
+      // case 5 accept-version=1.2, result error
+      connV11 = StompClientConnectionFactory.createClientConnection("1.1", hostname, port);
+      frame = connV11.createFrame("CONNECT");
+      frame.addHeader("accept-version", "1.2");
+      frame.addHeader("host", "127.0.0.1");
+      frame.addHeader("login", this.defUser);
+      frame.addHeader("passcode", this.defPass);
+      
+      reply = connV11.sendFrame(frame);
+      
+      assertEquals("ERROR", reply.getCommand());
+      
+      System.out.println("Got error frame " + reply);
+      
+      connV11.disconnect();
    }
 }



More information about the hornetq-commits mailing list