Search in sources :

Example 1 with IssueDownloader

use of org.sonarsource.sonarlint.core.container.connected.update.IssueDownloader in project sonarlint-core by SonarSource.

the class ModuleStorageUpdateExecutorTest method test_server_issues_are_downloaded_and_stored.

@Test
public void test_server_issues_are_downloaded_and_stored() throws IOException {
    WsClientTestUtils.addResponse(wsClient, getQualityProfileUrl(), newEmptyStream());
    when(storageReader.readQProfiles()).thenReturn(QProfiles.getDefaultInstance());
    when(storagePaths.getModuleStorageRoot(MODULE_KEY_WITH_BRANCH)).thenReturn(temp.newFolder().toPath());
    ScannerInput.ServerIssue fileIssue1 = ScannerInput.ServerIssue.newBuilder().setModuleKey("someModuleKey").setPath("some/path").setRuleKey("squid:x").build();
    ScannerInput.ServerIssue fileIssue2 = ScannerInput.ServerIssue.newBuilder().setModuleKey("someModuleKey").setPath("some/path").setRuleKey("squid:y").build();
    ScannerInput.ServerIssue anotherFileIssue = ScannerInput.ServerIssue.newBuilder().setModuleKey("someModuleKey").setPath("another/path").build();
    ScannerInput.ServerIssue notDownloadedIssue = ScannerInput.ServerIssue.newBuilder().setModuleKey("someModuleKey").setPath("yet/another/path").build();
    IssueDownloader issueDownloader = moduleKey -> Arrays.asList(fileIssue1, fileIssue2, anotherFileIssue);
    moduleUpdate = new ModuleStorageUpdateExecutor(storageReader, storagePaths, wsClient, issueDownloader, issueStoreFactory, tempFolder, moduleConfigurationDownloader);
    moduleUpdate.update(MODULE_KEY_WITH_BRANCH, new ProgressWrapper(null));
    assertThat(issueStore.load(createFileKey(fileIssue1))).containsOnly(fileIssue1, fileIssue2);
    assertThat(issueStore.load(createFileKey(anotherFileIssue))).containsOnly(anotherFileIssue);
    assertThat(issueStore.load(createFileKey(notDownloadedIssue))).isEmpty();
}
Also used : ScannerInput(org.sonar.scanner.protocol.input.ScannerInput) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) IssueStoreFactory(org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) HashMap(java.util.HashMap) StoragePaths(org.sonarsource.sonarlint.core.container.storage.StoragePaths) Map(java.util.Map) QProfiles(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles) Path(java.nio.file.Path) ExpectedException(org.junit.rules.ExpectedException) ModuleConfigurationDownloader(org.sonarsource.sonarlint.core.container.connected.update.ModuleConfigurationDownloader) Nullable(javax.annotation.Nullable) Parameterized(org.junit.runners.Parameterized) TempFolder(org.sonar.api.utils.TempFolder) Before(org.junit.Before) IssueStore(org.sonarsource.sonarlint.core.container.connected.IssueStore) GlobalProperties(org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties) ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ModuleQualityProfilesDownloader(org.sonarsource.sonarlint.core.container.connected.update.ModuleQualityProfilesDownloader) IssueDownloader(org.sonarsource.sonarlint.core.container.connected.update.IssueDownloader) SettingsDownloader(org.sonarsource.sonarlint.core.container.connected.update.SettingsDownloader) StorageReader(org.sonarsource.sonarlint.core.container.storage.StorageReader) ProtobufUtilTest.newEmptyStream(org.sonarsource.sonarlint.core.container.storage.ProtobufUtilTest.newEmptyStream) IOException(java.io.IOException) Test(org.junit.Test) WsClientTestUtils(org.sonarsource.sonarlint.core.WsClientTestUtils) ModuleConfiguration(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration) Mockito.when(org.mockito.Mockito.when) ScannerInput(org.sonar.scanner.protocol.input.ScannerInput) Assertions.entry(org.assertj.core.api.Assertions.entry) File(java.io.File) InMemoryIssueStore(org.sonarsource.sonarlint.core.container.connected.InMemoryIssueStore) Rule(org.junit.Rule) StringUtils(org.sonarsource.sonarlint.core.util.StringUtils) ProtobufUtil(org.sonarsource.sonarlint.core.container.storage.ProtobufUtil) IssueUtils.createFileKey(org.sonarsource.sonarlint.core.container.connected.update.IssueUtils.createFileKey) ModuleHierarchyDownloader(org.sonarsource.sonarlint.core.container.connected.update.ModuleHierarchyDownloader) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) Mockito.mock(org.mockito.Mockito.mock) ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) IssueDownloader(org.sonarsource.sonarlint.core.container.connected.update.IssueDownloader) Test(org.junit.Test)

Example 2 with IssueDownloader

use of org.sonarsource.sonarlint.core.container.connected.update.IssueDownloader in project sonarlint-core by SonarSource.

the class PartialUpdater method create.

public static PartialUpdater create(StorageReader storageReader, StoragePaths storagePaths, ServerConfiguration serverConfig, IssueStoreReader issueStoreReader) {
    SonarLintWsClient client = new SonarLintWsClient(serverConfig);
    IssueStoreFactory issueStoreFactory = new IssueStoreFactory();
    IssueDownloader downloader = new IssueDownloaderImpl(client);
    ModuleListDownloader moduleListDownloader = new ModuleListDownloader(client);
    return new PartialUpdater(issueStoreFactory, downloader, storageReader, storagePaths, issueStoreReader, moduleListDownloader);
}
Also used : IssueDownloader(org.sonarsource.sonarlint.core.container.connected.update.IssueDownloader) IssueDownloaderImpl(org.sonarsource.sonarlint.core.container.connected.update.IssueDownloaderImpl) ModuleListDownloader(org.sonarsource.sonarlint.core.container.connected.update.ModuleListDownloader) IssueStoreFactory(org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)

Aggregations

IssueStoreFactory (org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory)2 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)2 IssueDownloader (org.sonarsource.sonarlint.core.container.connected.update.IssueDownloader)2 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.entry (org.assertj.core.api.Assertions.entry)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 ExpectedException (org.junit.rules.ExpectedException)1 TemporaryFolder (org.junit.rules.TemporaryFolder)1 RunWith (org.junit.runner.RunWith)1 Parameterized (org.junit.runners.Parameterized)1