Search in sources :

Example 11 with WsResponse

use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.

the class WsClientTestUtils method addFailedResponse.

public static SonarLintWsClient addFailedResponse(SonarLintWsClient wsClient, String url, int errorCode, @Nullable String errorMsg) {
    WsResponse wsResponse = mock(WsResponse.class);
    IllegalStateException ex = new IllegalStateException("Error " + errorCode + " on " + url + (errorMsg != null ? (": " + errorMsg) : ""));
    when(wsClient.get(url)).thenThrow(ex);
    when(wsClient.rawGet(url)).thenReturn(wsResponse);
    when(wsResponse.content()).thenReturn(errorMsg).thenThrow(new IllegalStateException("Should not call content() twice"));
    when(wsResponse.hasContent()).thenReturn(errorMsg != null);
    when(wsResponse.requestUrl()).thenReturn(url);
    when(wsResponse.isSuccessful()).thenReturn(false);
    when(wsResponse.code()).thenReturn(errorCode);
    return wsClient;
}
Also used : WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse)

Example 12 with WsResponse

use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.

the class WsClientTestUtils method addReaderResponse.

public static SonarLintWsClient addReaderResponse(SonarLintWsClient wsClient, String url, String resourcePath) {
    WsResponse wsResponse = mock(WsResponse.class);
    when(wsClient.get(url)).thenReturn(wsResponse);
    when(wsClient.rawGet(url)).thenReturn(wsResponse);
    when(wsResponse.requestUrl()).thenReturn(url);
    InputStream is = requireNonNull(WsClientTestUtils.class.getResourceAsStream(resourcePath));
    when(wsResponse.contentReader()).thenReturn(new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)));
    when(wsResponse.isSuccessful()).thenReturn(true);
    return wsClient;
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse)

Example 13 with WsResponse

use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.

the class WsClientTestUtils method addReaderResponse.

public static SonarLintWsClient addReaderResponse(SonarLintWsClient wsClient, String url, Reader reader) {
    WsResponse wsResponse = mock(WsResponse.class);
    when(wsClient.get(url)).thenReturn(wsResponse);
    when(wsResponse.requestUrl()).thenReturn(url);
    when(wsResponse.contentReader()).thenReturn(reader);
    when(wsResponse.isSuccessful()).thenReturn(true);
    return wsClient;
}
Also used : WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse)

Example 14 with WsResponse

use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.

the class WsClientTestUtils method addPostResponse.

public static SonarLintWsClient addPostResponse(SonarLintWsClient wsClient, String url, String response) {
    WsResponse wsResponse = mock(WsResponse.class);
    when(wsClient.post(url)).thenReturn(wsResponse);
    when(wsClient.rawPost(url)).thenReturn(wsResponse);
    when(wsResponse.requestUrl()).thenReturn(url);
    when(wsResponse.content()).thenReturn(response).thenThrow(new IllegalStateException("Should not call content() twice"));
    when(wsResponse.isSuccessful()).thenReturn(true);
    return wsClient;
}
Also used : WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse)

Example 15 with WsResponse

use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.

the class NotificationCheckerTest method testIsNotSupported.

@Test
public void testIsNotSupported() {
    String expectedUrl = "api/developers/search_events?projects=&from=";
    SonarLintWsClient client = WsClientTestUtils.createMock();
    WsResponse wsResponse = mock(WsResponse.class);
    when(client.rawGet(startsWith(expectedUrl))).thenReturn(wsResponse);
    when(wsResponse.isSuccessful()).thenReturn(false);
    NotificationChecker checker = new NotificationChecker(client);
    assertThat(checker.isSupported()).isFalse();
}
Also used : WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Aggregations

WsResponse (org.sonarsource.sonarlint.core.util.ws.WsResponse)23 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 Gson (com.google.gson.Gson)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 CheckForNull (javax.annotation.CheckForNull)2 Test (org.junit.Test)2 ValuesWsResponse (org.sonarqube.ws.Settings.ValuesWsResponse)2 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)2 ServerInfos (org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)2 JsonReader (com.google.gson.stream.JsonReader)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 LinkedList (java.util.LinkedList)1 Scanner (java.util.Scanner)1 Paging (org.sonarqube.ws.Common.Paging)1 Setting (org.sonarqube.ws.Settings.Setting)1