Search in sources :

Example 51 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.

the class ReferencesTest method testVersionReferencesVH.

public void testVersionReferencesVH() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    superuser.save();
    String p = n.getPath();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    VersionHistory vh = vMgr.getVersionHistory(p);
    // check if versionable node has references to root version
    assertEquals("Version History", vh.getIdentifier(), n.getProperty(Property.JCR_VERSION_HISTORY).getString());
    checkReferences("Version History", vh.getReferences(), p + "/jcr:versionHistory");
}
Also used : Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory)

Example 52 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.

the class ReferencesTest method testVersionedReferences.

// OAK-1196 - Node.getReferences() should not show references in frozen nodes
public void testVersionedReferences() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName2, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    n.setProperty("myref", ref);
    superuser.save();
    String p = n.getPath();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    Version v1 = vMgr.checkpoint(p);
    Node frozen = v1.getFrozenNode();
    assertEquals("ref", ref.getPath(), frozen.getProperty("myref").getNode().getPath());
    checkReferences("ref in version store", ref.getReferences(), n.getPath() + "/myref");
    // also test what happens if node is removed
    n.remove();
    ref.remove();
    superuser.save();
    try {
        frozen.getProperty("myref").getNode();
        fail("removed reference should not be accessible");
    } catch (ItemNotFoundException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 53 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.

the class ReferencesTest method testVersionReferencesV0.

public void testVersionReferencesV0() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    superuser.save();
    String p = n.getPath();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    Version v0 = vMgr.getVersionHistory(p).getRootVersion();
    // check if versionable node has references to root version
    assertEquals("Root Version", v0.getIdentifier(), n.getProperty(Property.JCR_BASE_VERSION).getString());
    assertEquals("Root Version", v0.getIdentifier(), n.getProperty(Property.JCR_PREDECESSORS).getValues()[0].getString());
    checkReferences("Root Version", v0.getReferences(), p + "/jcr:baseVersion", p + "/jcr:predecessors");
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

Example 54 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.

the class VersionTest method testFrozenNode.

public void testFrozenNode() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    Node child = n.addNode(nodeName2, ntUnstructured);
    superuser.save();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    vMgr.checkpoint(n.getPath());
    Version v = vMgr.getBaseVersion(n.getPath());
    Node frozenChild = v.getFrozenNode().getNode(child.getName());
    assertEquals(ntFrozenNode, frozenChild.getPrimaryNodeType().getName());
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

Example 55 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.

the class VersionTest method testVersionReferences.

// OAK-3130
public void testVersionReferences() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    superuser.save();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    Version v = vMgr.checkin(n.getPath());
    Version rootVersion = v.getContainingHistory().getRootVersion();
    Set<String> refs = getReferencingPaths(rootVersion);
    // the rootVersion actually has referencing property
    // from the version 'v' created by checkin() (jcr:predecessors
    // points to the rootVersion), but for compatibility with
    // Jackrabbit 2.x it is not returned by Node.getReferences()
    assertEquals("references mismatch", emptySet(), refs);
    refs = getReferencingPaths(v);
    // Similar to above, the version is actually also referenced
    // from the rootVersion's jcr:successors property, but for
    // compatibility reasons it is not returned
    Set<String> expected = ImmutableSet.of(concat(n.getPath(), jcrBaseVersion));
    assertEquals("references mismatch", expected, refs);
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

Aggregations

VersionManager (javax.jcr.version.VersionManager)154 Node (javax.jcr.Node)97 Version (javax.jcr.version.Version)65 VersionHistory (javax.jcr.version.VersionHistory)17 RepositoryException (javax.jcr.RepositoryException)11 Value (javax.jcr.Value)10 Test (org.junit.Test)9 Property (javax.jcr.Property)8 Session (javax.jcr.Session)8 NodeIterator (javax.jcr.NodeIterator)7 VersionException (javax.jcr.version.VersionException)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 MergeException (javax.jcr.MergeException)4 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)4 VersionIterator (javax.jcr.version.VersionIterator)4 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)3 InvalidItemStateException (javax.jcr.InvalidItemStateException)2