Search in sources :

Example 1 with HandlerMethodArgumentResolver

use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-data-commons by spring-projects.

the class PageableDefaultUnitTests method rejectsInvalidQulifiers.

@Test
public void rejectsInvalidQulifiers() throws Exception {
    MethodParameter parameter = TestUtils.getParameterOfMethod(getControllerClass(), "invalidQualifiers", Pageable.class, Pageable.class);
    HandlerMethodArgumentResolver resolver = getResolver();
    assertThat(resolver.supportsParameter(parameter)).isTrue();
    exception.expect(IllegalStateException.class);
    exception.expectMessage("unique");
    resolver.resolveArgument(parameter, null, TestUtils.getWebRequest(), null);
}
Also used : MethodParameter(org.springframework.core.MethodParameter) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) Test(org.junit.Test)

Example 2 with HandlerMethodArgumentResolver

use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-data-commons by spring-projects.

the class SortDefaultUnitTests method rejectsDoubleAnnotatedMethod.

@Test
public void rejectsDoubleAnnotatedMethod() throws Exception {
    MethodParameter parameter = getParameterOfMethod("invalid");
    HandlerMethodArgumentResolver resolver = new SortHandlerMethodArgumentResolver();
    assertThat(resolver.supportsParameter(parameter)).isTrue();
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage(SortDefault.class.getSimpleName());
    exception.expectMessage(SortDefaults.class.getSimpleName());
    exception.expectMessage(parameter.toString());
    resolver.resolveArgument(parameter, null, TestUtils.getWebRequest(), null);
}
Also used : SortDefaults(org.springframework.data.web.SortDefault.SortDefaults) MethodParameter(org.springframework.core.MethodParameter) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) Test(org.junit.Test)

Example 3 with HandlerMethodArgumentResolver

use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.

the class ServletAnnotationControllerHandlerMethodTests method typedCommandProvidingFormController.

@PathPatternsParameterizedTest
void typedCommandProvidingFormController(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(MyTypedCommandProvidingFormController.class, usePathPatterns, wac -> {
        wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
        RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
        adapterDef.getPropertyValues().add("webBindingInitializer", new MyWebBindingInitializer());
        List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
        argumentResolvers.add(new ServletWebArgumentResolverAdapter(new MySpecialArgumentResolver()));
        adapterDef.getPropertyValues().add("customArgumentResolvers", argumentResolvers);
        wac.registerBeanDefinition("handlerAdapter", adapterDef);
    });
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
    request.addParameter("defaultName", "10");
    request.addParameter("age", "value2");
    request.addParameter("date", "2007-10-02");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("myView-Integer:10-typeMismatch-tb1-myOriginalValue");
    request = new MockHttpServletRequest("GET", "/myOtherPath.do");
    request.addParameter("defaultName", "10");
    request.addParameter("age", "value2");
    request.addParameter("date", "2007-10-02");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("myView-myName-typeMismatch-tb1-myOriginalValue");
    request = new MockHttpServletRequest("GET", "/myThirdPath.do");
    request.addParameter("defaultName", "10");
    request.addParameter("age", "100");
    request.addParameter("date", "2007-10-02");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("myView-special-99-special-99");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ArrayList(java.util.ArrayList) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 4 with HandlerMethodArgumentResolver

use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.

the class RequestMappingHandlerAdapterTests method setCustomArgumentResolvers.

@Test
public void setCustomArgumentResolvers() throws Exception {
    HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
    this.handlerAdapter.setCustomArgumentResolvers(Collections.singletonList(resolver));
    this.handlerAdapter.afterPropertiesSet();
    assertThat(this.handlerAdapter.getArgumentResolvers().contains(resolver)).isTrue();
    assertMethodProcessorCount(RESOLVER_COUNT + 1, INIT_BINDER_RESOLVER_COUNT + 1, HANDLER_COUNT);
}
Also used : HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) Test(org.junit.jupiter.api.Test)

Example 5 with HandlerMethodArgumentResolver

use of org.springframework.web.method.support.HandlerMethodArgumentResolver in project spring-framework by spring-projects.

the class RequestMappingHandlerAdapterTests method setArgumentResolvers.

@Test
public void setArgumentResolvers() throws Exception {
    HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
    this.handlerAdapter.setArgumentResolvers(Collections.singletonList(resolver));
    this.handlerAdapter.afterPropertiesSet();
    assertMethodProcessorCount(1, INIT_BINDER_RESOLVER_COUNT, HANDLER_COUNT);
}
Also used : HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) Test(org.junit.jupiter.api.Test)

Aggregations

HandlerMethodArgumentResolver (org.springframework.web.method.support.HandlerMethodArgumentResolver)19 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)5 ModelMethodProcessor (org.springframework.web.method.annotation.ModelMethodProcessor)4 Test (org.junit.Test)3 MethodParameter (org.springframework.core.MethodParameter)3 ExpressionValueMethodArgumentResolver (org.springframework.web.method.annotation.ExpressionValueMethodArgumentResolver)3 RequestParamMapMethodArgumentResolver (org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver)3 RequestParamMethodArgumentResolver (org.springframework.web.method.annotation.RequestParamMethodArgumentResolver)3 List (java.util.List)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 ErrorsMethodArgumentResolver (org.springframework.web.method.annotation.ErrorsMethodArgumentResolver)2 MapMethodProcessor (org.springframework.web.method.annotation.MapMethodProcessor)2 RequestHeaderMapMethodArgumentResolver (org.springframework.web.method.annotation.RequestHeaderMapMethodArgumentResolver)2 RequestHeaderMethodArgumentResolver (org.springframework.web.method.annotation.RequestHeaderMethodArgumentResolver)2 SessionStatusMethodArgumentResolver (org.springframework.web.method.annotation.SessionStatusMethodArgumentResolver)2 HandlerMethodReturnValueHandler (org.springframework.web.method.support.HandlerMethodReturnValueHandler)2 RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LinkedList (java.util.LinkedList)1