]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6437 Drop WS /api/coverage/show
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 21 Apr 2015 12:33:02 +0000 (14:33 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 21 Apr 2015 12:33:09 +0000 (14:33 +0200)
server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
server/sonar-server/src/main/java/org/sonar/server/test/ws/CoverageShowAction.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/test/ws/CoverageWs.java [deleted file]
server/sonar-server/src/main/resources/org/sonar/server/test/ws/coverage-example-show.json [deleted file]
server/sonar-server/src/test/java/org/sonar/server/test/ws/CoverageShowActionTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/test/ws/CoverageWsTest.java [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage_for_integration_test.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage_for_overall_test.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage_with_from_and_to.json [deleted file]

index 37c4f3c2687083bb24710bf07334e21550be0e73..95e0f4dcba8441bb002da4e725f3a9b4a3111703 100644 (file)
@@ -338,8 +338,6 @@ import org.sonar.server.startup.RenameDeprecatedPropertyKeys;
 import org.sonar.server.startup.RenameIssueWidgets;
 import org.sonar.server.startup.ServerMetadataPersister;
 import org.sonar.server.test.CoverageService;
-import org.sonar.server.test.ws.CoverageShowAction;
-import org.sonar.server.test.ws.CoverageWs;
 import org.sonar.server.test.ws.TestsCoveredFilesAction;
 import org.sonar.server.test.ws.TestsShowAction;
 import org.sonar.server.test.ws.TestsTestCasesAction;
@@ -847,8 +845,6 @@ class ServerComponents {
 
     // Tests
     pico.addSingleton(CoverageService.class);
-    pico.addSingleton(CoverageWs.class);
-    pico.addSingleton(CoverageShowAction.class);
     pico.addSingleton(TestsWs.class);
     pico.addSingleton(TestsTestCasesAction.class);
     pico.addSingleton(TestsCoveredFilesAction.class);
@@ -876,16 +872,16 @@ class ServerComponents {
 
     // System
     pico.addSingletons(Arrays.asList(
-        SystemRestartWsAction.class,
-        SystemInfoWsAction.class,
-        SystemWs.class,
-        SystemMonitor.class,
-        SonarQubeMonitor.class,
-        EsMonitor.class,
-        PluginsMonitor.class,
-        JvmPropertiesMonitor.class,
-        DatabaseMonitor.class
-    ));
+      SystemRestartWsAction.class,
+      SystemInfoWsAction.class,
+      SystemWs.class,
+      SystemMonitor.class,
+      SonarQubeMonitor.class,
+      EsMonitor.class,
+      PluginsMonitor.class,
+      JvmPropertiesMonitor.class,
+      DatabaseMonitor.class
+      ));
 
     // Plugins WS
     pico.addSingleton(PluginWSCommons.class);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoverageShowAction.java b/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoverageShowAction.java
deleted file mode 100644 (file)
index 2755098..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * 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.apache.commons.lang.ObjectUtils;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.server.test.CoverageService;
-
-import java.util.Map;
-
-public class CoverageShowAction implements RequestHandler {
-
-  private static final String KEY = "key";
-  private static final String FROM = "from";
-  private static final String TO = "to";
-  private static final String TYPE = "type";
-
-  private final CoverageService coverageService;
-
-  public CoverageShowAction(CoverageService coverageService) {
-    this.coverageService = coverageService;
-  }
-
-  void define(WebService.NewController controller) {
-    WebService.NewAction action = controller.createAction("show")
-      .setDescription("Get code coverage. Require Browse permission on file's project<br/>" +
-        "Each element of the result array is composed of:" +
-        "<ol>" +
-        "<li>Line number</li>" +
-        "<li>Is the line covered?</li>" +
-        "<li>Number of tests covering this line</li>" +
-        "<li>Number of branches</li>" +
-        "<li>Number of branches covered</li>" +
-        "</ol>")
-      .setSince("4.4")
-      .setResponseExample(Resources.getResource(getClass(), "coverage-example-show.json"))
-      .setHandler(this);
-
-    action
-      .createParam(KEY)
-      .setRequired(true)
-      .setDescription("File key")
-      .setExampleValue("my_project:/src/foo/Bar.php");
-
-    action
-      .createParam(FROM)
-      .setDescription("First line to return. Starts at 1")
-      .setExampleValue("10")
-      .setDefaultValue("1");
-
-    action
-      .createParam(TO)
-      .setDescription("Last line to return (inclusive)")
-      .setExampleValue("20");
-
-    action
-      .createParam(TYPE)
-      .setDescription("Type of coverage info to return :" +
-        "<ul>" +
-        "<li>UT : Unit Tests</li>" +
-        "<li>IT : Integration Tests</li>" +
-        "<li>OVERALL : Unit and Integration Tests</li>" +
-        "</ul>")
-      .setPossibleValues(CoverageService.TYPE.values())
-      .setDefaultValue(CoverageService.TYPE.UT.name());
-  }
-
-  @Override
-  public void handle(Request request, Response response) {
-    String fileKey = request.mandatoryParam(KEY);
-    coverageService.checkPermission(fileKey);
-
-    int from = Math.max(request.mandatoryParamAsInt(FROM), 1);
-    int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt(TO), Integer.MAX_VALUE);
-    CoverageService.TYPE type = CoverageService.TYPE.valueOf(request.mandatoryParam(TYPE));
-
-    JsonWriter json = response.newJsonWriter().beginObject();
-
-    Map<Integer, Integer> hits = coverageService.getHits(fileKey, type);
-    if (!hits.isEmpty()) {
-      Map<Integer, Integer> testCases = coverageService.getTestCases(fileKey, type);
-      Map<Integer, Integer> conditions = coverageService.getConditions(fileKey, type);
-      Map<Integer, Integer> coveredConditions = coverageService.getCoveredConditions(fileKey, type);
-      writeCoverage(hits, testCases, conditions, coveredConditions, from, to, json);
-    }
-
-    json.endObject().close();
-  }
-
-  private void writeCoverage(Map<Integer, Integer> hitsByLine,
-                             Map<Integer, Integer> testCasesByLines,
-                             Map<Integer, Integer> conditionsByLine,
-                             Map<Integer, Integer> coveredConditionsByLine,
-                             int from, int to, JsonWriter json) {
-    json.name("coverage").beginArray();
-    for (Map.Entry<Integer, Integer> entry : hitsByLine.entrySet()) {
-      Integer line = entry.getKey();
-      if (line >= from && line <= to) {
-        Integer hits = entry.getValue();
-        json.beginArray();
-        json.value(line);
-        json.value(hits > 0);
-        json.value(testCasesByLines.get(line));
-        json.value(conditionsByLine.get(line));
-        json.value(coveredConditionsByLine.get(line));
-        json.endArray();
-      }
-    }
-    json.endArray();
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoverageWs.java b/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoverageWs.java
deleted file mode 100644 (file)
index a85f07d..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.sonar.api.server.ws.WebService;
-
-public class CoverageWs implements WebService {
-
-  private final CoverageShowAction showAction;
-
-  public CoverageWs(CoverageShowAction showAction) {
-    this.showAction = showAction;
-  }
-
-  @Override
-  public void define(Context context) {
-    NewController controller = context.createController("api/coverage")
-      .setSince("4.4")
-      .setDescription("Display coverage information");
-
-    showAction.define(controller);
-
-    controller.done();
-  }
-
-}
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/test/ws/coverage-example-show.json b/server/sonar-server/src/main/resources/org/sonar/server/test/ws/coverage-example-show.json
deleted file mode 100644 (file)
index 6513a5a..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-{
-  "coverage": [
-    [49, true, 14, null, null],
-    [52, false, null, null, null],
-    [72, true, 4, 2, 1]
-  ]
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/ws/CoverageShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/ws/CoverageShowActionTest.java
deleted file mode 100644 (file)
index e4c7c88..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.collect.ImmutableMap;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.server.test.CoverageService;
-import org.sonar.server.ws.WsTester;
-
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class CoverageShowActionTest {
-
-  @Mock
-  CoverageService coverageService;
-
-  WsTester tester;
-
-  @Before
-  public void setUp() throws Exception {
-    tester = new WsTester(new CoverageWs(new CoverageShowAction(coverageService)));
-  }
-
-  @Test
-  public void show_coverage_for_unit_test() throws Exception {
-    String fileKey = "src/Foo.java";
-    when(coverageService.getHits(fileKey, CoverageService.TYPE.UT)).thenReturn(ImmutableMap.of(1, 1, 2, 1, 3, 0, 4, 1, 5 , 1));
-    when(coverageService.getTestCases(fileKey, CoverageService.TYPE.UT)).thenReturn(ImmutableMap.of(4, 8, 1, 2));
-    when(coverageService.getConditions(fileKey, CoverageService.TYPE.UT)).thenReturn(ImmutableMap.of(2, 3, 3, 2));
-    when(coverageService.getCoveredConditions(fileKey, CoverageService.TYPE.UT)).thenReturn(ImmutableMap.of(2, 1, 3, 2));
-
-    WsTester.TestRequest request = tester.newGetRequest("api/coverage", "show").setParam("key", fileKey).setParam("type", "UT");
-
-    request.execute().assertJson(getClass(), "show_coverage.json");
-  }
-
-  @Test
-  public void show_coverage_for_unit_test_with_from_and_to() throws Exception {
-    String fileKey = "src/Foo.java";
-    when(coverageService.getHits(fileKey, CoverageService.TYPE.UT)).thenReturn(ImmutableMap.of(1, 1, 2, 1, 3, 0, 4, 1, 5 , 1));
-    when(coverageService.getTestCases(fileKey, CoverageService.TYPE.UT)).thenReturn(ImmutableMap.of(4, 8, 1, 2));
-    when(coverageService.getConditions(fileKey, CoverageService.TYPE.UT)).thenReturn(ImmutableMap.of(2, 3, 3, 2));
-    when(coverageService.getCoveredConditions(fileKey, CoverageService.TYPE.UT)).thenReturn(ImmutableMap.of(2, 1, 3, 2));
-
-    WsTester.TestRequest request = tester.newGetRequest("api/coverage", "show").setParam("key", fileKey).setParam("from", "3").setParam("to", "4").setParam("type", "UT");
-
-    request.execute().assertJson(getClass(), "show_coverage_with_from_and_to.json");
-  }
-
-  @Test
-  public void show_coverage_for_integration_test() throws Exception {
-    String fileKey = "src/Foo.java";
-    when(coverageService.getHits(fileKey, CoverageService.TYPE.IT)).thenReturn(ImmutableMap.of(1, 1, 2, 1, 3, 0, 4, 1, 5 , 1));
-    when(coverageService.getConditions(fileKey, CoverageService.TYPE.IT)).thenReturn(ImmutableMap.of(2, 3, 3, 2));
-    when(coverageService.getCoveredConditions(fileKey, CoverageService.TYPE.IT)).thenReturn(ImmutableMap.of(2, 1, 3, 2));
-
-    WsTester.TestRequest request = tester.newGetRequest("api/coverage", "show").setParam("key", fileKey).setParam("type", "IT");
-
-    request.execute().assertJson(getClass(), "show_coverage_for_integration_test.json");
-  }
-
-  @Test
-  public void show_coverage_for_overall_test() throws Exception {
-    String fileKey = "src/Foo.java";
-    when(coverageService.getHits(fileKey, CoverageService.TYPE.OVERALL)).thenReturn(ImmutableMap.of(1, 1, 2, 1, 3, 0, 4, 1, 5 , 1));
-    when(coverageService.getConditions(fileKey, CoverageService.TYPE.OVERALL)).thenReturn(ImmutableMap.of(2, 3, 3, 2));
-    when(coverageService.getCoveredConditions(fileKey, CoverageService.TYPE.OVERALL)).thenReturn(ImmutableMap.of(2, 1, 3, 2));
-
-    WsTester.TestRequest request = tester.newGetRequest("api/coverage", "show").setParam("key", fileKey).setParam("type", "OVERALL");
-
-    request.execute().assertJson(getClass(), "show_coverage_for_overall_test.json");
-  }
-
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/ws/CoverageWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/ws/CoverageWsTest.java
deleted file mode 100644 (file)
index 4529abf..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.WebService;
-import org.sonar.server.test.CoverageService;
-import org.sonar.server.ws.WsTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class CoverageWsTest {
-
-  WebService.Controller controller;
-
-  @Before
-  public void setUp() throws Exception {
-    WsTester tester = new WsTester(new CoverageWs(new CoverageShowAction(mock(CoverageService.class))));
-    controller = tester.controller("api/coverage");
-  }
-
-  @Test
-  public void define_controller() throws Exception {
-    assertThat(controller).isNotNull();
-    assertThat(controller.description()).isNotEmpty();
-    assertThat(controller.since()).isEqualTo("4.4");
-    assertThat(controller.isInternal()).isFalse();
-    assertThat(controller.actions()).hasSize(1);
-  }
-
-  @Test
-  public void define_show_action() throws Exception {
-    WebService.Action action = controller.action("show");
-    assertThat(action).isNotNull();
-    assertThat(action.isPost()).isFalse();
-    assertThat(action.handler()).isNotNull();
-    assertThat(action.responseExampleAsString()).isNotEmpty();
-    assertThat(action.params()).hasSize(4);
-  }
-
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage.json b/server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage.json
deleted file mode 100644 (file)
index 8061b1b..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-{
-  "coverage": [
-    [1, true, 2, null, null],
-    [2, true, null, 3, 1],
-    [3, false, null, 2, 2],
-    [4, true, 8, null, null],
-    [5, true, null, null, null]
-  ]
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage_for_integration_test.json b/server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage_for_integration_test.json
deleted file mode 100644 (file)
index e393012..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-{
-  "coverage": [
-    [1, true, null, null, null],
-    [2, true, null, 3, 1],
-    [3, false, null, 2, 2],
-    [4, true, null, null, null],
-    [5, true, null, null, null]
-  ]
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage_for_overall_test.json b/server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage_for_overall_test.json
deleted file mode 100644 (file)
index e393012..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-{
-  "coverage": [
-    [1, true, null, null, null],
-    [2, true, null, 3, 1],
-    [3, false, null, 2, 2],
-    [4, true, null, null, null],
-    [5, true, null, null, null]
-  ]
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage_with_from_and_to.json b/server/sonar-server/src/test/resources/org/sonar/server/test/ws/CoverageShowActionTest/show_coverage_with_from_and_to.json
deleted file mode 100644 (file)
index 9bf3ce2..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-{
-  "coverage": [
-    [3, false, null, 2, 2],
-    [4, true, 8, null, null]
-  ]
-}