From eef926f10db5b75ad083e1e3412021e6538417f2 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 1 Apr 2021 19:17:09 +0300 Subject: [PATCH] Fix flaky rest-client test Relates to: https://github.com/quarkusio/quarkus/pull/16138#issuecomment-811880118 --- .../io/quarkus/it/rest/client/BasicTest.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/integration-tests/resteasy-reactive-rest-client/src/test/java/io/quarkus/it/rest/client/BasicTest.java b/integration-tests/resteasy-reactive-rest-client/src/test/java/io/quarkus/it/rest/client/BasicTest.java index c4d622802fd5d..6b0b985d0cf3b 100644 --- a/integration-tests/resteasy-reactive-rest-client/src/test/java/io/quarkus/it/rest/client/BasicTest.java +++ b/integration-tests/resteasy-reactive-rest-client/src/test/java/io/quarkus/it/rest/client/BasicTest.java @@ -1,7 +1,12 @@ package io.quarkus.it.rest.client; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.equalTo; +import static java.util.stream.Collectors.counting; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import org.junit.jupiter.api.Test; @@ -15,21 +20,18 @@ public class BasicTest { @TestHTTPResource("/apples") String appleUrl; + @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void shouldWork() { - RestAssured.with().body(appleUrl).post("/call-client") + List results = RestAssured.with().body(appleUrl).post("/call-client") .then() .statusCode(200) .contentType("application/json") - .body("size()", is(9)) - .body("[0].cultivar", equalTo("cortland")) - .body("[1].cultivar", equalTo("cortland2")) - .body("[2].cultivar", equalTo("cortland3")) - .body("[3].cultivar", equalTo("cortland")) - .body("[4].cultivar", equalTo("cortland2")) - .body("[5].cultivar", equalTo("cortland3")) - .body("[6].cultivar", equalTo("cortland")) - .body("[7].cultivar", equalTo("cortland2")) - .body("[8].cultivar", equalTo("cortland3")); + .extract().body().jsonPath().getList(".", Map.class); + assertThat(results).hasSize(9).allSatisfy(m -> { + assertThat(m).containsOnlyKeys("cultivar"); + }); + Map valueByCount = results.stream().collect(Collectors.groupingBy(m -> m.get("cultivar"), counting())); + assertThat(valueByCount).containsOnly(entry("cortland", 3L), entry("cortland2", 3L), entry("cortland3", 3L)); } }