Search in sources :

Example 6 with SonarLintWsClient

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

Example 7 with SonarLintWsClient

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

the class SettingsDownloaderTest method invalidResponseSettings.

@Test(expected = IllegalStateException.class)
public void invalidResponseSettings() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    WsClientTestUtils.addResponse(wsClient, "/api/settings/values.protobuf", new ByteArrayInputStream("foo bar".getBytes()));
    new SettingsDownloader(wsClient).fetchGlobalSettingsTo("6.3", destDir);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 8 with SonarLintWsClient

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

the class SettingsDownloaderTest method testFetchGlobalProperties.

@Test
public void testFetchGlobalProperties() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithReaderResponse("/api/properties?format=json", new StringReader("[{\"key\": \"sonar.core.treemap.colormetric\",\"value\": \"violations_density\"}," + "{\"key\": \"sonar.core.treemap.sizemetric\",\"value\": \"ncloc\"}," + "{\"key\": \"views.servers\",\"value\": \"135817900907501\",\"values\": [\"135817900907501\"]}]"));
    new SettingsDownloader(wsClient).fetchGlobalSettingsTo("6.2", destDir);
    GlobalProperties properties = ProtobufUtil.readFile(destDir.resolve(StoragePaths.PROPERTIES_PB), GlobalProperties.parser());
    assertThat(properties.getPropertiesMap()).containsOnly(entry("sonar.core.treemap.colormetric", "violations_density"), entry("sonar.core.treemap.sizemetric", "ncloc"), entry("views.servers", "135817900907501"));
}
Also used : GlobalProperties(org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties) StringReader(java.io.StringReader) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 9 with SonarLintWsClient

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

the class SettingsDownloaderTest method testFetchGlobalSettings.

@Test
public void testFetchGlobalSettings() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    ValuesWsResponse response = ValuesWsResponse.newBuilder().addSettings(Setting.newBuilder().setKey("sonar.core.treemap.colormetric").setValue("violations_density").setInherited(true)).addSettings(Setting.newBuilder().setKey("sonar.core.treemap.sizemetric").setValue("ncloc")).addSettings(Setting.newBuilder().setKey("views.servers").setValues(Values.newBuilder().addValues("135817900907501"))).build();
    PipedInputStream in = new PipedInputStream();
    final PipedOutputStream out = new PipedOutputStream(in);
    response.writeTo(out);
    out.close();
    WsClientTestUtils.addResponse(wsClient, "/api/settings/values.protobuf", in);
    new SettingsDownloader(wsClient).fetchGlobalSettingsTo("6.3", destDir);
    GlobalProperties properties = ProtobufUtil.readFile(destDir.resolve(StoragePaths.PROPERTIES_PB), GlobalProperties.parser());
    assertThat(properties.getPropertiesMap()).containsOnly(entry("sonar.core.treemap.sizemetric", "ncloc"), entry("views.servers", "135817900907501"));
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) GlobalProperties(org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 10 with SonarLintWsClient

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

the class SettingsDownloaderTest method invalidResponseProperties.

@Test(expected = IllegalStateException.class)
public void invalidResponseProperties() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithReaderResponse("/api/properties?format=json", new StringReader("foo bar"));
    new SettingsDownloader(wsClient).fetchGlobalSettingsTo("6.2", destDir);
}
Also used : StringReader(java.io.StringReader) 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