Search in sources :

Example 1 with ReferentialIntegrityException

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

the class ReferencesTest method testRecreateWithDifferentUUID.

public void testRecreateWithDifferentUUID() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName1, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    String uuid = ref.getIdentifier();
    Node n1 = testRootNode.addNode(nodeName2, testNodeType);
    n1.setProperty("ref", ref);
    assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
    superuser.save();
    // recreate
    ref.remove();
    ref = testRootNode.addNode(nodeName1, testNodeType);
    ref.addMixin(mixReferenceable);
    assertFalse(uuid.equals(ref.getIdentifier()));
    try {
        superuser.save();
        fail("must fail with ReferentialIntegrityException");
    } catch (ReferentialIntegrityException e) {
    // expected
    }
}
Also used : ReferentialIntegrityException(javax.jcr.ReferentialIntegrityException) Node(javax.jcr.Node)

Example 2 with ReferentialIntegrityException

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

the class ReferencesTest method testRemoveReferenced3.

public void testRemoveReferenced3() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName1, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    Node n1 = testRootNode.addNode(nodeName2, testNodeType);
    n1.setProperty("ref", ref);
    assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
    superuser.save();
    Node n2 = testRootNode.addNode(nodeName3, testNodeType);
    n2.setProperty("ref", ref);
    assertEquals(PropertyType.REFERENCE, n2.getProperty("ref").getType());
    ref.remove();
    n1.remove();
    try {
        superuser.save();
        fail("must fail with ReferentialIntegrityException");
    } catch (ReferentialIntegrityException e) {
    // expected
    }
}
Also used : ReferentialIntegrityException(javax.jcr.ReferentialIntegrityException) Node(javax.jcr.Node)

Example 3 with ReferentialIntegrityException

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

the class VersionTest method testRemoveVersion.

// OAK-3130
public void testRemoveVersion() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    superuser.save();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    vMgr.checkin(n.getPath());
    Version v = vMgr.getBaseVersion(n.getPath());
    try {
        v.getContainingHistory().removeVersion(v.getName());
        fail("removeVersion() must fail with ReferentialIntegrityException");
    } catch (ReferentialIntegrityException e) {
    // expected
    }
    vMgr.checkout(n.getPath());
    v = vMgr.getBaseVersion(n.getPath());
    try {
        v.getContainingHistory().removeVersion(v.getName());
        fail("removeVersion() must fail with ReferentialIntegrityException");
    } catch (ReferentialIntegrityException e) {
    // expected
    }
}
Also used : Version(javax.jcr.version.Version) ReferentialIntegrityException(javax.jcr.ReferentialIntegrityException) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

Example 4 with ReferentialIntegrityException

use of javax.jcr.ReferentialIntegrityException in project jackrabbit by apache.

the class CheckinRemoveVersionTest method testCheckinRemoveVersionWithXA.

public void testCheckinRemoveVersionWithXA() throws Exception {
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    testRootNode.save();
    UserTransactionImpl tx = new UserTransactionImpl(superuser);
    tx.begin();
    try {
        Version v10 = n.checkin();
        assertTrue("Version.getReferences() must return base version", v10.getReferences().hasNext());
        try {
            n.getVersionHistory().removeVersion(v10.getName());
            fail("VersionHistory.removeVersion() must throw ReferentialIntegrityException when" + " version is still referenced.");
        } catch (ReferentialIntegrityException e) {
        // expected
        }
    } finally {
        tx.rollback();
    }
}
Also used : Version(javax.jcr.version.Version) ReferentialIntegrityException(javax.jcr.ReferentialIntegrityException) Node(javax.jcr.Node) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl)

Example 5 with ReferentialIntegrityException

use of javax.jcr.ReferentialIntegrityException in project jackrabbit by apache.

the class NodeUUIDTest method testSaveReferentialIntegrityException.

/**
 * Tries to remove a node that is a reference target using {@link
 * Node#save()}.<br> <br>Procedure: <ul> <li>Creates two nodes with same
 * session</li> <li>One has a referencing property pointing to the other
 * node</li> <li>Target node gets removed.</li> </ul> This should
 * generate a {@link javax.jcr.ReferentialIntegrityException} upon save.
 * <br><br>Prerequisites: <ul> <li><code>javax.jcr.tck.NodeUUIDTest.nodetype</code>
 * must allow a property of type {@link javax.jcr.PropertyType#REFERENCE}</li>
 * <li><code>javax.jcr.tck.NodeUUIDTest.propertyname1</code> name of the
 * property of type {@link javax.jcr.PropertyType#REFERENCE}</li>
 * <li><code>javax.jcr.tck.NodeUUIDTest.nodetype2</code> must have the mixin
 * type <code>mix:referenceable</code> assigned.</li> </ul>
 */
public void testSaveReferentialIntegrityException() throws RepositoryException, NotExecutableException {
    checkMixReferenceable();
    // get default workspace test root node using superuser session
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    // create a node with a property of type PropertyType.REFERENCE
    Node referencingNode = defaultRootNode.addNode(nodeName1, testNodeType);
    // create a node with a jcr:uuid property to serve as target
    Node refTargetNode = defaultRootNode.addNode(nodeName2, getProperty("nodetype2"));
    // make sure, mix:referenceable is effective. some impls may require a save() call.
    defaultRootNode.save();
    // abort test if the repository does not allow setting
    // reference properties on this node
    ensureCanSetProperty(referencingNode, propertyName1, referencingNode.getSession().getValueFactory().createValue(refTargetNode));
    // set the reference
    referencingNode.setProperty(propertyName1, refTargetNode);
    // save the new nodes
    defaultRootNode.save();
    // remove the referenced node
    refTargetNode.remove();
    // try to save
    try {
        defaultRootNode.save();
        fail("Saving a deleted node using Node.save() that is a reference target should throw ReferentialIntegrityException");
    } catch (ReferentialIntegrityException e) {
    // ok, works as expected
    }
}
Also used : ReferentialIntegrityException(javax.jcr.ReferentialIntegrityException) Node(javax.jcr.Node)

Aggregations

ReferentialIntegrityException (javax.jcr.ReferentialIntegrityException)14 Node (javax.jcr.Node)11 RepositoryException (javax.jcr.RepositoryException)3 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)3 ItemExistsException (javax.jcr.ItemExistsException)2 Session (javax.jcr.Session)2 Version (javax.jcr.version.Version)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)2 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)2 Name (org.apache.jackrabbit.spi.Name)2 AccessDeniedException (javax.jcr.AccessDeniedException)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 Value (javax.jcr.Value)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 VersionException (javax.jcr.version.VersionException)1 VersionManager (javax.jcr.version.VersionManager)1 UserTransactionImpl (org.apache.jackrabbit.core.UserTransactionImpl)1 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)1