Search in sources :

Example 36 with SonarLintWsClient

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

the class AuthenticationCheckerTest method test_authentication_ko.

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

Example 37 with SonarLintWsClient

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

the class ServerVersionAndStatusCheckerTest method no_fallback_if_not_404.

@Test
public void no_fallback_if_not_404() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    WsClientTestUtils.addFailedResponse(wsClient, "api/system/status", HttpURLConnection.HTTP_UNAUTHORIZED, "Not authorized");
    ServerVersionAndStatusChecker checker = new ServerVersionAndStatusChecker(wsClient);
    try {
        checker.checkVersionAndStatus();
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(IllegalStateException.class).hasMessage("Not authorized. Please check server credentials.");
    }
}
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 38 with SonarLintWsClient

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

the class ServerVersionAndStatusCheckerTest method incompatibleVersion.

@Test
public void incompatibleVersion() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/system/status", "{\"id\": \"20160308094653\",\"version\": \"4.5\",\"status\": \"UP\"}");
    ServerVersionAndStatusChecker checker = new ServerVersionAndStatusChecker(wsClient);
    ValidationResult validateStatusAndVersion = checker.validateStatusAndVersion();
    assertThat(validateStatusAndVersion.success()).isFalse();
    assertThat(validateStatusAndVersion.message()).isEqualTo("SonarQube server has version 4.5. Version should be greater or equal to 5.6");
}
Also used : ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 39 with SonarLintWsClient

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

the class ServerVersionAndStatusCheckerTest method failWhenServerNotReady.

@Test
public void failWhenServerNotReady() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/system/status", "{\"id\": \"20160308094653\",\"version\": \"5.5-SNAPSHOT\",\"status\": \"DOWN\"}");
    ServerVersionAndStatusChecker checker = new ServerVersionAndStatusChecker(wsClient);
    try {
        checker.checkVersionAndStatus();
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Server not ready (DOWN)");
    }
}
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 40 with SonarLintWsClient

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

the class ServerVersionAndStatusCheckerTest method serverNotReady.

@Test
public void serverNotReady() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/system/status", "{\"id\": \"20160308094653\",\"version\": \"5.5-SNAPSHOT\",\"status\": \"DOWN\"}");
    ServerVersionAndStatusChecker checker = new ServerVersionAndStatusChecker(wsClient);
    ValidationResult validateStatusAndVersion = checker.validateStatusAndVersion();
    assertThat(validateStatusAndVersion.success()).isFalse();
    assertThat(validateStatusAndVersion.message()).isEqualTo("Server not ready (DOWN)");
}
Also used : ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) 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