aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-07-27 10:59:00 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-07-27 12:12:01 +0200
commit58a8a74c05def9176479b2cf951c49f398cb72f8 (patch)
tree336eabec56e974a6668c3547c1ee64c12dca5a66 /sonar-ws-client/src/test
parentea0fb362a7dd6188973c0cb27291720ae71c29ca (diff)
downloadsonarqube-58a8a74c05def9176479b2cf951c49f398cb72f8.tar.gz
sonarqube-58a8a74c05def9176479b2cf951c49f398cb72f8.zip
SONAR-2648 New web service /api/manual_measures
Diffstat (limited to 'sonar-ws-client/src/test')
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/ManualMeasureQueryTest.java41
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java59
-rw-r--r--sonar-ws-client/src/test/resources/manual_measures/all_measures.json22
-rw-r--r--sonar-ws-client/src/test/resources/manual_measures/single_measure.json12
4 files changed, 134 insertions, 0 deletions
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ManualMeasureQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ManualMeasureQueryTest.java
new file mode 100644
index 00000000000..dc3c38c071c
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ManualMeasureQueryTest.java
@@ -0,0 +1,41 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class ManualMeasureQueryTest extends QueryTestCase {
+
+ @Test
+ public void shouldGetAllResourceMeasures() {
+ ManualMeasureQuery query = ManualMeasureQuery.create("foo");
+ assertThat(query.getUrl(), is("/api/manual_measures?resource=foo&"));
+ assertThat(query.getModelClass().getName(), is(ManualMeasure.class.getName()));
+ }
+
+ @Test
+ public void shouldFilterMetric() {
+ ManualMeasureQuery query = ManualMeasureQuery.create("foo").setMetricKey("burned_budget");
+ assertThat(query.getUrl(), is("/api/manual_measures?resource=foo&metric=burned_budget&"));
+ }
+}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java
new file mode 100644
index 00000000000..cc6667bc4f9
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java
@@ -0,0 +1,59 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.junit.Test;
+import org.sonar.wsclient.services.ManualMeasure;
+import org.sonar.wsclient.services.Metric;
+
+import java.util.Collection;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public class ManualMeasureUnmarshallerTest extends UnmarshallerTestCase {
+
+ @Test
+ public void testSingleMeasure() {
+ ManualMeasure measure = new ManualMeasureUnmarshaller().toModel("[]");
+ assertThat(measure, nullValue());
+
+ measure = new ManualMeasureUnmarshaller().toModel(loadFile("/manual_measures/single_measure.json"));
+ assertThat(measure.getId(), is(1L));
+ assertThat(measure.getMetricKey(), is("burned_budget"));
+ assertThat(measure.getResourceKey(), is("org.apache.struts:struts-parent"));
+ assertThat(measure.getValue(), is(302.5));
+ assertThat(measure.getUserLogin(), is("admin"));
+ assertThat(measure.getUserName(), is("Administrator"));
+ assertThat(measure.getCreatedAt().getDate(), is(27));
+ assertThat(measure.getUpdatedAt().getDate(), is(3));
+ }
+
+
+ @Test
+ public void testAllMeasures() {
+ List<ManualMeasure> measures = new ManualMeasureUnmarshaller().toModels(loadFile("/manual_measures/all_measures.json"));
+ assertThat(measures.size(), is(2));
+ }
+}
diff --git a/sonar-ws-client/src/test/resources/manual_measures/all_measures.json b/sonar-ws-client/src/test/resources/manual_measures/all_measures.json
new file mode 100644
index 00000000000..05bce196c2d
--- /dev/null
+++ b/sonar-ws-client/src/test/resources/manual_measures/all_measures.json
@@ -0,0 +1,22 @@
+[
+ {
+ "id":1,
+ "metric":"burned_budget",
+ "resource":"org.apache.struts:struts-parent",
+ "val":302.0,
+ "created_at":"2011-07-27T10:22:34+0200",
+ "updated_at":"2011-07-27T10:22:34+0200",
+ "login":"admin",
+ "username":"Administrator"
+ },
+ {
+ "id":2,
+ "metric":"team_size",
+ "resource":"org.apache.struts:struts-parent",
+ "val":555.0,
+ "created_at":"2011-07-27T10:53:33+0200",
+ "updated_at":"2011-07-27T10:53:33+0200",
+ "login":"admin",
+ "username":"Administrator"
+ }
+] \ No newline at end of file
diff --git a/sonar-ws-client/src/test/resources/manual_measures/single_measure.json b/sonar-ws-client/src/test/resources/manual_measures/single_measure.json
new file mode 100644
index 00000000000..587d63bced8
--- /dev/null
+++ b/sonar-ws-client/src/test/resources/manual_measures/single_measure.json
@@ -0,0 +1,12 @@
+[
+ {
+ "id":1,
+ "metric":"burned_budget",
+ "resource":"org.apache.struts:struts-parent",
+ "val":302.5,
+ "created_at":"2011-06-27T10:22:34+0200",
+ "updated_at":"2011-07-03T12:02:12+0200",
+ "login":"admin",
+ "username":"Administrator"
+ }
+] \ No newline at end of file