}
@Test
public void checkResourceAccessRights() throws Exception {
Realm realm = getDefaultRealm();
Policy policy = createPolicy(realm);
User user = createAccount();
getPolicyService().grantPolicyToPrincipal(policy, user);
AccessRights accessRights = createAssignAccessRights(getResourceType().getPermissionClass());
PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()});
PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo());
PropertyProfile resource = createResource();
assertTrue("Should be, as one already exists.", getPolicyService().isPrincipalGrantedResourcesOfType(user, resource.getResourceType(), null));
assertEquals("Should be only one.", getPolicyService().getGrantedResourcesOfType(user, getResourceType()).size(), 1);
PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(resource, selectedPolicies, getSessionInfo());
assertEquals("Should be two.", getPolicyService().getGrantedResourcesOfType(user, getResourceType()).size(), 2);
PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(resource, getSessionInfo());
assertEquals("Should be only one.", getPolicyService().getGrantedResourcesOfType(user, getResourceType()).size(), 1);
getPolicyService().revokePolicyFromPrincipal(policy, user);
deleteAccount(user);
PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo());
deleteResource(resource);
getPolicyService().deleteAccessRights(accessRights.getResourceId());
getPolicyService().deletePolicy(policy.getResourceId());
}