@Test
  public void testPublishing() {
    DocumentModel folder = session.createDocumentModel("/", "folder", "Folder");
    folder = session.createDocument(folder);
    DocumentModel doc = session.createDocumentModel("/", "file", "File");
    doc = session.createDocument(doc);
    checkVersions(doc);

    // publish
    DocumentModel proxy = session.publishDocument(doc, folder);
    session.save();
    String versionSeriesId = doc.getVersionSeriesId();
    assertFalse(proxy.isVersion());
    assertTrue(proxy.isProxy());
    assertTrue(proxy.hasFacet(FacetNames.IMMUTABLE));
    assertTrue(proxy.isImmutable());
    assertEquals(versionSeriesId, proxy.getVersionSeriesId());
    assertNotSame(versionSeriesId, proxy.getId());
    assertEquals("0.1", proxy.getVersionLabel());
    assertNull(proxy.getCheckinComment());
    assertFalse(proxy.isMajorVersion());
    assertTrue(proxy.isLatestVersion());
    assertFalse(proxy.isLatestMajorVersion());

    checkVersions(doc, "0.1");
    VersionModel lastVersion = session.getLastVersion(doc.getRef());
    assertNotNull(lastVersion);
    assertEquals("0.1", lastVersion.getLabel());
    DocumentModel lastVersionDocument = session.getLastDocumentVersion(doc.getRef());
    assertNotNull(lastVersionDocument);
    assertEquals("file", lastVersionDocument.getName());
  }
  @Test
  public void testPublishingAfterVersionDelete() {
    DocumentModel folder = session.createDocumentModel("/", "folder", "Folder");
    folder = session.createDocument(folder);
    DocumentModel doc = session.createDocumentModel("/", "file", "File");
    doc = session.createDocument(doc);
    checkVersions(doc);

    VersionModel lastVersion = session.getLastVersion(doc.getRef());
    assertNull(lastVersion);
    DocumentModel lastVersionDocument = session.getLastDocumentVersion(doc.getRef());
    assertNull(lastVersionDocument);

    // publish
    DocumentModel proxy = session.publishDocument(doc, folder);
    checkVersions(doc, "0.1");
    lastVersion = session.getLastVersion(doc.getRef());
    assertNotNull(lastVersion);
    assertEquals("0.1", lastVersion.getLabel());
    lastVersionDocument = session.getLastDocumentVersion(doc.getRef());
    assertNotNull(lastVersionDocument);
    assertEquals("file", lastVersionDocument.getName());

    // unpublish
    session.removeDocument(proxy.getRef());
    // delete the version
    List<VersionModel> versions = session.getVersionsForDocument(doc.getRef());
    assertEquals(1, versions.size());
    DocumentModel docVersion = session.getDocumentWithVersion(doc.getRef(), versions.get(0));
    session.removeDocument(docVersion.getRef());

    checkVersions(doc);
    lastVersion = session.getLastVersion(doc.getRef());
    assertNull(lastVersion);
    lastVersionDocument = session.getLastDocumentVersion(doc.getRef());
    assertNull(lastVersionDocument);

    // republish
    DocumentModel newProxy = session.publishDocument(doc, folder);
    checkVersions(doc, "0.2");
    lastVersion = session.getLastVersion(doc.getRef());
    assertNotNull(lastVersion);
    assertEquals("0.2", lastVersion.getLabel());
    lastVersionDocument = session.getLastDocumentVersion(doc.getRef());
    assertNotNull(lastVersionDocument);
    assertEquals("file", lastVersionDocument.getName());
  }
示例#3
0
 @Override
 public Document getVersion(String versionableId, VersionModel versionModel) {
   Serializable vid = idFromString(versionableId);
   Node versionNode = session.getVersionByLabel(vid, versionModel.getLabel());
   if (versionNode == null) {
     return null;
   }
   versionModel.setDescription(
       versionNode.getSimpleProperty(Model.VERSION_DESCRIPTION_PROP).getString());
   versionModel.setCreated(
       (Calendar) versionNode.getSimpleProperty(Model.VERSION_CREATED_PROP).getValue());
   return newDocument(versionNode);
 }
 private void checkVersions(DocumentModel doc, String... labels) {
   List<String> actual = new LinkedList<String>();
   for (DocumentModel ver : session.getVersions(doc.getRef())) {
     assertTrue(ver.isVersion());
     actual.add(ver.getVersionLabel());
   }
   // build a debug list of versions and creation times
   // in case of failure
   StringBuilder buf = new StringBuilder("version time: ");
   for (VersionModel vm : session.getVersionsForDocument(doc.getRef())) {
     buf.append(vm.getLabel());
     buf.append("=");
     buf.append(vm.getCreated().getTimeInMillis());
     buf.append(", ");
   }
   buf.setLength(buf.length() - 2);
   assertEquals(buf.toString(), Arrays.asList(labels), actual);
   List<DocumentRef> versionsRefs = session.getVersionsRefs(doc.getRef());
   assertEquals(labels.length, versionsRefs.size());
 }