Search in sources :

Example 1 with SonarLintWsClient

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

the class IssueDownloaderImplTest method test_code404.

@Test
public void test_code404() throws IOException {
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    String key = "dummyKey";
    WsClientTestUtils.addFailedResponse(wsClient, "/batch/issues?key=" + key, 404, "");
    IssueDownloader issueDownloader = new IssueDownloaderImpl(wsClient);
    assertThat(issueDownloader.apply(key)).isEmpty();
}
Also used : SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 2 with SonarLintWsClient

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

the class IssueDownloaderImplTest method test_download.

@Test
public void test_download() throws IOException {
    ScannerInput.ServerIssue issue = ScannerInput.ServerIssue.newBuilder().build();
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    String key = "dummyKey";
    try (InputStream inputStream = new ByteArrayInputStream(toByteArray(issue))) {
        WsClientTestUtils.addResponse(wsClient, "/batch/issues?key=" + key, inputStream);
    }
    IssueDownloader issueDownloader = new IssueDownloaderImpl(wsClient);
    assertThat(issueDownloader.apply(key)).containsOnly(issue);
}
Also used : ScannerInput(org.sonar.scanner.protocol.input.ScannerInput) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 3 with SonarLintWsClient

use of org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient 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 SonarLintWsClient

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

the class QualityProfilesDownloaderTest method testParsingError.

@Test
public void testParsingError() throws IOException {
    // wrong file
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithStreamResponse("/api/qualityprofiles/search.protobuf", "/update/all_projects.json");
    qProfilesDownloader = new QualityProfilesDownloader(wsClient);
    exception.expect(IllegalStateException.class);
    exception.expectMessage("Failed to load default quality profiles");
    qProfilesDownloader.fetchQualityProfilesTo(temp.getRoot().toPath());
}
Also used : SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 5 with SonarLintWsClient

use of org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient 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)

Aggregations

SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)40 Test (org.junit.Test)37 ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)8 File (java.io.File)7 UnsupportedServerException (org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)6 NotFoundException (org.sonarsource.sonarlint.core.container.connected.exceptions.NotFoundException)6 ValidationResult (org.sonarsource.sonarlint.core.client.api.connected.ValidationResult)5 StringReader (java.io.StringReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ZonedDateTime (java.time.ZonedDateTime)3 SonarQubeNotification (org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification)3 ActiveRules (org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules)3 Builder (org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder)3 ModuleList (org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleList)3 Rules (org.sonarsource.sonarlint.core.proto.Sonarlint.Rules)3 InputStream (java.io.InputStream)2 PipedInputStream (java.io.PipedInputStream)2 PipedOutputStream (java.io.PipedOutputStream)2 ValuesWsResponse (org.sonarqube.ws.Settings.ValuesWsResponse)2 GlobalProperties (org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties)2