Search in sources :

Example 6 with ModelAndViewContainer

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

the class ModelAndViewResolverMethodReturnValueHandlerTests method setup.

@BeforeEach
public void setup() {
    mavResolvers = new ArrayList<>();
    handler = new ModelAndViewResolverMethodReturnValueHandler(mavResolvers);
    mavContainer = new ModelAndViewContainer();
    request = new ServletWebRequest(new MockHttpServletRequest());
}
Also used : ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with ModelAndViewContainer

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

the class ViewMethodReturnValueHandlerTests method setup.

@BeforeEach
public void setup() {
    this.handler = new ViewMethodReturnValueHandler();
    this.mavContainer = new ModelAndViewContainer();
    this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
}
Also used : ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with ModelAndViewContainer

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

the class ModelAttributeMethodProcessorTests method setup.

@BeforeEach
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, TestBeanWithConstructorArgs.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);
    this.beanWithConstructorArgs = new SynthesizingMethodParameter(method, 6);
    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.web.testfixture.servlet.MockHttpServletRequest) Method(java.lang.reflect.Method) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with ModelAndViewContainer

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

the class ModelFactoryTests method updateModelSessionAttributesRemoved.

@Test
public void updateModelSessionAttributesRemoved() throws Exception {
    String attributeName = "sessionAttr";
    String attribute = "value";
    ModelAndViewContainer container = new ModelAndViewContainer();
    container.addAttribute(attributeName, attribute);
    this.attributeStore.storeAttribute(this.webRequest, attributeName, attribute);
    WebDataBinder dataBinder = new WebDataBinder(attribute, attributeName);
    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(this.webRequest, attribute, attributeName)).willReturn(dataBinder);
    container.getSessionStatus().setComplete();
    ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.attributeHandler);
    modelFactory.updateModel(this.webRequest, container);
    assertThat(container.getModel().get(attributeName)).isEqualTo(attribute);
    assertThat(this.attributeStore.retrieveAttribute(this.webRequest, attributeName)).isNull();
}
Also used : WebDataBinder(org.springframework.web.bind.WebDataBinder) ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) WebDataBinderFactory(org.springframework.web.bind.support.WebDataBinderFactory) Test(org.junit.jupiter.api.Test)

Example 10 with ModelAndViewContainer

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

the class ReactiveTypeHandlerTests method handleValue.

private ResponseBodyEmitter handleValue(Object returnValue, Class<?> asyncType, ResolvableType genericType) throws Exception {
    ModelAndViewContainer mavContainer = new ModelAndViewContainer();
    MethodParameter returnType = on(TestController.class).resolveReturnType(asyncType, genericType);
    return this.handler.handleValue(returnValue, returnType, mavContainer, this.webRequest);
}
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