Search in sources :

Example 16 with SonarLintWsClient

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

the class ServerVersionAndStatusCheckerTest method responseParsingError.

@Test
public void responseParsingError() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/system/status", "bla bla");
    ServerVersionAndStatusChecker checker = new ServerVersionAndStatusChecker(wsClient);
    try {
        checker.checkVersionAndStatus();
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Unable to parse server infos from: bla bla");
    }
}
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 17 with SonarLintWsClient

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

the class ServerVersionAndStatusCheckerTest method fallbackOnDeprecatedWs_if_404.

@Test
public void fallbackOnDeprecatedWs_if_404() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/server/version", "4.5");
    WsClientTestUtils.addFailedResponse(wsClient, "api/system/status", HttpURLConnection.HTTP_NOT_FOUND, "");
    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 18 with SonarLintWsClient

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

the class WsHelperImpl method listOrganizations.

@Override
public List<RemoteOrganization> listOrganizations(ServerConfiguration serverConfig, @Nullable ProgressMonitor monitor) {
    SonarLintWsClient client = createClient(serverConfig);
    ServerVersionAndStatusChecker serverChecker = new ServerVersionAndStatusChecker(client);
    return listOrganizations(client, serverChecker, new ProgressWrapper(monitor));
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ServerVersionAndStatusChecker(org.sonarsource.sonarlint.core.container.connected.validate.ServerVersionAndStatusChecker) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)

Example 19 with SonarLintWsClient

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

the class NotificationCheckerTest method testFailCode.

@Test
public void testFailCode() {
    ZonedDateTime timestamp = ZonedDateTime.of(2017, 06, 04, 20, 0, 0, 0, ZoneOffset.ofHours(0));
    String expectedUrl = "api/developers/search_events?projects=myproject&from=2017-06-04T20%3A00%3A00%2B0000";
    SonarLintWsClient client = WsClientTestUtils.createMock();
    WsClientTestUtils.addFailedResponse(client, expectedUrl, 404, "failed");
    NotificationChecker checker = new NotificationChecker(client);
    List<SonarQubeNotification> notifications = checker.request(Collections.singletonMap("myproject", timestamp));
    assertThat(notifications).isEmpty();
}
Also used : ZonedDateTime(java.time.ZonedDateTime) SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 20 with SonarLintWsClient

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

the class NotificationCheckerTest method testFailParsing.

@Test
public void testFailParsing() {
    ZonedDateTime timestamp = ZonedDateTime.of(2017, 06, 04, 20, 0, 0, 0, ZoneOffset.ofHours(0));
    String expectedUrl = "api/developers/search_events?projects=myproject&from=2017-06-04T20%3A00%3A00%2B0000";
    SonarLintWsClient client = WsClientTestUtils.createMockWithResponse(expectedUrl, INVALID_RESPONSE);
    NotificationChecker checker = new NotificationChecker(client);
    List<SonarQubeNotification> notifications = checker.request(Collections.singletonMap("myproject", timestamp));
    assertThat(notifications).isEmpty();
}
Also used : ZonedDateTime(java.time.ZonedDateTime) SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) 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