Search in sources :

Example 21 with TestRequest

use of org.sonar.server.ws.TestRequest in project sonarqube by SonarSource.

the class ProvisionedActionTest method provisioned_projects_with_correct_pagination.

@Test
public void provisioned_projects_with_correct_pagination() throws Exception {
    OrganizationDto org = db.organizations().insert();
    for (int i = 1; i <= 10; i++) {
        db.components().insertComponent(newProvisionedProject(org, String.valueOf(i)));
    }
    userSessionRule.logIn().addPermission(PROVISION_PROJECTS, org);
    TestRequest request = underTest.newRequest().setParam(PARAM_ORGANIZATION, org.getKey()).setParam(Param.PAGE, "3").setParam(Param.PAGE_SIZE, "4");
    String jsonOutput = request.execute().getInput();
    assertThat(StringUtils.countMatches(jsonOutput, "provisioned-uuid-")).isEqualTo(2);
}
Also used : OrganizationDto(org.sonar.db.organization.OrganizationDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 22 with TestRequest

use of org.sonar.server.ws.TestRequest in project sonarqube by SonarSource.

the class CreateEventActionTest method call.

private CreateEventResponse call(CreateEventRequest.Builder requestBuilder) {
    CreateEventRequest request = requestBuilder.build();
    TestRequest httpRequest = ws.newRequest().setMethod(POST.name()).setMediaType(MediaTypes.PROTOBUF);
    httpRequest.setParam(PARAM_CATEGORY, request.getCategory().name()).setParam(PARAM_NAME, request.getName()).setParam(PARAM_ANALYSIS, request.getAnalysis());
    try {
        return CreateEventResponse.parseFrom(httpRequest.execute().getInputStream());
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : CreateEventRequest(org.sonarqube.ws.client.projectanalysis.CreateEventRequest) IOException(java.io.IOException) TestRequest(org.sonar.server.ws.TestRequest)

Example 23 with TestRequest

use of org.sonar.server.ws.TestRequest in project sonarqube by SonarSource.

the class SearchActionTest method call.

private SearchWsResponse call(SearchWsRequest wsRequest) {
    TestRequest request = ws.newRequest().setMediaType(PROTOBUF);
    setNullable(wsRequest.getOrganization(), organization -> request.setParam(PARAM_ORGANIZATION, organization));
    List<String> qualifiers = wsRequest.getQualifiers();
    if (!qualifiers.isEmpty()) {
        request.setParam(ComponentsWsParameters.PARAM_QUALIFIERS, Joiner.on(",").join(qualifiers));
    }
    setNullable(wsRequest.getQuery(), query -> request.setParam(TEXT_QUERY, query));
    setNullable(wsRequest.getPage(), page -> request.setParam(PAGE, String.valueOf(page)));
    setNullable(wsRequest.getPageSize(), pageSize -> request.setParam(PAGE_SIZE, String.valueOf(pageSize)));
    try {
        return SearchWsResponse.parseFrom(request.execute().getInputStream());
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : IOException(java.io.IOException) TestRequest(org.sonar.server.ws.TestRequest)

Example 24 with TestRequest

use of org.sonar.server.ws.TestRequest in project sonarqube by SonarSource.

the class SearchActionTest method call.

private SearchResponse call(@Nullable String textQuery, @Nullable Integer pageSize) {
    TestRequest request = ws.newRequest().setMediaType(PROTOBUF);
    setNullable(textQuery, s -> request.setParam("q", s));
    setNullable(pageSize, ps -> request.setParam("ps", ps.toString()));
    try {
        return SearchResponse.parseFrom(request.execute().getInputStream());
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : IOException(java.io.IOException) TestRequest(org.sonar.server.ws.TestRequest)

Example 25 with TestRequest

use of org.sonar.server.ws.TestRequest in project sonarqube by SonarSource.

the class SearchActionTest method call.

private SearchResponse call(SearchRequest wsRequest) {
    TestRequest request = ws.newRequest().setMediaType(PROTOBUF).setMethod(POST.name());
    setNullable(wsRequest.getProject(), project -> request.setParam(PARAM_PROJECT, project));
    setNullable(wsRequest.getCategory(), category -> request.setParam(PARAM_CATEGORY, category.name()));
    setNullable(wsRequest.getPage(), page -> request.setParam(Param.PAGE, String.valueOf(page)));
    setNullable(wsRequest.getPageSize(), pageSize -> request.setParam(Param.PAGE_SIZE, String.valueOf(pageSize)));
    try {
        return SearchResponse.parseFrom(request.execute().getInputStream());
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : IOException(java.io.IOException) TestRequest(org.sonar.server.ws.TestRequest)

Aggregations

TestRequest (org.sonar.server.ws.TestRequest)48 IOException (java.io.IOException)19 Test (org.junit.Test)4 InputStream (java.io.InputStream)3 OrganizationDto (org.sonar.db.organization.OrganizationDto)2 AddRequest (org.sonarqube.ws.client.notification.AddRequest)2 DbSession (org.sonar.db.DbSession)1 CoveredFileDoc (org.sonar.server.test.index.CoveredFileDoc)1 TestDoc (org.sonar.server.test.index.TestDoc)1 TestResponse (org.sonar.server.ws.TestResponse)1 WsActionTester (org.sonar.server.ws.WsActionTester)1 SearchProjectsRequest (org.sonarqube.ws.client.component.SearchProjectsRequest)1 SearchHistoryRequest (org.sonarqube.ws.client.measure.SearchHistoryRequest)1 CreateEventRequest (org.sonarqube.ws.client.projectanalysis.CreateEventRequest)1