summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-09-05 11:38:21 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2017-09-05 14:24:05 +0200
commitf820596782c010252f0de679903493790a96def5 (patch)
treeb18be770eb5089269c480dc40a5f87c0da04d010 /server
parent9cff6b3dbd1f2ceb973f3ccec234c344a5809aba (diff)
downloadsonarqube-f820596782c010252f0de679903493790a96def5.tar.gz
sonarqube-f820596782c010252f0de679903493790a96def5.zip
Improve coverage of ComponentTreeAction
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
index 1674c35e36e..c4ff5c7957c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
@@ -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;
@@ -454,6 +456,25 @@ public class ComponentTreeActionTest {
}
@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"));