Search in sources :

Example 11 with SonarLintWsClient

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

the class SettingsDownloaderTest method testFetchProjectSettings.

@Test
public void testFetchProjectSettings() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    Settings.FieldValues.Value.Builder valuesBuilder = Value.newBuilder();
    valuesBuilder.getMutableValue().put("filepattern", "**/*.xml");
    valuesBuilder.getMutableValue().put("rulepattern", "*:S12345");
    Value value1 = valuesBuilder.build();
    valuesBuilder.clear();
    valuesBuilder.getMutableValue().put("filepattern", "**/*.java");
    valuesBuilder.getMutableValue().put("rulepattern", "*:S456");
    Value value2 = valuesBuilder.build();
    ValuesWsResponse response = ValuesWsResponse.newBuilder().addSettings(Setting.newBuilder().setKey("sonar.inclusions").setValues(Values.newBuilder().addValues("**/*.java"))).addSettings(Setting.newBuilder().setKey("sonar.java.fileSuffixes").setValue("*.java")).addSettings(Setting.newBuilder().setKey("sonar.issue.exclusions.multicriteria").setFieldValues(FieldValues.newBuilder().addFieldValues(value1).addFieldValues(value2)).build()).build();
    PipedInputStream in = new PipedInputStream();
    final PipedOutputStream out = new PipedOutputStream(in);
    response.writeTo(out);
    out.close();
    WsClientTestUtils.addResponse(wsClient, "/api/settings/values.protobuf?component=foo", in);
    Builder builder = ModuleConfiguration.newBuilder();
    new SettingsDownloader(wsClient).fetchProjectSettings("6.3", "foo", null, builder);
    assertThat(builder.getPropertiesMap()).containsOnly(entry("sonar.inclusions", "**/*.java"), entry("sonar.java.fileSuffixes", "*.java"), entry("sonar.issue.exclusions.multicriteria", "1,2"), entry("sonar.issue.exclusions.multicriteria.1.filepattern", "**/*.xml"), entry("sonar.issue.exclusions.multicriteria.1.rulepattern", "*:S12345"), entry("sonar.issue.exclusions.multicriteria.2.filepattern", "**/*.java"), entry("sonar.issue.exclusions.multicriteria.2.rulepattern", "*:S456"));
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder) Value(org.sonarqube.ws.Settings.FieldValues.Value) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Settings(org.sonarqube.ws.Settings) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 12 with SonarLintWsClient

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

the class SettingsDownloaderTest method testFetchProjectProperties_exclude_global_props.

@Test
public void testFetchProjectProperties_exclude_global_props() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithReaderResponse("/api/properties?format=json&resource=foo", new StringReader("[{\"key\": \"sonar.inclusions\",\"value\": \"**/*.java\"}," + "{\"key\": \"sonar.java.fileSuffixes\",\"value\": \"*.java\"}]"));
    Builder builder = ModuleConfiguration.newBuilder();
    new SettingsDownloader(wsClient).fetchProjectSettings("6.2", "foo", GlobalProperties.newBuilder().putProperties("sonar.inclusions", "**/*.java").build(), builder);
    assertThat(builder.getPropertiesMap()).containsOnly(entry("sonar.java.fileSuffixes", "*.java"));
}
Also used : Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder) StringReader(java.io.StringReader) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 13 with SonarLintWsClient

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

the class AuthenticationCheckerTest method test_authentication_ok.

@Test
public void test_authentication_ok() {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/authentication/validate?format=json", "{\"valid\": true}");
    AuthenticationChecker checker = new AuthenticationChecker(wsClient);
    ValidationResult validationResult = checker.validateCredentials();
    assertThat(validationResult.success()).isTrue();
    assertThat(validationResult.message()).isEqualTo("Authentication successful");
}
Also used : ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 14 with SonarLintWsClient

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

the class ServerVersionAndStatusCheckerTest method failWhenIncompatibleVersion.

@Test
public void failWhenIncompatibleVersion() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/system/status", "{\"id\": \"20160308094653\",\"version\": \"4.5\",\"status\": \"UP\"}");
    ServerVersionAndStatusChecker checker = new ServerVersionAndStatusChecker(wsClient);
    try {
        checker.checkVersionAndStatus();
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(UnsupportedServerException.class).hasMessage("SonarQube server has version 4.5. Version should be greater or equal to 5.6");
    }
}
Also used : NotFoundException(org.sonarsource.sonarlint.core.container.connected.exceptions.NotFoundException) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 15 with SonarLintWsClient

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

the class ServerVersionAndStatusCheckerTest method report_original_error_if_fallback_failed.

@Test
public void report_original_error_if_fallback_failed() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    WsClientTestUtils.addFailedResponse(wsClient, "api/system/status", HttpURLConnection.HTTP_NOT_FOUND, "Not found");
    WsClientTestUtils.addFailedResponse(wsClient, "api/server/version", HttpURLConnection.HTTP_UNAUTHORIZED, "Unauthorized");
    ServerVersionAndStatusChecker checker = new ServerVersionAndStatusChecker(wsClient);
    try {
        checker.checkVersionAndStatus();
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(NotFoundException.class).hasMessage("Error 404 on api/system/status");
    }
}
Also used : NotFoundException(org.sonarsource.sonarlint.core.container.connected.exceptions.NotFoundException) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException) 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