.allowDirectoryListing().on("/test"))
.build())
.setRouterPath("/api").setPort(WebServers.findAvailablePort()).build();
server.start();
try {
HttpRequest httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
assertThat(httpRequest.code()).isEqualTo(200);
assertThat(httpRequest.body().trim()).isEqualTo("[\n]");
httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/test.txt").send("bonjour");
assertThat(httpRequest.code()).isEqualTo(HttpStatus.CREATED.getCode());
httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/test.txt");
assertThat(httpRequest.code()).isEqualTo(200);
assertThat(httpRequest.body().trim()).isEqualTo("bonjour");
httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
assertThat(httpRequest.code()).isEqualTo(200);
assertThat(httpRequest.body().trim()).isEqualTo("[\n" +
"\"test.txt\"\n" +
"]");
httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/test.txt").send("hello");
assertThat(httpRequest.code()).isEqualTo(HttpStatus.ACCEPTED.getCode());
httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/test.txt");
assertThat(httpRequest.code()).isEqualTo(200);
assertThat(httpRequest.body().trim()).isEqualTo("hello");
httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/test2.txt").send("bonjour");
assertThat(httpRequest.code()).isEqualTo(HttpStatus.CREATED.getCode());
httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
assertThat(httpRequest.code()).isEqualTo(200);
assertThat(httpRequest.body().trim()).isIn("[\n" +
"\"test.txt\",\n" +
"\"test2.txt\"\n" +
"]", "[\n" +
"\"test2.txt\",\n" +
"\"test.txt\"\n" +
"]");
httpRequest = HttpRequest.delete(server.baseUrl() + "/api/test/test.txt");
assertThat(httpRequest.code()).isEqualTo(HttpStatus.NO_CONTENT.getCode());
httpRequest = HttpRequest.delete(server.baseUrl() + "/api/test/test2.txt");
assertThat(httpRequest.code()).isEqualTo(HttpStatus.NO_CONTENT.getCode());
httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
assertThat(httpRequest.code()).isEqualTo(200);
assertThat(httpRequest.body().trim()).isEqualTo("[\n]");
httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/dir/").send("[]");
assertThat(httpRequest.code()).isEqualTo(HttpStatus.CREATED.getCode());
httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
assertThat(httpRequest.code()).isEqualTo(200);
assertThat(httpRequest.body().trim()).isEqualTo("[\n" +
"\"dir/\"\n" +
"]");
httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/dir/");
assertThat(httpRequest.code()).isEqualTo(200);
assertThat(httpRequest.body().trim()).isEqualTo("[\n]");
httpRequest = HttpRequest.delete(server.baseUrl() + "/api/test/dir/");
assertThat(httpRequest.code()).isEqualTo(HttpStatus.NO_CONTENT.getCode());
httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/");
assertThat(httpRequest.code()).isEqualTo(200);
assertThat(httpRequest.body().trim()).isEqualTo("[\n]");
httpRequest = HttpRequest.put(server.baseUrl() + "/api/test/dir/test.txt").send("bonjour");
assertThat(httpRequest.code()).isEqualTo(HttpStatus.CREATED.getCode());
httpRequest = HttpRequest.get(server.baseUrl() + "/api/test/dir/test.txt");
assertThat(httpRequest.code()).isEqualTo(200);
assertThat(httpRequest.body().trim()).isEqualTo("bonjour");
} finally {
server.stop();
}
}