コード例 #1
0
  public void testFindByPrimaryKeyExisting() throws Exception {
    Content content = addContent();

    Content existingContent = _persistence.findByPrimaryKey(content.getContentId());

    assertTrue(existingContent.equals(content));
  }
コード例 #2
0
  public void testUpdateNew() throws Exception {
    Content content = addContent();

    Blob data = content.getData();

    assertFalse(data.getClass().equals(OutputBlob.class));
    assertEquals(1024, data.length());
  }
コード例 #3
0
  protected Content addContent() throws Exception {
    Content content = createContent();

    _persistence.update(content);

    // Reload for a fresh Blob

    content = _persistence.findByPrimaryKey(content.getContentId());

    return content;
  }
コード例 #4
0
  public void testUpdateExisting() throws Exception {
    Content content = addContent();

    byte[] bytes = new byte[1024];

    Blob data = new OutputBlob(new ByteArrayInputStream(bytes), bytes.length);

    Content newContent =
        new Content(
            content.getContentId(),
            nextLong(),
            randomString(),
            nextLong(),
            nextLong(),
            randomString(),
            randomString(),
            data,
            data.length());

    _persistence.update(newContent);

    Content existingContent = _persistence.findByPrimaryKey(newContent.getContentId());

    assertTrue(existingContent.equals(newContent));
  }
コード例 #5
0
  public void testRemoveByC_R_P_V() throws Exception {
    Content content = addContent();

    Content existingContent = _persistence.fetchByPrimaryKey(content.getContentId());

    assertNotNull(existingContent);

    boolean removed =
        _persistence.removeByC_R_P_V(
            existingContent.getCompanyId(), existingContent.getRepositoryId(),
            existingContent.getPath(), existingContent.getVersion());

    assertTrue(removed);

    existingContent = _persistence.fetchByPrimaryKey(content.getContentId());

    assertNull(existingContent);
  }
コード例 #6
0
  public void testRemove() throws Exception {
    Content content = addContent();

    Content existingContent = _persistence.fetchByPrimaryKey(content.getContentId());

    assertNotNull(existingContent);
    assertTrue(existingContent.equals(content));

    _persistence.remove(content.getContentId());

    existingContent = _persistence.fetchByPrimaryKey(content.getContentId());

    assertNull(existingContent);
  }
コード例 #7
0
  public void testFetchByC_R_P() throws Exception {
    Content content1 = addContent();

    long contentId2 = content1.getContentId() + 1;

    String version2 = content1.getVersion().concat("-2");

    int size = (int) content1.getSize();

    Blob data = new OutputBlob(new ByteArrayInputStream(new byte[size]), size);

    Content content2 =
        new Content(
            contentId2,
            content1.getCompanyId(),
            content1.getPortletId(),
            content1.getGroupId(),
            content1.getRepositoryId(),
            content1.getPath(),
            version2,
            data,
            size);

    _persistence.update(content2);

    Content existingContent2 =
        _persistence.fetchByC_R_P(
            content1.getCompanyId(), content1.getRepositoryId(), content1.getPath());

    assertTrue(existingContent2.equals(content2));

    _persistence.remove(existingContent2.getContentId());

    Content existingContent1 =
        _persistence.fetchByC_R_P(
            content1.getCompanyId(), content1.getRepositoryId(), content1.getPath());

    assertTrue(existingContent1.equals(content1));

    _persistence.remove(existingContent1.getContentId());

    Content missingContent =
        _persistence.fetchByC_R_P(
            content1.getCompanyId(), content1.getRepositoryId(), content1.getPath());

    assertNull(missingContent);
  }
コード例 #8
0
  public void testCountByC_R_P_V() throws Exception {
    Content content = createContent();

    int count =
        _persistence.countByC_R_P_V(
            content.getCompanyId(), content.getRepositoryId(),
            content.getPath(), content.getVersion());

    assertEquals(0, count);

    _persistence.update(content);

    count =
        _persistence.countByC_R_P_V(
            content.getCompanyId(), content.getRepositoryId(),
            content.getPath(), content.getVersion());

    assertEquals(1, count);

    _persistence.remove(content.getContentId());

    count =
        _persistence.countByC_R_P_V(
            content.getCompanyId(), content.getRepositoryId(),
            content.getPath(), content.getVersion());

    assertEquals(0, count);
  }
コード例 #9
0
  public void testFindByC_R_P_V() throws Exception {
    Content content = addContent();

    Content existingContent =
        _persistence.findByC_R_P_V(
            content.getCompanyId(), content.getRepositoryId(),
            content.getPath(), content.getVersion());

    assertTrue(existingContent.equals(content));

    _persistence.remove(existingContent.getContentId());

    try {
      _persistence.findByC_R_P_V(
          content.getCompanyId(), content.getRepositoryId(), content.getPath(), randomString());

      fail("Missing entity did not throw NoSuchContentException");
    } catch (NoSuchContentException nsce) {
    }
  }
コード例 #10
0
  public void testFindByC_R_P() throws Exception {
    Content content1 = addContent();

    long contentId2 = content1.getContentId() + 1;

    String version2 = content1.getVersion().concat("-2");

    int size = (int) content1.getSize();

    Blob data = new OutputBlob(new ByteArrayInputStream(new byte[size]), size);

    Content content2 =
        new Content(
            contentId2,
            content1.getCompanyId(),
            content1.getPortletId(),
            content1.getGroupId(),
            content1.getRepositoryId(),
            content1.getPath(),
            version2,
            data,
            size);

    _persistence.update(content2);

    Content existingContent2 =
        _persistence.findByC_R_P(
            content1.getCompanyId(), content1.getRepositoryId(), content1.getPath());

    assertTrue(existingContent2.equals(content2));

    _persistence.remove(existingContent2.getContentId());

    Content existingContent1 =
        _persistence.findByC_R_P(
            content1.getCompanyId(), content1.getRepositoryId(), content1.getPath());

    assertTrue(existingContent1.equals(content1));

    _persistence.remove(existingContent1.getContentId());

    try {
      _persistence.findByC_R_P(
          content1.getCompanyId(), content1.getRepositoryId(), content1.getPath());

      fail("Missing entity did not throw NoSuchContentException");
    } catch (NoSuchContentException nsce) {
    }
  }
コード例 #11
0
  public void testFetchByC_R_P_V() throws Exception {
    Content content = addContent();

    Content existingContent =
        _persistence.fetchByC_R_P_V(
            content.getCompanyId(), content.getRepositoryId(),
            content.getPath(), content.getVersion());

    assertTrue(existingContent.equals(content));

    _persistence.remove(existingContent.getContentId());

    Content missingContent =
        _persistence.fetchByC_R_P_V(
            content.getCompanyId(), content.getRepositoryId(),
            content.getPath(), randomString());

    assertNull(missingContent);
  }