]> source.dussan.org Git - sonarqube.git/commitdiff
Improve coverage of ComponentTreeAction
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 5 Sep 2017 09:38:21 +0000 (11:38 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 5 Sep 2017 12:24:05 +0000 (14:24 +0200)
server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java

index 1674c35e36e32f17a7c1112ec9c6ee744671ec85..c4ff5c7957ce8aa223570ad79465c94cd9adf507 100644 (file)
@@ -53,6 +53,7 @@ import org.sonarqube.ws.WsMeasures;
 import org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY;
 import static org.sonar.api.measures.Metric.ValueType.DISTRIB;
 import static org.sonar.api.measures.Metric.ValueType.FLOAT;
@@ -62,6 +63,7 @@ import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
+import static org.sonar.db.component.ComponentTesting.newProjectCopy;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
 import static org.sonar.server.measure.ws.ComponentTreeAction.LEAVES_STRATEGY;
@@ -453,6 +455,25 @@ public class ComponentTreeActionTest {
     assertThat(responseMetric.hasDomain()).isFalse();
   }
 
+  @Test
+  public void reference_component() {
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto view = db.components().insertView();
+    SnapshotDto viewAnalysis = db.components().insertSnapshot(view);
+    ComponentDto projectCopy = db.components().insertComponent(newProjectCopy(project, view));
+    MetricDto ncloc = insertNclocMetric();
+    db.measures().insertMeasure(projectCopy, viewAnalysis, ncloc, m -> m.setValue(5d));
+
+    ComponentTreeWsResponse result = ws.newRequest()
+      .setParam(PARAM_BASE_COMPONENT_KEY, view.getKey())
+      .setParam(PARAM_METRIC_KEYS, ncloc.getKey())
+      .executeProtobuf(ComponentTreeWsResponse.class);
+
+    assertThat(result.getComponentsList())
+      .extracting(WsMeasures.Component::getKey, WsMeasures.Component::getRefId, WsMeasures.Component::getRefKey)
+      .containsExactlyInAnyOrder(tuple(projectCopy.getKey(), project.uuid(), project.getKey()));
+  }
+
   @Test
   public void fail_when_metric_keys_parameter_is_empty() {
     componentDb.insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));