Search in sources :

Example 1 with SearchWsResponse

use of org.sonarqube.ws.WsComponents.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method search_with_language.

@Test
public void search_with_language() throws IOException {
    OrganizationDto organizationDto = db.organizations().insert();
    insertProjectsAuthorizedForUser(newProjectDto(organizationDto).setKey("java-project").setLanguage("java"), newProjectDto(organizationDto).setKey("cpp-project").setLanguage("cpp"));
    SearchWsResponse response = call(new SearchWsRequest().setOrganization(organizationDto.getKey()).setLanguage("java").setQualifiers(singletonList(PROJECT)));
    assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("java-project");
}
Also used : SearchWsRequest(org.sonarqube.ws.client.component.SearchWsRequest) SearchWsResponse(org.sonarqube.ws.WsComponents.SearchWsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 2 with SearchWsResponse

use of org.sonarqube.ws.WsComponents.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method search_for_files.

@Test
public void search_for_files() throws IOException {
    ComponentDto project = newProjectDto(db.getDefaultOrganization());
    ComponentDto file1 = newFileDto(project).setKey("file1");
    ComponentDto file2 = newFileDto(project).setKey("file2");
    db.components().insertComponents(project, file1, file2);
    setBrowsePermissionOnUser(project);
    SearchWsResponse response = call(new SearchWsRequest().setQuery(file1.key()).setQualifiers(singletonList(FILE)));
    assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(file1.getKey());
}
Also used : SearchWsRequest(org.sonarqube.ws.client.component.SearchWsRequest) ComponentDto(org.sonar.db.component.ComponentDto) SearchWsResponse(org.sonarqube.ws.WsComponents.SearchWsResponse) Test(org.junit.Test)

Example 3 with SearchWsResponse

use of org.sonarqube.ws.WsComponents.SearchWsResponse in project sonarqube by SonarSource.

the class SearchAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    SearchWsResponse searchWsResponse = doHandle(toSearchWsRequest(wsRequest));
    writeProtobuf(searchWsResponse, wsRequest, wsResponse);
}
Also used : SearchWsResponse(org.sonarqube.ws.WsComponents.SearchWsResponse)

Example 4 with SearchWsResponse

use of org.sonarqube.ws.WsComponents.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method search_by_key_query.

@Test
public void search_by_key_query() throws IOException {
    insertProjectsAuthorizedForUser(newProjectDto(db.getDefaultOrganization()).setKey("project-_%-key"), newProjectDto(db.getDefaultOrganization()).setKey("project-key-without-escaped-characters"));
    SearchWsResponse response = call(new SearchWsRequest().setQuery("project-_%-key").setQualifiers(singletonList(PROJECT)));
    assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("project-_%-key");
}
Also used : SearchWsRequest(org.sonarqube.ws.client.component.SearchWsRequest) SearchWsResponse(org.sonarqube.ws.WsComponents.SearchWsResponse) Test(org.junit.Test)

Example 5 with SearchWsResponse

use of org.sonarqube.ws.WsComponents.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method search_with_pagination.

@Test
public void search_with_pagination() throws IOException {
    OrganizationDto organizationDto = db.organizations().insert();
    List<ComponentDto> componentDtoList = new ArrayList<>();
    for (int i = 1; i <= 9; i++) {
        componentDtoList.add(newProjectDto(organizationDto, "project-uuid-" + i).setKey("project-key-" + i).setName("Project Name " + i));
    }
    insertProjectsAuthorizedForUser(componentDtoList.toArray(new ComponentDto[] {}));
    SearchWsResponse response = call(new SearchWsRequest().setOrganization(organizationDto.getKey()).setPage(2).setPageSize(3).setQualifiers(singletonList(PROJECT)));
    assertThat(response.getComponentsList()).extracting(Component::getKey).containsExactly("project-key-4", "project-key-5", "project-key-6");
}
Also used : SearchWsRequest(org.sonarqube.ws.client.component.SearchWsRequest) ArrayList(java.util.ArrayList) ComponentDto(org.sonar.db.component.ComponentDto) SearchWsResponse(org.sonarqube.ws.WsComponents.SearchWsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

SearchWsResponse (org.sonarqube.ws.WsComponents.SearchWsResponse)6 Test (org.junit.Test)5 SearchWsRequest (org.sonarqube.ws.client.component.SearchWsRequest)5 ComponentDto (org.sonar.db.component.ComponentDto)3 OrganizationDto (org.sonar.db.organization.OrganizationDto)2 ArrayList (java.util.ArrayList)1