コード例 #1
0
  /**
   * Tests the checkinExternal service method
   *
   * @throws Exception
   */
  public void testCheckinExternal() throws Exception {
    // First we need to check a document out
    Reference workingCopy = doCheckOut();

    // Check in with external content
    NamedValue[] comments = getVersionComments();
    ContentFormat contentFormat = new ContentFormat(Constants.MIMETYPE_TEXT_PLAIN, "UTF-8");
    Reference origionalNode =
        this.authoringService.checkinExternal(
            workingCopy, comments, false, contentFormat, SECOND_VERSION_CONTENT.getBytes());

    // Check the origianl Node
    assertNotNull(origionalNode);
    Content[] contents =
        this.contentService.read(
            new Predicate(new Reference[] {origionalNode}, BaseWebServiceSystemTest.store, null),
            Constants.PROP_CONTENT.toString());
    Content readResult = contents[0];
    assertNotNull(readResult);
    String checkedInContent = ContentUtils.getContentAsString(readResult);
    assertNotNull(checkedInContent);
    assertEquals(SECOND_VERSION_CONTENT, checkedInContent);
  }
コード例 #2
0
  /**
   * Tests the createVersion service method
   *
   * @throws Exception
   */
  public void testVersionMethods() throws Exception {
    Reference reference = createContentAtRoot("create_version_test.txt", INITIAL_VERSION_CONTENT);
    Predicate predicate = convertToPredicate(reference);

    // Get the version history (before its been versioned)
    VersionHistory emptyVersionHistory = this.authoringService.getVersionHistory(reference);
    assertNotNull(emptyVersionHistory);
    assertNull(emptyVersionHistory.getVersions());

    // Create the version
    VersionResult result =
        this.authoringService.createVersion(predicate, getVersionComments(), false);
    assertNotNull(result);
    assertEquals(1, result.getNodes().length);
    assertEquals(1, result.getVersions().length);
    Version version = result.getVersions()[0];
    assertEquals("1.0", version.getLabel());
    // TODO check commentaries
    // TODO check creator

    // Get the version history
    this.authoringService.createVersion(predicate, getVersionComments(), false);
    VersionHistory versionHistory = this.authoringService.getVersionHistory(reference);
    assertNotNull(versionHistory);
    assertEquals(2, versionHistory.getVersions().length);
    // TODO some more tests ...

    // Update the content
    this.contentService.write(
        reference, Constants.PROP_CONTENT, SECOND_VERSION_CONTENT.getBytes(), null);

    // Create another version
    VersionResult versionResult2 =
        this.authoringService.createVersion(predicate, getVersionComments(), false);
    assertNotNull(versionResult2);
    assertEquals(1, versionResult2.getNodes().length);
    assertEquals(1, versionResult2.getVersions().length);
    Version version2 = versionResult2.getVersions()[0];
    assertEquals("1.3", version2.getLabel());
    // TODO check commentaries
    // TODO check creator

    // Check the version history
    VersionHistory versionHistory2 = this.authoringService.getVersionHistory(reference);
    assertNotNull(versionHistory2);
    assertEquals(4, versionHistory2.getVersions().length);
    // TODO some more tests ...

    // Create a major version
    NamedValue versionVal = Utils.createNamedValue("versionType", "MAJOR");
    NamedValue descriptionVal = Utils.createNamedValue("description", "new description");
    NamedValue[] comments = new NamedValue[] {versionVal, descriptionVal};
    VersionResult result5 = this.authoringService.createVersion(predicate, comments, false);
    assertNotNull(result5);
    assertEquals(1, result5.getNodes().length);
    assertEquals(1, result5.getVersions().length);
    Version version5 = result5.getVersions()[0];
    assertEquals("2.0", version5.getLabel());

    // Confirm the current content of the node
    Content[] contents =
        this.contentService.read(
            new Predicate(new Reference[] {reference}, BaseWebServiceSystemTest.store, null),
            Constants.PROP_CONTENT.toString());
    Content readResult1 = contents[0];
    String content1 = ContentUtils.getContentAsString(readResult1);
    assertEquals(SECOND_VERSION_CONTENT, content1);

    // Revert the node to the first version
    this.authoringService.revertVersion(reference, "1.0");

    // Confirm that the state of the node has been reverted
    Content[] contents2 =
        this.contentService.read(
            new Predicate(new Reference[] {reference}, BaseWebServiceSystemTest.store, null),
            Constants.PROP_CONTENT.toString());
    Content readResult2 = contents2[0];
    String content2 = ContentUtils.getContentAsString(readResult2);
    assertEquals(INITIAL_VERSION_CONTENT, content2);

    // Now delete the version history
    VersionHistory deletedVersionHistory = this.authoringService.deleteAllVersions(reference);
    assertNotNull(deletedVersionHistory);
    assertNull(deletedVersionHistory.getVersions());

    // Check the version history
    VersionHistory versionHistory3 = this.authoringService.getVersionHistory(reference);
    assertNotNull(versionHistory3);
    assertNull(versionHistory3.getVersions());
  }