Search in sources :

Example 11 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class VersionLabelTest method testGetVersionLabels.

/**
     * Test VersionHistory.getVersionLabels() returns all labels present on the version history.
     *
     * @throws RepositoryException
     * @see javax.jcr.version.VersionHistory#getVersionLabels()
     */
@SuppressWarnings("deprecation")
public void testGetVersionLabels() throws RepositoryException {
    Set<String> testLabels = new HashSet<String>(Arrays.asList(vHistory.getVersionLabels()));
    versionableNode.checkout();
    Version v = versionableNode.checkin();
    vHistory.addVersionLabel(v.getName(), versionLabel, false);
    testLabels.add(versionLabel);
    vHistory.addVersionLabel(version.getName(), versionLabel2, false);
    testLabels.add(versionLabel2);
    String[] labels = vHistory.getVersionLabels();
    for (int i = 0; i < labels.length; i++) {
        String l = labels[i];
        if (!testLabels.contains(l)) {
            fail("VersionHistory.getVersionLabels() must only return labels, that have been added to the history.");
        }
        testLabels.remove(l);
    }
    assertTrue("VersionHistory.getVersionLabels() must return all labels, that have been added to the history.", testLabels.isEmpty());
}
Also used : Version(javax.jcr.version.Version) HashSet(java.util.HashSet)

Example 12 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class VersionGraphTest method testInitialNodePredecessors.

/**
     * Test if after creation of a versionable node N the multi-value
     * REFERENCE property jcr:predecessors of N is initialized to contain a
     * single UUID, that of the root version (the same as jcr:baseVersion).
     *
     * @throws RepositoryException
     */
public void testInitialNodePredecessors() throws RepositoryException {
    Property predecessors = versionableNode.getProperty(jcrPredecessors);
    Value[] values = predecessors.getValues();
    Version rV = versionableNode.getVersionHistory().getRootVersion();
    if (values.length != 1) {
        fail("The jcr:predecessors property of a versionable node must be initialized to contain a single value");
    }
    Value initialVal = values[0];
    assertTrue("The jcr:predecessors property of a versionable node is initialized to contain a single UUID, that of the root version", initialVal.equals(superuser.getValueFactory().createValue(rV)));
}
Also used : Version(javax.jcr.version.Version) Value(javax.jcr.Value) Property(javax.jcr.Property)

Example 13 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class VersionGraphTest method testInitialBaseVersionPointsToRootVersion.

/**
     * Test that the initial base version after creation of a versionable node
     * points to the root version.
     *
     * @throws javax.jcr.RepositoryException
     */
public void testInitialBaseVersionPointsToRootVersion() throws RepositoryException {
    Version rV = versionableNode.getVersionHistory().getRootVersion();
    Version bV = versionableNode.getBaseVersion();
    assertTrue("After creation of a versionable node the node's baseVersion must point to the rootVersion in the version history.", rV.isSame(bV));
}
Also used : Version(javax.jcr.version.Version)

Example 14 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class VersionHistoryTest method testGetAllVersionsJcr2.

/**
     * Test that {@link VersionHistory#getAllVersions()} returns an iterator
     * containing the root version and all versions that have been created by
     * Node.checkin().
     *
     * @see javax.jcr.version.VersionHistory#getAllVersions()
     */
public void testGetAllVersionsJcr2() throws RepositoryException {
    int cnt = 5;
    Map<String, Version> versions = new HashMap<String, Version>();
    List<String> vnames = new ArrayList<String>();
    Version v = vHistory.getRootVersion();
    versions.put(v.getIdentifier(), v);
    vnames.add(v.getIdentifier());
    for (int i = 0; i < cnt; i++) {
        v = versionManager.checkin(versionableNode.getPath());
        vnames.add(v.getIdentifier());
        versions.put(v.getIdentifier(), v);
        versionManager.checkout(versionableNode.getPath());
    }
    VersionIterator it = vHistory.getAllVersions();
    while (it.hasNext()) {
        v = it.nextVersion();
        if (!versions.containsKey(v.getIdentifier())) {
            fail("VersionHistory.getAllVersions() must only contain the root version and versions, that have been created by a Node.checkin() call.");
        }
        versions.remove(v.getIdentifier());
        // check order of linear version history (see JCR 2.0, 15.1.1.2)
        assertEquals("versions in a linear version history should be sorted by creation time", vnames.remove(0), v.getIdentifier());
    }
    assertTrue("VersionHistory.getAllVersions() must only contain the root version and all versions that have been created with a Node.checkin() call.", versions.isEmpty());
}
Also used : HashMap(java.util.HashMap) Version(javax.jcr.version.Version) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator)

Example 15 with Version

use of javax.jcr.version.Version in project jackrabbit by apache.

the class OnParentVersionComputeTest method testRestorePropJcr2.

/**
     * Test the restore of a OnParentVersion-COMPUTE property
     *
     * @throws javax.jcr.RepositoryException
     */
public void testRestorePropJcr2() throws RepositoryException {
    Node propParent = p.getParent();
    VersionManager versionManager = propParent.getSession().getWorkspace().getVersionManager();
    String path = propParent.getPath();
    versionManager.checkout(path);
    Version v = versionManager.checkin(path);
    versionManager.checkout(path);
    p.setValue(newPropValue);
    p.getSession().save();
    versionManager.restore(v, false);
    assertEquals("On restore of a OnParentVersion-COMPUTE property P, the current P in the workspace will be left unchanged.", p.getString(), newPropValue);
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

Aggregations

Version (javax.jcr.version.Version)265 Node (javax.jcr.Node)155 VersionManager (javax.jcr.version.VersionManager)65 RepositoryException (javax.jcr.RepositoryException)45 VersionHistory (javax.jcr.version.VersionHistory)29 VersionException (javax.jcr.version.VersionException)25 NodeIterator (javax.jcr.NodeIterator)23 Session (javax.jcr.Session)19 Test (org.junit.Test)19 Property (javax.jcr.Property)16 VersionIterator (javax.jcr.version.VersionIterator)16 Value (javax.jcr.Value)14 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)14 ItemExistsException (javax.jcr.ItemExistsException)13 HashSet (java.util.HashSet)12 NodeDefinition (javax.jcr.nodetype.NodeDefinition)12 ArrayList (java.util.ArrayList)11 Set (java.util.Set)7 DavException (org.apache.jackrabbit.webdav.DavException)7 UserTransaction (javax.transaction.UserTransaction)6