예제 #1
0
  @Test
  @Ignore
  public void request_content_image_that_binary_is_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);

    BinaryDataEntity binaryDataOfMainVersion = content.getMainVersion().getBinaryData("source");

    // exercise & verify
    String imageRequestPath =
        "_image/" + contentKey + "/binary/" + binaryDataOfMainVersion.getKey() + ".jpg";
    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);
    assertEquals("image/jpg", httpServletResponse.getContentType());
  }
예제 #2
0
  @Test
  public void request_content_image_with_no_access() throws Exception {
    byte[] bytes = loadImage("Arn.JPG");
    ContentKey contentKey =
        createImageContent(
            "MyImage.jpg", 2, bytes, "ImageCategory", new DateTime(2011, 6, 27, 10, 0, 0, 0), null);

    fixture.createAndStoreUserAndUserGroup(
        "user-with-no-access", "testuser fullname", UserType.NORMAL, "testuserstore");
    loginUserInPortal(fixture.findUserByName("user-with-no-access").getKey());

    String imageRequestPath = "_image/" + contentKey + ".jpg";
    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);
      ImageRequestException imageRequestException = (ImageRequestException) e;
      assertTrue(
          imageRequestException
              .getMessage()
              .contains("Resource '/_image/" + contentKey + ".jpg' not found"));
    }
  }
예제 #3
0
  @Test
  public void request_content_image_that_is_deleted() throws Exception {
    byte[] bytes = loadImage("Arn.JPG");
    ContentKey contentKey =
        createImageContent(
            "MyImage.jpg", 2, bytes, "ImageCategory", new DateTime(2011, 6, 27, 10, 0, 0, 0), null);
    ContentEntity content = fixture.findContentByKey(contentKey);
    content.setDeleted(true);

    String imageRequestPath = "_image/" + contentKey + ".jpg";
    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);
      ImageRequestException imageRequestException = (ImageRequestException) e;
      assertTrue(
          imageRequestException
              .getMessage()
              .contains("Resource '/_image/" + contentKey + ".jpg' not found"));
    }
  }
예제 #4
0
  @Before
  public void before() {
    fixture = new DomainFixture(hibernateTemplate);
    factory = new DomainFactory(fixture);

    fixture.initSystemData();
    fixture.createAndStoreUserAndUserGroup(
        "testuser", "testuser fullname", UserType.NORMAL, "testuserstore");

    httpServletRequest.setCharacterEncoding("UTF-8");
    ServletRequestAccessor.setRequest(httpServletRequest);
    loginUserInPortal(fixture.findUserByName("testuser").getKey());

    previewService = Mockito.mock(PreviewService.class);
    Mockito.when(previewService.isInPreview()).thenReturn(false);
    Mockito.when(previewService.getPreviewContext()).thenReturn(PreviewContext.NO_PREVIEW);
    imageController.setPreviewService(previewService);

    MockTimeService timeService = new MockTimeService(new DateTime(2011, 6, 27, 12, 0, 0, 0));
    imageController.setTimeService(timeService);

    site1 = factory.createSite("MySite", new Date(), null, "en");
    fixture.save(site1);
    MenuItemEntity firstPage = createPage("Firstpage", null, "MySite");
    fixture.save(firstPage);

    site1.setFirstPage(firstPage);

    fixture.flushAndClearHibernateSesssion();

    fixture.save(
        factory.createContentHandler(
            "Image content", ContentHandlerName.IMAGE.getHandlerClassShortName()));
    fixture.save(
        factory.createContentType(
            "ImageContentType", ContentHandlerName.IMAGE.getHandlerClassShortName()));
    fixture.save(factory.createUnit("ImageUnit"));
    fixture.save(
        factory.createCategory(
            "ImageCategory", "ImageContentType", "ImageUnit", "testuser", "testuser"));
    fixture.save(
        factory.createCategoryAccessForUser("ImageCategory", "testuser", "read, create, approve"));

    fixture.flushAndClearHibernateSesssion();
  }
예제 #5
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"));
    }
  }
예제 #6
0
 @Test
 public void request_content_image_that_does_not_exist() throws Exception {
   String imageRequestPath = "_image/123" + ".jpg";
   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);
     ImageRequestException imageRequestException = (ImageRequestException) e;
     assertTrue(
         imageRequestException.getMessage().contains("Resource '/_image/123.jpg' not found"));
   }
 }
예제 #7
0
  @Test
  @Ignore
  public void request_content_image_with_label_small() throws Exception {
    byte[] bytes = loadImage("Arn.JPG");
    ContentKey contentKey =
        createImageContent(
            "MyImage.jpg", 2, bytes, "ImageCategory", new DateTime(2011, 6, 27, 10, 0, 0, 0), null);

    String imageRequestPath = "_image/" + contentKey.toString() + "/label/small";
    setPathInfoAndRequestURI(httpServletRequest, imageRequestPath);
    httpServletRequest.setParameter("_background", "0xffffff");
    httpServletRequest.setParameter("_quality", "100");
    imageController.handleRequestInternal(httpServletRequest, httpServletResponse);

    assertEquals("image/png", httpServletResponse.getContentType());
    assertEquals(HttpServletResponse.SC_OK, httpServletResponse.getStatus());
  }
예제 #8
0
  @Test
  @Ignore
  public void request_user_image() throws Exception {
    byte[] bytes = loadImage("Arn.JPG");
    UserEntity testUser = fixture.findUserByName("testuser");
    testUser.setPhoto(bytes);

    fixture.flushAndClearHibernateSesssion();

    String imageRequestPath = "_image/user/" + testUser.getKey() + ".jpg";
    setPathInfoAndRequestURI(httpServletRequest, imageRequestPath);
    httpServletRequest.setParameter("_background", "0xffffff");
    httpServletRequest.setParameter("_quality", "100");
    imageController.handleRequestInternal(httpServletRequest, httpServletResponse);

    assertEquals(HttpServletResponse.SC_OK, httpServletResponse.getStatus());
    assertEquals("image/jpg", httpServletResponse.getContentType());
  }
예제 #9
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"));
    }
  }
예제 #10
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);
  }