Policy policy = createPolicy(realm);
int users = getDefaultUserDatabase().listAllUsers(UserDatabase.WILDCARD_SEARCH, Integer.MAX_VALUE).length ;
User user = createAccount();
assertEquals(getDefaultUserDatabase().listAllUsers(UserDatabase.WILDCARD_SEARCH, Integer.MAX_VALUE).length, users +1);
getPolicyService().grantPolicyToPrincipal(policy, user);
AccessRights accessRights = createEditAssignAccessRights(getResourceType().getPermissionClass());
PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()});
PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo());
Permission[] permissions = new Permission[] {PolicyConstants.PERM_EDIT_AND_ASSIGN};
assertTrue("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false));
permissions = new Permission[] {PolicyConstants.PERM_DELETE};
assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false));
permissions = new Permission[] {PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN};
assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false));
permissions = new Permission[] {PolicyConstants.PERM_ASSIGN};
assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false));
getPolicyService().revokePolicyFromPrincipal(policy, user);
deleteAccount(user);
PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo());
getPolicyService().deleteAccessRights(accessRights.getResourceId());
getPolicyService().deletePolicy(policy.getResourceId());
}