@Test
public void checkUserPermissions() throws Exception {

    SecurityCatalogService catalogService = new SecurityCatalogService(null);
    AclEntry userAclEntry = new AclEntry();
    userAclEntry.setSidType(AclEntry.SidType.USER);
    userAclEntry.setSidId(1L);
    userAclEntry.setObjectId(1L);
    userAclEntry.setObjectNamespace("topology");
    userAclEntry.setPermissions(EnumSet.of(Permission.WRITE));
    AclEntry roleAclEntry = new AclEntry();
    roleAclEntry.setSidType(AclEntry.SidType.ROLE);
    roleAclEntry.setSidId(1L);
    roleAclEntry.setObjectId(1L);
    roleAclEntry.setObjectNamespace("topology");
    roleAclEntry.setPermissions(EnumSet.of(Permission.READ));
    Role role = new Role();
    role.setId(1L);
    role.setName("ROLE_FOO");
    List<QueryParam> qps1 = QueryParam.params(
            AclEntry.OBJECT_NAMESPACE, "topology",
            AclEntry.OBJECT_ID, "1",
            AclEntry.SID_TYPE, USER.toString(),
            AclEntry.SID_ID, "1");
    List<QueryParam> qps2 = QueryParam.params(
            AclEntry.OBJECT_NAMESPACE, "topology",
            AclEntry.OBJECT_ID, "1",
            AclEntry.SID_TYPE, AclEntry.SidType.ROLE.toString());
    User user = new User();
    user.setRoles(Sets.newHashSet("ROLE_FOO"));
    new Expectations(catalogService) {{
        catalogService.getUser(anyLong);
        result = user;
        catalogService.listAcls(qps1);
        result = Arrays.asList(userAclEntry);
        catalogService.getAllUserRoles(user);
        result = Sets.newHashSet(role);
        catalogService.listAcls(qps2);
        result = Arrays.asList(roleAclEntry);
        catalogService.getRole(1L);
        result = role;
    }};
    assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.READ)));
    assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE)));
    assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE, Permission.READ)));
    assertFalse(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE, Permission.DELETE)));
}