You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2012/05/23 19:10:43 UTC
svn commit: r1341949 - in /activemq/activemq-apollo/trunk/apollo-stomp: ./
src/test/resources/ src/test/resources/org/apache/activemq/apollo/stomp/
src/test/scala/org/apache/activemq/apollo/stomp/
Author: chirino
Date: Wed May 23 17:10:42 2012
New Revision: 1341949
URL: http://svn.apache.org/viewvc?rev=1341949&view=rev
Log:
Added a selenium based test case for STOMP over websockets.
Added:
activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-websocket.xml
activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/org/apache/activemq/apollo/stomp/websocket.html
activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/StompWebTest.scala
Modified:
activemq/activemq-apollo/trunk/apollo-stomp/pom.xml
Modified: activemq/activemq-apollo/trunk/apollo-stomp/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/pom.xml?rev=1341949&r1=1341948&r2=1341949&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/pom.xml (original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/pom.xml Wed May 23 17:10:42 2012
@@ -116,6 +116,25 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.seleniumhq.selenium</groupId>
+ <artifactId>selenium-java</artifactId>
+ <version>2.21.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.seleniumhq.selenium</groupId>
+ <artifactId>selenium-chrome-driver</artifactId>
+ <version>2.21.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.seleniumhq.selenium</groupId>
+ <artifactId>selenium-firefox-driver</artifactId>
+ <version>2.21.0</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<build>
Added: activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-websocket.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-websocket.xml?rev=1341949&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-websocket.xml (added)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/apollo-stomp-websocket.xml Wed May 23 17:10:42 2012
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ 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.
+-->
+<broker xmlns="http://activemq.apache.org/schema/activemq/apollo">
+ <notes>This broker configuration is what the unit tests in this module load up.</notes>
+
+ <virtual_host id="default">
+ <host_name>localhost</host_name>
+ </virtual_host>
+
+ <!--<web_admin bind="http://0.0.0.0:61680"/>-->
+ <connector id="tcp" bind="tcp://0.0.0.0:0"/>
+ <connector id="ws" bind="ws://0.0.0.0:0"/>
+
+</broker>
\ No newline at end of file
Added: activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/org/apache/activemq/apollo/stomp/websocket.html
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/org/apache/activemq/apollo/stomp/websocket.html?rev=1341949&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/org/apache/activemq/apollo/stomp/websocket.html (added)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/resources/org/apache/activemq/apollo/stomp/websocket.html Wed May 23 17:10:42 2012
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<!--
+ 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.
+-->
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>Chat Example Using STOMP Over WebSockets</title>
+ <!--[if lt IE 9]>
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+ <![endif]-->
+ <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
+ <script src="../../../../../../../../apollo-distro/src/main/release/examples/websocket/js/stomp.js"></script>
+ <script>//<![CDATA[
+ $(document).ready(function() {
+ if(window.WebSocket) {
+ var url = "ws://localhost:61623";
+ if(window.location.hash) {
+ url = window.location.hash.substring(1);
+ }
+ var login = "admin";
+ var passcode = "password";
+ destination = "/queue/websocket";
+
+ $("#status").html("Connecting");
+ client = Stomp.client(url);
+
+ // the client is notified when it is connected to the server.
+ client.connect(login, passcode, function(frame) {
+ $("#status").html("Connected");
+ client.subscribe(destination, function(message) {
+ $("#received").html(message.body);
+ });
+ });
+ } else {
+ $("#status").html("No WebSockets");
+ }
+ });
+ //]]></script>
+ </head>
+ <body>
+ <div id="status">Loading</div>
+ <div id="received"></div>
+ </body>
+</html>
Added: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/StompWebTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/StompWebTest.scala?rev=1341949&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/StompWebTest.scala (added)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/StompWebTest.scala Wed May 23 17:10:42 2012
@@ -0,0 +1,146 @@
+package org.apache.activemq.apollo.stomp
+
+/**
+ * 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.
+ */
+
+import java.io.File
+import org.openqa.selenium.{By, WebDriver}
+import org.openqa.selenium.chrome.{ChromeOptions, ChromeDriver}
+import org.openqa.selenium.remote.DesiredCapabilities
+import java.util.Arrays
+import org.apache.activemq.apollo.util.FileSupport._
+import org.openqa.selenium.firefox.{FirefoxDriver, FirefoxProfile}
+import java.util.concurrent.TimeUnit._
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+
+trait WebDriverTrait {
+ def create_web_driver(profileDir: File): WebDriver
+}
+
+trait ChromeWebDriverTrait extends WebDriverTrait {
+ def create_web_driver(profileDir: File) = {
+ // val f = new File("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
+ // if( f.exists() ) {
+ // System.setProperty("webdriver.chrome.driver", f.getCanonicalPath)
+ // }
+
+ val file = profileDir / "chrome"
+ file.mkdirs
+ val options = new ChromeOptions()
+ options.addArguments("--enable-udd-profiles", "--user-data-dir=" + file, "--allow-file-access-from-files")
+ // val capabilities = new DesiredCapabilities
+ // capabilities.setCapability("chrome.switches", Arrays.asList("--enable-udd-profiles", "--user-data-dir="+file, "--allow-file-access-from-files"));
+ new ChromeDriver(options)
+ }
+}
+
+trait FirefoxWebDriverTrait extends WebDriverTrait {
+ def create_web_driver(profileDir: File) = {
+ var file = profileDir / "firefox"
+ file.mkdirs
+ val profile = new FirefoxProfile(file);
+ new FirefoxDriver(profile)
+ }
+}
+
+
+abstract class StompWebSocketTestSupport extends StompTestSupport with WebDriverTrait {
+
+ var driver: WebDriver = _
+
+ override def broker_config_uri = "xml:classpath:apollo-stomp-websocket.xml"
+
+ def ws_port: Int = connector_port("ws").get
+
+ override protected def beforeAll() = {
+ try {
+ driver = create_web_driver(test_data_dir / "profile")
+ super.beforeAll()
+ } catch {
+ case ignore: Exception =>
+ println("ignoring tests, could not create web driver: " + ignore)
+ }
+ }
+
+ override protected def afterAll() = {
+ if (driver != null) {
+ driver.quit()
+ driver = null
+ }
+ }
+
+ override protected def test(testName: String, testTags: org.scalatest.Tag*)(testFun: => scala.Unit): Unit = {
+ super.test(testName, testTags: _*) {
+ if (driver != null) {
+ testFun
+ }
+ }
+ }
+
+ test("websocket") {
+ val url = getClass.getResource("websocket.html")
+
+ System.out.println("url: " + url)
+ driver.get(url + "#ws://127.0.0.1:" + ws_port);
+ val web_status = driver.findElement(By.id("status"));
+ val web_received = driver.findElement(By.id("received"));
+
+ while ("Loading" == web_status.getText) {
+ Thread.sleep(100)
+ }
+
+ // Skip test if browser does not support websockets..
+ if (web_status.getText != "No WebSockets") {
+
+ // Wait for it to get connected..
+ within(2, SECONDS) {
+ web_status.getText should be("Connected")
+ }
+
+ // Send a message via normal TCP stomp..
+ connect("1.1")
+ async_send("/queue/websocket", "Hello")
+ within(2, SECONDS) {
+ // it should get received by the websocket client.
+ web_received.getText should be("Hello")
+ }
+
+ // Send a bunch of messages..
+ val send_count = 100000
+ for (i <- 1 to send_count) {
+ async_send("/queue/websocket", "messages #" + i)
+ }
+
+ within(10, SECONDS) {
+ // it should get received by the websocket client.
+ web_received.getText should be("messages #" + send_count)
+ }
+
+ }
+
+ }
+}
+
+class ChromeStompWebSocketTest extends StompWebSocketTestSupport with ChromeWebDriverTrait
+
+class FirefoxStompWebSocketTest extends StompWebSocketTestSupport with FirefoxWebDriverTrait
\ No newline at end of file