@Test
  public void testChangeTarget() throws Exception {
    RepositoryTargetResource target = new RepositoryTargetResource();
    target.setContentClass("maven2");
    target.setName("nexus3257-target");
    target.addPattern("/some-pattern");

    target = targetUtil.createTarget(target);

    // now add some privs
    PrivilegeResource privReq = new PrivilegeResource();
    privReq.setDescription("nexus3257-target repo-target privilege");
    privReq.setMethod(Arrays.asList("create", "read", "update", "delete"));
    privReq.setName("nexus-3257-priv");
    privReq.setRepositoryTargetId(target.getId());
    privReq.setType(TargetPrivilegeDescriptor.TYPE);

    List<PrivilegeStatusResource> privs = privUtil.createPrivileges(privReq);

    // now make sure the privs exist
    checkPrivs(privs);

    // now lets change the target and add a new path
    target.addPattern("/other-pattern");
    targetUtil.saveTarget(target, true);

    // now make sure the privs still exist
    checkPrivs(privs);
  }
  @Test
  @Category(SECURITY.class)
  public void deletePriv() throws Exception {
    RoleResource role = roleUtil.getRole(ROLE_ID);
    Assert.assertNotNull(role);
    MatcherAssert.assertThat(role.getPrivileges(), hasItems(PRIVS));
    privUtil.assertExists(PRIVS);

    // remove read
    Assert.assertTrue(privUtil.delete(READ_PRIV_ID).getStatus().isSuccess());
    role = roleUtil.getRole(ROLE_ID);
    MatcherAssert.assertThat(role.getPrivileges(), not(hasItems(READ_PRIV_ID)));
    MatcherAssert.assertThat(
        role.getPrivileges(), hasItems(CREATE_PRIV_ID, UPDATE_PRIV_ID, DELETE_PRIV_ID));

    // remove create
    Assert.assertTrue(privUtil.delete(CREATE_PRIV_ID).getStatus().isSuccess());
    role = roleUtil.getRole(ROLE_ID);
    MatcherAssert.assertThat(role.getPrivileges(), not(hasItems(READ_PRIV_ID, CREATE_PRIV_ID)));
    MatcherAssert.assertThat(role.getPrivileges(), hasItems(UPDATE_PRIV_ID, DELETE_PRIV_ID));

    // remove update
    Assert.assertTrue(privUtil.delete(UPDATE_PRIV_ID).getStatus().isSuccess());
    role = roleUtil.getRole(ROLE_ID);
    MatcherAssert.assertThat(
        role.getPrivileges(), not(hasItems(READ_PRIV_ID, CREATE_PRIV_ID, UPDATE_PRIV_ID)));
    MatcherAssert.assertThat(role.getPrivileges(), hasItems(DELETE_PRIV_ID));

    // remove delete
    Assert.assertTrue(privUtil.delete(DELETE_PRIV_ID).getStatus().isSuccess());
    role = roleUtil.getRole(ROLE_ID);
    MatcherAssert.assertThat(
        role.getPrivileges(),
        not(hasItems(READ_PRIV_ID, CREATE_PRIV_ID, UPDATE_PRIV_ID, DELETE_PRIV_ID)));
    Assert.assertTrue(role.getPrivileges().isEmpty());

    privUtil.assertNotExists(PRIVS);
  }
 private void checkPrivs(List<PrivilegeStatusResource> privs) throws Exception {
   for (PrivilegeStatusResource priv : privs) {
     privUtil.getPrivilegeResource(priv.getId());
   }
 }