Search in sources :

Example 1 with ComponentTreeWsRequest

use of org.sonarqube.ws.client.measure.ComponentTreeWsRequest in project sonarqube by SonarSource.

the class MeasuresWsTest method verifyComponentTreeWithChildren.

private void verifyComponentTreeWithChildren(String baseComponentKey, String... childKeys) {
    ComponentTreeWsResponse response = wsClient.measures().componentTree(new ComponentTreeWsRequest().setBaseComponentKey(baseComponentKey).setMetricKeys(singletonList("ncloc")).setStrategy("children"));
    assertThat(response.getBaseComponent().getKey()).isEqualTo(baseComponentKey);
    assertThat(response.getComponentsList()).extracting("key").containsOnly(childKeys);
}
Also used : ComponentTreeWsRequest(org.sonarqube.ws.client.measure.ComponentTreeWsRequest) ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)

Example 2 with ComponentTreeWsRequest

use of org.sonarqube.ws.client.measure.ComponentTreeWsRequest in project sonarqube by SonarSource.

the class MeasuresWsTest method component_tree.

@Test
public void component_tree() {
    scanXooSample();
    ComponentTreeWsResponse response = wsClient.measures().componentTree(new ComponentTreeWsRequest().setBaseComponentKey("sample").setMetricKeys(singletonList("ncloc")).setAdditionalFields(newArrayList("metrics", "periods")));
    assertThat(response).isNotNull();
    assertThat(response.getBaseComponent().getKey()).isEqualTo("sample");
    assertThat(response.getMetrics().getMetricsList()).extracting("key").containsOnly("ncloc");
    List<WsMeasures.Component> components = response.getComponentsList();
    assertThat(components).hasSize(2).extracting("key").containsOnly(DIR_KEY, FILE_KEY);
    assertThat(components.get(0).getMeasuresList().get(0).getValue()).isEqualTo("13");
}
Also used : ComponentTreeWsRequest(org.sonarqube.ws.client.measure.ComponentTreeWsRequest) ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse) Test(org.junit.Test)

Example 3 with ComponentTreeWsRequest

use of org.sonarqube.ws.client.measure.ComponentTreeWsRequest in project sonarqube by SonarSource.

the class ComponentTreeAction method toComponentTreeWsRequest.

private static ComponentTreeWsRequest toComponentTreeWsRequest(Request request) {
    ComponentTreeWsRequest componentTreeWsRequest = new ComponentTreeWsRequest().setBaseComponentId(request.param(PARAM_BASE_COMPONENT_ID)).setBaseComponentKey(request.param(PARAM_BASE_COMPONENT_KEY)).setMetricKeys(request.mandatoryParamAsStrings(PARAM_METRIC_KEYS)).setStrategy(request.mandatoryParam(PARAM_STRATEGY)).setQualifiers(request.paramAsStrings(PARAM_QUALIFIERS)).setAdditionalFields(request.paramAsStrings(PARAM_ADDITIONAL_FIELDS)).setSort(request.paramAsStrings(Param.SORT)).setAsc(request.paramAsBoolean(Param.ASCENDING)).setMetricSort(request.param(PARAM_METRIC_SORT)).setMetricSortFilter(request.mandatoryParam(PARAM_METRIC_SORT_FILTER)).setMetricPeriodSort(request.paramAsInt(PARAM_METRIC_PERIOD_SORT)).setDeveloperId(request.param(PARAM_DEVELOPER_ID)).setDeveloperKey(request.param(PARAM_DEVELOPER_KEY)).setPage(request.mandatoryParamAsInt(Param.PAGE)).setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)).setQuery(request.param(Param.TEXT_QUERY));
    checkRequest(componentTreeWsRequest.getPageSize() <= MAX_SIZE, "The '%s' parameter must be less than %d", Param.PAGE_SIZE, MAX_SIZE);
    String searchQuery = componentTreeWsRequest.getQuery();
    checkRequest(searchQuery == null || searchQuery.length() >= QUERY_MINIMUM_LENGTH, "The '%s' parameter must have at least %d characters", Param.TEXT_QUERY, QUERY_MINIMUM_LENGTH);
    String metricSortValue = componentTreeWsRequest.getMetricSort();
    checkRequest(!componentTreeWsRequest.getMetricKeys().isEmpty(), "The '%s' parameter must contain at least one metric key", PARAM_METRIC_KEYS);
    checkRequest(metricSortValue == null ^ componentTreeWsRequest.getSort().contains(METRIC_SORT) ^ componentTreeWsRequest.getSort().contains(METRIC_PERIOD_SORT), "To sort by a metric, the '%s' parameter must contain '%s' or '%s', and a metric key must be provided in the '%s' parameter", Param.SORT, METRIC_SORT, METRIC_PERIOD_SORT, PARAM_METRIC_SORT);
    checkRequest(metricSortValue == null ^ componentTreeWsRequest.getMetricKeys().contains(metricSortValue), "To sort by the '%s' metric, it must be in the list of metric keys in the '%s' parameter", metricSortValue, PARAM_METRIC_KEYS);
    checkRequest(componentTreeWsRequest.getMetricPeriodSort() == null ^ componentTreeWsRequest.getSort().contains(METRIC_PERIOD_SORT), "To sort by a metric period, the '%s' parameter must contain '%s' and the '%s' must be provided.", Param.SORT, METRIC_PERIOD_SORT, PARAM_METRIC_PERIOD_SORT);
    checkRequest(ALL_METRIC_SORT_FILTER.equals(componentTreeWsRequest.getMetricSortFilter()) || metricSortValue != null, "To filter components based on the sort metric, the '%s' parameter must contain '%s' or '%s' and the '%s' parameter must be provided", Param.SORT, METRIC_SORT, METRIC_PERIOD_SORT, PARAM_METRIC_SORT);
    return componentTreeWsRequest;
}
Also used : ComponentTreeWsRequest(org.sonarqube.ws.client.measure.ComponentTreeWsRequest)

Example 4 with ComponentTreeWsRequest

use of org.sonarqube.ws.client.measure.ComponentTreeWsRequest in project sonarqube by SonarSource.

the class ComponentTreeSortTest method sort_by_numerical_metric_key_ascending.

@Test
public void sort_by_numerical_metric_key_ascending() {
    components.add(newComponentWithoutSnapshotId("name-without-measure", "qualifier-without-measure", "path-without-measure"));
    ComponentTreeWsRequest wsRequest = newRequest(singletonList(METRIC_SORT), true, NUM_METRIC_KEY);
    List<ComponentDto> result = sortComponents(wsRequest);
    assertThat(result).extracting("path").containsExactly("path-1", "path-2", "path-3", "path-4", "path-5", "path-6", "path-7", "path-8", "path-9", "path-without-measure");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsRequest(org.sonarqube.ws.client.measure.ComponentTreeWsRequest) Test(org.junit.Test)

Example 5 with ComponentTreeWsRequest

use of org.sonarqube.ws.client.measure.ComponentTreeWsRequest in project sonarqube by SonarSource.

the class ComponentTreeSortTest method sort_by_textual_metric_key_ascending.

@Test
public void sort_by_textual_metric_key_ascending() {
    components.add(newComponentWithoutSnapshotId("name-without-measure", "qualifier-without-measure", "path-without-measure"));
    ComponentTreeWsRequest wsRequest = newRequest(singletonList(METRIC_SORT), true, TEXT_METRIC_KEY);
    List<ComponentDto> result = sortComponents(wsRequest);
    assertThat(result).extracting("path").containsExactly("path-1", "path-2", "path-3", "path-4", "path-5", "path-6", "path-7", "path-8", "path-9", "path-without-measure");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsRequest(org.sonarqube.ws.client.measure.ComponentTreeWsRequest) Test(org.junit.Test)

Aggregations

ComponentTreeWsRequest (org.sonarqube.ws.client.measure.ComponentTreeWsRequest)16 Test (org.junit.Test)14 ComponentDto (org.sonar.db.component.ComponentDto)12 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)2 CollectionCondition (com.codeborne.selenide.CollectionCondition)1 Condition (com.codeborne.selenide.Condition)1 Condition.hasText (com.codeborne.selenide.Condition.hasText)1 Condition.or (com.codeborne.selenide.Condition.or)1 Orchestrator (com.sonar.orchestrator.Orchestrator)1 Arrays.asList (java.util.Arrays.asList)1 Collections.singletonList (java.util.Collections.singletonList)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 BeforeClass (org.junit.BeforeClass)1 ClassRule (org.junit.ClassRule)1 MeasureDto (org.sonar.db.measure.MeasureDto)1 Issues (org.sonarqube.ws.Issues)1 WsComponents (org.sonarqube.ws.WsComponents)1 WsMeasures (org.sonarqube.ws.WsMeasures)1 WsClient (org.sonarqube.ws.client.WsClient)1 TreeWsRequest (org.sonarqube.ws.client.component.TreeWsRequest)1