Пример #1
0
 private ContentVersionEntity createDraftVersion(String title) {
   ContentVersionEntity draftVersion =
       factory.createContentVersion("" + ContentStatus.DRAFT.getKey(), "testuser/testuserstore");
   draftVersion.setCreatedAt(new Date());
   draftVersion.setModifiedAt(new Date());
   draftVersion.setModifiedBy(fixture.findUserByName("testuser"));
   draftVersion.setTitle(title);
   return draftVersion;
 }
Пример #2
0
  @Test
  @Ignore
  public void exception_thrown_for_request_to_content_image_that_binary_is_not_on_main_version()
      throws Exception {
    // setup: content
    byte[] bytes = loadImage("Arn.JPG");
    ContentKey contentKey =
        createImageContent(
            "MyImage.jpg", 2, bytes, "ImageCategory", new DateTime(2011, 6, 27, 10, 0, 0, 0), null);

    // setup: draft version of content
    ContentEntity content = fixture.findContentByKey(contentKey);
    ContentVersionEntity draftVersion = createDraftVersion("Arn.JPG");
    draftVersion.setContentDataXml(content.getMainVersion().getContentDataAsXmlString());
    content.setDraftVersion(draftVersion);
    content.addVersion(draftVersion);
    fixture.save(draftVersion);

    BinaryDataEntity binaryDataForDraftVersion = factory.createBinaryData("Arn.JPG", bytes.length);
    binaryDataForDraftVersion.setBlobKey(
        content.getMainVersion().getBinaryData("source").getBlobKey());
    fixture.save(binaryDataForDraftVersion);

    ContentBinaryDataEntity contentBinaryDataForDraftVersion =
        factory.createContentBinaryData("source", binaryDataForDraftVersion, draftVersion);
    draftVersion.addContentBinaryData(contentBinaryDataForDraftVersion);
    fixture.save(contentBinaryDataForDraftVersion);

    fixture.flushAndClearHibernateSesssion();

    // exercise & verify
    String imageRequestPath =
        "_image/" + contentKey + "/binary/" + binaryDataForDraftVersion.getKey() + ".jpg";
    setPathInfoAndRequestURI(httpServletRequest, imageRequestPath);
    httpServletRequest.setParameter("_version", draftVersion.getKey().toString());
    httpServletRequest.setParameter("_background", "0xffffff");
    httpServletRequest.setParameter("_quality", "100");

    try {
      imageController.handleRequestInternal(httpServletRequest, httpServletResponse);
      fail("Expected exception");
    } catch (Exception e) {
      assertTrue(e instanceof ImageRequestException);
      ImageRequestException imageRequestException = (ImageRequestException) e;
      assertTrue(
          imageRequestException
              .getMessage()
              .contains(
                  "Resource '/_image/"
                      + contentKey
                      + "/binary/"
                      + binaryDataForDraftVersion.getKey()
                      + ".jpg' not found"));
    }
  }
Пример #3
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"));
    }
  }
Пример #4
0
  public BinaryData getBinaryData(User oldUser, int binaryKey, long timestamp) {

    UserEntity user = securityService.getUser(oldUser);
    BinaryDataEntity binaryData = binaryDataDao.findByKey(new BinaryDataKey(binaryKey));
    if (!binaryAccessResolver.hasReadAndIsAccessibleOnline(binaryData, user, new DateTime())) {
      return null;
    }

    ContentBinaryDataEntity contentBinaryData =
        contentBinaryDataDao.findByBinaryKey(binaryData.getKey());
    ContentVersionEntity contentVersion = contentBinaryData.getContentVersion();
    ContentEntity content = contentVersion.getContent();

    // fast check if anonymous have read
    UserEntity anonymousUser = securityService.getUser(securityService.getAnonymousUserKey());
    boolean anonAccess =
        content.hasAccessRightSet(anonymousUser.getUserGroup(), ContentAccessType.READ);
    return getBinaryData(contentBinaryData, anonAccess, timestamp);
  }
Пример #5
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);
  }