|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -13,6 +13,7 @@
@@ -13,6 +13,7 @@
|
|
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
|
* limitations under the License. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
package org.springframework.web.reactive.result.method.annotation; |
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
@ -46,11 +47,11 @@ import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod
@@ -46,11 +47,11 @@ import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod
|
|
|
|
|
import org.springframework.web.server.ResponseStatusException; |
|
|
|
|
import org.springframework.web.server.ServerWebExchange; |
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Unit tests for {@link ControllerMethodResolver}. |
|
|
|
|
* |
|
|
|
|
* @author Rossen Stoyanchev |
|
|
|
|
*/ |
|
|
|
|
public class ControllerMethodResolverTests { |
|
|
|
@ -61,8 +62,7 @@ public class ControllerMethodResolverTests {
@@ -61,8 +62,7 @@ public class ControllerMethodResolverTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
public void setUp() throws Exception { |
|
|
|
|
|
|
|
|
|
public void setup() { |
|
|
|
|
ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer(); |
|
|
|
|
resolvers.addCustomResolver(new CustomArgumentResolver()); |
|
|
|
|
resolvers.addCustomResolver(new CustomSyncArgumentResolver()); |
|
|
|
@ -84,8 +84,7 @@ public class ControllerMethodResolverTests {
@@ -84,8 +84,7 @@ public class ControllerMethodResolverTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void requestMappingArgumentResolvers() throws Exception { |
|
|
|
|
|
|
|
|
|
public void requestMappingArgumentResolvers() { |
|
|
|
|
InvocableHandlerMethod invocable = this.methodResolver.getRequestMappingMethod(this.handlerMethod); |
|
|
|
|
List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers(); |
|
|
|
|
|
|
|
|
@ -122,10 +121,8 @@ public class ControllerMethodResolverTests {
@@ -122,10 +121,8 @@ public class ControllerMethodResolverTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void modelAttributeArgumentResolvers() throws Exception { |
|
|
|
|
|
|
|
|
|
List<InvocableHandlerMethod> methods = |
|
|
|
|
this.methodResolver.getModelAttributeMethods(this.handlerMethod); |
|
|
|
|
public void modelAttributeArgumentResolvers() { |
|
|
|
|
List<InvocableHandlerMethod> methods = this.methodResolver.getModelAttributeMethods(this.handlerMethod); |
|
|
|
|
|
|
|
|
|
assertEquals("Expected one each from Controller + ControllerAdvice", 2, methods.size()); |
|
|
|
|
InvocableHandlerMethod invocable = methods.get(0); |
|
|
|
@ -160,8 +157,7 @@ public class ControllerMethodResolverTests {
@@ -160,8 +157,7 @@ public class ControllerMethodResolverTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void initBinderArgumentResolvers() throws Exception { |
|
|
|
|
|
|
|
|
|
public void initBinderArgumentResolvers() { |
|
|
|
|
List<SyncInvocableHandlerMethod> methods = |
|
|
|
|
this.methodResolver.getInitBinderMethods(this.handlerMethod); |
|
|
|
|
|
|
|
|
@ -191,11 +187,9 @@ public class ControllerMethodResolverTests {
@@ -191,11 +187,9 @@ public class ControllerMethodResolverTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void exceptionHandlerArgumentResolvers() throws Exception { |
|
|
|
|
|
|
|
|
|
InvocableHandlerMethod invocable = |
|
|
|
|
this.methodResolver.getExceptionHandlerMethod( |
|
|
|
|
new ResponseStatusException(HttpStatus.BAD_REQUEST, "reason"), this.handlerMethod); |
|
|
|
|
public void exceptionHandlerArgumentResolvers() { |
|
|
|
|
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod( |
|
|
|
|
new ResponseStatusException(HttpStatus.BAD_REQUEST, "reason"), this.handlerMethod); |
|
|
|
|
|
|
|
|
|
assertNotNull("No match", invocable); |
|
|
|
|
assertEquals(TestController.class, invocable.getBeanType()); |
|
|
|
@ -227,11 +221,9 @@ public class ControllerMethodResolverTests {
@@ -227,11 +221,9 @@ public class ControllerMethodResolverTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void exceptionHandlerFromControllerAdvice() throws Exception { |
|
|
|
|
|
|
|
|
|
InvocableHandlerMethod invocable = |
|
|
|
|
this.methodResolver.getExceptionHandlerMethod( |
|
|
|
|
new IllegalStateException("reason"), this.handlerMethod); |
|
|
|
|
public void exceptionHandlerFromControllerAdvice() { |
|
|
|
|
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod( |
|
|
|
|
new IllegalStateException("reason"), this.handlerMethod); |
|
|
|
|
|
|
|
|
|
assertNotNull(invocable); |
|
|
|
|
assertEquals(TestControllerAdvice.class, invocable.getBeanType()); |
|
|
|
@ -246,7 +238,7 @@ public class ControllerMethodResolverTests {
@@ -246,7 +238,7 @@ public class ControllerMethodResolverTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
private static class TestController { |
|
|
|
|
static class TestController { |
|
|
|
|
|
|
|
|
|
@InitBinder |
|
|
|
|
void initDataBinder() {} |
|
|
|
@ -262,8 +254,9 @@ public class ControllerMethodResolverTests {
@@ -262,8 +254,9 @@ public class ControllerMethodResolverTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ControllerAdvice |
|
|
|
|
private static class TestControllerAdvice { |
|
|
|
|
static class TestControllerAdvice { |
|
|
|
|
|
|
|
|
|
@InitBinder |
|
|
|
|
void initDataBinder() {} |
|
|
|
@ -276,7 +269,8 @@ public class ControllerMethodResolverTests {
@@ -276,7 +269,8 @@ public class ControllerMethodResolverTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static class CustomArgumentResolver implements HandlerMethodArgumentResolver { |
|
|
|
|
|
|
|
|
|
static class CustomArgumentResolver implements HandlerMethodArgumentResolver { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean supportsParameter(MethodParameter p) { |
|
|
|
@ -289,7 +283,8 @@ public class ControllerMethodResolverTests {
@@ -289,7 +283,8 @@ public class ControllerMethodResolverTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static class CustomSyncArgumentResolver extends CustomArgumentResolver |
|
|
|
|
|
|
|
|
|
static class CustomSyncArgumentResolver extends CustomArgumentResolver |
|
|
|
|
implements SyncHandlerMethodArgumentResolver { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|