use of cn.taketoday.web.testfixture.servlet.MockMultipartFile in project today-framework by TAKETODAY.
the class RequestContextDataBinderTests method testMultipartFileAsStringArray.
@Test
public void testMultipartFileAsStringArray() {
TestBean target = new TestBean();
RequestContextDataBinder binder = new RequestContextDataBinder(target);
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("stringArray", "Juergen".getBytes()));
binder.bind(new MockMultipartServletRequestContext(request, null));
assertThat(target.getStringArray().length).isEqualTo(1);
assertThat(target.getStringArray()[0]).isEqualTo("Juergen");
}
use of cn.taketoday.web.testfixture.servlet.MockMultipartFile in project today-framework by TAKETODAY.
the class RequestContextDataBinderTests method testMultipartFileAsString.
@Test
public void testMultipartFileAsString() {
TestBean target = new TestBean();
RequestContextDataBinder binder = new RequestContextDataBinder(target);
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("name", "Juergen".getBytes()));
binder.bind(new MockMultipartServletRequestContext(request, null));
assertThat(target.getName()).isEqualTo("Juergen");
}
use of cn.taketoday.web.testfixture.servlet.MockMultipartFile in project today-framework by TAKETODAY.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFile.
@Test
public void resolveMultipartFile() throws Throwable {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("mfile", "Hello World".getBytes());
request.addFile(expected);
webRequest = new ServletRequestContext(null, request, null);
webRequest.setBindingContext(new BindingContext());
ResolvableMethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile.class);
Object result = resolver.resolveArgument(webRequest, param);
boolean condition = result instanceof MultipartFile;
assertThat(condition).isTrue();
assertThat(result).as("Invalid result").isEqualTo(expected);
}
use of cn.taketoday.web.testfixture.servlet.MockMultipartFile in project today-framework by TAKETODAY.
the class RequestParamMapMethodArgumentResolverTests method resolveMultiValueMapOfMultipartFile.
@Test
@SuppressWarnings("unchecked")
public void resolveMultiValueMapOfMultipartFile() throws Throwable {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected1 = new MockMultipartFile("mfilelist", "Hello World 1".getBytes());
MultipartFile expected2 = new MockMultipartFile("mfilelist", "Hello World 2".getBytes());
MultipartFile expected3 = new MockMultipartFile("other", "Hello World 3".getBytes());
request.addFile(expected1);
request.addFile(expected2);
request.addFile(expected3);
webRequest = new ServletRequestContext(null, request, null);
ResolvableMethodParameter param = this.testMethod.annot(requestParam().noName()).arg(MultiValueMap.class, String.class, MultipartFile.class);
Object result = resolver.resolveArgument(webRequest, param);
boolean condition = result instanceof MultiValueMap;
assertThat(condition).isTrue();
MultiValueMap<String, MultipartFile> resultMap = (MultiValueMap<String, MultipartFile>) result;
assertThat(resultMap.size()).isEqualTo(2);
assertThat(resultMap.get("mfilelist").size()).isEqualTo(2);
assertThat(resultMap.get("mfilelist").get(0)).isEqualTo(expected1);
assertThat(resultMap.get("mfilelist").get(1)).isEqualTo(expected2);
assertThat(resultMap.get("other").size()).isEqualTo(1);
assertThat(resultMap.get("other").get(0)).isEqualTo(expected3);
}
use of cn.taketoday.web.testfixture.servlet.MockMultipartFile in project today-framework by TAKETODAY.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileNotAnnot.
@Test
public void resolveMultipartFileNotAnnot() throws Throwable {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("multipartFileNotAnnot", "Hello World".getBytes());
request.addFile(expected);
ServletRequestContext webRequest = new ServletRequestContext(null, request, null);
webRequest.setBindingContext(new BindingContext());
ResolvableMethodParameter param = this.testMethod.annotNotPresent().arg(MultipartFile.class);
Object result = resolver.resolveArgument(webRequest, param);
boolean condition = result instanceof MultipartFile;
assertThat(condition).isTrue();
assertThat(result).as("Invalid result").isEqualTo(expected);
}
Aggregations