diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2018-04-16 18:06:08 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-05-02 20:20:56 +0200 |
commit | d13e2d9a08ea6fc3cb29bcf4add0c4f2f12cc3b8 (patch) | |
tree | 73bffcc464d1995e7c90fd27af1f84ea7f608b09 /tests/src/test/java | |
parent | 5c78e445609eaf1c6bb00b0c863623ea497237a0 (diff) | |
download | sonarqube-d13e2d9a08ea6fc3cb29bcf4add0c4f2f12cc3b8.tar.gz sonarqube-d13e2d9a08ea6fc3cb29bcf4add0c4f2f12cc3b8.zip |
SONAR-9384 Fix computation of project without src but with test measures
Diffstat (limited to 'tests/src/test/java')
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/Category3Suite.java | 9 | ||||
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/analysis/ProjectMeasureTest.java | 121 |
2 files changed, 129 insertions, 1 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category3Suite.java b/tests/src/test/java/org/sonarqube/tests/Category3Suite.java index 912aab2381f..6cec2f483b3 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category3Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category3Suite.java @@ -32,6 +32,7 @@ import org.sonarqube.tests.analysis.LinksTest; import org.sonarqube.tests.analysis.MultiLanguageTest; import org.sonarqube.tests.analysis.PermissionTest; import org.sonarqube.tests.analysis.ProjectBuilderTest; +import org.sonarqube.tests.analysis.ProjectMeasureTest; import org.sonarqube.tests.analysis.RedirectTest; import org.sonarqube.tests.analysis.ReportDumpTest; import org.sonarqube.tests.analysis.SSLTest; @@ -66,7 +67,8 @@ import static util.ItUtils.xooPlugin; ReportDumpTest.class, SSLTest.class, FavoriteTest.class, - RedirectTest.class + RedirectTest.class, + ProjectMeasureTest.class }) public class Category3Suite { @@ -90,5 +92,10 @@ public class Category3Suite { // used by ProjectBuilderTest .addPlugin(pluginArtifact("project-builder-plugin")) + // used by ProjectWithoutSourceTest + .addPlugin(pluginArtifact("save-measure-on-project-plugin")) + + .setServerProperty("sonar.ce.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005") + .build(); } diff --git a/tests/src/test/java/org/sonarqube/tests/analysis/ProjectMeasureTest.java b/tests/src/test/java/org/sonarqube/tests/analysis/ProjectMeasureTest.java new file mode 100644 index 00000000000..a43bf1d4de5 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/analysis/ProjectMeasureTest.java @@ -0,0 +1,121 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.sonarqube.tests.analysis; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.SonarScanner; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.qa.util.Tester; +import org.sonarqube.tests.Category3Suite; +import org.sonarqube.ws.Measures; +import org.sonarqube.ws.Projects.CreateWsResponse.Project; +import org.sonarqube.ws.client.measures.ComponentRequest; + +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; +import static util.ItUtils.projectDir; + +public class ProjectMeasureTest { + + @ClassRule + public static final Orchestrator orchestrator = Category3Suite.ORCHESTRATOR; + + @Rule + public Tester tester = new Tester(orchestrator); + + @Test + public void project_without_source_but_tests_related_measures() { + Project project = tester.projects().provision(); + + orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"), + "sonar.projectKey", project.getKey(), + // Exclude all file => no source code + "sonar.exclusions", "**/*", + "sonar.measure.valueByMetric", "tests=20;test_errors=1;test_failures=2;skipped_tests=3")); + + assertThat(tester.wsClient().measures().component( + new ComponentRequest() + .setComponent(project.getKey()) + .setMetricKeys(asList("tests", "test_errors", "test_failures", "skipped_tests"))) + .getComponent().getMeasuresList()) + .extracting(Measures.Measure::getMetric, Measures.Measure::getValue) + .containsExactlyInAnyOrder( + tuple("tests", "20"), + tuple("test_errors", "1"), + tuple("test_failures", "2"), + tuple("skipped_tests", "3")); + } + + @Test + public void module_without_source_but_tests_related_measure() { + Project project = tester.projects().provision(); + + orchestrator.executeBuild(SonarScanner.create(projectDir("analysis/xoo-module-b-without-source"), + "sonar.projectKey", project.getKey(), + "sonar.measure.valueByMetric", "tests=20;test_errors=1;test_failures=2;skipped_tests=3")); + + String moduleBKey = project.getKey() + ":module_b"; + assertThat(tester.wsClient().measures().component( + new ComponentRequest() + .setComponent(moduleBKey) + .setMetricKeys(asList("tests", "test_errors", "test_failures", "skipped_tests"))) + .getComponent().getMeasuresList()) + .extracting(Measures.Measure::getMetric, Measures.Measure::getValue) + .containsExactlyInAnyOrder( + tuple("tests", "20"), + tuple("test_errors", "1"), + tuple("test_failures", "2"), + tuple("skipped_tests", "3")); + + assertThat(tester.wsClient().measures().component( + new ComponentRequest() + .setComponent(project.getKey()) + .setMetricKeys(asList("tests", "test_errors", "test_failures", "skipped_tests"))) + .getComponent().getMeasuresList()) + .extracting(Measures.Measure::getMetric, Measures.Measure::getValue) + .containsExactlyInAnyOrder( + tuple("tests", "20"), + tuple("test_errors", "1"), + tuple("test_failures", "2"), + tuple("skipped_tests", "3")); + } + + @Test + public void ignore_measure_injected_at_project_level_when_measure_is_defined_on_file() { + Project project = tester.projects().provision(); + + orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample-with-tests"), + "sonar.projectKey", project.getKey(), + "sonar.measure.valueByMetric", "tests=12")); + + assertThat(tester.wsClient().measures().component( + new ComponentRequest() + .setComponent(project.getKey()) + .setMetricKeys(singletonList("tests"))) + .getComponent().getMeasuresList()) + .extracting(Measures.Measure::getMetric, Measures.Measure::getValue) + // Measure set by the sensor is ignored + .containsExactlyInAnyOrder(tuple("tests", "2")); + } +} |