You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2015/09/25 20:53:55 UTC

[2/3] activemq-artemis git commit: Small tweak on test: Using Parameterized instead of exension

Small tweak on test: Using Parameterized instead of exension


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/f0fd89f2
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/f0fd89f2
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/f0fd89f2

Branch: refs/heads/master
Commit: f0fd89f24f738765891495366e6f7bc5c94a0789
Parents: f64c435
Author: Clebert Suconic <cl...@apache.org>
Authored: Fri Sep 25 14:47:49 2015 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Fri Sep 25 14:47:49 2015 -0400

----------------------------------------------------------------------
 .../stomp/AbstractStompOverWebsocketTest.java   | 127 ---------------
 .../stomp/StompOverWebsocketBinaryTest.java     |  30 ----
 .../stomp/StompOverWebsocketTest.java           | 158 +++++++++++++++++++
 .../stomp/StompOverWebsocketTextTest.java       |  27 ----
 4 files changed, 158 insertions(+), 184 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f0fd89f2/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/AbstractStompOverWebsocketTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/AbstractStompOverWebsocketTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/AbstractStompOverWebsocketTest.java
deleted file mode 100644
index ba760fb..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/AbstractStompOverWebsocketTest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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.activemq.artemis.tests.integration.stomp;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.charset.StandardCharsets;
-
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelDuplexHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelPromise;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.codec.http.FullHttpResponse;
-import io.netty.handler.codec.http.HttpClientCodec;
-import io.netty.handler.codec.http.HttpObjectAggregator;
-import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
-import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
-import io.netty.handler.codec.http.websocketx.WebSocketFrame;
-import io.netty.handler.codec.http.websocketx.WebSocketVersion;
-import io.netty.handler.codec.string.StringDecoder;
-
-public abstract class AbstractStompOverWebsocketTest extends StompTest {
-
-   private ChannelPromise handshakeFuture;
-
-   @Override
-   protected void addChannelHandlers(SocketChannel ch) throws URISyntaxException {
-      ch.pipeline().addLast("http-codec", new HttpClientCodec());
-      ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192));
-      ch.pipeline().addLast(new WebsocketHandler(WebSocketClientHandshakerFactory.newHandshaker(new URI("ws://localhost:8080/websocket"), WebSocketVersion.V13, null, false, null)));
-      ch.pipeline().addLast("decoder", new StringDecoder(StandardCharsets.UTF_8));
-      ch.pipeline().addLast(new StompClientHandler());
-   }
-
-   @Override
-   protected void handshake() throws InterruptedException {
-      handshakeFuture.sync();
-   }
-
-   class WebsocketHandler extends ChannelDuplexHandler {
-
-      private WebSocketClientHandshaker handshaker;
-
-      public WebsocketHandler(WebSocketClientHandshaker webSocketClientHandshaker) {
-         this.handshaker = webSocketClientHandshaker;
-      }
-
-      @Override
-      public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
-         handshakeFuture = ctx.newPromise();
-      }
-
-      @Override
-      public void channelActive(ChannelHandlerContext ctx) throws Exception {
-         handshaker.handshake(ctx.channel());
-      }
-
-      @Override
-      public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-         System.out.println("WebSocket Client disconnected!");
-      }
-
-      @Override
-      public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-         Channel ch = ctx.channel();
-         if (!handshaker.isHandshakeComplete()) {
-            handshaker.finishHandshake(ch, (FullHttpResponse) msg);
-            System.out.println("WebSocket Client connected!");
-            handshakeFuture.setSuccess();
-            return;
-         }
-
-         if (msg instanceof FullHttpResponse) {
-            FullHttpResponse response = (FullHttpResponse) msg;
-            throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" + response.content().toString(StandardCharsets.UTF_8) + ')');
-         }
-
-         WebSocketFrame frame = (WebSocketFrame) msg;
-         if (frame instanceof BinaryWebSocketFrame) {
-            BinaryWebSocketFrame dataFrame = (BinaryWebSocketFrame) frame;
-            super.channelRead(ctx, dataFrame.content());
-         }
-         else if (frame instanceof PongWebSocketFrame) {
-            System.out.println("WebSocket Client received pong");
-         }
-         else if (frame instanceof CloseWebSocketFrame) {
-            System.out.println("WebSocket Client received closing");
-            ch.close();
-         }
-      }
-
-      @Override
-      public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
-         try {
-            if (msg instanceof String) {
-               ctx.write(createFrame((String) msg), promise);
-            }
-            else {
-               super.write(ctx, msg, promise);
-            }
-         }
-         catch (Exception e) {
-            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-         }
-      }
-   }
-
-   abstract WebSocketFrame createFrame(String msg);
-}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f0fd89f2/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketBinaryTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketBinaryTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketBinaryTest.java
deleted file mode 100644
index f0d3782..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketBinaryTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.activemq.artemis.tests.integration.stomp;
-
-import java.nio.charset.Charset;
-
-import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.WebSocketFrame;
-import io.netty.buffer.Unpooled;
-
-public class StompOverWebsocketBinaryTest extends AbstractStompOverWebsocketTest {
-
-   protected WebSocketFrame createFrame(String msg) {
-      return new BinaryWebSocketFrame(Unpooled.copiedBuffer(msg, Charset.forName("UTF-8")));
-   }
-}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f0fd89f2/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java
new file mode 100644
index 0000000..4d900ba
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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.activemq.artemis.tests.integration.stomp;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelDuplexHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelPromise;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.codec.http.FullHttpResponse;
+import io.netty.handler.codec.http.HttpClientCodec;
+import io.netty.handler.codec.http.HttpObjectAggregator;
+import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
+import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
+import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
+import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
+import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
+import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
+import io.netty.handler.codec.http.websocketx.WebSocketFrame;
+import io.netty.handler.codec.http.websocketx.WebSocketVersion;
+import io.netty.handler.codec.string.StringDecoder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class StompOverWebsocketTest extends StompTest {
+
+   private ChannelPromise handshakeFuture;
+
+   private final boolean useBinaryFrames;
+
+   @Parameterized.Parameters(name = "useBinaryFrames={0}")
+   public static Collection<Object[]> data() {
+      List<Object[]> list = Arrays.asList(new Object[][]{{Boolean.TRUE}, {Boolean.FALSE}});
+      return list;
+   }
+
+   public StompOverWebsocketTest(Boolean useBinaryFrames) {
+      super();
+      this.useBinaryFrames = useBinaryFrames;
+   }
+
+   @Override
+   protected void addChannelHandlers(SocketChannel ch) throws URISyntaxException {
+      ch.pipeline().addLast("http-codec", new HttpClientCodec());
+      ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192));
+      ch.pipeline().addLast(new WebsocketHandler(WebSocketClientHandshakerFactory.newHandshaker(new URI("ws://localhost:8080/websocket"), WebSocketVersion.V13, null, false, null)));
+      ch.pipeline().addLast("decoder", new StringDecoder(StandardCharsets.UTF_8));
+      ch.pipeline().addLast(new StompClientHandler());
+   }
+
+   @Override
+   protected void handshake() throws InterruptedException {
+      handshakeFuture.sync();
+   }
+
+   class WebsocketHandler extends ChannelDuplexHandler {
+
+      private WebSocketClientHandshaker handshaker;
+
+      public WebsocketHandler(WebSocketClientHandshaker webSocketClientHandshaker) {
+         this.handshaker = webSocketClientHandshaker;
+      }
+
+      @Override
+      public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
+         handshakeFuture = ctx.newPromise();
+      }
+
+      @Override
+      public void channelActive(ChannelHandlerContext ctx) throws Exception {
+         handshaker.handshake(ctx.channel());
+      }
+
+      @Override
+      public void channelInactive(ChannelHandlerContext ctx) throws Exception {
+         System.out.println("WebSocket Client disconnected!");
+      }
+
+      @Override
+      public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+         Channel ch = ctx.channel();
+         if (!handshaker.isHandshakeComplete()) {
+            handshaker.finishHandshake(ch, (FullHttpResponse) msg);
+            System.out.println("WebSocket Client connected!");
+            handshakeFuture.setSuccess();
+            return;
+         }
+
+         if (msg instanceof FullHttpResponse) {
+            FullHttpResponse response = (FullHttpResponse) msg;
+            throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" + response.content().toString(StandardCharsets.UTF_8) + ')');
+         }
+
+         WebSocketFrame frame = (WebSocketFrame) msg;
+         if (frame instanceof BinaryWebSocketFrame) {
+            BinaryWebSocketFrame dataFrame = (BinaryWebSocketFrame) frame;
+            super.channelRead(ctx, dataFrame.content());
+         }
+         else if (frame instanceof PongWebSocketFrame) {
+            System.out.println("WebSocket Client received pong");
+         }
+         else if (frame instanceof CloseWebSocketFrame) {
+            System.out.println("WebSocket Client received closing");
+            ch.close();
+         }
+      }
+
+      @Override
+      public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
+         try {
+            if (msg instanceof String) {
+               ctx.write(createFrame((String) msg), promise);
+            }
+            else {
+               super.write(ctx, msg, promise);
+            }
+         }
+         catch (Exception e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+         }
+      }
+   }
+
+
+   protected WebSocketFrame createFrame(String msg) {
+      if (useBinaryFrames) {
+         return new BinaryWebSocketFrame(Unpooled.copiedBuffer(msg, Charset.forName("UTF-8")));
+      }
+      else {
+         return new TextWebSocketFrame(msg);
+      }
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f0fd89f2/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTextTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTextTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTextTest.java
deleted file mode 100644
index ac11d71..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTextTest.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.activemq.artemis.tests.integration.stomp;
-
-import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.WebSocketFrame;
-
-public class StompOverWebsocketTextTest extends AbstractStompOverWebsocketTest {
-
-   protected WebSocketFrame createFrame(String msg) {
-      return new TextWebSocketFrame(msg);
-   }
-}