PrivilegeApiResource extends PrivilegeApiResourceSupport implements Resource, PrivilegeApiResourceDoc { @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:privileges:create") @Path("application") public Response createPrivilege(final ApiPrivilegeApplicationRequest privilege) { return doCreate(ApplicationPrivilegeDescriptor.TYPE, privilege); } @Inject  PrivilegeApiResource(final SecuritySystem securitySystem,
                              final Map<String, PrivilegeDescriptor> privilegeDescriptors); @Override @GET @RequiresAuthentication @RequiresPermissions("nexus:privileges:read") List<ApiPrivilege> getPrivileges(); @Override @GET @RequiresAuthentication @RequiresPermissions("nexus:privileges:read") @Path("{privilegeId}") ApiPrivilege getPrivilege(@PathParam("privilegeId") final String privilegeId); @Override @DELETE @RequiresAuthentication @RequiresPermissions("nexus:privileges:delete") @Path("{privilegeId}") void deletePrivilege(@PathParam("privilegeId") final String privilegeId); @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:privileges:create") @Path("application") Response createPrivilege(final ApiPrivilegeApplicationRequest privilege); @Override @PUT @RequiresAuthentication @RequiresPermissions("nexus:privileges:update") @Path("application/{privilegeId}") void updatePrivilege(@PathParam("privilegeId") final String privilegeId,
                              final ApiPrivilegeApplicationRequest privilege); @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:privileges:create") @Path("wildcard") Response createPrivilege(final ApiPrivilegeWildcardRequest privilege); @Override @PUT @RequiresAuthentication @RequiresPermissions("nexus:privileges:update") @Path("wildcard/{privilegeId}") void updatePrivilege(@PathParam("privilegeId") final String privilegeId,
                              final ApiPrivilegeWildcardRequest privilege);  }
@Test public void testCreatePrivilege_alreadyExists() { when(authorizationManager.addPrivilege(any())).thenThrow(new DuplicatePrivilegeException("name")); ApiPrivilegeWildcardRequest apiPrivilege = new ApiPrivilegeWildcardRequest("name", "description", "pattern"); try { underTest.createPrivilege(apiPrivilege); fail("create should have failed as privilege exists."); } catch (WebApplicationMessageException e) { assertThat(e.getResponse().getStatus(), is(400)); assertThat(e.getResponse().getMediaType(), is(MediaType.APPLICATION_JSON_TYPE)); assertThat(e.getResponse().getEntity().toString(), is("\"Privilege 'name' already exists, use a unique name.\"")); } }