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 @@ test + + org.seleniumhq.selenium + selenium-java + 2.21.0 + test + + + org.seleniumhq.selenium + selenium-chrome-driver + 2.21.0 + test + + + org.seleniumhq.selenium + selenium-firefox-driver + 2.21.0 + test + + 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 @@ + + + + This broker configuration is what the unit tests in this module load up. + + + localhost + + + + + + + \ 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 @@ + + + + + + Chat Example Using STOMP Over WebSockets + + + + + + +
Loading
+
+ + 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._ + +/** + *

+ *

+ * + * @author Hiram Chirino + */ + +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