Updates circuit breaker error page assertions

This commit is contained in:
Spencer Gibb
2019-12-10 13:51:39 -05:00
parent c8df400f01
commit 1eb84605ee
2 changed files with 9 additions and 30 deletions

View File

@@ -30,12 +30,11 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.core.StringContains.containsString;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.cloud.gateway.filter.factory.ExceptionFallbackHandler.RETRIEVED_EXCEPTION;
import static org.springframework.http.MediaType.TEXT_HTML;
import static org.springframework.http.MediaType.APPLICATION_JSON;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT, properties = "debug=true")
@@ -125,18 +124,9 @@ public class HystrixGatewayFilterFactoryTests extends BaseWebClientTests {
@Test
public void hystrixFilterErrorPage() {
testClient.get().uri("/delay/3").header("Host", "www.hystrixconnectfail.org")
.accept(TEXT_HTML).exchange().expectStatus().is5xxServerError()
.expectBody().consumeWith(res -> {
assertThat(res.getResponseBody()).isNotNull();
String body = new String(res.getResponseBody(), UTF_8);
assertThat(body).as(
"Cannot find the expected white-label error page title in the response")
.contains("<h1>Whitelabel Error Page</h1>");
assertThat(body).as(
"Cannot find the expected error status report in the response")
.contains("(type=Internal Server Error, status=500)");
});
.accept(APPLICATION_JSON).exchange().expectStatus().is5xxServerError()
.expectBody().jsonPath("$.status").isEqualTo(500).jsonPath("$.message")
.isNotEmpty().jsonPath("$.error").isEqualTo("Internal Server Error");
}
@Test

View File

@@ -21,9 +21,7 @@ import org.junit.Test;
import org.springframework.cloud.gateway.test.BaseWebClientTests;
import org.springframework.http.HttpStatus;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.MediaType.TEXT_HTML;
import static org.springframework.http.MediaType.APPLICATION_JSON;
/**
* @author Ryan Baxter
@@ -92,19 +90,10 @@ public abstract class SpringCloudCircuitBreakerFilterFactoryTests
@Test
public void filterErrorPage() {
testClient.get().uri("/delay/3")
.header("Host", "www.circuitbreakerconnectfail.org").accept(TEXT_HTML)
.exchange().expectStatus().is5xxServerError().expectBody()
.consumeWith(res -> {
assertThat(res.getResponseBody()).isNotNull();
String body = new String(res.getResponseBody(), UTF_8);
assertThat(body).as(
"Cannot find the expected white-label error page title in the response")
.contains("<h1>Whitelabel Error Page</h1>");
assertThat(body).as(
"Cannot find the expected error status report in the response")
.contains("(type=Internal Server Error, status=500)");
});
.header("Host", "www.circuitbreakerconnectfail.org")
.accept(APPLICATION_JSON).exchange().expectStatus().is5xxServerError()
.expectBody().jsonPath("$.status").isEqualTo(500).jsonPath("$.message")
.isNotEmpty().jsonPath("$.error").isEqualTo("Internal Server Error");
}
}