use of org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory 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();
}
use of org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory in project sonarlint-core by SonarSource.
the class ModuleStorageUpdateExecutorTest method exception_ws_load_qps.
@Test
public void exception_ws_load_qps() throws IOException {
when(wsClient.get(getQualityProfileUrl())).thenThrow(IOException.class);
File destDir = temp.newFolder();
QProfiles.Builder builder = QProfiles.newBuilder();
builder.putQprofilesByKey("java-empty-74333", QProfiles.QProfile.newBuilder().build());
when(storageReader.readQProfiles()).thenReturn(builder.build());
when(storagePaths.getModuleStorageRoot(MODULE_KEY_WITH_BRANCH)).thenReturn(destDir.toPath());
moduleUpdate = new ModuleStorageUpdateExecutor(storageReader, storagePaths, wsClient, (key) -> Collections.emptyList(), issueStoreFactory, tempFolder, moduleConfigurationDownloader);
exception.expect(IllegalStateException.class);
exception.expectMessage("Failed to load module quality profiles");
moduleUpdate.update(MODULE_KEY_WITH_BRANCH, new ProgressWrapper(null));
}
use of org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory in project sonarlint-core by SonarSource.
the class ModuleStorageUpdateExecutorTest method setUp.
@Before
public void setUp() throws IOException {
wsClient = WsClientTestUtils.createMockWithStreamResponse(getQualityProfileUrl(), "/update/qualityprofiles_project.pb");
when(wsClient.getOrganizationKey()).thenReturn(organizationKey);
WsClientTestUtils.addResponse(wsClient, "/api/properties?format=json&resource=" + MODULE_KEY_WITH_BRANCH_URLENCODED, "[{\"key\":\"sonar.qualitygate\",\"value\":\"1\",\"values\": []}," + "{\"key\":\"sonar.core.version\",\"value\":\"5.5-SNAPSHOT\"}," + "{\"key\":\"sonar.java.someProp\",\"value\":\"foo\"}]");
WsClientTestUtils.addResponse(wsClient, "/batch/issues?key=" + MODULE_KEY_WITH_BRANCH_URLENCODED, newEmptyStream());
File tempDir = temp.newFolder();
tempFolder = mock(TempFolder.class);
when(tempFolder.newDir()).thenReturn(tempDir);
storagePaths = mock(StoragePaths.class);
storageReader = mock(StorageReader.class);
org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties.Builder propBuilder = GlobalProperties.newBuilder();
propBuilder.getMutableProperties().put("sonar.qualitygate", "2");
propBuilder.getMutableProperties().put("sonar.core.version", "5.5-SNAPSHOT");
when(storageReader.readGlobalProperties()).thenReturn(propBuilder.build());
when(storageReader.readServerInfos()).thenReturn(ServerInfos.newBuilder().build());
moduleHierarchy = mock(ModuleHierarchyDownloader.class);
Map<String, String> modulesPath = new HashMap<>();
modulesPath.put(MODULE_KEY_WITH_BRANCH, "");
modulesPath.put(MODULE_KEY_WITH_BRANCH + "child1", "child 1");
when(moduleHierarchy.fetchModuleHierarchy(eq(MODULE_KEY_WITH_BRANCH), any(ProgressWrapper.class))).thenReturn(modulesPath);
issueStoreFactory = mock(IssueStoreFactory.class);
issueStore = new InMemoryIssueStore();
when(issueStoreFactory.apply(any(Path.class))).thenReturn(issueStore);
moduleConfigurationDownloader = new ModuleConfigurationDownloader(moduleHierarchy, new ModuleQualityProfilesDownloader(wsClient), mock(SettingsDownloader.class));
}
use of org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory in project sonarlint-core by SonarSource.
the class ModuleStorageUpdateExecutorTest method test_error_if_qp_doesnt_exist.
@Test
public void test_error_if_qp_doesnt_exist() throws IOException {
File destDir = temp.newFolder();
QProfiles.Builder builder = QProfiles.newBuilder();
Map<String, QProfiles.QProfile> mutableQprofilesByKey = builder.getMutableQprofilesByKey();
mutableQprofilesByKey.put("cs-sonar-way-58886", QProfiles.QProfile.newBuilder().build());
mutableQprofilesByKey.put("java-empty-74333", QProfiles.QProfile.newBuilder().build());
mutableQprofilesByKey.put("xoo2-basic-34035", QProfiles.QProfile.newBuilder().build());
when(storageReader.readQProfiles()).thenReturn(builder.build());
when(storagePaths.getModuleStorageRoot(MODULE_KEY_WITH_BRANCH)).thenReturn(destDir.toPath());
moduleUpdate = new ModuleStorageUpdateExecutor(storageReader, storagePaths, wsClient, (key) -> Collections.emptyList(), issueStoreFactory, tempFolder, moduleConfigurationDownloader);
exception.expect(IllegalStateException.class);
exception.expectMessage("is associated to quality profile 'js-sonar-way-60746' that is not in the storage");
moduleUpdate.update(MODULE_KEY_WITH_BRANCH, new ProgressWrapper(null));
}
use of org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory 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);
}
Aggregations