summaryrefslogtreecommitdiffstats
path: root/sonar-ws-client
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-03-11 11:04:08 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-03-11 11:04:16 +0100
commit2c87cf24627e959c2f2ebf2b0414df38fc401b2b (patch)
tree13eccf4f0aceaf6b8be6d4083ef3543d37eae1cc /sonar-ws-client
parent062003a55219febbd536fdeee866c24908b09a13 (diff)
downloadsonarqube-2c87cf24627e959c2f2ebf2b0414df38fc401b2b.tar.gz
sonarqube-2c87cf24627e959c2f2ebf2b0414df38fc401b2b.zip
SONAR-5094 Add project/quality gate association capabilities to WS client
Diffstat (limited to 'sonar-ws-client')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateClient.java4
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java20
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java32
3 files changed, 56 insertions, 0 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateClient.java
index fd499276dd2..34a8f5315cf 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateClient.java
@@ -46,4 +46,8 @@ public interface QualityGateClient {
void setDefault(long qGateId);
void unsetDefault();
+
+ void selectProject(long qGateId, long projectId);
+
+ void deselectProject(long qGateId, long projectId);
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java
index 032a3fbf5c0..26b7963dadf 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java
@@ -38,6 +38,8 @@ public class DefaultQualityGateClient implements QualityGateClient {
private static final String DESTROY_URL = ROOT_URL + "/destroy";
private static final String SET_DEFAULT_URL = ROOT_URL + "/set_as_default";
private static final String UNSET_DEFAULT_URL = ROOT_URL + "/unset_default";
+ private static final String SELECT_URL = ROOT_URL + "/select";
+ private static final String DESELECT_URL = ROOT_URL + "/deselect";
private final HttpRequestFactory requestFactory;
@@ -110,6 +112,24 @@ public class DefaultQualityGateClient implements QualityGateClient {
requestFactory.post(UNSET_DEFAULT_URL, Collections.<String, Object> emptyMap());
}
+ @Override
+ public void selectProject(long qGateId, long projectId) {
+ requestFactory.post(SELECT_URL, selectionParams(qGateId, projectId));
+ }
+
+ @Override
+ public void deselectProject(long qGateId, long projectId) {
+ requestFactory.post(DESELECT_URL, selectionParams(qGateId, projectId));
+ }
+
+ private Map<String, Object> selectionParams(long qGateId, long projectId) {
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("gateId", Long.toString(qGateId));
+ params.put("projectId", Long.toString(projectId));
+ return params;
+ }
+
+
@SuppressWarnings({"rawtypes", "unchecked"})
private QualityGate jsonToQualityGate(String json) {
Map jsonRoot = (Map) JSONValue.parse(json);
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java
index f5f7595976b..3a3dd9d55f3 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java
@@ -288,4 +288,36 @@ public class DefaultQualityGateClientTest {
entry("id", "666")
);
}
+
+ @Test
+ public void should_select_project() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
+
+ httpServer.stubStatusCode(HttpURLConnection.HTTP_NO_CONTENT);
+
+ QualityGateClient client = new DefaultQualityGateClient(requestFactory);
+ client.selectProject(666L, 999L);
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/qualitygates/select");
+ assertThat(httpServer.requestParams()).includes(
+ entry("gateId", "666"),
+ entry("projectId", "999")
+ );
+ }
+
+ @Test
+ public void should_deselect_project() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
+
+ httpServer.stubStatusCode(HttpURLConnection.HTTP_NO_CONTENT);
+
+ QualityGateClient client = new DefaultQualityGateClient(requestFactory);
+ client.deselectProject(666L, 999L);
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/qualitygates/deselect");
+ assertThat(httpServer.requestParams()).includes(
+ entry("gateId", "666"),
+ entry("projectId", "999")
+ );
+ }
}