GerritProvider extends DefaultProvider { @Override public void updateStatus(String url, PluginSettings pluginSettings, String branch, String revision, String pipelineInstance, String result, String trackbackURL) throws Exception { GerritPluginSettings settings = (GerritPluginSettings) pluginSettings; String endPointToUse = settings.getEndPoint(); String usernameToUse = settings.getUsername(); String passwordToUse = settings.getPassword(); String codeReviewLabel = settings.getReviewLabel(); if (StringUtils.isEmpty(endPointToUse)) { endPointToUse = System.getProperty("go.plugin.build.status.gerrit.endpoint"); } if (StringUtils.isEmpty(usernameToUse)) { usernameToUse = System.getProperty("go.plugin.build.status.gerrit.username"); } if (StringUtils.isEmpty(passwordToUse)) { passwordToUse = System.getProperty("go.plugin.build.status.gerrit.password"); } if (StringUtils.isEmpty(codeReviewLabel)) { codeReviewLabel = System.getProperty("go.plugin.build.status.gerrit.codeReviewLabel"); } String commitDetailsURL = String.format("%s/a/changes/?q=commit:%s", endPointToUse, revision); String commitDetailsResponse = httpClient.getRequest(commitDetailsURL, AuthenticationType.DIGEST, usernameToUse, passwordToUse); CommitDetails commitDetails = new ResponseParser().parseCommitDetails(commitDetailsResponse); Map<String, Object> request = new HashMap<String, Object>(); request.put("message", String.format("%s: %s", pipelineInstance, trackbackURL)); Map<String, Object> labels = new HashMap<String, Object>(); request.put("labels", labels); labels.put(codeReviewLabel, getCodeReviewValue(result)); String updateStatusURL = String.format("%s/a/changes/%s/revisions/%s/review", endPointToUse, commitDetails.getId(), revision); httpClient.postRequest(updateStatusURL, AuthenticationType.DIGEST, usernameToUse, passwordToUse, JSONUtils.toJSON(request)); } GerritProvider();  GerritProvider(HTTPClient httpClient); @Override String pluginId(); @Override String pollerPluginId(); @Override void updateStatus(String url, PluginSettings pluginSettings, String branch, String revision, String pipelineInstance,
                             String result, String trackbackURL); @Override List<Map<String, Object>> validateConfig(Map<String, Object> fields); @Override PluginSettings pluginSettings(Map<String, String> responseBodyMap); int getCodeReviewValue(String result); static final String PLUGIN_ID; static final String GERRIT_CS_POLLER_PLUGIN_ID; static final int IN_PROGRESS_VALUE; static final int SUCCESS_VALUE; static final int FAILURE_VALUE; }
@Test public void shouldUpdateStatus() throws Exception { when(mockHttpClient.getRequest( eq("http: any(AuthenticationType.class), eq(USERNAME), eq(PASSWORD)) ).thenReturn(COMMIT_DETAILS_RESPONSE); provider.updateStatus(null, pluginSettings, null, "64bdf589adda32a0652f8b3335b15bb8f53fe2cf", "pipeline-name/stage-name", "Passed", "https: verify(mockHttpClient).postRequest( "http: AuthenticationType.DIGEST, USERNAME, PASSWORD, "{" + "\"message\":\"pipeline-name/stage-name: https: "\"labels\":{\"Verified\":1}" + "}" ); }