use of javax.jcr.Session in project jackrabbit by apache.
the class RemoveVersionTest method testRemoveVersionAndCheckinXA.
/**
* Removes a version in 1 transaction and tries to commit afterwards the
* versionable node using a 2nd transaction.
*
* Tests error reported in JCR-2613
*
* @throws Exception if an error occurs
*/
public void testRemoveVersionAndCheckinXA() throws Exception {
UserTransaction tx = new UserTransactionImpl(superuser);
tx.begin();
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
n.addMixin(mixReferenceable);
testRootNode.save();
String uuid = n.getUUID();
// create two versions
String v1 = n.checkin().getName();
n.checkout();
n.checkin();
n.checkout();
tx.commit();
tx = new UserTransactionImpl(superuser);
tx.begin();
// remove one version
n = superuser.getNodeByUUID(uuid);
n.getVersionHistory().removeVersion(v1);
n.save();
tx.commit();
// new session
Session session = getHelper().getSuperuserSession();
tx = new UserTransactionImpl(session);
tx.begin();
n = session.getNodeByUUID(uuid);
n.checkin();
tx.commit();
}
use of javax.jcr.Session in project jackrabbit by apache.
the class HasPermissionTest method testReadOnlyPermission.
/**
* Tests if <code>Session.hasPermission(String, String)</code> returns
* <ul>
* <li><code>true</code> for READ.</li>
* <li><code>false</code> for all other actions.</li>
* </ul>
*/
public void testReadOnlyPermission() throws Exception {
Node n = testRootNode.addNode(nodeName2, testNodeType);
superuser.save();
Session readOnly = getHelper().getReadOnlySession();
try {
String path = n.getPath();
assertTrue(readOnly.hasPermission(path, Session.ACTION_READ));
assertFalse(readOnly.hasPermission(path + "newNode", Session.ACTION_ADD_NODE));
assertFalse(readOnly.hasPermission(path, Session.ACTION_REMOVE));
assertFalse(readOnly.hasPermission(path, Session.ACTION_SET_PROPERTY));
assertFalse(readOnly.hasPermission(path, ACTION_ALL));
assertFalse(readOnly.hasPermission(path, Session.ACTION_REMOVE + "," + Session.ACTION_SET_PROPERTY));
} finally {
readOnly.logout();
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class CheckPermissionTest method testCheckPermission.
/**
* Tests if <code>Session.checkPermission(String, String)</code> works
* properly: <ul> <li>Returns quietly if access is permitted.</li>
* <li>Throws an {@link java.security.AccessControlException} if access is
* denied.</li> </ul>
*/
public void testCheckPermission() throws Exception {
testRootNode.addNode(nodeName2, testNodeType);
superuser.save();
Session readOnly = getHelper().getReadOnlySession();
try {
permissionCheckReadOnly(readOnly);
permissionCheckReadWrite(superuser);
} finally {
readOnly.logout();
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class HasPermissionTest method testReadWritePermission.
/**
* Tests if <code>Session.hasPermission(String, String)</code> returns
* <ul>
* <li><code>true</code> for all actions.</li>
* </ul>
*/
public void testReadWritePermission() throws Exception {
Node n = testRootNode.addNode(nodeName2, testNodeType);
superuser.save();
String path = n.getPath();
Session rwSession = getHelper().getReadWriteSession();
try {
assertTrue(rwSession.hasPermission(path, Session.ACTION_READ));
assertTrue(rwSession.hasPermission(path + "newNode", Session.ACTION_ADD_NODE));
assertTrue(rwSession.hasPermission(path, Session.ACTION_REMOVE));
assertTrue(rwSession.hasPermission(path, Session.ACTION_SET_PROPERTY));
assertTrue(rwSession.hasPermission(path, ACTION_ALL));
} finally {
rwSession.logout();
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class NodeAddMixinTest method testAddSuccessfully.
/**
* Tests if <code>Node.addMixin(String mixinName)</code> adds the requested
* mixin and stores it in property <code>jcr:mixinTypes</code>
*/
public void testAddSuccessfully() throws NotExecutableException, RepositoryException {
Session session = testRootNode.getSession();
Node node = testRootNode.addNode(nodeName1, testNodeType);
String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
if (mixinName == null) {
throw new NotExecutableException("No testable mixin node type found");
}
node.addMixin(mixinName);
// test if mixin is written to property jcr:mixinTypes immediately
Value[] mixinValues = node.getProperty(jcrMixinTypes).getValues();
boolean found = false;
for (int i = 0; i < mixinValues.length; i++) {
found |= mixinName.equals(mixinValues[i].getString());
}
if (!found) {
fail("Mixin type must be added to property " + jcrMixinTypes + " immediately.");
}
// it is implementation-specific if a added mixin is available
// before or after save therefore save before further tests
testRootNode.getSession().save();
// test if added mixin is available by node.getMixinNodeTypes()
NodeType[] mixins = node.getMixinNodeTypes();
found = false;
for (int i = 0; i < mixins.length; i++) {
found |= mixinName.equals(mixins[i].getName());
}
if (!found) {
fail("Mixin '" + mixinName + "' type not added.");
}
}
Aggregations