Search in sources :

Example 1 with ModelAndViewContainer

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

the class ErrorsMethodHandlerArgumentResolverTests method bindingResultNotFound.

@Test(expected = IllegalStateException.class)
public void bindingResultNotFound() throws Exception {
    ModelAndViewContainer mavContainer = new ModelAndViewContainer();
    mavContainer.addAllAttributes(bindingResult.getModel());
    mavContainer.addAttribute("ignore1", "value1");
    resolver.resolveArgument(paramErrors, mavContainer, webRequest, null);
}
Also used : ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) Test(org.junit.Test)

Example 2 with ModelAndViewContainer

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

the class DeferredResultReturnValueHandlerTests 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 3 with ModelAndViewContainer

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

the class RequestMappingInfoHandlerMappingTests method testHttpOptions.

private void testHttpOptions(String requestURI, String allowHeader) throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", requestURI);
    HandlerMethod handlerMethod = getHandler(request);
    ServletWebRequest webRequest = new ServletWebRequest(request);
    ModelAndViewContainer mavContainer = new ModelAndViewContainer();
    Object result = new InvocableHandlerMethod(handlerMethod).invokeForRequest(webRequest, mavContainer);
    assertNotNull(result);
    assertEquals(HttpHeaders.class, result.getClass());
    assertEquals(allowHeader, ((HttpHeaders) result).getFirst("Allow"));
}
Also used : ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 4 with ModelAndViewContainer

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

the class ModelAndViewMethodReturnValueHandlerTests method setup.

@BeforeEach
public void setup() throws Exception {
    this.handler = new ModelAndViewMethodReturnValueHandler();
    this.mavContainer = new ModelAndViewContainer();
    this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
    this.returnParamModelAndView = getReturnValueParam("modelAndView");
}
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 5 with ModelAndViewContainer

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

the class HttpEntityMethodProcessorMockTests method setup.

@BeforeEach
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    stringHttpMessageConverter = mock(HttpMessageConverter.class);
    given(stringHttpMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(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 HttpEntityMethodProcessor(Arrays.asList(stringHttpMessageConverter, resourceMessageConverter, resourceRegionMessageConverter));
    Method handle1 = getClass().getMethod("handle1", HttpEntity.class, ResponseEntity.class, Integer.TYPE, RequestEntity.class);
    paramHttpEntity = new MethodParameter(handle1, 0);
    paramRequestEntity = new MethodParameter(handle1, 3);
    paramResponseEntity = new MethodParameter(handle1, 1);
    paramInt = new MethodParameter(handle1, 2);
    returnTypeResponseEntity = new MethodParameter(handle1, -1);
    returnTypeResponseEntityProduces = new MethodParameter(getClass().getMethod("handle4"), -1);
    returnTypeHttpEntity = new MethodParameter(getClass().getMethod("handle2", HttpEntity.class), -1);
    returnTypeHttpEntitySubclass = new MethodParameter(getClass().getMethod("handle2x", HttpEntity.class), -1);
    returnTypeInt = new MethodParameter(getClass().getMethod("handle3"), -1);
    returnTypeResponseEntityResource = new MethodParameter(getClass().getMethod("handle5"), -1);
    mavContainer = new ModelAndViewContainer();
    servletRequest = new MockHttpServletRequest("GET", "/foo");
    servletResponse = new MockHttpServletResponse();
    webRequest = new ServletWebRequest(servletRequest, servletResponse);
}
Also used : ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) Method(java.lang.reflect.Method) HttpMethod(org.springframework.http.HttpMethod) MethodParameter(org.springframework.core.MethodParameter) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

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