Search in sources :

Example 1 with ProgressWrapper

use of org.sonarsource.sonarlint.core.util.ProgressWrapper in project sonarlint-core by SonarSource.

the class WsHelperImplTest method testListOrganizations.

@Test
public void testListOrganizations() {
    WsClientTestUtils.addStreamResponse(client, "api/organizations/search.protobuf?ps=500&p=1", "/orgs/orgsp1.pb");
    WsClientTestUtils.addStreamResponse(client, "api/organizations/search.protobuf?ps=500&p=2", "/orgs/orgsp2.pb");
    WsClientTestUtils.addStreamResponse(client, "api/organizations/search.protobuf?ps=500&p=3", "/orgs/orgsp3.pb");
    List<RemoteOrganization> orgs = WsHelperImpl.listOrganizations(client, serverChecker, new ProgressWrapper(null));
    assertThat(orgs).hasSize(4);
    verify(serverChecker).checkVersionAndStatus("6.3");
    when(serverChecker.checkVersionAndStatus("6.3")).thenThrow(UnsupportedServerException.class);
    try {
        WsHelperImpl.listOrganizations(client, serverChecker, new ProgressWrapper(null));
        fail("Expected exception");
    } catch (UnsupportedServerException e) {
    // Success
    }
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) RemoteOrganization(org.sonarsource.sonarlint.core.client.api.connected.RemoteOrganization) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException) Test(org.junit.Test)

Example 2 with ProgressWrapper

use of org.sonarsource.sonarlint.core.util.ProgressWrapper in project sonarlint-core by SonarSource.

the class ModuleHierarchyDownloaderTest method simpleTest.

@Test
public void simpleTest() {
    WsClientTestUtils.addStreamResponse(wsClient, "api/components/tree.protobuf?qualifiers=BRC&baseComponentKey=testRoot&ps=500&p=1", "/update/tree.pb");
    WsClientTestUtils.addStreamResponse(wsClient, "api/components/show.protobuf?id=AVeumyM5SDj1uJJMtck2", "/update/show_module1.pb");
    WsClientTestUtils.addStreamResponse(wsClient, "api/components/show.protobuf?id=AVeumyM5SDj1uJJMtck3", "/update/show_module1_module11.pb");
    WsClientTestUtils.addStreamResponse(wsClient, "api/components/show.protobuf?id=AVeumyM5SDj1uJJMtck6", "/update/show_module1_module12.pb");
    WsClientTestUtils.addStreamResponse(wsClient, "api/components/show.protobuf?id=AVeumyM5SDj1uJJMtck9", "/update/show_module2.pb");
    Map<String, String> fetchModuleHierarchy = downloader.fetchModuleHierarchy("testRoot", new ProgressWrapper(null));
    assertThat(fetchModuleHierarchy).contains(entry("testRoot", ""), entry("testRoot:module1", "module1"), entry("testRoot:module2", "module2"), entry("testRoot:module1:module12", "module1/module12"), entry("testRoot:module1:module11", "module1/module11"));
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) Test(org.junit.Test)

Example 3 with ProgressWrapper

use of org.sonarsource.sonarlint.core.util.ProgressWrapper in project sonarlint-core by SonarSource.

the class ModuleListDownloaderTest method update_modules_before_6_dot_3.

@Test
public void update_modules_before_6_dot_3() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    WsClientTestUtils.addReaderResponse(wsClient, "api/projects/index?format=json&subprojects=true", "/update/all_projects.json");
    File tempDir = temp.newFolder();
    ModuleListDownloader moduleListUpdate = new ModuleListDownloader(wsClient);
    moduleListUpdate.fetchModulesListTo(tempDir.toPath(), "6.2", new ProgressWrapper(null));
    ModuleList moduleList = ProtobufUtil.readFile(tempDir.toPath().resolve(StoragePaths.MODULE_LIST_PB), ModuleList.parser());
    assertThat(moduleList.getModulesByKeyMap()).hasSize(1559);
    assertThat(moduleList.getModulesByKeyMap().values()).extracting("qu").contains("TRK", "BRC");
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ModuleList(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleList) File(java.io.File) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 4 with ProgressWrapper

use of org.sonarsource.sonarlint.core.util.ProgressWrapper in project sonarlint-core by SonarSource.

the class RulesDownloaderTest method errorReadingStream.

@Test
public void errorReadingStream() throws IOException {
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    InputStream stream = new ByteArrayInputStream("trash".getBytes(StandardCharsets.UTF_8));
    WsClientTestUtils.addResponse(wsClient, RULES_SEARCH_URL + "&p=1&ps=500", stream);
    RulesDownloader rulesUpdate = new RulesDownloader(wsClient);
    File tempDir = temp.newFolder();
    exception.expect(IllegalStateException.class);
    exception.expectMessage("Failed to load rules");
    rulesUpdate.fetchRulesTo(tempDir.toPath(), new ProgressWrapper(null));
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) File(java.io.File) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 5 with ProgressWrapper

use of org.sonarsource.sonarlint.core.util.ProgressWrapper in project sonarlint-core by SonarSource.

the class RulesDownloaderTest method unknown_type.

@Test
public void unknown_type() throws IOException {
    org.sonarqube.ws.Rules.SearchResponse response = org.sonarqube.ws.Rules.SearchResponse.newBuilder().addRules(org.sonarqube.ws.Rules.Rule.newBuilder().setKey("S:101").build()).build();
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    WsClientTestUtils.addResponse(wsClient, RULES_SEARCH_URL + "&p=1&ps=500", response);
    RulesDownloader rulesUpdate = new RulesDownloader(wsClient);
    File tempDir = temp.newFolder();
    rulesUpdate.fetchRulesTo(tempDir.toPath(), new ProgressWrapper(null));
    Rules saved = ProtobufUtil.readFile(tempDir.toPath().resolve(StoragePaths.RULES_PB), Rules.parser());
    assertThat(saved.getRulesByKeyMap()).hasSize(1);
    assertThat(saved.getRulesByKeyMap().get("S:101").getType()).isEqualTo("");
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) Rules(org.sonarsource.sonarlint.core.proto.Sonarlint.Rules) ActiveRules(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules) File(java.io.File) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Aggregations

ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)38 Test (org.junit.Test)31 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)14 File (java.io.File)11 StorageUpdateCheckResult (org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult)9 GlobalProperties (org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties)8 Map (java.util.Map)6 Nullable (javax.annotation.Nullable)6 ServerInfos (org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)6 Path (java.nio.file.Path)5 IssueListener (org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener)5 IOException (java.io.IOException)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.entry (org.assertj.core.api.Assertions.entry)4 Before (org.junit.Before)4 Rule (org.junit.Rule)4 ExpectedException (org.junit.rules.ExpectedException)4