GrapesClient { public void promoteModule(final String name, final String version, final String user, final String password) throws GrapesCommunicationException, AuthenticationException{ final Client client = getClient(user, password); final WebResource resource = client.resource(serverURL).path(RequestUtils.promoteModulePath(name, version)); final ClientResponse response = resource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class); client.destroy(); if(ClientResponse.Status.OK.getStatusCode() != response.getStatus()){ final String message = String.format(FAILED_TO_GET_MODULE, "promote module", name, version); if(LOG.isErrorEnabled()) { LOG.error(String.format(HTTP_STATUS_TEMPLATE_MSG, message, response.getStatus())); } throw new GrapesCommunicationException(message, response.getStatus()); } } 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 promoteModule(){ String moduleName = "module"; String moduleVersion = "1.0.0-SNAPSHOT"; stubFor(post(urlEqualTo("/" + ServerAPI.MODULE_RESOURCE + "/" + moduleName + "/" + moduleVersion + ServerAPI.PROMOTION)) .willReturn(aResponse() .withStatus(Status.OK.getStatusCode()))); Exception exception = null; try{ client.promoteModule(moduleName, moduleVersion, "user", "password"); }catch (Exception e) { exception = e; } assertNull(exception); }
@Test public void promoteModuleNotFound(){ String moduleName = "module"; String moduleVersion = "1.0.0-SNAPSHOT"; stubFor(post(urlEqualTo("/" + ServerAPI.MODULE_RESOURCE + "/" + moduleName + "/" + moduleVersion + ServerAPI.PROMOTION)) .willReturn(aResponse() .withStatus(Status.NOT_FOUND.getStatusCode()))); Exception exception = null; try{ client.promoteModule(moduleName, moduleVersion, "user", "password"); }catch (Exception e) { exception = e; } assertNotNull(exception); }