ModuleResource extends AbstractResource { @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.GET_LICENSES) public Response getLicenses(@PathParam("name") final String name, @PathParam("version") final String version) { if (LOG.isInfoEnabled()) { LOG.info(String.format("Got a get module licenses request [%s %s]", name, version)); } if (name == null || version == null) { return Response.serverError().status(HttpStatus.BAD_REQUEST_400).build(); } final LicenseListView view = new LicenseListView(String.format("Licenses of %s in version %s", name, version)); final String moduleId = DbModule.generateID(name, version); final List<DbLicense> dbLicenses = getModuleHandler().getModuleLicenses(moduleId, getLicenseHandler()); for (final DbLicense dbLicense : dbLicenses) { final License license = getModelMapper().getLicense(dbLicense); view.add(license); } return Response.ok(view).build(); } ModuleResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); @POST @Produces(MediaType.TEXT_HTML) Response postModule(@Auth final DbCredential credential, final Module module); @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 getVersionsRedirection(@PathParam("name") final String name, @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}" + ServerAPI.GET_VERSIONS) Response getVersions(@PathParam("name") final String name, @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}") Response get(@PathParam("name") final String name, @PathParam("version") final String version); @DELETE @Path("/{name}/{version}") Response delete(@Auth final DbCredential credential, @PathParam("name") final String name, @PathParam("version") final String version); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.GET_ORGANIZATION) Response getOrganization(@PathParam("name") final String name, @PathParam("version") final String version); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.GET_ANCESTORS) Response getAncestors(@PathParam("name") final String name,
                                 @PathParam("version") final String version,
                                 @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.GET_DEPENDENCIES) Response getDependencies(@PathParam("name") final String name,
                                    @PathParam("version") final String version,
                                    @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.GET_DEPENDENCIES + ServerAPI.GET_REPORT) Response getDependencyReport(@PathParam("name") final String name,
                                        @PathParam("version") final String version,
                                        @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.GET_LICENSES) Response getLicenses(@PathParam("name") final String name, @PathParam("version") final String version); @POST @Path("/{name}/{version}" + ServerAPI.PROMOTION) Response promote(@Auth final DbCredential credential, @PathParam("name") final String name, @PathParam("version") final String version); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{name}/{version}" + ServerAPI.PROMOTION + ServerAPI.GET_FEASIBLE) Response canBePromoted(@PathParam("name") final String name, @PathParam("version") final String version); @GET @Produces({MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.PROMOTION + ServerAPI.GET_REPORT) Response getPromotionStatusReport(@PathParam("name") final String name,
                                             @PathParam("version") final String version,
                                             @QueryParam(ServerAPI.EXCLUDE_SNAPSHOT_PARAM) boolean excludeSnapshot); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{name}/{version}" + ServerAPI.PROMOTION) Response isPromoted(@PathParam("name") final String name, @PathParam("version") final String version); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{name}/{version}" + ServerAPI.GET_BUILD_INFO) Response getBuildInfo(@PathParam("name") final String name, @PathParam("version") final String version); @POST @Path("/{name}/{version}" + ServerAPI.GET_BUILD_INFO) Response updateBuildInfo(@PathParam("name") final String name, @PathParam("version") final String version, final Map<String, String> buildInfo); @GET @Produces(MediaType.APPLICATION_JSON) @Path(ServerAPI.GET_ALL) Response getAllModules(@Context final UriInfo uriInfo);  }
@Test public void getLicenses() { final DbModule dbModule = new DbModule(); dbModule.setName("moduleTest"); dbModule.setVersion("1.0.0"); final DbArtifact dbArtifact = new DbArtifact(); dbArtifact.setGroupId(GrapesTestUtils.CORPORATE_GROUPID_4TEST); dbArtifact.setArtifactId("artifact1"); dbArtifact.setVersion("1.2.3"); final DbLicense dbLicense = new DbLicense(); dbLicense.setName("license1"); dbArtifact.addLicense(dbLicense); dbModule.addArtifact(dbArtifact); when(repositoryHandler.getModule(dbModule.getId())).thenReturn(dbModule); when(repositoryHandler.getArtifact(dbArtifact.getGavc())).thenReturn(dbArtifact); when(repositoryHandler.getLicense(dbLicense.getName())).thenReturn(dbLicense); final WebResource resource = client().resource("/" + ServerAPI.MODULE_RESOURCE + "/" + dbModule.getName() + "/" + dbModule.getVersion() + ServerAPI.GET_LICENSES); final ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.OK_200, response.getStatus()); final List<License> results = response.getEntity(new GenericType<List<License>>() { }); assertNotNull(results); assertEquals(1, results.size()); assertEquals(dbLicense.getName(), results.get(0).getName()); }