use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class MapMethodProcessorTests method setUp.
@BeforeEach
public void setUp() throws Exception {
this.processor = new MapMethodProcessor();
this.mavContainer = new BindingContext();
this.webRequest = new ServletRequestContext(null, new MockHttpServletRequest(), null);
webRequest.setBindingContext(mavContainer);
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileArrayMissing.
@Test
public void resolveMultipartFileArrayMissing() throws Throwable {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes()));
webRequest = new ServletRequestContext(null, request, null);
webRequest.setBindingContext(new BindingContext());
ResolvableMethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile[].class);
assertThatExceptionOfType(MissingRequestPartException.class).isThrownBy(() -> resolver.resolveArgument(webRequest, param));
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class RequestParamMethodArgumentResolverTests method resolveOptionalParamArray.
@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamArray() throws Throwable {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
ServletRequestContext webRequest = new ServletRequestContext(null, request, new MockHttpServletResponse());
BindingContext binderFactory = new BindingContext(initializer);
webRequest.setBindingContext(binderFactory);
ResolvableMethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, Integer[].class);
Object result = resolver.resolveArgument(webRequest, param);
assertThat(result).isEqualTo(Optional.empty());
request.addParameter("name", "123", "456");
result = resolver.resolveArgument(webRequest, param);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat((Integer[]) ((Optional) result).get()).isEqualTo(new Integer[] { 123, 456 });
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class RequestParamMethodArgumentResolverTests method isMultipartRequestHttpPut.
// SPR-9079
@Test
public void isMultipartRequestHttpPut() throws Throwable {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("multipartFileList", "Hello World".getBytes());
request.addFile(expected);
request.setMethod("PUT");
webRequest = new ServletRequestContext(null, request, null);
webRequest.setBindingContext(new BindingContext());
ResolvableMethodParameter param = testMethod.annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
Object actual = resolver.resolveArgument(webRequest, param);
boolean condition = actual instanceof List;
assertThat(condition).isTrue();
assertThat(((List<?>) actual).get(0)).isEqualTo(expected);
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class RequestParamMethodArgumentResolverTests method resolvePartNotAnnot.
@Test
public void resolvePartNotAnnot() throws Throwable {
MockPart expected = new MockPart("part", "Hello World".getBytes());
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("multipart/form-data");
request.addPart(expected);
webRequest = new ServletRequestContext(null, request, null);
webRequest.setBindingContext(new BindingContext());
ResolvableMethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(Part.class);
Object result = resolver.resolveArgument(webRequest, param);
boolean condition = result instanceof Part;
assertThat(condition).isTrue();
assertThat(result).as("Invalid result").isEqualTo(expected);
}
Aggregations