-
Notifications
You must be signed in to change notification settings - Fork 825
Closed
Description
Description
Refactor TestHTTPServer for cleaner use
Background
As part of the work to add HTTP authentication and cleaner SSL support into HTTPServer, as well as other other test, we have a large number of request helper methods.
request(String requestMethod, HTTPServer s, String context, String suffix) throws IOException
request(HTTPServer s, String context, String suffix) throws IOException
request(HTTPServer s, String suffix) throws IOException
... etc.
Refactoring would allow cleaner tests.
Proposal
Create Request and Response classes. Provider a Request.Builder class to allow easy Request configuration for the associated test.
Example (using Request and Response):
@Test
public void testSimpleRequest() throws IOException {
HTTPServer httpServer = new HTTPServer(new InetSocketAddress(0), registry);
Request request =
new Request.Builder(Request.TYPE.GET, "localhost", httpServer.getPort())
.withContext("/metrics")
.build();
try {
String body = request.execute().getBody();
assertThat(body).contains("a 0.0");
assertThat(body).contains("b 0.0");
assertThat(body).contains("c 0.0");
} finally {
httpServer.close();
}
}
Impact
Easier test creation.
Reuse of HTTP client code (minimize code paths)
Metadata
Metadata
Assignees
Labels
No labels