Skip to content

Commit

Permalink
AlexeiBarantsev: Using Jetty7AppServer to serve test pages for Seleni…
Browse files Browse the repository at this point in the history
…um RC and WebDriverBackedSelenium tests. It's a prerequisite to run WDBS tests on CI.

r18268
  • Loading branch information
barancev committed Dec 6, 2012
1 parent cd9bd84 commit 691e709
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -244,7 +244,7 @@ public void addFilter(Class<? extends Filter> 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());
}

Expand Down
64 changes: 15 additions & 49 deletions java/client/test/org/openqa/selenium/v1/SeleniumAppServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Servlet> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 691e709

Please sign in to comment.