Search in sources :

Example 16 with SynthesizingMethodParameter

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

the class ModelAttributeMethodProcessorTests method setUp.

@Before
public void setUp() throws Exception {
    this.request = new ServletWebRequest(new MockHttpServletRequest());
    this.container = new ModelAndViewContainer();
    this.processor = new ModelAttributeMethodProcessor(false);
    Method method = ModelAttributeHandler.class.getDeclaredMethod("modelAttribute", TestBean.class, Errors.class, int.class, TestBean.class, TestBean.class, TestBean.class);
    this.paramNamedValidModelAttr = new SynthesizingMethodParameter(method, 0);
    this.paramErrors = new SynthesizingMethodParameter(method, 1);
    this.paramInt = new SynthesizingMethodParameter(method, 2);
    this.paramModelAttr = new SynthesizingMethodParameter(method, 3);
    this.paramBindingDisabledAttr = new SynthesizingMethodParameter(method, 4);
    this.paramNonSimpleType = new SynthesizingMethodParameter(method, 5);
    method = getClass().getDeclaredMethod("annotatedReturnValue");
    this.returnParamNamedModelAttr = new MethodParameter(method, -1);
    method = getClass().getDeclaredMethod("notAnnotatedReturnValue");
    this.returnParamNonSimpleType = new MethodParameter(method, -1);
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Method(java.lang.reflect.Method) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) Before(org.junit.Before)

Example 17 with SynthesizingMethodParameter

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

the class CookieValueMethodArgumentResolverTests method setUp.

@Before
public void setUp() throws Exception {
    resolver = new TestCookieValueMethodArgumentResolver();
    Method method = getClass().getMethod("params", Cookie.class, String.class, String.class);
    paramNamedCookie = new SynthesizingMethodParameter(method, 0);
    paramNamedDefaultValueString = new SynthesizingMethodParameter(method, 1);
    paramString = new SynthesizingMethodParameter(method, 2);
    request = new MockHttpServletRequest();
    webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Method(java.lang.reflect.Method) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 18 with SynthesizingMethodParameter

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

the class SessionAttributeMethodArgumentResolverTests method initMethodParameter.

private MethodParameter initMethodParameter(int parameterIndex) {
    MethodParameter param = new SynthesizingMethodParameter(this.handleMethod, parameterIndex);
    param.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
    GenericTypeResolver.resolveParameterType(param, this.resolver.getClass());
    return param;
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) DefaultParameterNameDiscoverer(org.springframework.core.DefaultParameterNameDiscoverer) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter)

Example 19 with SynthesizingMethodParameter

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

the class RequestPartMethodArgumentResolverTests method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    messageConverter = mock(HttpMessageConverter.class);
    given(messageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
    resolver = new RequestPartMethodArgumentResolver(Collections.<HttpMessageConverter<?>>singletonList(messageConverter));
    reset(messageConverter);
    byte[] content = "doesn't matter as long as not empty".getBytes(StandardCharsets.UTF_8);
    multipartFile1 = new MockMultipartFile("requestPart", "", "text/plain", content);
    multipartFile2 = new MockMultipartFile("requestPart", "", "text/plain", content);
    multipartRequest = new MockMultipartHttpServletRequest();
    multipartRequest.addFile(multipartFile1);
    multipartRequest.addFile(multipartFile2);
    multipartRequest.addFile(new MockMultipartFile("otherPart", "", "text/plain", content));
    webRequest = new ServletWebRequest(multipartRequest, new MockHttpServletResponse());
    Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
    paramRequestPart = new SynthesizingMethodParameter(method, 0);
    paramRequestPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    paramNamedRequestPart = new SynthesizingMethodParameter(method, 1);
    paramValidRequestPart = new SynthesizingMethodParameter(method, 2);
    paramMultipartFile = new SynthesizingMethodParameter(method, 3);
    paramMultipartFileList = new SynthesizingMethodParameter(method, 4);
    paramMultipartFileArray = new SynthesizingMethodParameter(method, 5);
    paramInt = new SynthesizingMethodParameter(method, 6);
    paramMultipartFileNotAnnot = new SynthesizingMethodParameter(method, 7);
    paramMultipartFileNotAnnot.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    paramPart = new SynthesizingMethodParameter(method, 8);
    paramPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    paramPartList = new SynthesizingMethodParameter(method, 9);
    paramPartArray = new SynthesizingMethodParameter(method, 10);
    paramRequestParamAnnot = new SynthesizingMethodParameter(method, 11);
    optionalMultipartFile = new SynthesizingMethodParameter(method, 12);
    optionalMultipartFile.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    optionalMultipartFileList = new SynthesizingMethodParameter(method, 13);
    optionalMultipartFileList.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    optionalPart = new SynthesizingMethodParameter(method, 14);
    optionalPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    optionalPartList = new SynthesizingMethodParameter(method, 15);
    optionalPartList.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    optionalRequestPart = new SynthesizingMethodParameter(method, 16);
}
Also used : MockMultipartFile(org.springframework.mock.web.test.MockMultipartFile) LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) MockMultipartHttpServletRequest(org.springframework.mock.web.test.MockMultipartHttpServletRequest) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) Method(java.lang.reflect.Method) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 20 with SynthesizingMethodParameter

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

the class SendToMethodReturnValueHandlerTests method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
    messagingTemplate.setMessageConverter(new StringMessageConverter());
    this.handler = new SendToMethodReturnValueHandler(messagingTemplate, true);
    this.handlerAnnotationNotRequired = new SendToMethodReturnValueHandler(messagingTemplate, false);
    SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
    jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
    this.jsonHandler = new SendToMethodReturnValueHandler(jsonMessagingTemplate, true);
    Method method = getClass().getDeclaredMethod("handleNoAnnotations");
    this.noAnnotationsReturnType = new SynthesizingMethodParameter(method, -1);
    method = getClass().getDeclaredMethod("handleAndSendToDefaultDestination");
    this.sendToDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);
    method = getClass().getDeclaredMethod("handleAndSendTo");
    this.sendToReturnType = new SynthesizingMethodParameter(method, -1);
    method = getClass().getDeclaredMethod("handleAndSendToWithPlaceholders");
    this.sendToWithPlaceholdersReturnType = new SynthesizingMethodParameter(method, -1);
    method = getClass().getDeclaredMethod("handleAndSendToUser");
    this.sendToUserReturnType = new SynthesizingMethodParameter(method, -1);
    method = getClass().getDeclaredMethod("handleAndSendToUserSingleSession");
    this.sendToUserSingleSessionReturnType = new SynthesizingMethodParameter(method, -1);
    method = getClass().getDeclaredMethod("handleAndSendToUserDefaultDestination");
    this.sendToUserDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);
    method = getClass().getDeclaredMethod("handleAndSendToUserDefaultDestinationSingleSession");
    this.sendToUserSingleSessionDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);
    method = getClass().getDeclaredMethod("handleAndSendToJsonView");
    this.jsonViewReturnType = new SynthesizingMethodParameter(method, -1);
    method = SendToTestBean.class.getDeclaredMethod("handleNoAnnotation");
    this.defaultNoAnnotation = new SynthesizingMethodParameter(method, -1);
    method = SendToTestBean.class.getDeclaredMethod("handleAndSendToDefaultDestination");
    this.defaultEmptyAnnotation = new SynthesizingMethodParameter(method, -1);
    method = SendToTestBean.class.getDeclaredMethod("handleAndSendToOverride");
    this.defaultOverrideAnnotation = new SynthesizingMethodParameter(method, -1);
    method = SendToUserTestBean.class.getDeclaredMethod("handleNoAnnotation");
    this.userDefaultNoAnnotation = new SynthesizingMethodParameter(method, -1);
    method = SendToUserTestBean.class.getDeclaredMethod("handleAndSendToDefaultDestination");
    this.userDefaultEmptyAnnotation = new SynthesizingMethodParameter(method, -1);
    method = SendToUserTestBean.class.getDeclaredMethod("handleAndSendToOverride");
    this.userDefaultOverrideAnnotation = new SynthesizingMethodParameter(method, -1);
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) Method(java.lang.reflect.Method) Before(org.junit.Before)

Aggregations

SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)22 Method (java.lang.reflect.Method)17 Before (org.junit.Before)15 MethodParameter (org.springframework.core.MethodParameter)8 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)8 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)7 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)7 DefaultParameterNameDiscoverer (org.springframework.core.DefaultParameterNameDiscoverer)4 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)4 ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)3 Test (org.junit.Test)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 LocalVariableTableParameterNameDiscoverer (org.springframework.core.LocalVariableTableParameterNameDiscoverer)2 Message (org.springframework.messaging.Message)2 StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)2 BindingContext (org.springframework.web.reactive.BindingContext)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 DependencyDescriptor (org.springframework.beans.factory.config.DependencyDescriptor)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1