Search in sources :

Example 51 with MethodParameter

use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.

the class RequestParamMapMethodArgumentResolverTests method supportsParameter.

@Test
public void supportsParameter() {
    MethodParameter param = this.testMethod.annot(requestParam().noName()).arg(Map.class);
    assertTrue(resolver.supportsParameter(param));
    param = this.testMethod.annotPresent(RequestParam.class).arg(MultiValueMap.class);
    assertTrue(resolver.supportsParameter(param));
    param = this.testMethod.annot(requestParam().name("name")).arg(Map.class);
    assertFalse(resolver.supportsParameter(param));
    param = this.testMethod.annotNotPresent(RequestParam.class).arg(Map.class);
    assertFalse(resolver.supportsParameter(param));
}
Also used : MethodParameter(org.springframework.core.MethodParameter) MultiValueMap(org.springframework.util.MultiValueMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test)

Example 52 with MethodParameter

use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.

the class HandlerMethodArgumentResolverCompositeTests method setUp.

@Before
public void setUp() throws Exception {
    resolvers = new HandlerMethodArgumentResolverComposite();
    Method method = getClass().getDeclaredMethod("handle", Integer.class, String.class);
    paramInt = new MethodParameter(method, 0);
    paramStr = new MethodParameter(method, 1);
}
Also used : Method(java.lang.reflect.Method) MethodParameter(org.springframework.core.MethodParameter) Before(org.junit.Before)

Example 53 with MethodParameter

use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.

the class HandlerMethodReturnValueHandlerCompositeTests method handleReturnValueWithAsyncHandler.

// SPR-13083
@Test
public void handleReturnValueWithAsyncHandler() throws Exception {
    Promise<Integer> promise = new Promise<>();
    MethodParameter promiseType = new MethodParameter(getClass().getDeclaredMethod("handlePromise"), -1);
    HandlerMethodReturnValueHandler responseBodyHandler = mock(HandlerMethodReturnValueHandler.class);
    when(responseBodyHandler.supportsReturnType(promiseType)).thenReturn(true);
    this.handlers.addHandler(responseBodyHandler);
    AsyncHandlerMethodReturnValueHandler promiseHandler = mock(AsyncHandlerMethodReturnValueHandler.class);
    when(promiseHandler.supportsReturnType(promiseType)).thenReturn(true);
    when(promiseHandler.isAsyncReturnValue(promise, promiseType)).thenReturn(true);
    this.handlers.addHandler(promiseHandler);
    this.handlers.handleReturnValue(promise, promiseType, this.mavContainer, null);
    verify(promiseHandler).isAsyncReturnValue(promise, promiseType);
    verify(promiseHandler).supportsReturnType(promiseType);
    verify(promiseHandler).handleReturnValue(promise, promiseType, this.mavContainer, null);
    verifyNoMoreInteractions(promiseHandler);
    verifyNoMoreInteractions(responseBodyHandler);
}
Also used : MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 54 with MethodParameter

use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.

the class HandlerMethodReturnValueHandlerCompositeTests method setUp.

@Before
public void setUp() throws Exception {
    this.integerType = new MethodParameter(getClass().getDeclaredMethod("handleInteger"), -1);
    this.stringType = new MethodParameter(getClass().getDeclaredMethod("handleString"), -1);
    this.integerHandler = mock(HandlerMethodReturnValueHandler.class);
    when(this.integerHandler.supportsReturnType(this.integerType)).thenReturn(true);
    this.handlers = new HandlerMethodReturnValueHandlerComposite();
    this.handlers.addHandler(this.integerHandler);
    mavContainer = new ModelAndViewContainer();
}
Also used : MethodParameter(org.springframework.core.MethodParameter) Before(org.junit.Before)

Example 55 with MethodParameter

use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.

the class RequestParamMethodArgumentResolverTests method resolveSimpleTypeParamToNull.

// SPR-8561
@Test
public void resolveSimpleTypeParamToNull() throws Exception {
    MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
    Object result = resolver.resolveArgument(param, null, webRequest, null);
    assertNull(result);
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Aggregations

MethodParameter (org.springframework.core.MethodParameter)322 Test (org.junit.Test)251 Method (java.lang.reflect.Method)65 ArrayList (java.util.ArrayList)35 RequestParam (org.springframework.web.bind.annotation.RequestParam)30 HandlerMethod (org.springframework.web.method.HandlerMethod)28 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)27 Before (org.junit.Before)25 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)25 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)23 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)23 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)23 ResolvableType (org.springframework.core.ResolvableType)21 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)21 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)21 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)20 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)20 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)20 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)20 Mono (reactor.core.publisher.Mono)19