aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-05-05 18:09:51 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-05-05 18:09:51 +0200
commit9aa35c6e74e737fc5874cd10be6d72f2b60afe5c (patch)
tree99d218a5606ca504a9ec2b924845a68bebc1370c
parentb5927b4ff0b01aba260c2097eda96578428a723f (diff)
downloadsonarqube-9aa35c6e74e737fc5874cd10be6d72f2b60afe5c.tar.gz
sonarqube-9aa35c6e74e737fc5874cd10be6d72f2b60afe5c.zip
SONAR-5111 Add api/tests WS documentations
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/test/ws/TestsWs.java69
-rw-r--r--sonar-server/src/main/resources/org/sonar/server/test/ws/example-plan.json41
-rw-r--r--sonar-server/src/main/resources/org/sonar/server/test/ws/example-testable.json49
-rw-r--r--sonar-server/src/test/java/org/sonar/server/test/ws/TestsWsTest.java71
5 files changed, 234 insertions, 0 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
index 3912430445a..dfbb4a140dd 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
@@ -131,6 +131,7 @@ import org.sonar.server.source.ws.ScmWriter;
import org.sonar.server.source.ws.ShowAction;
import org.sonar.server.source.ws.SourcesWs;
import org.sonar.server.startup.*;
+import org.sonar.server.test.ws.TestsWs;
import org.sonar.server.text.MacroInterpreter;
import org.sonar.server.text.RubyTextService;
import org.sonar.server.ui.JRubyI18n;
@@ -451,6 +452,9 @@ class ServerComponents {
pico.addSingleton(NotificationCenter.class);
pico.addSingleton(DefaultNotificationManager.class);
+ // Tests
+ pico.addSingleton(TestsWs.class);
+
// graphs and perspective related classes
pico.addSingleton(TestablePerspectiveLoader.class);
pico.addSingleton(TestPlanPerspectiveLoader.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/test/ws/TestsWs.java b/sonar-server/src/main/java/org/sonar/server/test/ws/TestsWs.java
new file mode 100644
index 00000000000..87e20b42fb5
--- /dev/null
+++ b/sonar-server/src/main/java/org/sonar/server/test/ws/TestsWs.java
@@ -0,0 +1,69 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.test.ws;
+
+import com.google.common.io.Resources;
+import org.sonar.api.server.ws.RailsHandler;
+import org.sonar.api.server.ws.WebService;
+
+public class TestsWs implements WebService {
+
+ @Override
+ public void define(Context context) {
+ NewController controller = context.createController("api/tests")
+ .setSince("3.5")
+ .setDescription("Tests management");
+
+ definePlanAction(controller);
+ defineTestableAction(controller);
+
+ controller.done();
+ }
+
+ private void definePlanAction(NewController controller) {
+ NewAction action = controller.createAction("plan")
+ .setDescription("Get the details of a given test plan : test cases, resources covered by test cases. Requires Browse permission on resource")
+ .setSince("3.5")
+ .setInternal(true)
+ .setHandler(RailsHandler.INSTANCE)
+ .setResponseExample(Resources.getResource(this.getClass(), "example-plan.json"));
+
+ action.createParam("resource")
+ .setRequired(true)
+ .setDescription("id or key of the test resource")
+ .setExampleValue("org.codehaus.sonar.plugins:sonar-cpd-plugin:src/test/java/org/sonar/plugins/cpd/SonarBridgeEngineTest.java");
+ }
+
+ private void defineTestableAction(NewController controller) {
+ NewAction action = controller.createAction("testable")
+ .setDescription("Get the details of a given resource : test plan, test cases covering lines. Requires Browse permission on resource")
+ .setSince("3.5")
+ .setInternal(true)
+ .setHandler(RailsHandler.INSTANCE)
+ .setResponseExample(Resources.getResource(this.getClass(), "example-testable.json"));
+
+ action.createParam("resource")
+ .setRequired(true)
+ .setDescription("id or key of the resource")
+ .setExampleValue("org.codehaus.sonar.plugins:sonar-cpd-plugin:src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java");
+ }
+
+}
diff --git a/sonar-server/src/main/resources/org/sonar/server/test/ws/example-plan.json b/sonar-server/src/main/resources/org/sonar/server/test/ws/example-plan.json
new file mode 100644
index 00000000000..5cc43b76e56
--- /dev/null
+++ b/sonar-server/src/main/resources/org/sonar/server/test/ws/example-plan.json
@@ -0,0 +1,41 @@
+{
+ "key": "org.codehaus.sonar.plugins:sonar-cpd-plugin:src/test/java/org/sonar/plugins/cpd/SonarBridgeEngineTest.java",
+ "name": "SonarBridgeEngineTest.java",
+ "longName": "src/test/java/org/sonar/plugins/cpd/SonarBridgeEngineTest.java",
+ "testCases": [
+ {
+ "name": "shouldReturnDefaultBlockSize",
+ "type": "UNIT",
+ "durationInMs": 2,
+ "status": "OK",
+ "coverages": [
+ {
+ "key": "org.codehaus.sonar.plugins:sonar-cpd-plugin:src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java",
+ "name": "SonarBridgeEngine.java",
+ "longName": "src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java",
+ "lines": [
+ 68,
+ 69,
+ 70,
+ 71,
+ 72,
+ 73,
+ 155,
+ 156,
+ 157,
+ 158,
+ 160
+ ]
+ },
+ {
+ "key": "org.codehaus.sonar.plugins:sonar-cpd-plugin:src/main/java/org/sonar/plugins/cpd/CpdEngine.java",
+ "name": "CpdEngine.java",
+ "longName": "src/main/java/org/sonar/plugins/cpd/CpdEngine.java",
+ "lines": [
+ 27
+ ]
+ }
+ ]
+ }
+ ]
+}
diff --git a/sonar-server/src/main/resources/org/sonar/server/test/ws/example-testable.json b/sonar-server/src/main/resources/org/sonar/server/test/ws/example-testable.json
new file mode 100644
index 00000000000..902aaa4f0fe
--- /dev/null
+++ b/sonar-server/src/main/resources/org/sonar/server/test/ws/example-testable.json
@@ -0,0 +1,49 @@
+{
+ "key": "org.codehaus.sonar.plugins:sonar-cpd-plugin:src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java",
+ "name": "SonarBridgeEngine.java",
+ "longName": "src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java",
+ "coveredLines": [
+ 56,
+ 68,
+ 69,
+ 70,
+ 71,
+ 72,
+ 73,
+ 76,
+ 77,
+ 146,
+ 147,
+ 148,
+ 150,
+ 155,
+ 156,
+ 157,
+ 158,
+ 160,
+ 166,
+ 167,
+ 168,
+ 170,
+ 171,
+ 174
+ ],
+ "coverages": [
+ {
+ "lines": [
+ 68,
+ 69,
+ 70,
+ 71,
+ 72,
+ 73,
+ 76,
+ 77
+ ],
+ "name": "test_engine",
+ "status": "OK",
+ "durationInMs": 2,
+ "testPlan": "org.codehaus.sonar.plugins:sonar-cpd-plugin:src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java"
+ }
+ ]
+}
diff --git a/sonar-server/src/test/java/org/sonar/server/test/ws/TestsWsTest.java b/sonar-server/src/test/java/org/sonar/server/test/ws/TestsWsTest.java
new file mode 100644
index 00000000000..ed6cd6cf82d
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/test/ws/TestsWsTest.java
@@ -0,0 +1,71 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.test.ws;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.server.ws.RailsHandler;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.ws.WsTester;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class TestsWsTest {
+
+ WebService.Controller controller;
+
+ @Before
+ public void setUp() throws Exception {
+ WsTester tester = new WsTester(new TestsWs());
+ controller = tester.controller("api/tests");
+ }
+
+ @Test
+ public void define_controller() throws Exception {
+ assertThat(controller).isNotNull();
+ assertThat(controller.since()).isEqualTo("3.5");
+ assertThat(controller.description()).isNotEmpty();
+ assertThat(controller.actions()).hasSize(2);
+ }
+
+ @Test
+ public void define_plan_action() throws Exception {
+ WebService.Action action = controller.action("plan");
+ assertThat(action).isNotNull();
+ assertThat(action.isInternal()).isTrue();
+ assertThat(action.isPost()).isFalse();
+ assertThat(action.handler()).isInstanceOf(RailsHandler.class);
+ assertThat(action.responseExampleAsString()).isNotEmpty();
+ assertThat(action.params()).hasSize(1);
+ }
+
+ @Test
+ public void define_testable_action() throws Exception {
+ WebService.Action action = controller.action("testable");
+ assertThat(action).isNotNull();
+ assertThat(action.isInternal()).isTrue();
+ assertThat(action.isPost()).isFalse();
+ assertThat(action.handler()).isInstanceOf(RailsHandler.class);
+ assertThat(action.responseExampleAsString()).isNotEmpty();
+ assertThat(action.params()).hasSize(1);
+ }
+
+}