diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-09-06 16:34:06 +0200 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-09-12 11:34:59 +0200 |
commit | 39c110298f71325ce73d584e5034acc904c32c40 (patch) | |
tree | 09da55bd5ec1affaa68d7d97dfd588e2a3d41efe /sonar-scanner-engine/src/test | |
parent | 579aa0457917229ed583c782563552ae957e121d (diff) | |
download | sonarqube-39c110298f71325ce73d584e5034acc904c32c40.tar.gz sonarqube-39c110298f71325ce73d584e5034acc904c32c40.zip |
SONAR-9701 Don't publish coverage, scm and source of unchanged files
Diffstat (limited to 'sonar-scanner-engine/src/test')
13 files changed, 40 insertions, 25 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java index b8bdfa48233..0d0ead878ab 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java @@ -49,7 +49,6 @@ import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.report.ReportPublisher; import org.sonar.scanner.scan.BranchConfiguration; -import org.sonar.scanner.scan.BranchConfiguration.BranchType; import org.sonar.scanner.scan.filesystem.InputComponentStore; import static org.assertj.core.api.Assertions.assertThat; @@ -91,7 +90,7 @@ public class CpdExecutorTest { index = new SonarCpdBlockIndex(publisher, settings); DefaultInputModule inputModule = TestInputFileBuilder.newDefaultInputModule("foo", baseDir); - componentStore = new InputComponentStore(inputModule, mock(AnalysisMode.class)); + componentStore = new InputComponentStore(inputModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); executor = new CpdExecutor(settings, index, publisher, componentStore, branchConfig); reader = new ScannerReportReader(outputDir); @@ -102,7 +101,7 @@ public class CpdExecutorTest { @Test public void skipIfShortBranch() { - when(branchConfig.branchType()).thenReturn(BranchType.SHORT); + when(branchConfig.isShortLivingBranch()).thenReturn(true); index = mock(SonarCpdBlockIndex.class); executor = new CpdExecutor(settings, index, publisher, componentStore, branchConfig); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java index bf4b0f4f310..58d9133dddc 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java @@ -42,8 +42,10 @@ import static org.assertj.core.api.Assertions.assertThat; public class BranchMediumTest { + private static final String PROJECT_KEY = "sample"; + private static final String FILE_PATH = "HelloJava.xoo"; + private static final String FILE_CONTENT = "xoooo"; private File baseDir; - private final String relativePath = "HelloJava.xoo"; @Rule public TemporaryFolder temp = new TemporaryFolder(); @@ -58,24 +60,31 @@ public class BranchMediumTest { @Before public void prepare() throws IOException { baseDir = temp.newFolder(); - Path filepath = baseDir.toPath().resolve(relativePath); - Files.write(filepath, "xoooo".getBytes()); + Path filepath = baseDir.toPath().resolve(FILE_PATH); + Files.write(filepath, FILE_CONTENT.getBytes()); String md5sum = new FileMetadata() - .readMetadata(Files.newInputStream(filepath), StandardCharsets.UTF_8, relativePath) + .readMetadata(Files.newInputStream(filepath), StandardCharsets.UTF_8, FILE_PATH) .hash(); - tester.addFileData("sample", relativePath, new FileData(md5sum, null)); + tester.addFileData(PROJECT_KEY, FILE_PATH, new FileData(md5sum, "1.1")); } @Test public void should_skip_report_for_unchanged_files_in_short_branch() { // sanity check, normally report gets generated TaskResult result = getResult(tester); - assertThat(getResult(tester).getReportComponent(result.inputFile(relativePath).key())).isNotNull(); + assertThat(getResult(tester).getReportComponent(result.inputFile(FILE_PATH).key())).isNotNull(); + int fileId = 2; + assertThat(result.getReportReader().readChangesets(fileId)).isNotNull(); + assertThat(result.getReportReader().hasCoverage(fileId)).isTrue(); + assertThat(result.getReportReader().readFileSource(fileId)).isNotNull(); // file is skipped for short branches (no report, no coverage, no duplications) TaskResult result2 = getResult(tester.setBranchType(BranchConfiguration.BranchType.SHORT)); - assertThat(result2.getReportComponent(result2.inputFile(relativePath).key())).isNull(); + assertThat(result2.getReportComponent(result2.inputFile(FILE_PATH).key())).isNull(); + assertThat(result2.getReportReader().readChangesets(fileId)).isNull(); + assertThat(result2.getReportReader().hasCoverage(fileId)).isFalse(); + assertThat(result.getReportReader().readFileSource(fileId)).isNull(); } @Test @@ -100,8 +109,9 @@ public class BranchMediumTest { .properties(ImmutableMap.<String, String>builder() .put("sonar.task", "scan") .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) - .put("sonar.projectKey", "sample") + .put("sonar.projectKey", PROJECT_KEY) .put("sonar.sources", ".") + .put("sonar.scm.provider", "xoo") .build()) .execute(); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java index fbf81aa0c7e..2fc4af185a3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java @@ -31,7 +31,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import org.sonar.api.utils.PathUtils; import org.sonar.api.utils.log.LogTester; import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.ScannerMediumTester.TaskBuilder; @@ -180,7 +179,7 @@ public class ScmMediumTest { assertThat(fileWithoutBlameScm).isNull(); assertThat(logTester.logs()).containsSubsequence("2 files to be analyzed", "1/2 files analyzed", MISSING_BLAME_INFORMATION_FOR_THE_FOLLOWING_FILES, - " * " + PathUtils.sanitize(xooFileWithoutBlame.toPath().toString())); + " * src/sample_no_blame.xoo"); } // SONAR-6397 @@ -239,7 +238,7 @@ public class ScmMediumTest { // 5 .xoo files + 3 .scm files, but only 4 marked for publishing. 1 file is SAME so not included in the total assertThat(logTester.logs()).containsSubsequence("8 files indexed"); assertThat(logTester.logs()).containsSubsequence("4 files to be analyzed", "3/4 files analyzed"); - assertThat(logTester.logs()).containsSubsequence(MISSING_BLAME_INFORMATION_FOR_THE_FOLLOWING_FILES, " * " + noBlameScmOnServer.getPath().replaceAll("\\\\", "/")); + assertThat(logTester.logs()).containsSubsequence(MISSING_BLAME_INFORMATION_FOR_THE_FOLLOWING_FILES, " * src/no_blame_scm_on_server.xoo"); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java index 8d0eb0085da..f39cafcadb7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java @@ -33,6 +33,7 @@ import org.sonar.api.batch.rule.Severity; import org.sonar.api.config.internal.MapSettings; import org.sonar.scanner.issue.IssueCache; import org.sonar.scanner.issue.tracking.TrackedIssue; +import org.sonar.scanner.scan.BranchConfiguration; import org.sonar.scanner.scan.filesystem.InputComponentStore; import static org.assertj.core.api.Assertions.assertThat; @@ -54,7 +55,7 @@ public class DefaultPostJobContextTest { public void setUp() throws IOException { issueCache = mock(IssueCache.class); DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule("foo", temp.newFolder()); - componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class)); + componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); settings = new MapSettings(); analysisMode = mock(AnalysisMode.class); context = new DefaultPostJobContext(settings.asConfig(), settings, issueCache, componentStore, analysisMode); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java index 5b0406bdfc1..a03afd14359 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java @@ -313,7 +313,7 @@ public class ComponentsPublisherTest { @Test public void skip_unchanged_components_in_short_branches() throws IOException { - when(branchConfiguration.branchType()).thenReturn(BranchType.SHORT); + when(branchConfiguration.isShortLivingBranch()).thenReturn(true); ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class); when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12")); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java index 76ce5527497..f2a0e614bae 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java @@ -35,6 +35,7 @@ import org.sonar.core.util.CloseableIterator; import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage; import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReportWriter; +import org.sonar.scanner.scan.BranchConfiguration; import org.sonar.scanner.scan.filesystem.InputComponentStore; import org.sonar.scanner.scan.measure.MeasureCache; @@ -58,7 +59,7 @@ public class CoveragePublisherTest { String moduleKey = "foo"; inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).build(); DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder()); - InputComponentStore componentCache = new InputComponentStore(rootModule, mock(AnalysisMode.class)); + InputComponentStore componentCache = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); componentCache.put(inputFile); measureCache = mock(MeasureCache.class); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java index 3e5c7d507e5..31a60b633c8 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java @@ -39,6 +39,7 @@ import org.sonar.scanner.deprecated.test.TestPlanBuilder; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReportWriter; +import org.sonar.scanner.scan.BranchConfiguration; import org.sonar.scanner.scan.filesystem.InputComponentStore; import org.sonar.scanner.scan.measure.MeasureCache; @@ -69,7 +70,7 @@ public class MeasuresPublisherTest { String moduleKey = "foo"; inputModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder()); inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setPublish(true).build(); - InputComponentStore componentCache = new InputComponentStore(inputModule, mock(AnalysisMode.class)); + InputComponentStore componentCache = new InputComponentStore(inputModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); componentCache.put(inputFile); measureCache = mock(MeasureCache.class); when(measureCache.byComponentKey(anyString())).thenReturn(Collections.<DefaultMeasure<?>>emptyList()); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java index 60b51e5a8f2..b859b3962e8 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java @@ -33,6 +33,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.scanner.protocol.output.ScannerReportWriter; +import org.sonar.scanner.scan.BranchConfiguration; import org.sonar.scanner.scan.filesystem.InputComponentStore; import static org.assertj.core.api.Assertions.assertThat; @@ -62,7 +63,7 @@ public class SourcePublisherTest { DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, baseDir); analysisMode = mock(AnalysisMode.class); - InputComponentStore componentStore = new InputComponentStore(rootModule, analysisMode); + InputComponentStore componentStore = new InputComponentStore(rootModule, analysisMode, mock(BranchConfiguration.class)); componentStore.put(inputFile); publisher = new SourcePublisher(componentStore); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java index a11e500c302..e9d075d327e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java @@ -38,7 +38,7 @@ public class ModuleIndexerTest { private InputComponentStore componentStore; public void createIndexer(DefaultInputModule rootModule) { - componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class)); + componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); tree = new DefaultComponentTree(); moduleHierarchy = mock(DefaultInputModuleHierarchy.class); indexer = new ModuleIndexer(tree, componentStore, moduleHierarchy); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java index 8d3f530c25f..aacfb609f52 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java @@ -36,6 +36,7 @@ import org.sonar.api.batch.fs.InputPath; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; +import org.sonar.scanner.scan.BranchConfiguration; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -59,7 +60,7 @@ public class InputComponentStoreTest { DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef); DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(moduleDef); - InputComponentStore cache = new InputComponentStore(rootModule, mock(AnalysisMode.class)); + InputComponentStore cache = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); cache.put(subModule); DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java") @@ -103,7 +104,7 @@ public class InputComponentStoreTest { static class InputComponentStoreTester extends InputComponentStore { InputComponentStoreTester() throws IOException { - super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(AnalysisMode.class)); + super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(AnalysisMode.class), mock(BranchConfiguration.class)); } InputFile addFile(String moduleKey, String relpath, String language) { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java index 0911d7436c7..9856377a92c 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java @@ -30,6 +30,7 @@ import org.sonar.api.batch.fs.InputModule; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.SensorStrategy; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; +import org.sonar.scanner.scan.BranchConfiguration; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -48,7 +49,7 @@ public class ModuleInputComponentStoreTest { @Before public void setUp() throws IOException { DefaultInputModule root = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder()); - componentStore = new InputComponentStore(root, mock(AnalysisMode.class)); + componentStore = new InputComponentStore(root, mock(AnalysisMode.class), mock(BranchConfiguration.class)); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java index 148dabfdab9..4b005062ddb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java @@ -48,6 +48,7 @@ import org.sonar.api.platform.Server; import org.sonar.api.rule.RuleKey; import org.sonar.scanner.issue.IssueCache; import org.sonar.scanner.issue.tracking.TrackedIssue; +import org.sonar.scanner.scan.BranchConfiguration; import org.sonar.scanner.scan.DefaultComponentTree; import org.sonar.scanner.scan.filesystem.InputComponentStore; @@ -83,7 +84,7 @@ public class JSONReportTest { DefaultComponentTree inputComponentTree = new DefaultComponentTree(); ProjectDefinition def = ProjectDefinition.create().setBaseDir(projectBaseDir).setWorkDir(temp.newFolder()).setKey("struts"); DefaultInputModule rootModule = new DefaultInputModule(def, 1); - InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class)); + InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); DefaultInputModule moduleA = new DefaultInputModule(ProjectDefinition.create().setKey("struts-core").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder())); inputComponentTree.index(moduleA, rootModule); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java index 92c62a33436..aa62800ee91 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java @@ -91,7 +91,7 @@ public class DefaultSensorContextTest { @Test public void shouldSkipDupsAndCoverageOnShortBranches() { - when(branchConfig.branchType()).thenReturn(BranchConfiguration.BranchType.SHORT); + when(branchConfig.isShortLivingBranch()).thenReturn(true); assertThat(adaptor.newCpdTokens()).isEqualTo(DefaultSensorContext.NO_OP_NEW_CPD_TOKENS); assertThat(adaptor.newCoverage()).isEqualTo(DefaultSensorContext.NO_OP_NEW_COVERAGE); } |