use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class ResponseEntityExceptionHandlerTests method setup.
@Before
public void setup() {
this.servletRequest = new MockHttpServletRequest("GET", "/");
this.servletResponse = new MockHttpServletResponse();
this.request = new ServletWebRequest(this.servletRequest, this.servletResponse);
this.exceptionHandlerSupport = new ApplicationExceptionHandler();
this.defaultExceptionResolver = new DefaultHandlerExceptionResolver();
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorMockTests method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
stringMessageConverter = mock(HttpMessageConverter.class);
given(stringMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
resourceMessageConverter = mock(HttpMessageConverter.class);
given(resourceMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.ALL));
processor = new RequestResponseBodyMethodProcessor(Arrays.asList(stringMessageConverter, resourceMessageConverter));
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.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorTests method setup.
@Before
public void setup() throws Exception {
container = new ModelAndViewContainer();
servletRequest = new MockHttpServletRequest();
servletRequest.setMethod("POST");
servletResponse = new MockHttpServletResponse();
request = new ServletWebRequest(servletRequest, servletResponse);
this.factory = new ValidatingBinderFactory();
Method method = getClass().getDeclaredMethod("handle", List.class, SimpleBean.class, MultiValueMap.class, String.class);
paramGenericList = new MethodParameter(method, 0);
paramSimpleBean = new MethodParameter(method, 1);
paramMultiValueMap = new MethodParameter(method, 2);
paramString = new MethodParameter(method, 3);
returnTypeString = new MethodParameter(method, -1);
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapterIntegrationTests method setup.
@Before
public void setup() throws Exception {
ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
bindingInitializer.setValidator(new StubValidator());
List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>();
customResolvers.add(new ServletWebArgumentResolverAdapter(new ColorArgumentResolver()));
GenericWebApplicationContext context = new GenericWebApplicationContext();
context.refresh();
handlerAdapter = new RequestMappingHandlerAdapter();
handlerAdapter.setWebBindingInitializer(bindingInitializer);
handlerAdapter.setCustomArgumentResolvers(customResolvers);
handlerAdapter.setApplicationContext(context);
handlerAdapter.setBeanFactory(context.getBeanFactory());
handlerAdapter.afterPropertiesSet();
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
request.setMethod("POST");
// Expose request to the current thread (for SpEL expressions)
RequestContextHolder.setRequestAttributes(new ServletWebRequest(request));
}
use of org.springframework.web.context.request.ServletWebRequest in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolveOptionalMultipartFileListNotPresent.
@Test
public void resolveOptionalMultipartFileListNotPresent() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
webRequest = new ServletWebRequest(request);
Object actualValue = resolver.resolveArgument(optionalMultipartFileList, null, webRequest, null);
assertEquals("Invalid argument value", Optional.empty(), actualValue);
actualValue = resolver.resolveArgument(optionalMultipartFileList, null, webRequest, null);
assertEquals("Invalid argument value", Optional.empty(), actualValue);
}
Aggregations