use of javax.jcr.version.VersionIterator in project jackrabbit-oak by apache.
the class CopyTest method testCopyVersionableNodeClearsVersions.
@Test
public void testCopyVersionableNodeClearsVersions() throws Exception {
Session session = getAdminSession();
Node toCopy = session.getNode(TEST_PATH + "/source/node");
toCopy.addMixin(JcrConstants.MIX_VERSIONABLE);
session.save();
Version v1 = toCopy.checkin();
toCopy.checkout();
Version v2 = toCopy.checkin();
toCopy.checkout();
session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
Node copy = testNode.getNode("target/copied");
VersionHistory vh = copy.getVersionHistory();
Version rootV = vh.getRootVersion();
assertEquals(0, rootV.getSuccessors().length);
VersionIterator vItr = vh.getAllVersions();
while (vItr.hasNext()) {
if (!rootV.isSame(vItr.nextVersion())) {
fail("Unexpected version in version history of copied node.");
}
}
try {
vh.getVersion(v1.getName());
fail("Unexpected version in version history of copied node.");
} catch (VersionException e) {
// success
}
try {
vh.getVersion(v2.getName());
fail("Unexpected version in version history of copied node.");
} catch (VersionException e) {
// success
}
}
use of javax.jcr.version.VersionIterator in project jackrabbit-oak by apache.
the class VersionCopyTestUtils method assertLabeledVersions.
public static void assertLabeledVersions(VersionHistory history) throws RepositoryException {
final VersionIterator versions = history.getAllVersions();
// root
assertFalse(versions.nextVersion().getFrozenNode().hasProperty("version"));
for (final String label : LABELS) {
assertEquals(label, versions.nextVersion().getFrozenNode().getProperty("version").getString());
}
}
use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class VersionHistoryResourceImpl method initProperties.
//--------------------------------------------------------------------------
/**
* Fill the property set for this resource.
*/
@Override
protected void initProperties() {
if (!propsInitialized) {
super.initProperties();
// change resource type defined by default item collection
properties.add(new ResourceType(new int[] { ResourceType.COLLECTION, ResourceType.VERSION_HISTORY }));
// required root-version property for version-history resource
try {
String rootVersionHref = getLocatorFromNode(((VersionHistory) getNode()).getRootVersion()).getHref(false);
properties.add(new HrefProperty(VersionHistoryResource.ROOT_VERSION, rootVersionHref, false));
} catch (RepositoryException e) {
log.error(e.getMessage());
}
// required, protected version-set property for version-history resource
try {
VersionIterator vIter = ((VersionHistory) getNode()).getAllVersions();
ArrayList<Version> l = new ArrayList<Version>();
while (vIter.hasNext()) {
l.add(vIter.nextVersion());
}
properties.add(getHrefProperty(VersionHistoryResource.VERSION_SET, l.toArray(new Version[l.size()]), true, false));
} catch (RepositoryException e) {
log.error(e.getMessage());
}
}
}
use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class RemoveVersionTest method testRemoveAllVersions.
/**
* Creates 3 versions and removes them afterwards. Checks if version history
* was purged, too.
*
* Tests error reported in JCR-2601
*
* @throws Exception if an error occurs
*/
public void testRemoveAllVersions() throws Exception {
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
superuser.save();
String path = n.getPath();
// create some versions
VersionManager mgr = superuser.getWorkspace().getVersionManager();
// v1.0
mgr.checkpoint(path);
// v1.1
mgr.checkpoint(path);
// v1.2
mgr.checkpoint(path);
// get version history
VersionHistory vh = mgr.getVersionHistory(path);
String id = vh.getIdentifier();
// remove versionable node
n.remove();
superuser.save();
// get the names of the versions
List<String> names = new LinkedList<String>();
VersionIterator vit = vh.getAllVersions();
while (vit.hasNext()) {
Version v = vit.nextVersion();
if (!v.getName().equals("jcr:rootVersion")) {
names.add(v.getName());
}
}
assertEquals("Number of versions", 3, names.size());
// remove all versions
for (String name : names) {
vh.removeVersion(name);
}
// assert that version history is gone
try {
superuser.getNodeByIdentifier(id);
fail("Version history not removed after last version was removed.");
} catch (RepositoryException e) {
// ok
}
}
use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class RestoreTest method testRestoreInvalidVersion2.
/**
* VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
*
* @throws RepositoryException
*/
@SuppressWarnings("deprecation")
public void testRestoreInvalidVersion2() throws RepositoryException {
String invalidName;
do {
invalidName = createRandomString(3);
for (VersionIterator it = versionableNode.getVersionHistory().getAllVersions(); it.hasNext(); ) {
Version v = it.nextVersion();
if (invalidName.equals(v.getName())) {
invalidName = null;
break;
}
}
} while (invalidName == null);
try {
versionableNode.restore(invalidName, true);
fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.");
} catch (VersionException e) {
// ok
}
}
Aggregations