From 691e709aa39dd8545d78930fb64e330367c6a380 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Thu, 6 Dec 2012 19:34:01 +0000 Subject: [PATCH] AlexeiBarantsev: Using Jetty7AppServer to serve test pages for Selenium RC and WebDriverBackedSelenium tests. It's a prerequisite to run WDBS tests on CI. r18268 --- .../webserver/Jetty7AppServer.java | 12 ++-- .../openqa/selenium/v1/SeleniumAppServer.java | 64 +++++-------------- .../selenium/v1/SeleniumTestEnvironment.java | 3 +- 3 files changed, 23 insertions(+), 56 deletions(-) diff --git a/java/client/test/org/openqa/selenium/environment/webserver/Jetty7AppServer.java b/java/client/test/org/openqa/selenium/environment/webserver/Jetty7AppServer.java index 48e422c652803..8d93e60b93508 100644 --- a/java/client/test/org/openqa/selenium/environment/webserver/Jetty7AppServer.java +++ b/java/client/test/org/openqa/selenium/environment/webserver/Jetty7AppServer.java @@ -145,26 +145,26 @@ public String getAlternateHostName() { } public String whereIs(String relativeUrl) { - relativeUrl = getCommonPath(relativeUrl); + relativeUrl = getMainContextPath(relativeUrl); return "http://" + getHostName() + ":" + port + relativeUrl; } public String whereElseIs(String relativeUrl) { - relativeUrl = getCommonPath(relativeUrl); + relativeUrl = getMainContextPath(relativeUrl); return "http://" + getAlternateHostName() + ":" + port + relativeUrl; } public String whereIsSecure(String relativeUrl) { - relativeUrl = getCommonPath(relativeUrl); + relativeUrl = getMainContextPath(relativeUrl); return "https://" + getHostName() + ":" + securePort + relativeUrl; } public String whereIsWithCredentials(String relativeUrl, String user, String pass) { - relativeUrl = getCommonPath(relativeUrl); + relativeUrl = getMainContextPath(relativeUrl); return "http://" + user + ":" + pass + "@" + getHostName() + ":" + port + relativeUrl; } - private String getCommonPath(String relativeUrl) { + protected String getMainContextPath(String relativeUrl) { if (!relativeUrl.startsWith("/")) { relativeUrl = DEFAULT_CONTEXT_PATH + "/" + relativeUrl; } @@ -244,7 +244,7 @@ public void addFilter(Class filter, String path, defaultContext.addFilter(filter, path, dispatches); } - private WebAppContext addWebApplication(String contextPath, File rootDir) { + protected WebAppContext addWebApplication(String contextPath, File rootDir) { return addWebApplication(contextPath, rootDir.getAbsolutePath()); } diff --git a/java/client/test/org/openqa/selenium/v1/SeleniumAppServer.java b/java/client/test/org/openqa/selenium/v1/SeleniumAppServer.java index 45945db57984a..2a3d0f454f99a 100644 --- a/java/client/test/org/openqa/selenium/v1/SeleniumAppServer.java +++ b/java/client/test/org/openqa/selenium/v1/SeleniumAppServer.java @@ -16,62 +16,28 @@ package org.openqa.selenium.v1; -import org.openqa.selenium.environment.webserver.AppServer; +import java.io.File; -import javax.servlet.Servlet; +import org.openqa.selenium.environment.webserver.Jetty7AppServer; +import org.openqa.selenium.testing.InProject; -public class SeleniumAppServer implements AppServer { - private final int port; +public class SeleniumAppServer extends Jetty7AppServer { - public SeleniumAppServer(int port) { - this.port = port; - } - - public String getHostName() { - return "localhost"; - } - - public String getAlternateHostName() { - throw new UnsupportedOperationException("getAlternateHostName"); - } - - public String whereIs(String relativeUrl) { - return "http://localhost:" + port + relativeUrl; - } - - public String whereElseIs(String relativeUrl) { - throw new UnsupportedOperationException("whereElseIs"); - } - - public String whereIsSecure(String relativeUrl) { - throw new UnsupportedOperationException("whereIsSecure"); - } - - public String whereIsWithCredentials(String relativeUrl, String user, String password) { - throw new UnsupportedOperationException("whereIsWithCredentials"); - } - - public void start() { - // does nothing - } - - public void stop() { - // does nothing - } - - public void addAdditionalWebApplication(String context, String absolutePath) { - throw new UnsupportedOperationException("addAdditionalWebApplication"); - } + private static final String RC_CONTEXT_PATH = "/selenium-server"; - public void addServlet(String name, String url, Class servletClass) { - throw new UnsupportedOperationException("addServlet"); + public SeleniumAppServer() { + super(); + addWebApplication(RC_CONTEXT_PATH, findRootOfRcTestPages()); } - public void listenOn(int port) { - throw new UnsupportedOperationException("listenOn"); + protected File findRootOfRcTestPages() { + return InProject.locate("java/server/test/org/openqa/selenium"); } - public void listenSecurelyOn(int port) { - throw new UnsupportedOperationException("listenSecurelyOn"); + protected String getMainContextPath(String relativeUrl) { + if (!relativeUrl.startsWith("/")) { + relativeUrl = RC_CONTEXT_PATH + "/" + relativeUrl; + } + return relativeUrl; } } diff --git a/java/client/test/org/openqa/selenium/v1/SeleniumTestEnvironment.java b/java/client/test/org/openqa/selenium/v1/SeleniumTestEnvironment.java index 0d03dc35f0214..47a90ba7ef590 100644 --- a/java/client/test/org/openqa/selenium/v1/SeleniumTestEnvironment.java +++ b/java/client/test/org/openqa/selenium/v1/SeleniumTestEnvironment.java @@ -78,7 +78,8 @@ public SeleniumTestEnvironment(int port, String... extraArgs) { throw new RuntimeException(e); } - appServer = new SeleniumAppServer(port); + appServer = new SeleniumAppServer(); + appServer.start(); } public SeleniumTestEnvironment(String... extraArgs) {