|
|
|
@ -52,10 +52,8 @@ import org.springframework.web.server.handler.ExceptionHandlingWebHandler; |
|
|
|
import static org.hamcrest.CoreMatchers.instanceOf; |
|
|
|
import static org.hamcrest.CoreMatchers.instanceOf; |
|
|
|
import static org.hamcrest.CoreMatchers.startsWith; |
|
|
|
import static org.hamcrest.CoreMatchers.startsWith; |
|
|
|
import static org.hamcrest.Matchers.is; |
|
|
|
import static org.hamcrest.Matchers.is; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.assertSame; |
|
|
|
import static org.springframework.http.MediaType.*; |
|
|
|
import static org.junit.Assert.assertThat; |
|
|
|
|
|
|
|
import static org.springframework.http.MediaType.APPLICATION_JSON; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Test the effect of exceptions at different stages of request processing by |
|
|
|
* Test the effect of exceptions at different stages of request processing by |
|
|
|
@ -72,7 +70,7 @@ public class DispatcherHandlerErrorTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
@Before |
|
|
|
public void setup() throws Exception { |
|
|
|
public void setup() { |
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
|
|
|
ctx.register(TestConfig.class); |
|
|
|
ctx.register(TestConfig.class); |
|
|
|
ctx.refresh(); |
|
|
|
ctx.refresh(); |
|
|
|
@ -81,7 +79,7 @@ public class DispatcherHandlerErrorTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void noHandler() throws Exception { |
|
|
|
public void noHandler() { |
|
|
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/does-not-exist")); |
|
|
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/does-not-exist")); |
|
|
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange); |
|
|
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange); |
|
|
|
|
|
|
|
|
|
|
|
@ -95,7 +93,7 @@ public class DispatcherHandlerErrorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void controllerReturnsMonoError() throws Exception { |
|
|
|
public void controllerReturnsMonoError() { |
|
|
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/error-signal")); |
|
|
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/error-signal")); |
|
|
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange); |
|
|
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange); |
|
|
|
|
|
|
|
|
|
|
|
@ -105,7 +103,7 @@ public class DispatcherHandlerErrorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void controllerThrowsException() throws Exception { |
|
|
|
public void controllerThrowsException() { |
|
|
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/raise-exception")); |
|
|
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/raise-exception")); |
|
|
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange); |
|
|
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange); |
|
|
|
|
|
|
|
|
|
|
|
@ -115,7 +113,7 @@ public class DispatcherHandlerErrorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void unknownReturnType() throws Exception { |
|
|
|
public void unknownReturnType() { |
|
|
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-return-type")); |
|
|
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-return-type")); |
|
|
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange); |
|
|
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange); |
|
|
|
|
|
|
|
|
|
|
|
@ -128,7 +126,7 @@ public class DispatcherHandlerErrorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void responseBodyMessageConversionError() throws Exception { |
|
|
|
public void responseBodyMessageConversionError() { |
|
|
|
ServerWebExchange exchange = MockServerWebExchange.from( |
|
|
|
ServerWebExchange exchange = MockServerWebExchange.from( |
|
|
|
MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body")); |
|
|
|
MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body")); |
|
|
|
|
|
|
|
|
|
|
|
@ -140,7 +138,7 @@ public class DispatcherHandlerErrorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void requestBodyError() throws Exception { |
|
|
|
public void requestBodyError() { |
|
|
|
ServerWebExchange exchange = MockServerWebExchange.from( |
|
|
|
ServerWebExchange exchange = MockServerWebExchange.from( |
|
|
|
MockServerHttpRequest.post("/request-body").body(Mono.error(EXCEPTION))); |
|
|
|
MockServerHttpRequest.post("/request-body").body(Mono.error(EXCEPTION))); |
|
|
|
|
|
|
|
|
|
|
|
@ -152,7 +150,7 @@ public class DispatcherHandlerErrorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void webExceptionHandler() throws Exception { |
|
|
|
public void webExceptionHandler() { |
|
|
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-argument-type")); |
|
|
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-argument-type")); |
|
|
|
|
|
|
|
|
|
|
|
List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler()); |
|
|
|
List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler()); |
|
|
|
@ -202,12 +200,12 @@ public class DispatcherHandlerErrorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/raise-exception") |
|
|
|
@RequestMapping("/raise-exception") |
|
|
|
public void raiseException() throws Exception { |
|
|
|
public void raiseException() { |
|
|
|
throw EXCEPTION; |
|
|
|
throw EXCEPTION; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/unknown-return-type") |
|
|
|
@RequestMapping("/unknown-return-type") |
|
|
|
public Foo unknownReturnType() throws Exception { |
|
|
|
public Foo unknownReturnType() { |
|
|
|
return new Foo(); |
|
|
|
return new Foo(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|