Search in sources :

Example 41 with WsResponse

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);
}
Also used : WsRequest(org.sonarqube.ws.client.WsRequest) WsResponse(org.sonarqube.ws.client.WsResponse) MockWsResponse(org.sonarqube.ws.client.MockWsResponse) Test(org.junit.Test)

Example 42 with WsResponse

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=");
}
Also used : WsRequest(org.sonarqube.ws.client.WsRequest) WsResponse(org.sonarqube.ws.client.WsResponse) MockWsResponse(org.sonarqube.ws.client.MockWsResponse) Test(org.junit.Test)

Example 43 with WsResponse

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);
}
Also used : WsRequest(org.sonarqube.ws.client.WsRequest) WsResponse(org.sonarqube.ws.client.WsResponse) MockWsResponse(org.sonarqube.ws.client.MockWsResponse) Test(org.junit.Test)

Example 44 with WsResponse

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);
}
Also used : WsResponse(org.sonarqube.ws.client.WsResponse)

Example 45 with WsResponse

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);
}
Also used : WsRequest(org.sonarqube.ws.client.WsRequest) WsResponse(org.sonarqube.ws.client.WsResponse)

Aggregations

WsResponse (org.sonarqube.ws.client.WsResponse)58 Test (org.junit.Test)34 GetRequest (org.sonarqube.ws.client.GetRequest)27 WsRequest (org.sonarqube.ws.client.WsRequest)20 MockWsResponse (org.sonarqube.ws.client.MockWsResponse)15 MessageException (org.sonar.api.utils.MessageException)6 HttpException (org.sonarqube.ws.client.HttpException)6 PipedInputStream (java.io.PipedInputStream)5 PipedOutputStream (java.io.PipedOutputStream)5 PostRequest (org.sonarqube.ws.client.PostRequest)3 WsClient (org.sonarqube.ws.client.WsClient)3 File (java.io.File)2 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)2 Profiler (org.sonar.api.utils.log.Profiler)2 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)2 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CheckForNull (javax.annotation.CheckForNull)1