Skip to content
Permalink
Browse files

Extracted RestxServerRule setup/teardown into dedicated public method…

…s, allowing to use this class outside a junit scope (for instance, for benchmarking)
  • Loading branch information
fcamblor committed Jan 3, 2015
1 parent 12a2f33 commit 3a259649784ea6a6b252daba026fcd4704bf8c30
Showing with 22 additions and 13 deletions.
  1. +22 −13 restx-specs-tests/src/main/java/restx/tests/RestxServerRule.java
@@ -45,27 +45,36 @@ public RestxServerRule setMode(final String mode) {
return this;
}

public void setup() throws Exception {
System.out.println("starting server");
server = webServerSupplier.newWebServer(WebServers.findAvailablePort());
contextLocal(server.getServerId()).set("restx.mode", getMode());
afterServerCreated();
server.start();
afterServerStarted();

System.out.println("server started");
}

public void tearDown() throws Exception {
beforeServerStop();
System.out.println("stopping server");
server.stop();
afterServerStop();
System.out.println("DONE");
}

@Override
public Statement apply(final Statement statement, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
System.out.println("starting server");
server = webServerSupplier.newWebServer(WebServers.findAvailablePort());
contextLocal(server.getServerId()).set("restx.mode", getMode());
afterServerCreated();
server.start();
afterServerStarted();

System.out.println("server started");
setup();

try {
statement.evaluate();
} finally {
beforeServerStop();
System.out.println("stopping server");
server.stop();
afterServerStop();
System.out.println("DONE");
tearDown();
}
}
};

0 comments on commit 3a25964

Please sign in to comment.
You can’t perform that action at this time.