|
| 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