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;
// 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);
// 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);
+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-/*
- * 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();
- }
-
-}
+++ /dev/null
-{
- "coverage": [
- [49, true, 14, null, null],
- [52, false, null, null, null],
- [72, true, 4, 2, 1]
- ]
-}
+++ /dev/null
-/*
- * 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");
- }
-
-}
+++ /dev/null
-/*
- * 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);
- }
-
-}
+++ /dev/null
-{
- "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]
- ]
-}
+++ /dev/null
-{
- "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]
- ]
-}
+++ /dev/null
-{
- "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]
- ]
-}
+++ /dev/null
-{
- "coverage": [
- [3, false, null, 2, 2],
- [4, true, 8, null, null]
- ]
-}