use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class RestoreTest method testRestoreWithInvalidVersion.
/**
* Test if restoring a node with an invalid Version throws a VersionException
*
* @throws RepositoryException
*/
@SuppressWarnings("deprecation")
public void testRestoreWithInvalidVersion() throws RepositoryException {
Version invalidVersion = versionableNode2.checkin();
try {
versionableNode.restore(invalidVersion, true);
fail("Node.restore(Version, boolean): A VersionException must be thrown if the specified version does not exists in this node's version history.");
} catch (VersionException e) {
// success
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class SetValueVersionExceptionTest method testInputStream.
/**
* Tests if setValue(InputStream) throws a VersionException immediately
* or on save if the parent node of this property is checked-in.
*/
public void testInputStream() throws RepositoryException {
try {
byte[] bytes = { 123 };
InputStream value = new ByteArrayInputStream(bytes);
property.setValue(value);
node.save();
fail("Property.setValue(InputStream) must throw a VersionException " + "immediately or on save if the parent node of this property " + "is checked-in.");
} catch (VersionException e) {
// success
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class RetentionPolicyTest method testRemoveRetentionPolicyOnCheckedInNode.
public void testRemoveRetentionPolicyOnCheckedInNode() throws NotExecutableException, RepositoryException {
Node child = getVersionableChildNode();
child.checkout();
retentionMgr.setRetentionPolicy(child.getPath(), getApplicableRetentionPolicy());
superuser.save();
child.checkin();
Session otherS = getHelper().getSuperuserSession();
try {
RetentionManager rmgr = getRetentionManager(otherS);
rmgr.removeRetentionPolicy(child.getPath());
otherS.save();
fail("Removing a retention policy on a checked-in node must throw VersionException.");
} catch (VersionException e) {
// success
} finally {
otherS.logout();
// clear policy added before
child.checkout();
try {
retentionMgr.removeRetentionPolicy(child.getPath());
superuser.save();
} catch (RepositoryException e) {
// should not get here if test is correctly executed.
}
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class SaveTest method testVersionException.
/**
* Tests if a {@link javax.jcr.version.VersionException} is thrown when a
* query is stored under a checked in node.
* <p>
* The tests creates a node under <code>testRoot</code> with name
* <code>nodeName1</code> and adds a mix:versionable mixin if the node is
* not already versionable.
* Then the test tries to store a query as <code>nodeName2</code> under node
* <code>nodeName1</code>.
* @throws NotExecutableException if nt:query is not supported.
*/
public void testVersionException() throws RepositoryException, NotExecutableException {
checkNtQuery();
// check if repository supports versioning
if (!isSupported(Repository.OPTION_VERSIONING_SUPPORTED)) {
throw new NotExecutableException();
}
Query query = superuser.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
// create a node that is versionable
Node versionable = testRootNode.addNode(nodeName1, testNodeType);
// or try to make it versionable if it is not
ensureMixinType(versionable, mixVersionable);
testRootNode.getSession().save();
versionable.checkin();
try {
query.storeAsNode(testRoot + "/" + nodeName1 + "/" + nodeName2);
fail("Query.storeAsNode() must throw VersionException, parent node is checked in.");
} catch (VersionException e) {
// expected behaviour
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class VersionHistoryImpl method getVersionByLabel.
/**
*
* @param qLabel
* @return
* @throws VersionException
* @throws RepositoryException
*/
private Version getVersionByLabel(Name qLabel) throws VersionException, RepositoryException {
refreshEntry(labelNodeEntry);
// retrieve reference property value -> and retrieve referenced node
PropertyEntry pEntry = labelNodeEntry.getPropertyEntry(qLabel, true);
if (pEntry == null) {
throw new VersionException("Version with label '" + qLabel + "' does not exist.");
}
Node version = ((Property) getItemManager().getItem(pEntry)).getNode();
return (Version) version;
}
Aggregations