Я хочу использовать WebTestClient для выполнения полного интеграционного теста.
Мой тест прост:
@Test
public void createPostTest() {
Post post = new Post("someUserId", "Kim", "Gysen",
"Some text", "http://zwoop.be/imagenr",
"googlePlaceId", "googlePlaceName", new Geolocation(50, 50));
webTestClient.post().uri(BASE_URI)
.contentType(MediaType.APPLICATION_JSON_UTF8)
.accept(MediaType.APPLICATION_JSON_UTF8)
.body(Mono.just(post), Post.class)
.exchange()
.expectStatus().isCreated()
.expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8)
.expectBody()
.jsonPath("$._id").isNotEmpty()
.jsonPath("$.userId").isEqualTo(post.getUserId())
.jsonPath("$.firstName").isEqualTo(post.getFirstName())
.jsonPath("$.lastName").isEqualTo(post.getLastName())
.jsonPath("$.postText").isEqualTo(post.getPostText())
.jsonPath("$.postImageUri").isEqualTo(post.getPostImageUri())
.jsonPath("$.location.latitude").isEqualTo(post.getLocation().getX())
.jsonPath("$.location.longitude").isEqualTo(post.getLocation().getY());
// Verify whether the post has properly been stored in db / cache
}
У меня вопрос, есть ли способ:
- Обеспечить обратный вызов, где я могу получить результат json в целом, чтобы проверить, правильно ли объект был сохранен в моей базе данных и кэше;
- Сделайте этот метод блокирующим, чтобы впоследствии я мог проверить результат.