use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class ScannerWsClientTest method fail_if_requires_permission.
@Test
public void fail_if_requires_permission() throws Exception {
expectedException.expect(MessageException.class);
expectedException.expectMessage("missing scan permission, missing another permission");
WsRequest request = newRequest();
WsResponse response = newResponse().setCode(403).setContent("{\"errors\":[{\"msg\":\"missing scan permission\"}, {\"msg\":\"missing another permission\"}]}");
when(wsClient.wsConnector().call(request)).thenReturn(response);
new ScannerWsClient(wsClient, true, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class ScannerWsClientTest method log_and_profile_request_if_debug_level.
@Test
public void log_and_profile_request_if_debug_level() throws Exception {
WsRequest request = newRequest();
WsResponse response = newResponse().setRequestUrl("https://local/api/issues/search");
when(wsClient.wsConnector().call(request)).thenReturn(response);
logTester.setLevel(LoggerLevel.DEBUG);
ScannerWsClient underTest = new ScannerWsClient(wsClient, false, new GlobalMode(new GlobalProperties(Collections.emptyMap())));
WsResponse result = underTest.call(request);
// do not fail the execution -> interceptor returns the response
assertThat(result).isSameAs(response);
// check logs
List<String> debugLogs = logTester.logs(LoggerLevel.DEBUG);
assertThat(debugLogs).hasSize(1);
assertThat(debugLogs.get(0)).contains("GET 200 https://local/api/issues/search | time=");
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class ScannerWsClientTest method fail_if_credentials_are_not_valid.
@Test
public void fail_if_credentials_are_not_valid() throws Exception {
expectedException.expect(MessageException.class);
expectedException.expectMessage("Not authorized. Please check the properties sonar.login and sonar.password.");
WsRequest request = newRequest();
WsResponse response = newResponse().setCode(401);
when(wsClient.wsConnector().call(request)).thenReturn(response);
new ScannerWsClient(wsClient, /* credentials are configured */
true, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class WsTestUtil method mockStream.
public static void mockStream(ScannerWsClient mock, String path, InputStream is) {
WsResponse response = mock(WsResponse.class);
when(response.contentStream()).thenReturn(is);
when(mock.call(argThat(new RequestMatcher(path)))).thenReturn(response);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class WsTestUtil method mockReader.
public static void mockReader(ScannerWsClient mock, Reader reader) {
WsResponse response = mock(WsResponse.class);
when(response.contentReader()).thenReturn(reader);
when(mock.call(any(WsRequest.class))).thenReturn(response);
}
Aggregations