Search in sources :

Example 21 with ComponentTreeWsResponse

use of org.sonarqube.ws.Measures.ComponentTreeWsResponse in project sonarqube by SonarSource.

the class ComponentTreeActionTest method new_issue_count_measures_are_not_transformed_if_they_dont_exist_in_pr.

@Test
public void new_issue_count_measures_are_not_transformed_if_they_dont_exist_in_pr() {
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setKey("pr").setBranchType(PULL_REQUEST));
    SnapshotDto analysis = db.components().insertSnapshot(pr);
    ComponentDto file = db.components().insertComponent(newFileDto(pr));
    MetricDto bug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.BUGS_KEY));
    MetricDto newBug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.NEW_BUGS_KEY));
    ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, "pr").setParam(PARAM_METRIC_KEYS, newBug.getKey() + "," + bug.getKey()).executeProtobuf(ComponentTreeWsResponse.class);
    assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getPullRequest).containsExactlyInAnyOrder(file.getKey(), "pr");
    assertThat(response.getBaseComponent().getMeasuresList()).isEmpty();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsResponse(org.sonarqube.ws.Measures.ComponentTreeWsResponse) Test(org.junit.Test)

Example 22 with ComponentTreeWsResponse

use of org.sonarqube.ws.Measures.ComponentTreeWsResponse in project sonarqube by SonarSource.

the class ComponentTreeActionTest method remove_components_without_measure_on_the_metric_period_sort.

@Test
public void remove_components_without_measure_on_the_metric_period_sort() {
    ComponentDto project = db.components().insertPrivateProject();
    SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
    ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setDbKey("file-4-key"));
    ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setDbKey("file-3-key"));
    ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setDbKey("file-2-key"));
    ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setDbKey("file-1-key"));
    MetricDto ncloc = newMetricDto().setKey("new_ncloc").setValueType(INT.name()).setDirection(1);
    dbClient.metricDao().insert(dbSession, ncloc);
    db.measures().insertLiveMeasure(file1, ncloc, m -> m.setData((String) null).setValue(null).setVariation(1.0d));
    db.measures().insertLiveMeasure(file2, ncloc, m -> m.setData((String) null).setValue(null).setVariation(2.0d));
    db.measures().insertLiveMeasure(file3, ncloc, m -> m.setData((String) null).setValue(null).setVariation(3.0d));
    // file 4 measure is on absolute value
    db.measures().insertLiveMeasure(file4, ncloc, m -> m.setData((String) null).setValue(4.0d).setVariation(null));
    db.commit();
    ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(SORT, METRIC_PERIOD_SORT + "," + NAME_SORT).setParam(PARAM_METRIC_SORT, "new_ncloc").setParam(PARAM_METRIC_KEYS, "new_ncloc").setParam(PARAM_METRIC_PERIOD_SORT, "1").setParam(PARAM_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER).executeProtobuf(ComponentTreeWsResponse.class);
    assertThat(response.getComponentsList()).extracting("key").containsExactly("file-1-key", "file-2-key", "file-3-key").doesNotContain("file-4-key");
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsResponse(org.sonarqube.ws.Measures.ComponentTreeWsResponse) Test(org.junit.Test)

Aggregations

ComponentTreeWsResponse (org.sonarqube.ws.Measures.ComponentTreeWsResponse)22 ComponentDto (org.sonar.db.component.ComponentDto)21 Test (org.junit.Test)20 MetricDto (org.sonar.db.metric.MetricDto)19 SnapshotDto (org.sonar.db.component.SnapshotDto)16 Measure (org.sonarqube.ws.Measures.Measure)6 Metric (org.sonar.api.measures.Metric)5 Joiner (com.google.common.base.Joiner)4 Double.parseDouble (java.lang.Double.parseDouble)4 String.format (java.lang.String.format)4 Collections.singletonList (java.util.Collections.singletonList)4 List (java.util.List)4 IntStream (java.util.stream.IntStream)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)4 Assertions.tuple (org.assertj.core.api.Assertions.tuple)4 Rule (org.junit.Rule)4 CoreMetrics (org.sonar.api.measures.CoreMetrics)4 NEW_SECURITY_RATING_KEY (org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY)4 DISTRIB (org.sonar.api.measures.Metric.ValueType.DISTRIB)4