Search in sources :

Example 1 with TreeWsResponse

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

the class TreeAction method buildResponse.

private static TreeWsResponse buildResponse(ComponentDto baseComponent, OrganizationDto organizationDto, List<ComponentDto> components, Map<String, ComponentDto> referenceComponentsByUuid, Paging paging) {
    TreeWsResponse.Builder response = TreeWsResponse.newBuilder();
    response.getPagingBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()).setTotal(paging.total()).build();
    response.setBaseComponent(toWsComponent(baseComponent, organizationDto, referenceComponentsByUuid));
    for (ComponentDto dto : components) {
        response.addComponents(toWsComponent(dto, organizationDto, referenceComponentsByUuid));
    }
    return response.build();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TreeWsResponse(org.sonarqube.ws.WsComponents.TreeWsResponse)

Example 2 with TreeWsResponse

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

the class TreeActionTest method return_projects_composing_a_view.

@Test
public void return_projects_composing_a_view() {
    ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid");
    componentDb.insertProjectAndSnapshot(project);
    ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid");
    componentDb.insertViewAndSnapshot(view);
    componentDb.insertComponent(newProjectCopy("project-copy-uuid", project, view));
    logInWithBrowsePermission(view);
    TreeWsResponse response = call(ws.newRequest().setParam(PARAM_COMPONENT_ID, view.uuid()));
    assertThat(response.getBaseComponent().getId()).isEqualTo(view.uuid());
    assertThat(response.getComponentsCount()).isEqualTo(1);
    assertThat(response.getComponents(0).getId()).isEqualTo("project-copy-uuid");
    assertThat(response.getComponents(0).getRefId()).isEqualTo("project-uuid");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TreeWsResponse(org.sonarqube.ws.WsComponents.TreeWsResponse) Test(org.junit.Test)

Example 3 with TreeWsResponse

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

the class TreeActionTest method return_children.

@Test
public void return_children() throws IOException {
    ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid");
    componentDb.insertProjectAndSnapshot(project);
    ComponentDto module = newModuleDto("module-uuid-1", project);
    componentDb.insertComponent(module);
    componentDb.insertComponent(newFileDto(project, 1));
    for (int i = 2; i <= 9; i++) {
        componentDb.insertComponent(newFileDto(module, i));
    }
    ComponentDto directory = newDirectory(module, "directory-path-1");
    componentDb.insertComponent(directory);
    componentDb.insertComponent(newFileDto(module, directory, 10));
    db.commit();
    logInWithBrowsePermission(project);
    TreeWsResponse response = call(ws.newRequest().setParam(PARAM_STRATEGY, "children").setParam(PARAM_COMPONENT_ID, "module-uuid-1").setParam(Param.PAGE, "2").setParam(Param.PAGE_SIZE, "3").setParam(Param.TEXT_QUERY, "file-name").setParam(Param.ASCENDING, "false").setParam(Param.SORT, "name"));
    assertThat(response.getComponentsCount()).isEqualTo(3);
    assertThat(response.getPaging().getTotal()).isEqualTo(8);
    assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-6", "file-uuid-5", "file-uuid-4");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TreeWsResponse(org.sonarqube.ws.WsComponents.TreeWsResponse) Test(org.junit.Test)

Example 4 with TreeWsResponse

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

the class TreeActionTest method return_descendants.

@Test
public void return_descendants() throws IOException {
    ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid");
    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
    ComponentDto module = newModuleDto("module-uuid-1", project);
    componentDb.insertComponent(module);
    componentDb.insertComponent(newFileDto(project, 10));
    for (int i = 2; i <= 9; i++) {
        componentDb.insertComponent(newFileDto(module, i));
    }
    ComponentDto directory = newDirectory(module, "directory-path-1");
    componentDb.insertComponent(directory);
    componentDb.insertComponent(newFileDto(module, directory, 1));
    db.commit();
    logInWithBrowsePermission(project);
    TreeWsResponse response = call(ws.newRequest().setParam(PARAM_STRATEGY, "all").setParam(PARAM_COMPONENT_ID, "module-uuid-1").setParam(Param.PAGE, "2").setParam(Param.PAGE_SIZE, "3").setParam(Param.TEXT_QUERY, "file-name").setParam(Param.ASCENDING, "true").setParam(Param.SORT, "path"));
    assertThat(response.getComponentsCount()).isEqualTo(3);
    assertThat(response.getPaging().getTotal()).isEqualTo(9);
    assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-4", "file-uuid-5", "file-uuid-6");
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) TreeWsResponse(org.sonarqube.ws.WsComponents.TreeWsResponse) Test(org.junit.Test)

Example 5 with TreeWsResponse

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

the class TreeActionTest method return_children_of_a_view.

@Test
public void return_children_of_a_view() {
    OrganizationDto organizationDto = db.organizations().insert();
    ComponentDto view = newView(organizationDto, "view-uuid");
    componentDb.insertViewAndSnapshot(view);
    ComponentDto project = newProjectDto(organizationDto, "project-uuid-1").setName("project-name").setKey("project-key-1");
    componentDb.insertProjectAndSnapshot(project);
    componentDb.insertComponent(newProjectCopy("project-uuid-1-copy", project, view));
    componentDb.insertComponent(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"));
    db.commit();
    logInWithBrowsePermission(view);
    TreeWsResponse response = call(ws.newRequest().setParam(PARAM_STRATEGY, "children").setParam(PARAM_COMPONENT_ID, "view-uuid").setParam(Param.TEXT_QUERY, "name"));
    assertThat(response.getComponentsList()).extracting("id").containsExactly("project-uuid-1-copy", "sub-view-uuid");
    assertThat(response.getComponentsList()).extracting("refId").containsExactly("project-uuid-1", "");
    assertThat(response.getComponentsList()).extracting("refKey").containsExactly("project-key-1", "");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) TreeWsResponse(org.sonarqube.ws.WsComponents.TreeWsResponse) Test(org.junit.Test)

Aggregations

TreeWsResponse (org.sonarqube.ws.WsComponents.TreeWsResponse)11 ComponentDto (org.sonar.db.component.ComponentDto)10 Test (org.junit.Test)9 SnapshotDto (org.sonar.db.component.SnapshotDto)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1