diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-08 15:23:15 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-09-07 08:33:31 +0200 |
commit | 6f777618d0ec3283600bccaae820a8b8783356db (patch) | |
tree | e0045b4286c4c67b0bbff27fc83a10828f95dcf9 /sonar-scanner-engine/src/test | |
parent | e4ec4b3ee79847c5bbbdce748982e4f1f18f7753 (diff) | |
download | sonarqube-6f777618d0ec3283600bccaae820a8b8783356db.tar.gz sonarqube-6f777618d0ec3283600bccaae820a8b8783356db.zip |
SONAR-9679 Add plugins and their updated_at date to the scanner report
Diffstat (limited to 'sonar-scanner-engine/src/test')
3 files changed, 34 insertions, 6 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java index 967c5c8f351..59bc8fc8c53 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java @@ -28,6 +28,7 @@ import org.sonar.core.platform.PluginLoader; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; import static org.mockito.Matchers.anyCollectionOf; +import static org.mockito.Matchers.anyMapOf; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -41,14 +42,15 @@ public class ScannerPluginRepositoryTest { @Test public void install_and_load_plugins() { PluginInfo info = new PluginInfo("squid"); - ImmutableMap<String, PluginInfo> infos = ImmutableMap.of("squid", info); + ImmutableMap<String, ScannerPlugin> plugins = ImmutableMap.of("squid", new ScannerPlugin("squid", 1L, info)); Plugin instance = mock(Plugin.class); - when(loader.load(infos)).thenReturn(ImmutableMap.of("squid", instance)); - when(installer.installRemotes()).thenReturn(infos); + when(loader.load(anyMapOf(String.class, PluginInfo.class))).thenReturn(ImmutableMap.of("squid", instance)); + when(installer.installRemotes()).thenReturn(plugins); underTest.start(); assertThat(underTest.getPluginInfos()).containsOnly(info); + assertThat(underTest.getPluginsByKey()).isEqualTo(plugins); assertThat(underTest.getPluginInfo("squid")).isSameAs(info); assertThat(underTest.getPluginInstance("squid")).isSameAs(instance); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java index 92d0cd0598f..e572f184aa2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java @@ -106,12 +106,20 @@ public class ScannerMediumTester extends ExternalResource { } public ScannerMediumTester registerPlugin(String pluginKey, File location) { - pluginInstaller.add(pluginKey, location); + return registerPlugin(pluginKey, location, 1L); + } + + public ScannerMediumTester registerPlugin(String pluginKey, File location, long lastUpdatedAt) { + pluginInstaller.add(pluginKey, location, lastUpdatedAt); return this; } public ScannerMediumTester registerPlugin(String pluginKey, Plugin instance) { - pluginInstaller.add(pluginKey, instance); + return registerPlugin(pluginKey, instance, 1L); + } + + public ScannerMediumTester registerPlugin(String pluginKey, Plugin instance, long lastUpdatedAt) { + pluginInstaller.add(pluginKey, instance, lastUpdatedAt); return this; } 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 fbe8a44cf43..a949364d429 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 @@ -19,6 +19,7 @@ */ package org.sonar.scanner.report; +import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; import java.util.Date; @@ -34,6 +35,8 @@ import org.sonar.api.batch.fs.internal.InputModuleHierarchy; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.config.internal.MapSettings; import org.sonar.scanner.ProjectAnalysisInfo; +import org.sonar.scanner.bootstrap.ScannerPlugin; +import org.sonar.scanner.bootstrap.ScannerPluginRepository; import org.sonar.scanner.cpd.CpdSettings; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReportReader; @@ -42,6 +45,7 @@ import org.sonar.scanner.rule.ModuleQProfiles; import org.sonar.scanner.rule.QProfile; import static java.util.Arrays.asList; +import static java.util.Collections.emptyMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import static org.mockito.Mockito.mock; @@ -60,6 +64,7 @@ public class MetadataPublisherTest { private CpdSettings cpdSettings; private InputModuleHierarchy inputModuleHierarchy; private AnalysisMode analysisMode; + private ScannerPluginRepository pluginRepository; @Before public void prepare() throws IOException { @@ -68,7 +73,9 @@ public class MetadataPublisherTest { when(projectAnalysisInfo.analysisDate()).thenReturn(new Date(1234567L)); settings = new MapSettings(); qProfiles = mock(ModuleQProfiles.class); + pluginRepository = mock(ScannerPluginRepository.class); createPublisher(ProjectDefinition.create().setKey("foo")); + when(pluginRepository.getPluginsByKey()).thenReturn(emptyMap()); } private void createPublisher(ProjectDefinition def) throws IOException { @@ -76,7 +83,7 @@ public class MetadataPublisherTest { inputModuleHierarchy = mock(InputModuleHierarchy.class); when(inputModuleHierarchy.root()).thenReturn(rootModule); analysisMode = mock(AnalysisMode.class); - underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings.asConfig(), qProfiles, cpdSettings, analysisMode); + underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings.asConfig(), qProfiles, cpdSettings, analysisMode, pluginRepository); } @Test @@ -84,6 +91,9 @@ public class MetadataPublisherTest { settings.setProperty(CoreProperties.CPD_CROSS_PROJECT, "true"); Date date = new Date(); when(qProfiles.findAll()).thenReturn(asList(new QProfile("q1", "Q1", "java", date))); + when(pluginRepository.getPluginsByKey()).thenReturn(ImmutableMap.of( + "java", new ScannerPlugin("java", 12345L, null), + "php", new ScannerPlugin("php", 45678L, null))); File outputDir = temp.newFolder(); ScannerReportWriter writer = new ScannerReportWriter(outputDir); @@ -101,6 +111,14 @@ public class MetadataPublisherTest { .setLanguage("java") .setRulesUpdatedAt(date.getTime()) .build())); + assertThat(metadata.getPluginsByKey()).containsOnly(entry("java", org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin.newBuilder() + .setKey("java") + .setUpdatedAt(12345) + .build()), + entry("php", org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin.newBuilder() + .setKey("php") + .setUpdatedAt(45678) + .build())); } @Test |