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
}
}
use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class RestoreTest method testRestoreInvalidVersion2Jcr2.
/**
* VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
*
* @throws RepositoryException
*/
public void testRestoreInvalidVersion2Jcr2() throws RepositoryException {
String invalidName;
do {
invalidName = createRandomString(3);
for (VersionIterator it = versionManager.getVersionHistory(versionableNode.getPath()).getAllVersions(); it.hasNext(); ) {
Version v = it.nextVersion();
if (invalidName.equals(v.getName())) {
invalidName = null;
break;
}
}
} while (invalidName == null);
try {
versionManager.restore(versionableNode.getPath(), 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
}
}
use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class VersionHistoryTest method testInitiallyGetAllLinearVersionsContainsTheRootAndTheBaseVersion.
/**
* Test if the iterator returned by {@link javax.jcr.version.VersionHistory#getAllLinearVersions()}
* contains both the root and the base version upon creation of the version history.
* @since JCR 2.0
*/
public void testInitiallyGetAllLinearVersionsContainsTheRootAndTheBaseVersion() throws RepositoryException {
VersionManager vm = versionableNode.getSession().getWorkspace().getVersionManager();
List<String> lvh = new ArrayList<String>();
for (VersionIterator it = vHistory.getAllLinearVersions(); it.hasNext(); ) {
lvh.add(it.nextVersion().getName());
}
String rootVersion = vm.getVersionHistory(versionableNode.getPath()).getRootVersion().getName();
String baseVersion = vm.getBaseVersion(versionableNode.getPath()).getName();
assertTrue("root version " + rootVersion + " must be part of the linear version history: " + lvh, lvh.contains(rootVersion));
assertTrue("base version " + baseVersion + " must be part of the linear version history: " + lvh, lvh.contains(baseVersion));
}
use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class VersionHistoryTest method testGetAllVersions.
/**
* Test that {@link VersionHistory#getAllVersions()} returns an iterator
* containing the root version and all versions that have been created by
* Node.checkin().
*
* @see javax.jcr.version.VersionHistory#getAllVersions()
*/
@SuppressWarnings("deprecation")
public void testGetAllVersions() throws RepositoryException {
int cnt = 5;
Map<String, Version> versions = new HashMap<String, Version>();
Version v = vHistory.getRootVersion();
versions.put(v.getUUID(), v);
for (int i = 0; i < cnt; i++) {
v = versionableNode.checkin();
versions.put(v.getUUID(), v);
versionableNode.checkout();
}
VersionIterator it = vHistory.getAllVersions();
while (it.hasNext()) {
v = it.nextVersion();
if (!versions.containsKey(v.getUUID())) {
fail("VersionHistory.getAllVersions() must only contain the root version and versions, that have been created by a Node.checkin() call.");
}
versions.remove(v.getUUID());
}
assertTrue("VersionHistory.getAllVersions() must contain the root version and all versions that have been created with a Node.checkin() call.", versions.isEmpty());
}
use of javax.jcr.version.VersionIterator in project jackrabbit by apache.
the class LsVersions method execute.
/**
* {@inheritDoc}
*/
public boolean execute(Context ctx) throws Exception {
String path = (String) ctx.get(this.pathKey);
Node n = CommandHelper.getNode(ctx, path);
// header
int[] width = new int[] { 20, 50 };
String[] header = new String[] { bundle.getString("word.version"), bundle.getString("word.labels") };
// print header
PrintHelper.printRow(ctx, width, header);
// print separator
PrintHelper.printSeparatorRow(ctx, width, '-');
VersionIterator iter = n.getVersionHistory().getAllVersions();
while (iter.hasNext()) {
Version v = iter.nextVersion();
Collection row = new ArrayList();
row.add(v.getName());
row.add(Arrays.asList(n.getVersionHistory().getVersionLabels(v)));
PrintHelper.printRow(ctx, width, row);
}
return false;
}
Aggregations