diff --git a/gateleen-test/src/test/java/org/swisspush/gateleen/routing/RequestHopValidationTest.java b/gateleen-test/src/test/java/org/swisspush/gateleen/routing/RequestHopValidationTest.java index b1d51a5ce..109c24dfc 100644 --- a/gateleen-test/src/test/java/org/swisspush/gateleen/routing/RequestHopValidationTest.java +++ b/gateleen-test/src/test/java/org/swisspush/gateleen/routing/RequestHopValidationTest.java @@ -1,6 +1,7 @@ package org.swisspush.gateleen.routing; import com.google.common.collect.ImmutableMap; +import com.jayway.awaitility.Duration; import com.jayway.restassured.RestAssured; import io.vertx.core.json.JsonObject; import io.vertx.ext.unit.Async; @@ -13,6 +14,7 @@ import static com.jayway.restassured.RestAssured.*; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.core.IsEqual.equalTo; import static org.swisspush.gateleen.core.util.HttpRequestHeader.X_HOPS; /** @@ -78,17 +80,23 @@ public void testRequestHopValidationLimitExceeded(TestContext context) { when().get("/loop/4/resource").then().assertThat().statusCode(200); // get the test data via looping rules - when().get("/loop/1/resource").then().assertThat() - .statusCode(500) - .statusLine(containsString("Request hops limit exceeded")) - .body(containsString(buildLimitExceededMessage(2))); - when().get("/loop/2/resource").then().assertThat() - .statusCode(500) - .statusLine(containsString("Request hops limit exceeded")) - .body(containsString(buildLimitExceededMessage(2))); - when().get("/loop/3/resource").then().assertThat() - .statusCode(200) - .body(not(containsString(buildLimitExceededMessage(2)))); + com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + when().get("/loop/1/resource").then().assertThat() + .statusCode(500) + .statusLine(containsString("Request hops limit exceeded")) + .body(containsString(buildLimitExceededMessage(2))) + ); + com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + when().get("/loop/2/resource").then().assertThat() + .statusCode(500) + .statusLine(containsString("Request hops limit exceeded")) + .body(containsString(buildLimitExceededMessage(2))) + ); + com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + when().get("/loop/3/resource").then().assertThat() + .statusCode(200) + .body(not(containsString(buildLimitExceededMessage(2)))) + ); async.complete(); } @@ -197,15 +205,19 @@ public void testRequestHopValidationWithLimitZero(TestContext context) { with().body("{\"request.hops.limit\":0}").put(ROUTING_CONFIG).then().assertThat().statusCode(200); // prepare test data - with().body("{\"someKey\":"+System.currentTimeMillis()+"}").put("/loop/4/resource").then().assertThat() - .statusCode(500) - .statusLine(containsString("Request hops limit exceeded")) - .body(containsString(buildLimitExceededMessage(0))); + com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + with().body("{\"someKey\":"+System.currentTimeMillis()+"}").put("/loop/4/resource").then().assertThat() + .statusCode(500) + .statusLine(containsString("Request hops limit exceeded")) + .body(containsString(buildLimitExceededMessage(0))) + ); - when().get("/loop/4/resource").then().assertThat() - .statusCode(500) - .statusLine(containsString("Request hops limit exceeded")) - .body(containsString(buildLimitExceededMessage(0))); + com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + when().get("/loop/4/resource").then().assertThat() + .statusCode(500) + .statusLine(containsString("Request hops limit exceeded")) + .body(containsString(buildLimitExceededMessage(0))) + ); delete(ROUTING_CONFIG); validateRoutingConfig(false, 0); @@ -228,7 +240,9 @@ public void testRequestHopValidationManualHeaderValue(TestContext context) { TestUtils.putRoutingRules(rules); // configure request hops limit to 10 - with().body("{\"request.hops.limit\":10}").put(ROUTING_CONFIG).then().assertThat().statusCode(200); + com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + with().body("{\"request.hops.limit\":10}").put(ROUTING_CONFIG).then().assertThat().statusCode(200) + ); validateRoutingConfig(true, 10); // prepare test data