use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method isMultipartRequest.
@Test
public void isMultipartRequest() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
assertThatExceptionOfType(MultipartException.class).isThrownBy(() -> resolver.resolveArgument(paramMultipartFile, new ModelAndViewContainer(), new ServletWebRequest(request), null));
}
use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorMockTests method setup.
@BeforeEach
@SuppressWarnings("unchecked")
public void setup() throws Exception {
stringMessageConverter = mock(HttpMessageConverter.class);
given(stringMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
given(stringMessageConverter.getSupportedMediaTypes(any())).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
resourceMessageConverter = mock(HttpMessageConverter.class);
given(resourceMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.ALL));
given(resourceMessageConverter.getSupportedMediaTypes(any())).willReturn(Collections.singletonList(MediaType.ALL));
resourceRegionMessageConverter = mock(HttpMessageConverter.class);
given(resourceRegionMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.ALL));
given(resourceRegionMessageConverter.getSupportedMediaTypes(any())).willReturn(Collections.singletonList(MediaType.ALL));
processor = new RequestResponseBodyMethodProcessor(Arrays.asList(stringMessageConverter, resourceMessageConverter, resourceRegionMessageConverter));
mavContainer = new ModelAndViewContainer();
servletRequest = new MockHttpServletRequest();
servletRequest.setMethod("POST");
servletResponse = new MockHttpServletResponse();
webRequest = new ServletWebRequest(servletRequest, servletResponse);
Method methodHandle1 = getClass().getMethod("handle1", String.class, Integer.TYPE);
paramRequestBodyString = new MethodParameter(methodHandle1, 0);
paramInt = new MethodParameter(methodHandle1, 1);
paramValidBean = new MethodParameter(getClass().getMethod("handle2", SimpleBean.class), 0);
paramStringNotRequired = new MethodParameter(getClass().getMethod("handle3", String.class), 0);
paramOptionalString = new MethodParameter(getClass().getMethod("handle4", Optional.class), 0);
returnTypeString = new MethodParameter(methodHandle1, -1);
returnTypeInt = new MethodParameter(getClass().getMethod("handle5"), -1);
returnTypeStringProduces = new MethodParameter(getClass().getMethod("handle6"), -1);
returnTypeResource = new MethodParameter(getClass().getMethod("handle7"), -1);
}
use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class StreamingResponseBodyReturnValueHandlerTests method setup.
@BeforeEach
public void setup() throws Exception {
this.handler = new StreamingResponseBodyReturnValueHandler();
this.mavContainer = new ModelAndViewContainer();
this.request = new MockHttpServletRequest("GET", "/path");
this.response = new MockHttpServletResponse();
this.webRequest = new ServletWebRequest(this.request, this.response);
AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response);
WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncWebRequest(asyncWebRequest);
this.request.setAsyncSupported(true);
}
use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class ModelFactoryTests method setUp.
@BeforeEach
public void setUp() throws Exception {
this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
this.attributeStore = new DefaultSessionAttributeStore();
this.attributeHandler = new SessionAttributesHandler(TestController.class, this.attributeStore);
this.controller = new TestController();
this.mavContainer = new ModelAndViewContainer();
}
use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class ModelFactoryTests method updateModelBindingResult.
@Test
public void updateModelBindingResult() throws Exception {
String commandName = "attr1";
Object command = new Object();
ModelAndViewContainer container = new ModelAndViewContainer();
container.addAttribute(commandName, command);
WebDataBinder dataBinder = new WebDataBinder(command, commandName);
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
given(binderFactory.createBinder(this.webRequest, command, commandName)).willReturn(dataBinder);
ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.attributeHandler);
modelFactory.updateModel(this.webRequest, container);
assertThat(container.getModel().get(commandName)).isEqualTo(command);
String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + commandName;
assertThat(container.getModel().get(bindingResultKey)).isSameAs(dataBinder.getBindingResult());
assertThat(container.getModel().size()).isEqualTo(2);
}
Aggregations