* @throws Exception if an error occurs when running the test.
*/
public void testIsGranted() throws Exception
{
// build the tested ACL.
ACL acl = new ACLImpl(new TestResource(10), Arrays.asList(this.entries));
assertEquals("Invalid number of entries", ACL_SIZE, acl.getEntries().size());
// test the identity associated with a basic permission.
assertTrue(acl.isGranted(BasicACLPermission.READ, this.identities[0]));
assertFalse(acl.isGranted(BasicACLPermission.DELETE, this.identities[0]));
assertFalse(acl.isGranted(new CompositeACLPermission(BasicACLPermission.CREATE, BasicACLPermission.UPDATE),
this.identities[0]));
// assert the empty permission is always granted.
ACLPermission emptyPermission = new CompositeACLPermission();
for (int i = 0; i < ACL_SIZE; i++)
assertTrue(acl.isGranted(emptyPermission, this.identities[i]));
// assert that identities[1] is only granted the empty permission.
for (BasicACLPermission permission : BasicACLPermission.values())
assertFalse(acl.isGranted(permission, this.identities[1]));
assertFalse(acl.isGranted(new CompositeACLPermission(BasicACLPermission.values()), this.identities[1]));
// test the identities associated to composite permissions.
assertTrue(acl.isGranted(BasicACLPermission.READ, this.identities[2]));
assertFalse(acl.isGranted(new CompositeACLPermission(BasicACLPermission.READ, BasicACLPermission.UPDATE),
this.identities[2]));
assertFalse(acl.isGranted(BasicACLPermission.CREATE, this.identities[2]));
assertFalse(acl.isGranted(new CompositeACLPermission(BasicACLPermission.UPDATE, BasicACLPermission.DELETE),
this.identities[2]));
assertTrue(acl.isGranted(BasicACLPermission.CREATE, this.identities[3]));
assertTrue(acl.isGranted(BasicACLPermission.UPDATE, this.identities[3]));
assertTrue(acl.isGranted(new CompositeACLPermission(BasicACLPermission.CREATE, BasicACLPermission.DELETE),
this.identities[3]));
assertFalse(acl.isGranted(BasicACLPermission.READ, this.identities[3]));
assertFalse(acl.isGranted(new CompositeACLPermission(BasicACLPermission.READ, BasicACLPermission.UPDATE),
this.identities[3]));
for (BasicACLPermission permission : BasicACLPermission.values())
assertTrue(acl.isGranted(permission, this.identities[4]));
assertTrue(acl.isGranted(new CompositeACLPermission(BasicACLPermission.READ), this.identities[4]));
assertTrue(acl.isGranted(new CompositeACLPermission(BasicACLPermission.CREATE, BasicACLPermission.DELETE),
this.identities[4]));
assertTrue(acl.isGranted(new CompositeACLPermission(BasicACLPermission.CREATE, BasicACLPermission.UPDATE,
BasicACLPermission.DELETE), this.identities[4]));
assertTrue(acl.isGranted(new CompositeACLPermission(BasicACLPermission.values()), this.identities[4]));
}