Search in sources :

Example 21 with GetRequest

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

the class WsLocalCallTest method propagates_authorization_rights.

@Test
public void propagates_authorization_rights() {
    WsClient wsClient = WsClientFactories.getDefault().newClient(HttpConnector.newBuilder().url(orchestrator.getServer().getUrl()).credentials("admin", "admin").build());
    WsResponse response = wsClient.wsConnector().call(new GetRequest("local_ws_call/require_permission"));
    assertThat(response.isSuccessful()).isTrue();
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newWsClient(util.ItUtils.newWsClient) Test(org.junit.Test)

Example 22 with GetRequest

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

the class WsTest method gets_json.

@Test
public void gets_json() {
    WsResponse response = newWsClient(orchestrator).wsConnector().call(new GetRequest("api/issues/search.json"));
    assertThat(response.isSuccessful()).isTrue();
    assertThat(response.contentType()).contains("application/json");
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) Test(org.junit.Test)

Example 23 with GetRequest

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

the class WsTest method fail_on_unknown_extension.

/**
   * SONAR-7484
   */
@Test
public void fail_on_unknown_extension() {
    WsResponse response = newWsClient(orchestrator).wsConnector().call(new GetRequest("api/issues/search.unknown"));
    assertThat(response.isSuccessful()).isFalse();
    assertThat(response.code()).isEqualTo(HTTP_BAD_REQUEST);
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) Test(org.junit.Test)

Example 24 with GetRequest

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

the class WsTest method gets_protobuf.

@Test
public void gets_protobuf() {
    WsResponse response = newWsClient(orchestrator).wsConnector().call(new GetRequest("api/issues/search.protobuf"));
    assertThat(response.isSuccessful()).isTrue();
    assertThat(response.contentType()).contains("application/x-protobuf");
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) Test(org.junit.Test)

Example 25 with GetRequest

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

the class DefaultMetricsRepositoryLoader method loadFromPaginatedWs.

private void loadFromPaginatedWs(List<Metric> metrics) throws IOException {
    int page = 1;
    WsMetricsResponse response;
    do {
        GetRequest getRequest = new GetRequest(METRICS_SEARCH_URL + page);
        try (Reader reader = wsClient.call(getRequest).contentReader()) {
            response = GsonHelper.create().fromJson(reader, WsMetricsResponse.class);
            for (WsMetric metric : response.metrics) {
                metrics.add(new Metric.Builder(metric.getKey(), metric.getName(), ValueType.valueOf(metric.getType())).create().setDirection(metric.getDirection()).setQualitative(metric.isQualitative()).setUserManaged(false).setDescription(metric.getDescription()).setUuid(metric.getUuid()));
            }
        }
        page++;
    } while (response.getP() < (response.getTotal() / response.getPs() + 1));
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) Reader(java.io.Reader) Metric(org.sonar.api.measures.Metric)

Aggregations

GetRequest (org.sonarqube.ws.client.GetRequest)59 Test (org.junit.Test)34 WsResponse (org.sonarqube.ws.client.WsResponse)27 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 Profiler (org.sonar.api.utils.log.Profiler)5 Reader (java.io.Reader)4 HttpException (org.sonarqube.ws.client.HttpException)4 WsClient (org.sonarqube.ws.client.WsClient)4 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)3 File (java.io.File)2 PipedInputStream (java.io.PipedInputStream)2 PipedOutputStream (java.io.PipedOutputStream)2 ShowWsResponse (org.sonarqube.ws.ServerId.ShowWsResponse)2 ItUtils.newWsClient (util.ItUtils.newWsClient)2 Gson (com.google.gson.Gson)1 LinkedList (java.util.LinkedList)1 CheckForNull (javax.annotation.CheckForNull)1 LoadedActiveRule (org.sonar.api.batch.rule.LoadedActiveRule)1 Metric (org.sonar.api.measures.Metric)1