Search in sources :

Example 1 with StringMultipartFileEditor

use of cn.taketoday.web.multipart.StringMultipartFileEditor in project today-infrastructure 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");
}
Also used : MockMultipartServletRequestContext(cn.taketoday.web.servlet.MockMultipartServletRequestContext) StringMultipartFileEditor(cn.taketoday.web.multipart.StringMultipartFileEditor) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) Test(org.junit.jupiter.api.Test)

Example 2 with StringMultipartFileEditor

use of cn.taketoday.web.multipart.StringMultipartFileEditor in project today-infrastructure 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");
}
Also used : MockMultipartServletRequestContext(cn.taketoday.web.servlet.MockMultipartServletRequestContext) StringMultipartFileEditor(cn.taketoday.web.multipart.StringMultipartFileEditor) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) Test(org.junit.jupiter.api.Test)

Example 3 with StringMultipartFileEditor

use of cn.taketoday.web.multipart.StringMultipartFileEditor in project today-infrastructure by TAKETODAY.

the class RequestContextDataBinderTests method testMultipartFilesAsStringArray.

@Test
public void testMultipartFilesAsStringArray() {
    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()));
    request.addFile(new MockMultipartFile("stringArray", "Eva".getBytes()));
    binder.bind(new MockMultipartServletRequestContext(request, null));
    assertThat(target.getStringArray().length).isEqualTo(2);
    assertThat(target.getStringArray()[0]).isEqualTo("Juergen");
    assertThat(target.getStringArray()[1]).isEqualTo("Eva");
}
Also used : MockMultipartServletRequestContext(cn.taketoday.web.servlet.MockMultipartServletRequestContext) StringMultipartFileEditor(cn.taketoday.web.multipart.StringMultipartFileEditor) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) Test(org.junit.jupiter.api.Test)

Aggregations

ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)3 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)3 StringMultipartFileEditor (cn.taketoday.web.multipart.StringMultipartFileEditor)3 MockMultipartServletRequestContext (cn.taketoday.web.servlet.MockMultipartServletRequestContext)3 Test (org.junit.jupiter.api.Test)3