diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactoryTests.java index 19717dd0..2ed797f1 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactoryTests.java @@ -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("

Whitelabel Error Page

"); - 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 diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactoryTests.java index e876371e..13209e19 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactoryTests.java @@ -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("

Whitelabel Error Page

"); - 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"); } }