Search in sources :

Example 1 with WsResponse

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

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

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

the class WsTestUtil method mockStream.

public static void mockStream(ScannerWsClient mock, InputStream is) {
    WsResponse response = mock(WsResponse.class);
    when(response.contentStream()).thenReturn(is);
    when(mock.call(any(WsRequest.class))).thenReturn(response);
}
Also used : WsRequest(org.sonarqube.ws.client.WsRequest) WsResponse(org.sonarqube.ws.client.WsResponse)

Example 4 with WsResponse

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

the class Validation method mustHaveSourceWithAtLeast.

private void mustHaveSourceWithAtLeast(String path, int minLines) {
    for (String filePath : toFiles(path)) {
        WsResponse response = newAdminWsClient(orchestrator).wsConnector().call(new GetRequest("api/sources/lines").setParam("key", filePathToKey(filePath)));
        errorCollector.checkThat("Source is set on file " + filePath, response.isSuccessful(), is(true));
        Sources source = Sources.parse(response.content());
        if (source != null) {
            errorCollector.checkThat("Source is empty on file " + filePath, source.getSources().size(), Matchers.greaterThanOrEqualTo(minLines));
        }
    }
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse)

Example 5 with WsResponse

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

the class DeprecatedPropertiesWsTest method getProperty.

@CheckForNull
private static Properties.Property getProperty(WsClient wsClient, String key, @Nullable String componentKey, boolean useIdParameter) throws UnsupportedEncodingException {
    GetRequest getRequest = useIdParameter ? new GetRequest("api/properties").setParam("id", encode(key, "UTF-8")).setParam("resource", componentKey) : new GetRequest("api/properties/" + encode(key, "UTF-8")).setParam("resource", componentKey);
    WsResponse response = wsClient.wsConnector().call(getRequest).failIfNotSuccessful();
    Properties.Property[] properties = Properties.parse(response.content());
    return Arrays.stream(properties).findFirst().orElseGet(() -> null);
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) CheckForNull(javax.annotation.CheckForNull)

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