aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-03-05 18:11:52 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-03-05 18:11:52 +0100
commit292c533649df419f3dd97036dc799624c48d3075 (patch)
tree324f4b58145b4addab3e5aca009e42d735d80272 /sonar-server/src
parentd5a6fb0e3f9714f4350afe8a2407b970d48eadfe (diff)
downloadsonarqube-292c533649df419f3dd97036dc799624c48d3075.tar.gz
sonarqube-292c533649df419f3dd97036dc799624c48d3075.zip
SONAR-5113 Move the contents of the /api/qualitygates/metrics WS to the app init WS
Diffstat (limited to 'sonar-server/src')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java18
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWs.java24
-rw-r--r--sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java18
-rw-r--r--sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGatesWsTest.java20
4 files changed, 37 insertions, 43 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java
index 8e74a1118c1..7da851cab39 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java
@@ -20,6 +20,7 @@
package org.sonar.server.qualitygate.ws;
import org.sonar.api.i18n.I18n;
+import org.sonar.api.measures.Metric;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
@@ -96,6 +97,7 @@ public class QgateAppHandler implements RequestHandler {
JsonWriter writer = response.newJsonWriter().beginObject();
addPermissions(writer);
addPeriods(writer);
+ addMetrics(writer);
addMessages(writer);
writer.endObject().close();
}
@@ -119,4 +121,20 @@ public class QgateAppHandler implements RequestHandler {
}
writer.endObject();
}
+
+ private void addMetrics(JsonWriter writer) {
+ writer.name("metrics").beginArray();
+ for (Metric metric: qualityGates.gateMetrics()) {
+ writer.beginObject()
+ .prop("id", metric.getId())
+ .prop("key", metric.getKey())
+ .prop("name", metric.getName())
+ .prop("type", metric.getType().toString())
+ .prop("domain", metric.getDomain())
+ .endObject();
+ }
+ writer.endArray();
+ }
+
+
}
diff --git a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWs.java b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWs.java
index 74ea268c1d7..71ca3ede91f 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWs.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWs.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.qualitygate.ws;
-import org.sonar.api.measures.Metric;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
@@ -200,15 +199,6 @@ public class QualityGatesWs implements WebService {
}
}).newParam(PARAM_ID).setDescription("The ID of the quality gate.");
- controller.newAction("metrics")
- .setDescription("List metrics available for definition of conditions.")
- .setHandler(new RequestHandler() {
- @Override
- public void handle(Request request, Response response) {
- listMetrics(request, response);
- }
- });
-
controller.newAction("destroy")
.setDescription("Destroy a quality gate, given its id.")
.setPost(true)
@@ -262,20 +252,6 @@ public class QualityGatesWs implements WebService {
writeQualityGate(newQualityGate, writer).close();
}
- protected void listMetrics(Request request, Response response) {
- JsonWriter writer = response.newJsonWriter().beginObject().name("metrics").beginArray();
- for (Metric metric: qualityGates.gateMetrics()) {
- writer.beginObject()
- .prop("id", metric.getId())
- .prop("key", metric.getKey())
- .prop("name", metric.getName())
- .prop("type", metric.getType().toString())
- .prop("domain", metric.getDomain())
- .endObject();
- }
- writer.endArray().endObject().close();
- }
-
protected void select(Request request, Response response) {
qualityGates.associateProject(parseId(request, PARAM_GATE_ID), parseId(request, PARAM_PROJECT_ID));
response.noContent();
diff --git a/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java
index 5b916d28c57..3a7fdba6415 100644
--- a/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.qualitygate.ws;
+import com.google.common.collect.ImmutableList;
import org.json.simple.JSONValue;
import org.junit.Before;
import org.junit.Test;
@@ -28,6 +29,8 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.sonar.api.i18n.I18n;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.server.ws.WsTester;
import org.sonar.core.timemachine.Periods;
import org.sonar.server.qualitygate.QualityGates;
@@ -38,6 +41,8 @@ import java.util.Map.Entry;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class QgateAppHandlerTest {
@@ -67,7 +72,17 @@ public class QgateAppHandlerTest {
return (String) invocation.getArguments()[1];
}
}).when(i18n).message(any(Locale.class), any(String.class), any(String.class));
+
+ Metric metric = mock(Metric.class);
+ when(metric.getId()).thenReturn(42);
+ when(metric.getKey()).thenReturn("metric");
+ when(metric.getName()).thenReturn("Metric");
+ when(metric.getType()).thenReturn(ValueType.BOOL);
+ when(metric.getDomain()).thenReturn("General");
+ when(qGates.gateMetrics()).thenReturn(ImmutableList.of(metric));
+
String json = tester.newRequest("app").execute().outputAsString();
+
Map responseJson = (Map) JSONValue.parse(json);
assertThat((Boolean) responseJson.get("edit")).isFalse();
Collection<Map> periods = (Collection<Map>) responseJson.get("periods");
@@ -77,5 +92,8 @@ public class QgateAppHandlerTest {
for (Entry message: (Set<Entry>) messages.entrySet()) {
assertThat(message.getKey()).isEqualTo(message.getValue());
}
+ Collection<Map> metrics = (Collection<Map>) responseJson.get("metrics");
+ assertThat(metrics).hasSize(1);
+ assertThat(metrics.iterator().next().get("key")).isEqualTo("metric");
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGatesWsTest.java b/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGatesWsTest.java
index e426d2b95cf..2011e67bef6 100644
--- a/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGatesWsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGatesWsTest.java
@@ -26,8 +26,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.server.ws.WebService.Action;
import org.sonar.api.server.ws.WebService.Controller;
import org.sonar.api.server.ws.WsTester;
@@ -40,7 +38,6 @@ import org.sonar.server.qualitygate.QgateProjectFinder;
import org.sonar.server.qualitygate.QgateProjectFinder.Association;
import org.sonar.server.qualitygate.QualityGates;
-import java.util.Collection;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
@@ -74,7 +71,7 @@ public class QualityGatesWsTest {
assertThat(controller).isNotNull();
assertThat(controller.path()).isEqualTo("api/qualitygates");
assertThat(controller.description()).isNotEmpty();
- assertThat(controller.actions()).hasSize(16);
+ assertThat(controller.actions()).hasSize(15);
Action list = controller.action("list");
assertThat(list).isNotNull();
@@ -387,19 +384,4 @@ public class QualityGatesWsTest {
.assertNoContent();
verify(qGates).dissociateProject(gateId, projectId);
}
-
- @Test
- public void metrics_nominal() throws Exception {
- Metric metric = mock(Metric.class);
- when(metric.getId()).thenReturn(42);
- when(metric.getKey()).thenReturn("metric");
- when(metric.getName()).thenReturn("Metric");
- when(metric.getType()).thenReturn(ValueType.BOOL);
- when(metric.getDomain()).thenReturn("General");
- Collection<Metric> metrics = ImmutableList.of(metric);
- when(qGates.gateMetrics()).thenReturn(metrics);
- tester.newRequest("metrics")
- .execute()
- .assertJson("{'metrics':[{'id':42,'key':'metric','name':'Metric','type':'BOOL','domain':'General'}]}");
- }
}