ArtifactResource extends AbstractResource { @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}") public Response get(@PathParam("gavc") final String gavc){ if(LOG.isInfoEnabled()) { LOG.info(String.format("Got a get artifact request [%s]", gavc)); } final ArtifactView view = new ArtifactView(); final DbArtifact dbArtifact = getArtifactHandler().getArtifact(gavc); view.setShouldNotBeUse(dbArtifact.getDoNotUse()); final Artifact artifact = getModelMapper().getArtifact(dbArtifact); view.setArtifact(artifact); final DbOrganization dbOrganization = getArtifactHandler().getOrganization(dbArtifact); if(dbOrganization != null){ final Organization organization = getModelMapper().getOrganization(dbOrganization); view.setOrganization(organization); } DbComment dbComment = getCommentHandler().getLatestComment(gavc, DbArtifact.class.getSimpleName()); if(dbComment != null) { final Comment comment = getModelMapper().getComment(dbComment); view.setComment(comment); } return Response.ok(view).build(); } ArtifactResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); @POST Response postArtifact(@Auth final DbCredential credential, final Artifact artifact); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_GAVCS) Response getGavcs(@Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_GROUPIDS) Response getGroupIds(@Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}" + ServerAPI.GET_VERSIONS) Response getVersions(@PathParam("gavc") final String gavc); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{gavc}" + ServerAPI.GET_LAST_VERSION) Response getLastVersion(@PathParam("gavc") final String gavc); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}") Response get(@PathParam("gavc") final String gavc); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/isPromoted") Response isPromoted(@QueryParam("user") final String user,
                               @QueryParam("stage") final int stage,
                               @QueryParam("name") final String filename,
                               @QueryParam("sha256") final String sha256,
                               @QueryParam("type") final String type,
                               @QueryParam("location") final String location); @POST @Path("/{gavc}" + ServerAPI.GET_DOWNLOAD_URL) Response updateDownloadUrl(@Auth final DbCredential credential, @PathParam("gavc") final String gavc, @QueryParam(ServerAPI.URL_PARAM) final String downLoadUrl); @POST @Path("/{gavc}" + ServerAPI.GET_PROVIDER) Response updateProvider(@Auth final DbCredential credential, @PathParam("gavc") final String gavc, @QueryParam(ServerAPI.PROVIDER_PARAM) final String provider); @DELETE @Path("/{gavc}") Response delete(@Auth final DbCredential credential, @PathParam("gavc") final String gavc); @POST @Path("/{gavc}" + ServerAPI.SET_DO_NOT_USE) Response postDoNotUse(@Auth final DbCredential credential,
                                 @PathParam("gavc") final String gavc,
                                 @QueryParam(ServerAPI.DO_NOT_USE) final BooleanParam doNotUse,
                                 final String commentText); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{gavc}" + ServerAPI.SET_DO_NOT_USE) Response getDoNotUse(@PathParam("gavc") final String gavc); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}" + ServerAPI.GET_ANCESTORS) Response getAncestors(@PathParam("gavc") final String gavc, @Context final UriInfo uriInfo); @GET @Produces({MediaType.APPLICATION_JSON}) @Path("/{gavc}" + ServerAPI.GET_LICENSES) Response getLicenses(@PathParam("gavc") final String gavc, @Context final UriInfo uriInfo); @POST @Path("/{gavc}" + ServerAPI.GET_LICENSES) Response addLicense(@Auth final DbCredential credential,
                               @PathParam("gavc") final String gavc,
                               @QueryParam(ServerAPI.LICENSE_ID_PARAM) final String licenseId); @DELETE @Path("/{gavc}" + ServerAPI.GET_LICENSES) Response deleteLicense(@Auth final DbCredential credential,
                                  @PathParam("gavc") final String gavc,
                                  @QueryParam(ServerAPI.LICENSE_ID_PARAM) final String licenseString); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}" + ServerAPI.GET_MODULE) Response getModule(@PathParam("gavc") final String gavc, @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}" + ServerAPI.GET_ORGANIZATION) Response getOrganization(@PathParam("gavc") final String gavc, @Context final UriInfo uriInfo); @GET @Produces(MediaType.APPLICATION_JSON) @Path(ServerAPI.GET_ALL) Response getAll(@Context final UriInfo uriInfo);  }
@Test public void getDocumentation(){ WebResource resource = client().resource("/" + ServerAPI.ARTIFACT_RESOURCE); ClientResponse response = resource.type(MediaType.TEXT_HTML).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.OK_200, response.getStatus()); }
@Test public void getAllArtifactsWithNoFilteringIsBadRequest() { final WebResource resource = client().resource("/" + ServerAPI.ARTIFACT_RESOURCE + ServerAPI.GET_ALL); final ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.BAD_REQUEST_400, response.getStatus()); final String entity = response.getEntity(String.class); assertTrue(entity.contains("provide at least one artifact filtering criteria")); }
@Test public void isPromotedNotValidTypeStageUpload(){ when(repositoryHandler.getArtifactUsingSHA256("6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c")).thenReturn(null); ArtifactQuery artifactQuery = new ArtifactQuery("User", 1, "File1", "6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c", "notValidType", ""); MultivaluedMap<String, String> params = makeParams(artifactQuery); WebResource resource = client().resource("/" + ServerAPI.ARTIFACT_RESOURCE + "/isPromoted"); ClientResponse response = resource.queryParams(params).type(MediaType.APPLICATION_JSON).get(ClientResponse.class); final String returnMessage = response.getEntity(String.class); assertNotNull(response); assertEquals(HttpStatus.UNPROCESSABLE_ENTITY_422, response.getStatus()); assertEquals("Validation is not supported for this type of file", returnMessage); }
@Test public void isPromotedNotValidTypeStagePublish(){ final String sha = "6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c"; when(repositoryHandler.getArtifactUsingSHA256(sha)).thenReturn(null); ArtifactQuery artifactQuery = new ArtifactQuery("User", 0, "File1", sha, "notValidType", ""); MultivaluedMap<String, String> params = makeParams(artifactQuery); WebResource resource = client().resource("/" + ServerAPI.ARTIFACT_RESOURCE + "/isPromoted"); ClientResponse response = resource.queryParams(params).type(MediaType.APPLICATION_JSON).get(ClientResponse.class); final String returnMessage = response.getEntity(String.class); assertNotNull(response); assertEquals(HttpStatus.UNPROCESSABLE_ENTITY_422, response.getStatus()); assertEquals("Validation is not supported for this type of file", returnMessage); }
@Test public void artifactNotKnownUploadTest(){ final String sha256 = "6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c"; when(repositoryHandler.getArtifactUsingSHA256(sha256)).thenReturn(null); ArtifactQuery artifactQuery = new ArtifactQuery("User", 0, "File1", sha256, "filetype1", ""); MultivaluedMap<String, String> params = makeParams(artifactQuery); Messages.init(templatePath); WebResource resource = client().resource("/" + ServerAPI.ARTIFACT_RESOURCE + "/isPromoted"); ClientResponse response = resource.queryParams(params).type(MediaType.APPLICATION_JSON).get(ClientResponse.class); final String returnMessage = response.getEntity(String.class); assertNotNull(response); assertEquals(HttpStatus.NOT_FOUND_404, response.getStatus()); assertEquals(Messages.get(MessageKey.ARTIFACT_VALIDATION_NOT_KNOWN), returnMessage); }
@Test public void artifactKnownButNotPromotedTest() { DbArtifact a = new DbArtifact(); a.setPromoted(false); a.setGroupId("com.axway.toto"); a.setSha256("6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c"); when(repositoryHandler.getArtifactUsingSHA256(a.getSha256())).thenReturn(a); ArtifactQuery artifactQuery = new ArtifactQuery("User", 1, "File1", "6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c", "filetype1", ""); MultivaluedMap<String, String> params = makeParams(artifactQuery); Messages.init(templatePath); WebResource resource = client().resource("/" + ServerAPI.ARTIFACT_RESOURCE + "/isPromoted"); ClientResponse response = resource.queryParams(params).type(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(ClientResponse.Status.OK, response.getClientResponseStatus()); String entity = response.getEntity(String.class); assertTrue(entity.contains(Messages.get(MessageKey.ARTIFACT_VALIDATION_NOT_PROMOTED_YET))); }
@Test public void getModuleThatDoesNotExist() throws UnknownHostException { final DbArtifact artifact = new DbArtifact(); artifact.setGroupId("groupId"); artifact.setArtifactId("artifactId"); artifact.setVersion("2.3.0"); when(repositoryHandler.getArtifact(artifact.getGavc())).thenReturn(artifact); when(repositoryHandler.getRootModuleOf(artifact.getGavc())).thenReturn(null); WebResource resource = client().resource("/" + ServerAPI.ARTIFACT_RESOURCE + "/" + artifact.getGavc() + ServerAPI.GET_MODULE); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.NO_CONTENT_204, response.getStatus()); }
@Test public void getOrganizationButTheModuleDoesNotHoldAny() throws UnknownHostException { final DbModule dbModule = new DbModule(); dbModule.setName("module1"); dbModule.setVersion("1.0.0"); final DbArtifact artifact = new DbArtifact(); artifact.setGroupId("groupId"); artifact.setArtifactId("artifactId"); artifact.setVersion("1.0.0"); when(repositoryHandler.getArtifact(artifact.getGavc())).thenReturn(artifact); when(repositoryHandler.getRootModuleOf(artifact.getGavc())).thenReturn(dbModule); WebResource resource = client().resource("/" + ServerAPI.ARTIFACT_RESOURCE + "/" + artifact.getGavc() + ServerAPI.GET_ORGANIZATION); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.NO_CONTENT_204, response.getStatus()); }
@Test public void getOrganizationButThereIsNoModule() throws UnknownHostException { final DbArtifact artifact = new DbArtifact(); artifact.setGroupId("groupId"); artifact.setArtifactId("artifactId"); artifact.setVersion("1.0.0"); when(repositoryHandler.getArtifact(artifact.getGavc())).thenReturn(artifact); WebResource resource = client().resource("/" + ServerAPI.ARTIFACT_RESOURCE + "/" + artifact.getGavc() + ServerAPI.GET_ORGANIZATION); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.NO_CONTENT_204, response.getStatus()); }