]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5094 Add project/quality gate association capabilities to WS client
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 11 Mar 2014 10:04:08 +0000 (11:04 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 11 Mar 2014 10:04:16 +0000 (11:04 +0100)
sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGateClient.java
sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClient.java
sonar-ws-client/src/test/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGateClientTest.java

index fd499276dd2fec4473b17b13a06813ffbdc771e1..34a8f5315cf1c35143e00127649bd1dd4f913304 100644 (file)
@@ -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);
 }
index 032a3fbf5c073df37aee17ad592b995b4756004e..26b7963dadf4f5eb51e8b019b4ecc8029300c5c3 100644 (file)
@@ -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);
index f5f7595976b2eb930db4db3bc8836b31f3ead91f..3a3dd9d55f3538bcfa39d029a27de80e4b46cfe3 100644 (file)
@@ -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")
+        );
+  }
 }