Search in sources :

Example 1 with WsRequest

use of org.sonarqube.ws.client.WsRequest in project sonarqube by SonarSource.

the class ScannerWsClientTest method fail_if_bad_request.

@Test
public void fail_if_bad_request() throws Exception {
    expectedException.expect(MessageException.class);
    expectedException.expectMessage("Boo! bad request! bad!");
    WsRequest request = newRequest();
    WsResponse response = newResponse().setCode(400).setContent("{\"errors\":[{\"msg\":\"Boo! bad request! bad!\"}]}");
    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 2 with WsRequest

use of org.sonarqube.ws.client.WsRequest in project sonarqube by SonarSource.

the class ScannerWsClientTest method fail_if_requires_credentials.

@Test
public void fail_if_requires_credentials() throws Exception {
    expectedException.expect(MessageException.class);
    expectedException.expectMessage("Not authorized. Analyzing this project requires to be authenticated. Please provide the values of 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, false, 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 3 with WsRequest

use of org.sonarqube.ws.client.WsRequest in project sonarqube by SonarSource.

the class ReportPublisherTest method test_ws_parameters.

@Test
public void test_ws_parameters() throws Exception {
    ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
    settings.setProperty(CoreProperties.PROJECT_ORGANIZATION_PROPERTY, "MyOrg");
    WsResponse response = mock(WsResponse.class);
    PipedOutputStream out = new PipedOutputStream();
    PipedInputStream in = new PipedInputStream(out);
    WsCe.SubmitResponse.newBuilder().build().writeTo(out);
    out.close();
    when(response.failIfNotSuccessful()).thenReturn(response);
    when(response.contentStream()).thenReturn(in);
    when(wsClient.call(any(WsRequest.class))).thenReturn(response);
    underTest.upload(temp.newFile());
    ArgumentCaptor<WsRequest> capture = ArgumentCaptor.forClass(WsRequest.class);
    verify(wsClient).call(capture.capture());
    WsRequest wsRequest = capture.getValue();
    assertThat(wsRequest.getParams()).containsOnly(entry("organization", "MyOrg"), entry("projectKey", "struts"));
}
Also used : WsRequest(org.sonarqube.ws.client.WsRequest) TempFolder(org.sonar.api.utils.TempFolder) WsResponse(org.sonarqube.ws.client.WsResponse) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Test(org.junit.Test)

Example 4 with WsRequest

use of org.sonarqube.ws.client.WsRequest 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 5 with WsRequest

use of org.sonarqube.ws.client.WsRequest 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)

Aggregations

Test (org.junit.Test)6 WsRequest (org.sonarqube.ws.client.WsRequest)6 WsResponse (org.sonarqube.ws.client.WsResponse)6 MockWsResponse (org.sonarqube.ws.client.MockWsResponse)5 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 TempFolder (org.sonar.api.utils.TempFolder)1