Example usage for org.springframework.mock.web MockMultipartFile MockMultipartFile

List of usage examples for org.springframework.mock.web MockMultipartFile MockMultipartFile

Introduction

In this page you can find the example usage for org.springframework.mock.web MockMultipartFile MockMultipartFile.

Prototype

public MockMultipartFile(String name, InputStream contentStream) throws IOException 

Source Link

Document

Create a new MockMultipartFile with the given content.

Usage

From source file:de.science.hack.jetstream.web.controller.UploadControllerTest.java

/**
 * Test of upload method, of class UploadController.
 *//*w ww  .j  a v  a  2s  .c o m*/
@Test
public void testFailedUpload() {
    byte[] content = new byte[0];
    MultipartFile file = new MockMultipartFile(NAME, content);
    ModelAndView result = classUnderTest.upload(file);
    assertNotNull(result);
    assertEquals(UploadController.FAILED_VIEW, result.getViewName());
    assertEquals(UploadController.FAILED_UPLOAD, result.getModel().get(UploadController.MSG_OBJ));
}

From source file:com.trenako.web.controllers.form.OptionFormTests.java

@Test
public void shouldReturnTheOptionObjectFilledWithFormValues() throws IOException {
    Option opt = new Option();
    opt.setName("optionName");
    opt.setFamily("optionFamily");

    OptionForm form = new OptionForm();
    form.setOption(opt);/*from  ww  w .  j a va  2s .c  o  m*/
    form.setFile(new MockMultipartFile("file.png", "content".getBytes()));

    Option option = form.buildOption();

    assertEquals("optionName", option.getName());
    assertEquals("optionFamily", option.getFamily());
    assertNotNull(option.getImage());
}

From source file:org.unidle.form.QuestionFormTest.java

@Test
public void testGetAttachments() throws Exception {
    final List<? extends MultipartFile> attachments = Lists.newArrayList(
            new MockMultipartFile("empty", new byte[0]), new MockMultipartFile("empty", new byte[0]));
    setField(subject, "attachments", attachments);

    final List<? extends MultipartFile> result = subject.getAttachments();

    assertThat(result).isEqualTo(attachments);
}

From source file:feign.form.feign.spring.FeignClientAnnotatedInterfaceTest.java

@Test
public void upload1Test() throws Exception {
    MultipartFile file = new MockMultipartFile("file", "test".getBytes(UTF_8));
    String response = client.upload1("test folder", file, "message text");

    Assert.assertEquals("test:message text", response);
}

From source file:com.epam.ta.reportportal.ws.MultipartRequestTest.java

@Test
public void testPageableLast() throws Exception {
    Resource multipartFile = new ClassPathResource(DEMO_FILE_NAME);
    MockMultipartFile mockMultipartFile = new MockMultipartFile(DEMO_FILE_NAME, multipartFile.getInputStream());

    this.mvcMock//from w w  w.j  ava 2 s.  c  om
            .perform(fileUpload(PROJECT_BASE_URL + "/log").file(mockMultipartFile).secure(true)
                    .accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
            .andExpect(status().is(400));

}

From source file:de.science.hack.jetstream.web.controller.UploadControllerTest.java

/**
 * Test of upload method, of class UploadController.
 *//* www .jav  a  2 s . c  o  m*/
@Test
public void testSuccessfulUpload() {
    byte[] content = ("0,69,-2.35675048828125\n" + "0,67.5,-2.00323486328125\n" + "0,66,-3.88800048828125")
            .getBytes();
    MultipartFile file = new MockMultipartFile(NAME, content);
    ModelAndView result = classUnderTest.upload(file);
    assertNotNull(result);
    assertEquals(UploadController.WEBGL_VIEW, result.getViewName());
}

From source file:com.epam.ta.reportportal.ws.controller.impl.FileStorageControllerTest.java

@Test
public void addPhotoWidthNegative() throws Exception {
    File file = new File("src/test/resources/500x383.jpg");
    MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.fileUpload("/data/photo")
            .file(new MockMultipartFile("file", new FileInputStream(file))).principal(authentication());
    this.mvcMock.perform(builder).andExpect(status().is(400));
}

From source file:feign.form.feign.spring.FeignClientAnnotatedInterfaceTest.java

@Test
public void upload2Test() throws Exception {
    MultipartFile file = new MockMultipartFile("file", "test".getBytes(UTF_8));
    String response = client.upload2(file, "test folder", "message text");

    Assert.assertEquals("test:message text", response);
}

From source file:com.carlos.projects.billing.ExcelToMySQLImporterTest.java

@Test
public void shouldImportZeroComponentsFromEmptyFile() throws Exception {
    //given/*from   www . ja  v  a 2  s.c om*/
    ExcelToMySQLImporter importer = new ExcelToMySQLImporter(familyDAO, componentDAO);
    MultipartFile file = new MockMultipartFile("emptyData.xlsx",
            getClass().getResourceAsStream("/emptyData.xlsx"));

    //when
    Long importedComponents = importer.importData(file);

    //then
    assertThat("The number of components imported is not 0", importedComponents, is(0L));
    verifyZeroInteractions(familyDAO);
    verifyZeroInteractions(componentDAO);
}

From source file:com.epam.ta.reportportal.ws.controller.impl.FileStorageControllerTest.java

@Test
public void addPhotoHeightNegative() throws Exception {
    File file = new File("src/test/resources/209x505.png");
    this.mvcMock/*from ww w .ja v a  2s  .  co m*/
            .perform(MockMvcRequestBuilders.fileUpload("/data/photo")
                    .file(new MockMultipartFile("file", new FileInputStream(file))).principal(authentication()))
            .andExpect(status().is(400));
}