ArtifactResource extends AbstractResource { @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}" + ServerAPI.GET_ANCESTORS) public Response getAncestors(@PathParam("gavc") final String gavc, @Context final UriInfo uriInfo){ if(LOG.isInfoEnabled()) { LOG.info(String.format("Got a get artifact request [%s]", gavc)); } final FiltersHolder filters = new FiltersHolder(); filters.getDecorator().setShowLicenses(false); filters.init(uriInfo.getQueryParameters()); final AncestorsView view = new AncestorsView("Ancestor List Of " + gavc, filters.getDecorator(), getLicenseHandler(), getModelMapper()); final List<DbModule> dbAncestors = getArtifactHandler().getAncestors(gavc, filters); final Artifact artifact = DataUtils.createArtifact(gavc); for(final DbModule dbAncestor : dbAncestors){ final Module ancestor = getModelMapper().getModule(dbAncestor); view.addAncestor(ancestor, artifact); } 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 getAncestors() throws UnknownHostException { final List<DbModule> dependencies = new ArrayList<DbModule>(); final DbModule module = new DbModule(); module.setName("module"); module.setVersion("version"); final DbArtifact artifact = new DbArtifact(); artifact.setGroupId("groupId"); artifact.setArtifactId("artifactId"); artifact.setVersion("version"); module.addDependency(artifact.getGavc(), Scope.TEST); dependencies.add(module); when(repositoryHandler.getAncestors((DbArtifact) anyObject(), (FiltersHolder) anyObject())).thenReturn(dependencies); when(repositoryHandler.getArtifact(artifact.getGavc())).thenReturn(artifact); WebResource resource = client().resource("/" + ServerAPI.ARTIFACT_RESOURCE + "/" + artifact.getGavc() + ServerAPI.GET_ANCESTORS); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.OK_200, response.getStatus()); final List<Dependency> dependencyList = response.getEntity(new GenericType<List<Dependency>>(){}); assertNotNull(dependencyList); assertEquals(1, dependencyList.size()); assertEquals(module.getName(), dependencyList.get(0).getSourceName()); assertEquals(module.getVersion(), dependencyList.get(0).getSourceVersion()); assertEquals(artifact.getGavc(), dependencyList.get(0).getTarget().getGavc()); assertEquals(Scope.TEST, dependencyList.get(0).getScope()); }