1. We use a different JDBC URL to use an in-memory database for the tests.
    1. @Test
    2. public void play_with_api(TestContext context) {
    3. Async async = context.async();
    4. JsonObject page = new JsonObject()
    5. .put("name", "Sample")
    6. .put("markdown", "# A page");
    7. Promise<HttpResponse<JsonObject>> postPagePromise = Promise.promise();
    8. webClient.post("/api/pages")
    9. .as(BodyCodec.jsonObject())
    10. .sendJsonObject(page, postPagePromise);
    11. Future<HttpResponse<JsonObject>> getPageFuture = postPagePromise.future().compose(resp -> {
    12. Promise<HttpResponse<JsonObject>> promise = Promise.promise();
    13. webClient.get("/api/pages")
    14. .as(BodyCodec.jsonObject())
    15. });
    16. Future<HttpResponse<JsonObject>> updatePageFuture = getPageFuture.compose(resp -> {
    17. JsonArray array = resp.body().getJsonArray("pages");
    18. context.assertEquals(1, array.size());
    19. context.assertEquals(0, array.getJsonObject(0).getInteger("id"));
    20. Promise<HttpResponse<JsonObject>> promise = Promise.promise();
    21. JsonObject data = new JsonObject()
    22. .put("id", 0)
    23. .put("markdown", "Oh Yeah!");
    24. webClient.put("/api/pages/0")
    25. .as(BodyCodec.jsonObject())
    26. .sendJsonObject(data, promise);
    27. return promise.future();
    28. });
    29. Future<HttpResponse<JsonObject>> deletePageFuture = updatePageFuture.compose(resp -> {
    30. webClient.delete("/api/pages/0")
    31. .as(BodyCodec.jsonObject())
    32. .send(promise);
    33. return promise.future();
    34. });
    35. deletePageFuture.setHandler(ar -> {
    36. if (ar.succeeded()) {
    37. context.assertTrue(ar.result().body().getBoolean("success"));
    38. async.complete();
    39. } else {
    40. context.fail(ar.cause());
    41. }
    42. });
    43. async.awaitSuccess(5000);
    44. }