Skip to content

Commit 3a25964

Browse files
committed
Extracted RestxServerRule setup/teardown into dedicated public methods, allowing to use this class outside a junit scope (for instance, for benchmarking)
1 parent 12a2f33 commit 3a25964

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

restx-specs-tests/src/main/java/restx/tests/RestxServerRule.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,36 @@ public RestxServerRule setMode(final String mode) {
4545
return this;
4646
}
4747

48+
public void setup() throws Exception {
49+
System.out.println("starting server");
50+
server = webServerSupplier.newWebServer(WebServers.findAvailablePort());
51+
contextLocal(server.getServerId()).set("restx.mode", getMode());
52+
afterServerCreated();
53+
server.start();
54+
afterServerStarted();
55+
56+
System.out.println("server started");
57+
}
58+
59+
public void tearDown() throws Exception {
60+
beforeServerStop();
61+
System.out.println("stopping server");
62+
server.stop();
63+
afterServerStop();
64+
System.out.println("DONE");
65+
}
66+
4867
@Override
4968
public Statement apply(final Statement statement, Description description) {
5069
return new Statement() {
5170
@Override
5271
public void evaluate() throws Throwable {
53-
System.out.println("starting server");
54-
server = webServerSupplier.newWebServer(WebServers.findAvailablePort());
55-
contextLocal(server.getServerId()).set("restx.mode", getMode());
56-
afterServerCreated();
57-
server.start();
58-
afterServerStarted();
59-
60-
System.out.println("server started");
72+
setup();
73+
6174
try {
6275
statement.evaluate();
6376
} finally {
64-
beforeServerStop();
65-
System.out.println("stopping server");
66-
server.stop();
67-
afterServerStop();
68-
System.out.println("DONE");
77+
tearDown();
6978
}
7079
}
7180
};

0 commit comments

Comments
 (0)