Skip to content

Commit

Permalink
Extracted RestxServerRule setup/teardown into dedicated public method…
Browse files Browse the repository at this point in the history
…s, allowing to use this class outside a junit scope (for instance, for benchmarking)
  • Loading branch information
fcamblor committed Jan 22, 2015
1 parent 12a2f33 commit 3a25964
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions restx-specs-tests/src/main/java/restx/tests/RestxServerRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
};
Expand Down

0 comments on commit 3a25964

Please sign in to comment.