@Test public void deleteALicense() throws UnknownHostException, AuthenticationException{ final String licenseName = "licenseId"; when(repositoryHandler.getLicense(anyString())).thenReturn(new DbLicense()); List<DbArtifact> artifacts = new ArrayList<DbArtifact>(); artifacts.add(new DbArtifact()); ArgumentCaptor<FiltersHolder> filters = ArgumentCaptor.forClass(FiltersHolder.class); when(repositoryHandler.getArtifacts(filters.capture())).thenReturn(artifacts); client().addFilter(new HTTPBasicAuthFilter(GrapesTestUtils.USER_4TEST, GrapesTestUtils.PASSWORD_4TEST)); WebResource resource = client().resource("/" + ServerAPI.LICENSE_RESOURCE + "/" + licenseName); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).delete(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.OK_200, response.getStatus()); ArgumentCaptor<String> strCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<LicenseMatcher> matcherCaptor = ArgumentCaptor.forClass(LicenseMatcher.class); verify(repositoryHandler, times(1)).removeLicenseFromArtifact( (DbArtifact)any(), strCaptor.capture(), matcherCaptor.capture()); assertEquals(licenseName, strCaptor.getValue()); }
@DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") public Response delete(@Auth final DbCredential credential, @PathParam("name") final String name){ if(!credential.getRoles().contains(AvailableRoles.DATA_DELETER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a delete license request."); getLicenseHandler().deleteLicense(name); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok("done").build(); }
LicenseResource extends AbstractResource { @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") public Response delete(@Auth final DbCredential credential, @PathParam("name") final String name){ if(!credential.getRoles().contains(AvailableRoles.DATA_DELETER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a delete license request."); getLicenseHandler().deleteLicense(name); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok("done").build(); } }
LicenseResource extends AbstractResource { @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") public Response delete(@Auth final DbCredential credential, @PathParam("name") final String name){ if(!credential.getRoles().contains(AvailableRoles.DATA_DELETER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a delete license request."); getLicenseHandler().deleteLicense(name); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok("done").build(); } LicenseResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); }
LicenseResource extends AbstractResource { @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") public Response delete(@Auth final DbCredential credential, @PathParam("name") final String name){ if(!credential.getRoles().contains(AvailableRoles.DATA_DELETER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a delete license request."); getLicenseHandler().deleteLicense(name); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok("done").build(); } LicenseResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); @POST Response postLicense(@Auth final DbCredential credential, final License license); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_NAMES) Response getNames(@Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response get(@PathParam("name") final String name); @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response delete(@Auth final DbCredential credential, @PathParam("name") final String name); @POST @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response approve(@Auth final DbCredential credential, @PathParam("name") final String name, @QueryParam(ServerAPI.APPROVED_PARAM) final BooleanParam approved); }
LicenseResource extends AbstractResource { @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") public Response delete(@Auth final DbCredential credential, @PathParam("name") final String name){ if(!credential.getRoles().contains(AvailableRoles.DATA_DELETER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a delete license request."); getLicenseHandler().deleteLicense(name); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok("done").build(); } LicenseResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); @POST Response postLicense(@Auth final DbCredential credential, final License license); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_NAMES) Response getNames(@Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response get(@PathParam("name") final String name); @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response delete(@Auth final DbCredential credential, @PathParam("name") final String name); @POST @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response approve(@Auth final DbCredential credential, @PathParam("name") final String name, @QueryParam(ServerAPI.APPROVED_PARAM) final BooleanParam approved);  }