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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations