@Test
public void testHasPermission() {

    Resource resource = new Resource();
    assertFalse(resource.hasPermission(guest, PermissionType.DOWNLOAD));
    assertFalse(resource.hasPermission(guest, PermissionType.EDIT_LAYER));
    resource.addPermission(getPermision(PermissionType.DOWNLOAD, guest));
    resource.addPermission(getPermision(PermissionType.DOWNLOAD, admin));
    assertTrue(resource.hasPermission(guest, PermissionType.DOWNLOAD));
    assertFalse(resource.hasPermission(guest, PermissionType.EDIT_LAYER));
    resource.removePermissionsOfType(PermissionType.DOWNLOAD, PermissionExternalType.ROLE, (int) guest.getId());
    assertFalse(resource.hasPermission(guest, PermissionType.DOWNLOAD));
    assertFalse(resource.hasPermission(guest, PermissionType.EDIT_LAYER));
    resource.addPermission(getPermision(PermissionType.EDIT_LAYER, guest));
    assertFalse(resource.hasPermission(guest, PermissionType.DOWNLOAD));
    assertTrue(resource.hasPermission(guest, PermissionType.EDIT_LAYER));
    User user = new User();
    user.setId(1);
    assertFalse(resource.hasPermission(user, PermissionType.EDIT_LAYER));
    assertFalse(resource.hasPermission(user, PermissionType.DOWNLOAD));
    user.addRole(guest);
    assertFalse(resource.hasPermission(user, PermissionType.DOWNLOAD));
    assertTrue(resource.hasPermission(user, PermissionType.EDIT_LAYER));
    user.clearRoles();
    assertFalse(resource.hasPermission(user, PermissionType.DOWNLOAD));
    assertFalse(resource.hasPermission(user, PermissionType.EDIT_LAYER));
    user.addRole(admin);
    assertTrue(resource.hasPermission(user, PermissionType.DOWNLOAD));
    assertTrue(resource.hasPermission(user, PermissionType.EDIT_LAYER));
}