- We use a different JDBC URL to use an in-memory database for the tests.
@Test
public void play_with_api(TestContext context) {
Async async = context.async();
JsonObject page = new JsonObject()
.put("name", "Sample")
.put("markdown", "# A page");
Promise<HttpResponse<JsonObject>> postPagePromise = Promise.promise();
webClient.post("/api/pages")
.as(BodyCodec.jsonObject())
.sendJsonObject(page, postPagePromise);
Future<HttpResponse<JsonObject>> getPageFuture = postPagePromise.future().compose(resp -> {
Promise<HttpResponse<JsonObject>> promise = Promise.promise();
webClient.get("/api/pages")
.as(BodyCodec.jsonObject())
});
Future<HttpResponse<JsonObject>> updatePageFuture = getPageFuture.compose(resp -> {
JsonArray array = resp.body().getJsonArray("pages");
context.assertEquals(1, array.size());
context.assertEquals(0, array.getJsonObject(0).getInteger("id"));
Promise<HttpResponse<JsonObject>> promise = Promise.promise();
JsonObject data = new JsonObject()
.put("id", 0)
.put("markdown", "Oh Yeah!");
webClient.put("/api/pages/0")
.as(BodyCodec.jsonObject())
.sendJsonObject(data, promise);
return promise.future();
});
Future<HttpResponse<JsonObject>> deletePageFuture = updatePageFuture.compose(resp -> {
webClient.delete("/api/pages/0")
.as(BodyCodec.jsonObject())
.send(promise);
return promise.future();
});
deletePageFuture.setHandler(ar -> {
if (ar.succeeded()) {
context.assertTrue(ar.result().body().getBoolean("success"));
async.complete();
} else {
context.fail(ar.cause());
}
});
async.awaitSuccess(5000);
}