Refine search
/** * Returns the date this version was created. */ public void testGetCreated() throws RepositoryException { // create version versionableNode.checkout(); Version version = versionableNode.checkin(); Calendar now = GregorianCalendar.getInstance(); now.add(Calendar.SECOND, 1); assertTrue("Method getCreated() should return a creation date before current date.", version.getCreated().before(now)); }
/** * Returns the predecessor versions of this version. This corresponds to * returning all the nt:version nodes whose jcr:successors property includes * a reference to the nt:version node that represents this version. A * RepositoryException is thrown if an error occurs. */ public void testGetPredecessors() throws RepositoryException { // create a new version versionableNode.checkout(); Version version = versionableNode.checkin(); assertTrue("Version should have at minimum one predecessor version.", version.getPredecessors().length > 0); }
/** * Node.merge(): If V' of a versionable subnode N' in the source workspace * is a successor of V (the base version of a subnode N in this workspace), * calling merge must fail. */ public void testFailIfCorrespondingNodeIsSuccessor() throws RepositoryException { // make V' of a subnode N' in source workspace be a successor version of // the base version of the corresponding subnode. Node n = testRootNode.getNode(nodeName1 + "/" + nodeName2); n.checkout(); n.checkin(); n.checkout(); try { // merge, besteffort set to false to stop at the first failure nodeToMerge.merge(workspace.getName(), false); fail("Merging a checkedout node if the version V' of the corresponding node is a successor of this node's base version must fail."); } catch (MergeException e) { // success } }
/** * Test if InvalidItemStateException is thrown if the session affected by * Workspace.restore(Version[], boolean) has pending changes. */ @SuppressWarnings("deprecation") public void testWorkspaceRestoreWithPendingChanges() throws RepositoryException { versionableNode.checkout(); try { // modify node without calling save() versionableNode.setProperty(propertyName1, propertyValue); // create version in second workspace Version v = wVersionableNode.checkin(); // try to restore that version superuser.getWorkspace().restore(new Version[]{v}, false); fail("InvalidItemStateException must be thrown on attempt to call Workspace.restore(Version[], boolean) in a session having any unsaved changes pending."); } catch (InvalidItemStateException e) { // success } }
/** * Node.merge(): If V' of a versionable subnode N' in the source workspace * is a predeccessor of V or V' identical to V (the base version of a * subnode N in this workspace), calling merge must be leave. */ public void testLeaveIfCorrespondingNodeIsPredeccessor() throws RepositoryException { // make V' of a subnode N' in source workspace be a predeccessor version of // the base version of the corresponding subnode. Node n = testRootNodeW2.getNode(nodeName1 + "/" + nodeName2); n.checkout(); n.setProperty(propertyName1, CHANGED_STRING); testRootNodeW2.save(); n.checkin(); n.checkout(); // merge, besteffort set to false to stop at the first failure nodeToMerge.merge(workspace.getName(), false); // check if subnode has status "leave" assertTrue(n.getProperty(propertyName1).getString().equals(CHANGED_STRING)); }
/** * Test the restore of a OnParentVersion-Ignore node * * @throws javax.jcr.RepositoryException */ public void testRestoreNode() throws RepositoryException { versionableNode.checkout(); Version v = versionableNode.checkin(); versionableNode.checkout(); // add 'ignore' child String childName = addChildNode(OPVAction).getName(); versionableNode.save(); versionableNode.restore(v, false); if (!versionableNode.hasNode(childName)) { fail("On restore of a OnParentVersion-Ignore child node, the node needs to be untouched."); } }
/** * Test the restore of a OnParentVersion-INITIALIZE property * * @throws javax.jcr.RepositoryException */ public void testRestoreProp() throws RepositoryException { Node propParent = p.getParent(); propParent.checkout(); Version v = propParent.checkin(); propParent.checkout(); p.setValue(newPropValue); p.save(); propParent.restore(v, false); assertEquals("On restore of a OnParentVersion-INITIALIZE property P, the current value of P must be left unchanged.", p.getString(), newPropValue); }
/** * Test the restore of a OnParentVersion-IGNORE property * * @throws javax.jcr.RepositoryException */ public void testRestoreProp() throws RepositoryException { Node propParent = p.getParent(); propParent.checkout(); Version v = propParent.checkin(); propParent.checkout(); p.setValue(newPropValue); p.save(); propParent.restore(v, false); assertEquals("On restore of a OnParentVersion-IGNORE property P, the current value of P must be left unchanged.", p.getString(), newPropValue); }
/** * Test the restore of a OnParentVersion-COMPUTE property * * @throws javax.jcr.RepositoryException */ public void testRestoreProp() throws RepositoryException { Node propParent = p.getParent(); propParent.checkout(); Version v = propParent.checkin(); propParent.checkout(); p.setValue(newPropValue); p.save(); propParent.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); }
public void testRestoreChild1() throws RepositoryException { versionableNode.addNode("child1"); versionableNode.getSession().save(); Version v1 = versionableNode.checkin(); versionableNode.checkout(); Version v2 = versionableNode.checkin(); versionableNode.restore(v1, true); assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1")); versionableNode.restore(version, true); assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1")); try { versionableNode.restore(v2, true); } catch (RepositoryException e) { fail("Node.restore('1.3') must fail."); } }
/** * Test the restore of a OnParentVersion-ABORT property * * @throws javax.jcr.RepositoryException */ public void testRestoreProp() throws RepositoryException { try { p.getParent().checkout(); p.getParent().checkin(); fail("On checkin of N which has a property with OnParentVersion ABORT defined, an UnsupportedRepositoryOperationException must be thrown."); } catch (VersionException e) { // success } }
@SuppressWarnings("deprecation") public void testRestoreChild1() throws RepositoryException { versionableNode.addNode("child1"); versionableNode.getSession().save(); Version v1 = versionableNode.checkin(); versionableNode.checkout(); Version v2 = versionableNode.checkin(); versionableNode.restore(v1, true); assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1")); versionableNode.restore(version, true); assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1")); try { versionableNode.restore(v2, true); } catch (RepositoryException e) { fail("Node.restore('1.3') must fail."); } }
/** * Node.merge(): bestEffort is false and any merge fails a MergeException is * thrown.<br> */ @SuppressWarnings("deprecation") public void testMergeNodeBestEffortFalse() throws RepositoryException { /// create successor versions for a node // so merge fails for this node // default workspace Node originalNode = testRootNode.getNode(nodeName1); originalNode.checkout(); originalNode.checkin(); // "merge" the clonedNode with the newNode from the default workspace // merge, besteffort set to false try { nodeToMerge.merge(workspace.getName(), false); fail("bestEffort is false and any merge should throw a MergeException."); } catch (MergeException e) { // successful } }
/** * Tests if VersionHistory.getVersionableUUID() returns the uuid of the * corresponding versionable node. */ public void testGetVersionableUUID() throws RepositoryException { // create version versionableNode.checkout(); Version version = versionableNode.checkin(); assertEquals("Method getVersionableUUID() must return the UUID of the corresponding Node.", version.getContainingHistory().getVersionableUUID(), versionableNode.getUUID()); }
/** * Tests if {@link javax.jcr.version.Version#getContainingHistory()} returns * the correct VersionHistory instance. */ public void testGetContainingHistory() throws RepositoryException { // create version versionableNode.checkout(); Version version = versionableNode.checkin(); assertTrue("Method getContainingHistory() must return the same VersionHistory " + "as getVersionHistory() of the corresponding Node.", versionableNode.getVersionHistory().isSame(version.getContainingHistory())); } }
/** * Returns the date this version was created. This corresponds to the value * of the jcr:created property in the nt:version node that represents this * version. */ public void testGetCreatedCheckAgainstProperty() throws RepositoryException { // create version versionableNode.checkout(); Version version = versionableNode.checkin(); Calendar calGetCreated = version.getCreated(); Calendar calCreatedProp = version.getProperty(jcrCreated).getValue().getDate(); assertEquals("Method getCreated() should return value of the jcr:created property.", calGetCreated, calCreatedProp); }
public void execute(Session session, Node test) throws RepositoryException { Node n = test.addNode("test"); n.addMixin(mixVersionable); session.save(); // create 3 version List versions = new ArrayList(); for (int i = 0; i < 3; i++) { n.checkout(); versions.add(n.checkin()); } // do random restores Random rand = new Random(); for (int i = 0; i < NUM_OPERATIONS / CONCURRENCY; i++) { Version v = (Version) versions.get(rand.nextInt(versions.size())); n.restore(v, true); } n.checkout(); } }, CONCURRENCY);