Search in sources :

Example 41 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 42 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 43 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)

Example 44 with MethodParameter

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

the class RequestParamMethodArgumentResolverTests method resolvePartNotAnnot.

@Test
public void resolvePartNotAnnot() throws Exception {
    MockPart expected = new MockPart("part", "Hello World".getBytes());
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("POST");
    request.setContentType("multipart/form-data");
    request.addPart(expected);
    webRequest = new ServletWebRequest(request);
    MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(Part.class);
    Object result = resolver.resolveArgument(param, null, webRequest, null);
    assertTrue(result instanceof Part);
    assertEquals("Invalid result", expected, result);
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) RequestPart(org.springframework.web.bind.annotation.RequestPart) MvcAnnotationPredicates.requestPart(org.springframework.web.method.MvcAnnotationPredicates.requestPart) MockPart(org.springframework.mock.web.test.MockPart) Part(javax.servlet.http.Part) MockPart(org.springframework.mock.web.test.MockPart) MethodParameter(org.springframework.core.MethodParameter) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) Test(org.junit.Test)

Example 45 with MethodParameter

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

the class RequestParamMethodArgumentResolverTests method resolveMultipartFileNotAnnot.

@Test
public void resolveMultipartFileNotAnnot() throws Exception {
    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
    MultipartFile expected = new MockMultipartFile("multipartFileNotAnnot", "Hello World".getBytes());
    request.addFile(expected);
    webRequest = new ServletWebRequest(request);
    MethodParameter param = this.testMethod.annotNotPresent().arg(MultipartFile.class);
    Object result = resolver.resolveArgument(param, null, webRequest, null);
    assertTrue(result instanceof MultipartFile);
    assertEquals("Invalid result", expected, result);
}
Also used : MockMultipartFile(org.springframework.mock.web.test.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.test.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) MockMultipartHttpServletRequest(org.springframework.mock.web.test.MockMultipartHttpServletRequest) MethodParameter(org.springframework.core.MethodParameter) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) Test(org.junit.Test)

Aggregations

MethodParameter (org.springframework.core.MethodParameter)320 Test (org.junit.Test)251 Method (java.lang.reflect.Method)64 ArrayList (java.util.ArrayList)35 RequestParam (org.springframework.web.bind.annotation.RequestParam)30 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)27 HandlerMethod (org.springframework.web.method.HandlerMethod)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