Skip to content

Commit

Permalink
Fix flaky rest-client test
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Apr 1, 2021
1 parent 23c529a commit eef926f
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<Map> 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<Object, Long> valueByCount = results.stream().collect(Collectors.groupingBy(m -> m.get("cultivar"), counting()));
assertThat(valueByCount).containsOnly(entry("cortland", 3L), entry("cortland2", 3L), entry("cortland3", 3L));
}
}

0 comments on commit eef926f

Please sign in to comment.