Esempio n. 1
0
  @Test
  public void uploadAvatarForChromeAndFFShouldReturnPreviewInResponce()
      throws ImageProcessException {
    MockHttpServletResponse response = new MockHttpServletResponse();

    avatarController.uploadAvatar(validAvatar, response);

    verify(imageControllerUtils).prepareResponse(eq(validAvatar), eq(response), any(HashMap.class));
  }
Esempio n. 2
0
  @Test
  @SuppressWarnings("unchecked")
  public void uploadAvatarForOperaAndIEShouldReturnPreviewInResponce()
      throws IOException, ImageProcessException {
    MultipartFile file = new MockMultipartFile("qqfile", validAvatar);

    ResponseEntity<String> actualResponseEntity = avatarController.uploadAvatar(file);

    verify(imageControllerUtils)
        .prepareResponse(eq(file), any(HttpHeaders.class), any(HashMap.class));
  }
Esempio n. 3
0
  @SuppressWarnings("unchecked")
  public void getDefaultAvatarShouldReturnDefaultAvatarInBase64String()
      throws IOException, ImageProcessException {
    String expectedJSON = "{\"team\": \"larks\"}";
    when(imageControllerUtils.getDefaultImage()).thenReturn(validAvatar);
    when(imageControllerUtils.convertImageToIcoInString64(validAvatar))
        .thenReturn(IMAGE_BYTE_ARRAY_IN_BASE_64_STRING);
    when(imageControllerUtils.getResponceJSONString(Matchers.anyMap())).thenReturn(expectedJSON);

    String actualJSON = avatarController.getDefaultAvatar();

    assertEquals(actualJSON, expectedJSON);
  }
Esempio n. 4
0
  @Test
  public void renderAvatarShouldNotReturnNotModifiedAvatarInResponse()
      throws IOException, NotFoundException {
    JCUser user = getUser();
    user.setAvatar(validAvatar);
    user.setAvatarLastModificationTime(new DateTime(0));
    when(userService.get(anyLong())).thenReturn(user);
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader(avatarController.IF_MODIFIED_SINCE_HEADER, new Date(1000));

    avatarController.renderAvatar(request, response, 0L);

    assertEquals(response.getStatus(), HttpServletResponse.SC_NOT_MODIFIED);
    assertNotSame(response.getContentAsByteArray(), validAvatar);
    assertEquals(response.getHeader("Pragma"), "public");
    List<String> cacheControlHeaders = response.getHeaders("Cache-Control");
    assertTrue(cacheControlHeaders.contains("public"));
    assertTrue(cacheControlHeaders.contains("must-revalidate"));
    assertTrue(cacheControlHeaders.contains("max-age=0"));
    assertNotNull(response.getHeader("Expires")); // System.currentTimeMillis() is used
    assertNotNull(response.getHeader("Last-Modified")); // depends on current timezone
  }