Skip to content

Commit 11b65ce

Browse files
committed
Added more tests.
1 parent bde7548 commit 11b65ce

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/ExampleWebExceptionHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
import reactor.core.publisher.Mono;
1919

20+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2021
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
22+
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
2123
import org.springframework.http.HttpStatus;
2224
import org.springframework.stereotype.Component;
2325
import org.springframework.web.server.ServerWebExchange;
@@ -27,9 +29,11 @@
2729
* Example {@link WebExceptionHandler} used with {@link WebFluxTest} tests.
2830
*
2931
* @author Madhura Bhave
32+
* @author Ali Dehghani
3033
*/
3134
@Component
32-
public class ExampleWebExceptionHandler implements WebExceptionHandler {
35+
@ConditionalOnProperty(name = "custom-error-handler.enable")
36+
public class ExampleWebExceptionHandler implements ErrorWebExceptionHandler {
3337

3438
@Override
3539
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebFluxTestAllControllersIntegrationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929
* Tests for {@link WebFluxTest} when no explicit controller is defined.
3030
*
3131
* @author Stephane Nicoll
32+
* @author Ali Dehghani
3233
*/
3334
@RunWith(SpringRunner.class)
3435
@WithMockUser
35-
@WebFluxTest
36+
@WebFluxTest(properties = "custom-error-handler.enable=true")
3637
public class WebFluxTestAllControllersIntegrationTests {
3738

3839
@Autowired
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.test.autoconfigure.web.reactive.webclient;
18+
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
24+
import org.springframework.security.test.context.support.WithMockUser;
25+
import org.springframework.test.context.junit4.SpringRunner;
26+
import org.springframework.test.web.reactive.server.WebTestClient;
27+
28+
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
29+
30+
/**
31+
* Tests for {@link WebFluxTest} when no explicit exception handler is defined.
32+
*
33+
* @author Ali Dehghani
34+
*/
35+
@RunWith(SpringRunner.class)
36+
@WithMockUser
37+
@WebFluxTest
38+
public class WebFluxTestWithDefaultErrorHandlerTests {
39+
40+
@Autowired
41+
private WebTestClient webClient;
42+
43+
@Test
44+
public void defaultWebExceptionHandling() {
45+
// @formatter:off
46+
this.webClient.get().uri("/one/error").exchange()
47+
.expectStatus().isEqualTo(INTERNAL_SERVER_ERROR)
48+
.expectBody()
49+
.jsonPath("$.timestamp").exists()
50+
.jsonPath("$.status").isEqualTo(500)
51+
.jsonPath("$.error").isEqualTo(INTERNAL_SERVER_ERROR.getReasonPhrase())
52+
.jsonPath("$.path").isEqualTo("/one/error")
53+
.jsonPath("$.message").isEqualTo("foo");
54+
// @formatter:on
55+
}
56+
57+
}

0 commit comments

Comments
 (0)