aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scanner/report
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2020-09-11 14:30:31 +0200
committersonartech <sonartech@sonarsource.com>2020-09-29 20:07:41 +0000
commit8a94f2ffc23369e675fceb34c03c98e1535d49d6 (patch)
treec5eb21cccc85b7d73af13e201387e52d51659156 /sonar-scanner-engine/src/test/java/org/sonar/scanner/report
parent4b3d914bf578d1eb88fc9ca79efef00843511865 (diff)
downloadsonarqube-8a94f2ffc23369e675fceb34c03c98e1535d49d6.tar.gz
sonarqube-8a94f2ffc23369e675fceb34c03c98e1535d49d6.zip
SONAR-13867 Collect number of indexed C/C++ files in the scanner
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner/report')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java12
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java47
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java3
3 files changed, 41 insertions, 21 deletions
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 c1458524e51..74bc606295f 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
@@ -27,6 +27,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
+import org.sonar.api.SonarRuntime;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Type;
@@ -49,6 +50,9 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class ComponentsPublisherTest {
+
+ private final SonarRuntime sonarRuntime = mock(SonarRuntime.class);
+
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@@ -77,7 +81,7 @@ public class ComponentsPublisherTest {
.setWorkDir(temp.newFolder());
DefaultInputProject project = new DefaultInputProject(rootDef, 1);
- InputComponentStore store = new InputComponentStore(branchConfiguration);
+ InputComponentStore store = new InputComponentStore(branchConfiguration, sonarRuntime);
Path moduleBaseDir = temp.newFolder().toPath();
ProjectDefinition module1Def = ProjectDefinition.create()
@@ -143,7 +147,7 @@ public class ComponentsPublisherTest {
.setWorkDir(temp.newFolder());
DefaultInputProject project = new DefaultInputProject(rootDef, 1);
- InputComponentStore store = new InputComponentStore(branchConfiguration);
+ InputComponentStore store = new InputComponentStore(branchConfiguration, sonarRuntime);
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.java", 5)
.setLines(2)
@@ -180,7 +184,7 @@ public class ComponentsPublisherTest {
.setWorkDir(temp.newFolder());
DefaultInputProject project = new DefaultInputProject(rootDef, 1);
- InputComponentStore store = new InputComponentStore(branchConfiguration);
+ InputComponentStore store = new InputComponentStore(branchConfiguration, sonarRuntime);
ComponentsPublisher publisher = new ComponentsPublisher(project, store);
publisher.publish(writer);
@@ -210,7 +214,7 @@ public class ComponentsPublisherTest {
.setWorkDir(temp.newFolder());
DefaultInputProject project = new DefaultInputProject(rootDef, 1);
- InputComponentStore store = new InputComponentStore(branchConfiguration);
+ InputComponentStore store = new InputComponentStore(branchConfiguration, sonarRuntime);
ComponentsPublisher publisher = new ComponentsPublisher(project, store);
publisher.publish(writer);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java
index 53d37e99363..f6f176d8cff 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java
@@ -56,6 +56,7 @@ import org.sonar.scanner.rule.QualityProfiles;
import org.sonar.scanner.scan.ScanProperties;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import org.sonar.scanner.scan.branch.BranchType;
+import org.sonar.scanner.scan.filesystem.InputComponentStore;
import org.sonar.scanner.scm.ScmConfiguration;
import org.sonar.scanner.scm.ScmRevision;
@@ -73,19 +74,18 @@ public class MetadataPublisherTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
- private DefaultInputModule rootModule;
private MetadataPublisher underTest;
- private ScanProperties properties = mock(ScanProperties.class);
- private QualityProfiles qProfiles = mock(QualityProfiles.class);
- private ProjectInfo projectInfo = mock(ProjectInfo.class);
- private CpdSettings cpdSettings = mock(CpdSettings.class);
- private InputModuleHierarchy inputModuleHierarchy;
- private ForkDateSupplier forkDateSupplier = mock(ForkDateSupplier.class);
- private ScannerPluginRepository pluginRepository = mock(ScannerPluginRepository.class);
+ private final ScanProperties properties = mock(ScanProperties.class);
+ private final QualityProfiles qProfiles = mock(QualityProfiles.class);
+ private final ProjectInfo projectInfo = mock(ProjectInfo.class);
+ private final CpdSettings cpdSettings = mock(CpdSettings.class);
+ private final ForkDateSupplier forkDateSupplier = mock(ForkDateSupplier.class);
+ private final ScannerPluginRepository pluginRepository = mock(ScannerPluginRepository.class);
private BranchConfiguration branches;
private ScmConfiguration scmConfiguration;
- private ScmProvider scmProvider = mock(ScmProvider.class);
- private ScmRevision scmRevision = mock(ScmRevision.class);
+ private final ScmProvider scmProvider = mock(ScmProvider.class);
+ private final ScmRevision scmRevision = mock(ScmRevision.class);
+ private final InputComponentStore componentStore = mock(InputComponentStore.class);
@Before
public void prepare() throws IOException {
@@ -101,11 +101,11 @@ public class MetadataPublisherTest {
Path rootBaseDir = temp.newFolder().toPath();
Path moduleBaseDir = rootBaseDir.resolve("moduleDir");
Files.createDirectory(moduleBaseDir);
- rootModule = new DefaultInputModule(def
+ DefaultInputModule rootModule = new DefaultInputModule(def
.setBaseDir(rootBaseDir.toFile())
.setKey("root")
.setWorkDir(temp.newFolder()), TestInputFileBuilder.nextBatchId());
- inputModuleHierarchy = mock(InputModuleHierarchy.class);
+ InputModuleHierarchy inputModuleHierarchy = mock(InputModuleHierarchy.class);
when(inputModuleHierarchy.root()).thenReturn(rootModule);
DefaultInputModule child = new DefaultInputModule(ProjectDefinition.create()
.setKey("module")
@@ -118,7 +118,7 @@ public class MetadataPublisherTest {
scmConfiguration = mock(ScmConfiguration.class);
when(scmConfiguration.provider()).thenReturn(scmProvider);
underTest = new MetadataPublisher(projectInfo, inputModuleHierarchy, properties, qProfiles, cpdSettings,
- pluginRepository, branches, scmRevision, forkDateSupplier, scmConfiguration);
+ pluginRepository, branches, scmRevision, forkDateSupplier, componentStore, scmConfiguration);
}
@Test
@@ -141,6 +141,7 @@ public class MetadataPublisherTest {
assertThat(metadata.getProjectKey()).isEqualTo("root");
assertThat(metadata.getModulesProjectRelativePathByKeyMap()).containsOnly(entry("module", "modulePath"), entry("root", ""));
assertThat(metadata.getProjectVersion()).isEmpty();
+ assertThat(metadata.getNotAnalyzedFilesByLanguageCount()).isZero();
assertThat(metadata.getQprofilesPerLanguageMap()).containsOnly(entry("java", org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile.newBuilder()
.setKey("q1")
.setName("Q1")
@@ -148,9 +149,9 @@ public class MetadataPublisherTest {
.setRulesUpdatedAt(date.getTime())
.build()));
assertThat(metadata.getPluginsByKey()).containsOnly(entry("java", org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin.newBuilder()
- .setKey("java")
- .setUpdatedAt(12345)
- .build()),
+ .setKey("java")
+ .setUpdatedAt(12345)
+ .build()),
entry("php", org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin.newBuilder()
.setKey("php")
.setUpdatedAt(45678)
@@ -158,6 +159,20 @@ public class MetadataPublisherTest {
}
@Test
+ public void write_not_analysed_file_counts() throws Exception {
+ when(componentStore.getNotAnalysedFilesByLanguage()).thenReturn(ImmutableMap.of("c", 10, "cpp", 20));
+
+ File outputDir = temp.newFolder();
+ ScannerReportWriter writer = new ScannerReportWriter(outputDir);
+
+ underTest.publish(writer);
+
+ ScannerReportReader reader = new ScannerReportReader(outputDir);
+ ScannerReport.Metadata metadata = reader.readMetadata();
+ assertThat(metadata.getNotAnalyzedFilesByLanguageMap()).contains(entry("c", 10), entry("cpp", 20));
+ }
+
+ @Test
public void write_project_organization() throws Exception {
when(properties.organizationKey()).thenReturn(Optional.of("SonarSource"));
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 4de345c222f..de69cdaea76 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
@@ -27,6 +27,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.SonarRuntime;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputProject;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
@@ -58,7 +59,7 @@ public class SourcePublisherTest {
.build();
DefaultInputProject rootProject = TestInputFileBuilder.newDefaultInputProject(moduleKey, baseDir);
- InputComponentStore componentStore = new InputComponentStore(mock(BranchConfiguration.class));
+ InputComponentStore componentStore = new InputComponentStore(mock(BranchConfiguration.class), mock(SonarRuntime.class));
componentStore.put(moduleKey, inputFile);
publisher = new SourcePublisher(componentStore);