GrapesClient { public List<String> getAllProductNames() throws GrapesCommunicationException{ final Client client = getClient(); final WebResource resource = client.resource(serverURL).path(RequestUtils.getProductNames()); final ClientResponse response = resource .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); client.destroy(); if(ClientResponse.Status.OK.getStatusCode() != response.getStatus()){ final String message = "Failed to get product names"; if(LOG.isErrorEnabled()) { LOG.error(String.format(HTTP_STATUS_TEMPLATE_MSG, message, response.getStatus())); } throw new GrapesCommunicationException(message, response.getStatus()); } return response.getEntity(new GenericType<List<String>>(){}); } GrapesClient(final String host, final String port); void setTimeout(final Integer timeout); String getServerURL(); boolean isServerAvailable(); void postBuildInfo(final String moduleName, final String moduleVersion, final Map<String, String> buildInfo, final String user, final String password); Map<String, String> getBuildInfo(final String moduleName, final String moduleVersion); void postModule(final Module module, final String user, final String password); void deleteModule(final String name, final String version, final String user, final String password); Module getModule(final String name, final String version); List<Module> getModules(final Map<String, String> filters); List<String> getModuleVersions(final String name); Boolean getModulePromotionStatus(final String name, final String version); void promoteModule(final String name, final String version, final String user, final String password); Boolean moduleCanBePromoted(final String name, final String version); T getModulePromotionReportRaw(final String name,
                                             final String version,
                                             final boolean excludeSnapshotValidation,
                                             final Class<T> entityClass); PromotionEvaluationReport getModulePromotionReport(final String name, final String version); void postArtifact(final Artifact artifact, final String user, final String password); void deleteArtifact(final String gavc, final String user, final String password); Artifact getArtifact(final String gavc); List<Artifact> getArtifacts(final Boolean hasLicense); void postDoNotUseArtifact(final String gavc, final Boolean doNotUse, final String user, final String password); Boolean isMarkedAsDoNotUse(final String gavc); List<String> getArtifactVersions(final String gavc); String getArtifactLastVersion(final String gavc); Module getArtifactModule(final String gavc); void addLicense(final String gavc, final String licenseId, final String user, final String password); void postLicense(final License license, final String user, final String password); void deleteLicense(final String licenseId, final String user, final String password); License getLicense(final String licenseId); void approveLicense(final String licenseId, final Boolean approve, final String user, final String password); List<Dependency> getModuleAncestors(final String moduleName, final String moduleVersion); List<Dependency> getModuleDependencies(final String moduleName, final String moduleVersion, final Boolean fullRecursive, final Boolean corporate, final Boolean thirdParty); Organization getModuleOrganization(final String moduleName, final String moduleVersion); List<String> getProductModuleNames(final String projectId); List<String> getAllProductNames(); Delivery getProductDelivery(final String productLogicalName, final String commercialName, final String commercialVersion); List<Delivery> getProductDeliveries(final String productLogicalName); void createProductDelivery(final String productLogicalName, final Delivery delivery, final String user, final String password); static final String FAILED_TO_GET_CORPORATE_FILTERS; static final String FAILED_TO_GET_MODULE; }
@Test public void getProductListTest() throws IOException { final List<String> productDummyList = new ArrayList<String>(); productDummyList.add("product1"); productDummyList.add("product2"); stubFor(get(urlMatching("/" + RequestUtils.getProductNames())) .willReturn(aResponse().withStatus(Status.OK.getStatusCode()) .withBody(JsonUtils.serialize(productDummyList)) .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))); List<String> productNameList = null; Exception exception = null; try { productNameList = client.getAllProductNames(); } catch (Exception e) { exception = e; } assertNull(exception); assertNotNull(productNameList); assertEquals(2, productNameList.size()); }