diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2019-01-17 16:03:25 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-01-17 20:21:00 +0100 |
commit | b5cc29188339a2bf7187de25be38853553a81482 (patch) | |
tree | 53d8a0c81a324ae2da694f7e71fa06179f4c33fe /sonar-scanner-engine | |
parent | 51578709a9f2168f6774de9da88ad5975b9455fd (diff) | |
download | sonarqube-b5cc29188339a2bf7187de25be38853553a81482.tar.gz sonarqube-b5cc29188339a2bf7187de25be38853553a81482.zip |
SONAR-11632 Remove api/tests WS
- Drop api/tests WS
- Drop persistance of tests and coverage details from compute engine
- Drop tests and coverage details from scanner report
Diffstat (limited to 'sonar-scanner-engine')
7 files changed, 6 insertions, 581 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java index 5f15ca7bd31..202c36149db 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java @@ -21,7 +21,6 @@ package org.sonar.scanner.mediumtest; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; -import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -29,7 +28,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.CheckForNull; -import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.fs.InputComponent; @@ -254,38 +252,6 @@ public class AnalysisResult implements AnalysisObserver { return null; } - public ScannerReport.Test firstTestExecutionForName(InputFile testFile, String testName) { - int ref = ((DefaultInputComponent) testFile).scannerId(); - try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readTests(ref))) { - ScannerReport.Test test = ScannerReport.Test.parser().parseDelimitedFrom(inputStream); - while (test != null) { - if (test.getName().equals(testName)) { - return test; - } - test = ScannerReport.Test.parser().parseDelimitedFrom(inputStream); - } - } catch (Exception e) { - throw new IllegalStateException(e); - } - return null; - } - - public ScannerReport.CoverageDetail coveragePerTestFor(InputFile testFile, String testName) { - int ref = ((DefaultInputComponent) testFile).scannerId(); - try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readCoverageDetails(ref))) { - ScannerReport.CoverageDetail details = ScannerReport.CoverageDetail.parser().parseDelimitedFrom(inputStream); - while (details != null) { - if (details.getTestName().equals(testName)) { - return details; - } - details = ScannerReport.CoverageDetail.parser().parseDelimitedFrom(inputStream); - } - } catch (Exception e) { - throw new IllegalStateException(e); - } - return null; - } - public List<ScannerReport.AdHocRule> adHocRules() { List<ScannerReport.AdHocRule> result = new ArrayList<>(); try (CloseableIterator<ScannerReport.AdHocRule> it = getReportReader().readAdHocRules()) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java deleted file mode 100644 index 1b15ec25e56..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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.sonar.scanner.report; - -import com.google.common.collect.Iterables; -import java.util.HashSet; -import java.util.Set; -import java.util.stream.StreamSupport; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.batch.fs.internal.DefaultInputComponent; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.MutableTestCase; -import org.sonar.api.test.MutableTestPlan; -import org.sonar.api.test.TestCase; -import org.sonar.scanner.deprecated.test.DefaultTestable; -import org.sonar.scanner.deprecated.test.TestPlanBuilder; -import org.sonar.scanner.protocol.output.ScannerReport; -import org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail; -import org.sonar.scanner.protocol.output.ScannerReport.Test; -import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus; -import org.sonar.scanner.protocol.output.ScannerReportWriter; -import org.sonar.scanner.scan.branch.BranchConfiguration; -import org.sonar.scanner.scan.filesystem.InputComponentStore; - -import static java.util.stream.Collectors.toList; - -public class TestExecutionAndCoveragePublisher implements ReportPublisherStep { - - private final InputComponentStore componentStore; - private final TestPlanBuilder testPlanBuilder; - private final BranchConfiguration branchConfiguration; - - public TestExecutionAndCoveragePublisher(InputComponentStore componentStore, TestPlanBuilder testPlanBuilder, BranchConfiguration branchConfiguration) { - this.componentStore = componentStore; - this.testPlanBuilder = testPlanBuilder; - this.branchConfiguration = branchConfiguration; - } - - @Override - public void publish(ScannerReportWriter writer) { - if (branchConfiguration.isShortOrPullRequest()) { - return; - } - final ScannerReport.Test.Builder testBuilder = ScannerReport.Test.newBuilder(); - final ScannerReport.CoverageDetail.Builder builder = ScannerReport.CoverageDetail.newBuilder(); - final ScannerReport.CoverageDetail.CoveredFile.Builder coveredBuilder = ScannerReport.CoverageDetail.CoveredFile.newBuilder(); - for (final InputComponent c : componentStore.all()) { - DefaultInputComponent component = (DefaultInputComponent) c; - final MutableTestPlan testPlan = testPlanBuilder.loadPerspective(MutableTestPlan.class, component); - if (testPlan == null || Iterables.isEmpty(testPlan.testCases())) { - continue; - } - - final Set<String> testNamesWithCoverage = new HashSet<>(); - - writer.writeTests(component.scannerId(), - StreamSupport.stream(testPlan.testCases().spliterator(), false) - .map(testCase -> toProtobufTest(testBuilder, testNamesWithCoverage, testCase)) - .collect(toList())); - - writer.writeCoverageDetails(component.scannerId(), testNamesWithCoverage.stream() - .map(testName -> toProtobufCoverageDetails(builder, coveredBuilder, testPlan, testName)) - .collect(toList())); - } - } - - private CoverageDetail toProtobufCoverageDetails(final ScannerReport.CoverageDetail.Builder builder, final ScannerReport.CoverageDetail.CoveredFile.Builder coveredBuilder, - final MutableTestPlan testPlan, String testName) { - // Take first test with provided name - MutableTestCase testCase = testPlan.testCasesByName(testName).iterator().next(); - builder.clear(); - builder.setTestName(testName); - for (CoverageBlock block : testCase.coverageBlocks()) { - coveredBuilder.clear(); - DefaultInputComponent c = (DefaultInputComponent) componentStore.getByKey(((DefaultTestable) block.testable()).inputFile().key()); - coveredBuilder.setFileRef(c.scannerId()); - for (int line : block.lines()) { - coveredBuilder.addCoveredLine(line); - } - builder.addCoveredFile(coveredBuilder.build()); - } - return builder.build(); - } - - private static Test toProtobufTest(final ScannerReport.Test.Builder testBuilder, final Set<String> testNamesWithCoverage, MutableTestCase testCase) { - testBuilder.clear(); - testBuilder.setName(testCase.name()); - if (testCase.doesCover()) { - testNamesWithCoverage.add(testCase.name()); - } - Long durationInMs = testCase.durationInMs(); - if (durationInMs != null) { - testBuilder.setDurationInMs(durationInMs.longValue()); - } - String msg = testCase.message(); - if (msg != null) { - testBuilder.setMsg(msg); - } - String stack = testCase.stackTrace(); - if (stack != null) { - testBuilder.setStacktrace(stack); - } - TestCase.Status status = testCase.status(); - if (status != null) { - testBuilder.setStatus(TestStatus.valueOf(status.name())); - } - return testBuilder.build(); - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java index 26b6ffa8079..049d49cdc04 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java @@ -80,7 +80,6 @@ import org.sonar.scanner.report.MeasuresPublisher; import org.sonar.scanner.report.MetadataPublisher; import org.sonar.scanner.report.ReportPublisher; import org.sonar.scanner.report.SourcePublisher; -import org.sonar.scanner.report.TestExecutionAndCoveragePublisher; import org.sonar.scanner.repository.ContextPropertiesCache; import org.sonar.scanner.repository.DefaultProjectRepositoriesLoader; import org.sonar.scanner.repository.DefaultQualityProfileLoader; @@ -294,8 +293,7 @@ public class ProjectScanContainer extends ComponentContainer { MeasuresPublisher.class, CoveragePublisher.class, SourcePublisher.class, - ChangedLinesPublisher.class, - TestExecutionAndCoveragePublisher.class); + ChangedLinesPublisher.class); } private void addIssueTrackingComponents() { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/CoveragePerTestMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/CoveragePerTestMediumTest.java deleted file mode 100644 index 20f5fbc1b49..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/CoveragePerTestMediumTest.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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.sonar.scanner.mediumtest.tests; - -import com.google.common.collect.ImmutableMap; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import org.apache.commons.io.FileUtils; -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.scanner.mediumtest.ScannerMediumTester; -import org.sonar.scanner.mediumtest.AnalysisResult; -import org.sonar.xoo.XooPlugin; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CoveragePerTestMediumTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Rule - public ExpectedException exception = ExpectedException.none(); - - @Rule - public ScannerMediumTester tester = new ScannerMediumTester() - .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way"); - - @Test - // SONAR-6183 - public void invalidCoverage() throws IOException { - File baseDir = createTestFiles(); - File srcDir = new File(baseDir, "src"); - - File coverageFile = new File(srcDir, "sample.xoo.coverage"); - FileUtils.write(coverageFile, "0:2\n", StandardCharsets.UTF_8); - - exception.expect(IllegalStateException.class); - exception.expectMessage("Error processing line 1 of file"); - exception.expectCause(new TypeSafeMatcher<Throwable>() { - - @Override - public void describeTo(Description description) { - // nothing to do - } - - @Override - protected boolean matchesSafely(Throwable item) { - return item.getMessage().contains("Line number must be strictly positive"); - } - }); - runTask(baseDir); - - } - - @Test - public void coveragePerTestInReport() throws IOException { - File baseDir = createTestFiles(); - File testDir = new File(baseDir, "test"); - - File xooTestExecutionFile = new File(testDir, "sampleTest.xoo.test"); - FileUtils.write(xooTestExecutionFile, "some test:4:::OK:UNIT\n" + - "another test:10:::OK:UNIT\n" + - "test without coverage:10:::OK:UNIT\n", StandardCharsets.UTF_8); - - File xooCoveragePerTestFile = new File(testDir, "sampleTest.xoo.testcoverage"); - FileUtils.write(xooCoveragePerTestFile, "some test;src/sample.xoo,10,11;src/sample2.xoo,1,2\n" + - "another test;src/sample.xoo,10,20\n", StandardCharsets.UTF_8); - - AnalysisResult result = runTask(baseDir); - - InputFile file = result.inputFile("test/sampleTest.xoo"); - org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail someTest = result.coveragePerTestFor(file, "some test"); - assertThat(someTest.getCoveredFileList()).hasSize(2); - assertThat(someTest.getCoveredFile(0).getFileRef()).isGreaterThan(0); - assertThat(someTest.getCoveredFile(0).getCoveredLineList()).containsExactly(10, 11); - assertThat(someTest.getCoveredFile(1).getFileRef()).isGreaterThan(0); - assertThat(someTest.getCoveredFile(1).getCoveredLineList()).containsExactly(1, 2); - - org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail anotherTest = result.coveragePerTestFor(file, "another test"); - assertThat(anotherTest.getCoveredFileList()).hasSize(1); - assertThat(anotherTest.getCoveredFile(0).getFileRef()).isGreaterThan(0); - assertThat(anotherTest.getCoveredFile(0).getCoveredLineList()).containsExactly(10, 20); - } - - private AnalysisResult runTask(File baseDir) { - return tester.newAnalysis() - .properties(ImmutableMap.<String, String>builder() - .put("sonar.task", "scan") - .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) - .put("sonar.projectKey", "com.foo.project") - .put("sonar.projectName", "Foo Project") - .put("sonar.projectVersion", "1.0-SNAPSHOT") - .put("sonar.projectDescription", "Description of Foo Project") - .put("sonar.sources", "src") - .put("sonar.tests", "test") - .build()) - .execute(); - } - - private File createTestFiles() throws IOException { - File baseDir = temp.getRoot(); - File srcDir = new File(baseDir, "src"); - srcDir.mkdir(); - File testDir = new File(baseDir, "test"); - testDir.mkdir(); - - File xooFile = new File(srcDir, "sample.xoo"); - FileUtils.write(xooFile, "foo", StandardCharsets.UTF_8); - - File xooFile2 = new File(srcDir, "sample2.xoo"); - FileUtils.write(xooFile2, "foo", StandardCharsets.UTF_8); - - File xooTestFile = new File(testDir, "sampleTest.xoo"); - FileUtils.write(xooTestFile, "failure\nerror\nok\nskipped", StandardCharsets.UTF_8); - - File xooTestFile2 = new File(testDir, "sample2Test.xoo"); - FileUtils.write(xooTestFile2, "test file tests", StandardCharsets.UTF_8); - - return baseDir; - } - -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java index c2bbe13c732..d19a51ad670 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java @@ -19,22 +19,15 @@ */ package org.sonar.scanner.mediumtest.tests; -import com.google.common.collect.ImmutableMap; import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.measures.CoreMetrics; -import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.AnalysisResult; -import org.sonar.scanner.protocol.output.ScannerReport; -import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus; +import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.xoo.XooPlugin; import static org.assertj.core.api.Assertions.assertThat; @@ -44,62 +37,12 @@ public class GenericTestExecutionMediumTest { private final List<String> logs = new ArrayList<>(); @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Rule public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way"); @Test - public void unitTests() throws IOException { - - File baseDir = temp.getRoot(); - File srcDir = new File(baseDir, "src"); - srcDir.mkdir(); - File testDir = new File(baseDir, "test"); - testDir.mkdir(); - - File xooFile = new File(srcDir, "sample.xoo"); - FileUtils.write(xooFile, "foo", StandardCharsets.UTF_8); - - File xooTestFile = new File(testDir, "sampleTest.xoo"); - FileUtils.write(xooTestFile, "failure\nerror\nok\nskipped", StandardCharsets.UTF_8); - - File xooTestExecutionFile = new File(testDir, "sampleTest.xoo.test"); - FileUtils.write(xooTestExecutionFile, "skipped::::SKIPPED:UNIT\n" + - "failure:2:Failure::FAILURE:UNIT\n" + - "error:2:Error:The stack:ERROR:UNIT\n" + - "success:4:::OK:INTEGRATION", StandardCharsets.UTF_8); - - AnalysisResult result = tester - .newAnalysis() - .properties(ImmutableMap.<String, String>builder() - .put("sonar.task", "scan") - .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) - .put("sonar.projectKey", "com.foo.project") - .put("sonar.projectName", "Foo Project") - .put("sonar.projectVersion", "1.0-SNAPSHOT") - .put("sonar.projectDescription", "Description of Foo Project") - .put("sonar.sources", "src") - .put("sonar.tests", "test") - .build()) - .execute(); - - InputFile file = result.inputFile("test/sampleTest.xoo"); - org.sonar.scanner.protocol.output.ScannerReport.Test success = result.firstTestExecutionForName(file, "success"); - assertThat(success.getDurationInMs()).isEqualTo(4); - assertThat(success.getStatus()).isEqualTo(TestStatus.OK); - - org.sonar.scanner.protocol.output.ScannerReport.Test error = result.firstTestExecutionForName(file, "error"); - assertThat(error.getDurationInMs()).isEqualTo(2); - assertThat(error.getStatus()).isEqualTo(TestStatus.ERROR); - assertThat(error.getMsg()).isEqualTo("Error"); - assertThat(error.getStacktrace()).isEqualTo("The stack"); - } - - @Test - public void singleReport() throws IOException { + public void singleReport() { File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-test-exec"); @@ -110,28 +53,6 @@ public class GenericTestExecutionMediumTest { .execute(); InputFile testFile = result.inputFile("testx/ClassOneTest.xoo"); - ScannerReport.Test success = result.firstTestExecutionForName(testFile, "test1"); - assertThat(success.getDurationInMs()).isEqualTo(5); - assertThat(success.getStatus()).isEqualTo(TestStatus.OK); - - ScannerReport.Test skipped = result.firstTestExecutionForName(testFile, "test2"); - assertThat(skipped.getDurationInMs()).isEqualTo(500); - assertThat(skipped.getStatus()).isEqualTo(TestStatus.SKIPPED); - assertThat(skipped.getMsg()).isEqualTo("short message"); - assertThat(skipped.getStacktrace()).isEqualTo("other"); - - ScannerReport.Test failed = result.firstTestExecutionForName(testFile, "test3"); - assertThat(failed.getDurationInMs()).isEqualTo(100); - assertThat(failed.getStatus()).isEqualTo(TestStatus.FAILURE); - assertThat(failed.getMsg()).isEqualTo("short"); - assertThat(failed.getStacktrace()).isEqualTo("stacktrace"); - - ScannerReport.Test error = result.firstTestExecutionForName(testFile, "test4"); - assertThat(error.getDurationInMs()).isEqualTo(500); - assertThat(error.getStatus()).isEqualTo(TestStatus.ERROR); - assertThat(error.getMsg()).isEqualTo("short"); - assertThat(error.getStacktrace()).isEqualTo("stacktrace"); - assertThat(result.allMeasures().get(testFile.key())).extracting("metricKey", "intValue.value", "longValue.value") .containsOnly( tuple(CoreMetrics.TESTS_KEY, 3, 0L), @@ -139,12 +60,12 @@ public class GenericTestExecutionMediumTest { tuple(CoreMetrics.TEST_ERRORS_KEY, 1, 0L), tuple(CoreMetrics.TEST_EXECUTION_TIME_KEY, 0, 1105L), tuple(CoreMetrics.TEST_FAILURES_KEY, 1, 0L)); - + assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.testExecutionReportPaths'")); } @Test - public void twoReports() throws IOException { + public void twoReports() { File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-test-exec"); @@ -155,32 +76,6 @@ public class GenericTestExecutionMediumTest { .execute(); InputFile testFile = result.inputFile("testx/ClassOneTest.xoo"); - ScannerReport.Test success = result.firstTestExecutionForName(testFile, "test1"); - assertThat(success.getDurationInMs()).isEqualTo(5); - assertThat(success.getStatus()).isEqualTo(TestStatus.OK); - - ScannerReport.Test success2 = result.firstTestExecutionForName(testFile, "test1b"); - assertThat(success2.getDurationInMs()).isEqualTo(5); - assertThat(success2.getStatus()).isEqualTo(TestStatus.OK); - - ScannerReport.Test skipped = result.firstTestExecutionForName(testFile, "test2"); - assertThat(skipped.getDurationInMs()).isEqualTo(500); - assertThat(skipped.getStatus()).isEqualTo(TestStatus.SKIPPED); - assertThat(skipped.getMsg()).isEqualTo("short message"); - assertThat(skipped.getStacktrace()).isEqualTo("other"); - - ScannerReport.Test failed = result.firstTestExecutionForName(testFile, "test3"); - assertThat(failed.getDurationInMs()).isEqualTo(100); - assertThat(failed.getStatus()).isEqualTo(TestStatus.FAILURE); - assertThat(failed.getMsg()).isEqualTo("short"); - assertThat(failed.getStacktrace()).isEqualTo("stacktrace"); - - ScannerReport.Test error = result.firstTestExecutionForName(testFile, "test4"); - assertThat(error.getDurationInMs()).isEqualTo(500); - assertThat(error.getStatus()).isEqualTo(TestStatus.ERROR); - assertThat(error.getMsg()).isEqualTo("short"); - assertThat(error.getStacktrace()).isEqualTo("stacktrace"); - assertThat(result.allMeasures().get(testFile.key())).extracting("metricKey", "intValue.value", "longValue.value") .containsOnly( tuple(CoreMetrics.TESTS_KEY, 4, 0L), @@ -188,7 +83,7 @@ public class GenericTestExecutionMediumTest { tuple(CoreMetrics.TEST_ERRORS_KEY, 1, 0L), tuple(CoreMetrics.TEST_EXECUTION_TIME_KEY, 0, 1610L), tuple(CoreMetrics.TEST_FAILURES_KEY, 1, 0L)); - + assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.testExecutionReportPaths'")); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/TestExecutionMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/TestExecutionMediumTest.java deleted file mode 100644 index 1a39263ce8a..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/TestExecutionMediumTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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.sonar.scanner.mediumtest.tests; - -import com.google.common.collect.ImmutableMap; -import java.io.File; -import java.io.IOException; -import org.apache.commons.io.FileUtils; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.scanner.mediumtest.ScannerMediumTester; -import org.sonar.scanner.mediumtest.AnalysisResult; -import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus; -import org.sonar.xoo.XooPlugin; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TestExecutionMediumTest { - - @org.junit.Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Rule - public ScannerMediumTester tester = new ScannerMediumTester() - .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way"); - - @Test - public void unitTests() throws IOException { - - File baseDir = temp.getRoot(); - File srcDir = new File(baseDir, "src"); - srcDir.mkdir(); - File testDir = new File(baseDir, "test"); - testDir.mkdir(); - - File xooFile = new File(srcDir, "sample.xoo"); - FileUtils.write(xooFile, "foo"); - - File xooTestFile = new File(testDir, "sampleTest.xoo"); - FileUtils.write(xooTestFile, "failure\nerror\nok\nskipped"); - - File xooTestExecutionFile = new File(testDir, "sampleTest.xoo.test"); - FileUtils.write(xooTestExecutionFile, "skipped::::SKIPPED:UNIT\n" + - "failure:2:Failure::FAILURE:UNIT\n" + - "error:2:Error:The stack:ERROR:UNIT\n" + - "success:4:::OK:INTEGRATION"); - - AnalysisResult result = tester.newAnalysis() - .properties(ImmutableMap.<String, String>builder() - .put("sonar.task", "scan") - .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) - .put("sonar.projectKey", "com.foo.project") - .put("sonar.projectName", "Foo Project") - .put("sonar.projectVersion", "1.0-SNAPSHOT") - .put("sonar.projectDescription", "Description of Foo Project") - .put("sonar.sources", "src") - .put("sonar.tests", "test") - .build()) - .execute(); - - InputFile file = result.inputFile("test/sampleTest.xoo"); - org.sonar.scanner.protocol.output.ScannerReport.Test success = result.firstTestExecutionForName(file, "success"); - assertThat(success.getDurationInMs()).isEqualTo(4); - assertThat(success.getStatus()).isEqualTo(TestStatus.OK); - - org.sonar.scanner.protocol.output.ScannerReport.Test error = result.firstTestExecutionForName(file, "error"); - assertThat(error.getDurationInMs()).isEqualTo(2); - assertThat(error.getStatus()).isEqualTo(TestStatus.ERROR); - assertThat(error.getMsg()).isEqualTo("Error"); - assertThat(error.getStacktrace()).isEqualTo("The stack"); - } - -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisherTest.java deleted file mode 100644 index 84153126978..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisherTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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.sonar.scanner.report; - -import java.io.File; -import java.io.IOException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.scanner.protocol.output.ScannerReportWriter; -import org.sonar.scanner.scan.branch.BranchConfiguration; -import org.sonar.scanner.scan.filesystem.InputComponentStore; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -public class TestExecutionAndCoveragePublisherTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Test - public void do_nothing_for_short_living_branches() throws IOException { - BranchConfiguration branchConfiguration = mock(BranchConfiguration.class); - when(branchConfiguration.isShortOrPullRequest()).thenReturn(true); - InputComponentStore componentStore = mock(InputComponentStore.class); - TestExecutionAndCoveragePublisher publisher = new TestExecutionAndCoveragePublisher(componentStore, null, branchConfiguration); - File outputDir = temp.newFolder(); - ScannerReportWriter writer = new ScannerReportWriter(outputDir); - - publisher.publish(writer); - - verifyZeroInteractions(componentStore); - } - - @Test - public void do_nothing_for_pull_requests() throws IOException { - BranchConfiguration branchConfiguration = mock(BranchConfiguration.class); - when(branchConfiguration.isShortOrPullRequest()).thenReturn(true); - InputComponentStore componentStore = mock(InputComponentStore.class); - TestExecutionAndCoveragePublisher publisher = new TestExecutionAndCoveragePublisher(componentStore, null, branchConfiguration); - File outputDir = temp.newFolder(); - ScannerReportWriter writer = new ScannerReportWriter(outputDir); - - publisher.publish(writer); - - verifyZeroInteractions(componentStore); - } - -} |