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);
}
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");
}
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;
}
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");
}
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");
}
Aggregations