use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class RestoreTest method testLinearVersionsJcr2.
/**
* Tests if restore on simple versioning creates a new version that is
* in the correct linear order.
*/
public void testLinearVersionsJcr2() throws Exception {
// first get all linear versions
VersionIterator iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
StringBuffer expected = new StringBuffer();
while (iter.hasNext()) {
expected.append(iter.nextVersion().getName()).append(",");
}
// restore version
versionManager.restore(version, true);
// append new base version
expected.append(versionManager.getBaseVersion(versionableNode.getPath()).getName()).append(",");
// get the version names again
iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
StringBuffer actual = new StringBuffer();
while (iter.hasNext()) {
actual.append(iter.nextVersion().getName()).append(",");
}
assertEquals("Node.restore() on simple versioning must create a new version.", expected.toString(), actual.toString());
}
use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class RestoreTest method testLinearVersions.
/**
* Tests if restore on simple versioning creates a new version that is
* in the correct linear order.
*/
@SuppressWarnings("deprecation")
public void testLinearVersions() throws Exception {
// first get all linear versions
VersionIterator iter = versionableNode.getVersionHistory().getAllLinearVersions();
StringBuffer expected = new StringBuffer();
while (iter.hasNext()) {
expected.append(iter.nextVersion().getName()).append(",");
}
// restore version
versionableNode.restore(version, true);
// append new base version
expected.append(versionableNode.getBaseVersion().getName()).append(",");
// get the version names again
iter = versionableNode.getVersionHistory().getAllLinearVersions();
StringBuffer actual = new StringBuffer();
while (iter.hasNext()) {
actual.append(iter.nextVersion().getName()).append(",");
}
assertEquals("Node.restore() on simple versioning must create a new version.", expected.toString(), actual.toString());
}
use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class RestoreTest method testLinearVersionsJcr2_4.
/**
* Tests if restore on simple versioning creates a new version that is
* in the correct linear order.
*/
public void testLinearVersionsJcr2_4() throws Exception {
// first get all linear versions
VersionIterator iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
StringBuffer expected = new StringBuffer();
while (iter.hasNext()) {
expected.append(iter.nextVersion().getName()).append(",");
}
// restore version
versionManager.restore(new Version[] { version }, true);
// append new base version
expected.append(versionManager.getBaseVersion(versionableNode.getPath()).getName()).append(",");
// get the version names again
iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
StringBuffer actual = new StringBuffer();
while (iter.hasNext()) {
actual.append(iter.nextVersion().getName()).append(",");
}
assertEquals("Node.restore() on simple versioning must create a new version.", expected.toString(), actual.toString());
}
use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class RestoreTest method testLinearVersionsJcr2_2.
/**
* Tests if restore on simple versioning creates a new version that is
* in the correct linear order.
*/
public void testLinearVersionsJcr2_2() throws Exception {
// first get all linear versions
VersionIterator iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
StringBuffer expected = new StringBuffer();
while (iter.hasNext()) {
expected.append(iter.nextVersion().getName()).append(",");
}
// restore version
versionManager.restore(version, true);
// append new base version
expected.append(versionManager.getBaseVersion(versionableNode.getPath()).getName()).append(",");
// get the version names again
iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
StringBuffer actual = new StringBuffer();
while (iter.hasNext()) {
actual.append(iter.nextVersion().getName()).append(",");
}
assertEquals("Node.restore() on simple versioning must create a new version.", expected.toString(), actual.toString());
}
use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class VersionOperation method getRandomVersion.
/**
* Returns a randomly chosen version for the current node or
* <code>null</code> if the current node only has a root version.
*
* @param excludeReferenced exclude versions that are still referenced.
* @return randomly chosen version or <code>null</code>.
* @throws RepositoryException if an error occurs while reading from the
* repository.
*/
protected Version getRandomVersion(boolean excludeReferenced) throws RepositoryException {
List allVersions = new ArrayList();
Node n = getNode();
for (VersionIterator it = n.getVersionHistory().getAllVersions(); it.hasNext(); ) {
Version v = it.nextVersion();
if (excludeReferenced) {
// quick check if it is the base version
if (n.getBaseVersion().isSame(v)) {
continue;
}
}
if (v.getPredecessors().length > 0) {
if (!excludeReferenced || !v.getReferences().hasNext()) {
allVersions.add(v);
}
}
}
if (allVersions.size() > 0) {
return (Version) allVersions.get(getRandom().nextInt(allVersions.size()));
} else {
return null;
}
}
Aggregations