Search in sources :

Example 16 with ModelAndViewContainer

use of org.springframework.web.method.support.ModelAndViewContainer 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 ModelAndViewContainer

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

the class ErrorsMethodHandlerArgumentResolverTests method bindingResult.

@Test
public void bindingResult() throws Exception {
    ModelAndViewContainer mavContainer = new ModelAndViewContainer();
    mavContainer.addAttribute("ignore1", "value1");
    mavContainer.addAttribute("ignore2", "value2");
    mavContainer.addAttribute("ignore3", "value3");
    mavContainer.addAttribute("ignore4", "value4");
    mavContainer.addAttribute("ignore5", "value5");
    mavContainer.addAllAttributes(bindingResult.getModel());
    Object actual = resolver.resolveArgument(paramErrors, mavContainer, webRequest, null);
    assertSame(actual, bindingResult);
}
Also used : ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) Test(org.junit.Test)

Example 18 with ModelAndViewContainer

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

the class ResponseBodyEmitterReturnValueHandlerTests method handleReturnValue.

private void handleReturnValue(Object returnValue, MethodParameter returnType) throws Exception {
    ModelAndViewContainer mavContainer = new ModelAndViewContainer();
    this.handler.handleReturnValue(returnValue, returnType, mavContainer, this.webRequest);
}
Also used : ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer)

Example 19 with ModelAndViewContainer

use of org.springframework.web.method.support.ModelAndViewContainer in project crnk-framework by crnk-project.

the class SpringParameterProvider method provide.

@Override
@SuppressWarnings("unchecked")
public <T> T provide(Method method, int parameterIndex) {
    MethodParameter methodParameter = new MethodParameter(method, parameterIndex);
    ModelAndViewContainer modelAndViewContainer = new ModelAndViewContainer();
    NativeWebRequest webRequest = new ServletWebRequest(request);
    DefaultDataBinderFactory binderFactory = new DefaultDataBinderFactory(new ConfigurableWebBindingInitializer());
    try {
        return (T) argumentResolvers.resolveArgument(methodParameter, modelAndViewContainer, webRequest, binderFactory);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) MethodParameter(org.springframework.core.MethodParameter) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) DefaultDataBinderFactory(org.springframework.web.bind.support.DefaultDataBinderFactory)

Example 20 with ModelAndViewContainer

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

the class DeferredResultReturnValueHandlerTests method testHandle.

private void testHandle(Object returnValue, Class<?> asyncType, Runnable setResultTask, Object expectedValue) throws Exception {
    ModelAndViewContainer mavContainer = new ModelAndViewContainer();
    MethodParameter returnType = on(TestController.class).resolveReturnType(asyncType, String.class);
    this.handler.handleReturnValue(returnValue, returnType, mavContainer, this.webRequest);
    assertThat(this.request.isAsyncStarted()).isTrue();
    assertThat(WebAsyncUtils.getAsyncManager(this.webRequest).hasConcurrentResult()).isFalse();
    setResultTask.run();
    assertThat(WebAsyncUtils.getAsyncManager(this.webRequest).hasConcurrentResult()).isTrue();
    assertThat(WebAsyncUtils.getAsyncManager(this.webRequest).getConcurrentResult()).isEqualTo(expectedValue);
}
Also used : ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) MethodParameter(org.springframework.core.MethodParameter)

Aggregations

ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)44 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)29 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)22 BeforeEach (org.junit.jupiter.api.BeforeEach)20 MethodParameter (org.springframework.core.MethodParameter)14 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)12 Method (java.lang.reflect.Method)10 Test (org.junit.jupiter.api.Test)10 WebDataBinderFactory (org.springframework.web.bind.support.WebDataBinderFactory)5 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)4 HandlerMethod (org.springframework.web.method.HandlerMethod)4 HttpMethod (org.springframework.http.HttpMethod)3 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)3 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)3 WebDataBinder (org.springframework.web.bind.WebDataBinder)3 LinkedHashMap (java.util.LinkedHashMap)2 Before (org.junit.Before)2 Test (org.junit.Test)2 HttpInputMessage (org.springframework.http.HttpInputMessage)2 Nullable (org.springframework.lang.Nullable)2