use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolveRequestPartWithoutContentType.
// gh-26501
@Test
public void resolveRequestPartWithoutContentType() throws Exception {
MockMultipartHttpServletRequest servletRequest = new MockMultipartHttpServletRequest();
servletRequest.addPart(new MockPart("requestPartString", "part value".getBytes(StandardCharsets.UTF_8)));
ServletWebRequest webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
List<HttpMessageConverter<?>> converters = Collections.singletonList(new StringHttpMessageConverter());
RequestPartMethodArgumentResolver resolver = new RequestPartMethodArgumentResolver(converters);
MethodParameter parameter = ResolvableMethod.on(getClass()).named("handle").build().arg(String.class);
Object actualValue = resolver.resolveArgument(parameter, new ModelAndViewContainer(), webRequest, new ValidatingBinderFactory());
assertThat(actualValue).isEqualTo("part value");
}
use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class ServletModelAttributeMethodProcessorTests method setup.
@BeforeEach
public void setup() throws Exception {
processor = new ServletModelAttributeMethodProcessor(false);
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
binderFactory = new ServletRequestDataBinderFactory(null, initializer);
mavContainer = new ModelAndViewContainer();
request = new MockHttpServletRequest();
webRequest = new ServletWebRequest(request);
Method method = getClass().getDeclaredMethod("modelAttribute", TestBean.class, TestBeanWithoutStringConstructor.class, Optional.class);
testBeanModelAttr = new MethodParameter(method, 0);
testBeanWithoutStringConstructorModelAttr = new MethodParameter(method, 1);
testBeanWithOptionalModelAttr = new MethodParameter(method, 2);
}
use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class ServletResponseMethodArgumentResolverTests method setup.
@BeforeEach
public void setup() throws Exception {
resolver = new ServletResponseMethodArgumentResolver();
mavContainer = new ModelAndViewContainer();
servletResponse = new MockHttpServletResponse();
webRequest = new ServletWebRequest(new MockHttpServletRequest(), servletResponse);
method = getClass().getMethod("supportedParams", ServletResponse.class, OutputStream.class, Writer.class);
}
use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class UriComponentsBuilderMethodArgumentResolverTests method resolveArgument.
@Test
public void resolveArgument() throws Exception {
this.servletRequest.setContextPath("/myapp");
this.servletRequest.setServletPath("/main");
this.servletRequest.setPathInfo("/accounts");
Object actual = this.resolver.resolveArgument(this.builderParam, new ModelAndViewContainer(), this.webRequest, null);
assertThat(actual).isNotNull();
assertThat(actual.getClass()).isEqualTo(ServletUriComponentsBuilder.class);
assertThat(((ServletUriComponentsBuilder) actual).build().toUriString()).isEqualTo("http://localhost/myapp/main");
}
use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class ServletRequestMethodArgumentResolverTests method setup.
@BeforeEach
public void setup() throws Exception {
resolver = new ServletRequestMethodArgumentResolver();
mavContainer = new ModelAndViewContainer();
servletRequest = new MockHttpServletRequest("GET", "");
webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class, HttpSession.class, Principal.class, Locale.class, InputStream.class, Reader.class, WebRequest.class, TimeZone.class, ZoneId.class, HttpMethod.class, PushBuilder.class);
}
Aggregations