Ejemplo n.º 1
0
  @Test
  @DirtiesContext
  public void fileWithIncorrectTypeNotAdded() throws Exception {
    assertEquals(0, imageRepo.count());

    MockMultipartFile multipartFile =
        new MockMultipartFile("image", "file.txt", "text/plain", "123".getBytes());

    this.mockMvc.perform(fileUpload("/images").file(multipartFile)).andReturn();

    assertEquals(0, imageRepo.count());
  }
Ejemplo n.º 2
0
  @Test
  @DirtiesContext
  public void gifAdded() throws Exception {
    assertEquals(0, imageRepo.count());

    MockMultipartFile multipartFile =
        new MockMultipartFile("image", "file.gif", "image/gif", "muah".getBytes());

    this.mockMvc.perform(fileUpload("/images").file(multipartFile)).andReturn();

    MvcResult result = this.mockMvc.perform(get("/images/1")).andReturn();
    assertEquals(1, imageRepo.count());
    assertTrue(Arrays.equals(result.getResponse().getContentAsByteArray(), "muah".getBytes()));
    assertTrue(result.getResponse().getContentType().equals("image/gif"));
    assertTrue(result.getResponse().getHeader("filename").equals("file.gif"));
    assertEquals("muah".getBytes().length, result.getResponse().getContentLength());
  }