Ejemplo n.º 1
0
  @Test
  public void
      exception_thrown_for_request_to_content_image_that_is_not_online_when_is_not_related_to_content_in_preview()
          throws Exception {
    // setup: content
    byte[] bytes = loadImage("Arn.JPG");
    ContentKey contentKey =
        createImageContent(
            "MyImage.jpg", 2, bytes, "ImageCategory", new DateTime(2011, 6, 27, 13, 0, 0, 0), null);

    // setup: preview
    Mockito.when(previewService.isInPreview()).thenReturn(true);

    ContentEntity contentPreviewed = new ContentEntity();

    ContentData contentData = Mockito.mock(ContentData.class);
    Mockito.when(contentData.resolveRelatedContentKeys())
        .thenReturn(Sets.newHashSet(new ContentKey(666)));
    ContentVersionEntity versionPreviewed = Mockito.mock(ContentVersionEntity.class);
    Mockito.when(versionPreviewed.getContentData()).thenReturn(contentData);
    versionPreviewed.setContentData(contentData);
    ContentAndVersion contentAndVersionPreviewed =
        new ContentAndVersion(contentPreviewed, versionPreviewed);
    ContentPreviewContext contentPreviewContext =
        new ContentPreviewContext(contentAndVersionPreviewed);
    PreviewContext previewContext = new PreviewContext(contentPreviewContext);

    Mockito.when(previewService.getPreviewContext()).thenReturn(previewContext);

    // exercise & verify
    String imageRequestPath = "_image/" + contentKey;
    setPathInfoAndRequestURI(httpServletRequest, imageRequestPath);
    httpServletRequest.setParameter("_background", "0xffffff");
    httpServletRequest.setParameter("_quality", "100");

    try {
      imageController.handleRequestInternal(httpServletRequest, httpServletResponse);
      fail("Expected exception");
    } catch (Exception e) {
      assertTrue(e instanceof ImageRequestException);
      assertTrue(e.getMessage().contains("Resource '/_image/" + contentKey + "' not found"));
    }
  }
Ejemplo n.º 2
0
  @Test
  @Ignore
  public void
      response_ok_for_request_to_content_image_that_is_not_online_when_is_related_to_content_in_preview()
          throws Exception {
    // setup: content
    byte[] bytes = loadImage("Arn.JPG");
    ContentKey contentKey =
        createImageContent(
            "MyImage.jpg", 2, bytes, "ImageCategory", new DateTime(2011, 6, 27, 13, 0, 0, 0), null);

    // setup: preview
    Mockito.when(previewService.isInPreview()).thenReturn(true);

    ContentEntity contentPreviewed = new ContentEntity();

    ContentData contentData = Mockito.mock(ContentData.class);
    Mockito.when(contentData.resolveRelatedContentKeys()).thenReturn(Sets.newHashSet(contentKey));
    ContentVersionEntity versionPreviewed = Mockito.mock(ContentVersionEntity.class);
    Mockito.when(versionPreviewed.getContentData()).thenReturn(contentData);
    versionPreviewed.setContentData(contentData);
    ContentAndVersion contentAndVersionPreviewed =
        new ContentAndVersion(contentPreviewed, versionPreviewed);
    ContentPreviewContext contentPreviewContext =
        new ContentPreviewContext(contentAndVersionPreviewed);
    PreviewContext previewContext = new PreviewContext(contentPreviewContext);

    Mockito.when(previewService.getPreviewContext()).thenReturn(previewContext);

    // exercise & verify
    String imageRequestPath = "_image/" + contentKey;
    setPathInfoAndRequestURI(httpServletRequest, imageRequestPath);
    httpServletRequest.setParameter("_background", "0xffffff");
    httpServletRequest.setParameter("_quality", "100");

    imageController.handleRequestInternal(httpServletRequest, httpServletResponse);

    assertEquals(HttpServletResponse.SC_OK, httpServletResponse.getStatus());
    assertTrue("Content Length", httpServletResponse.getContentLength() > 0);
  }