diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-01-06 17:46:38 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-01-13 14:13:35 +0100 |
commit | 0242e1da3fea5a96a9f0632156b1cacdd89b9ace (patch) | |
tree | 68166c8f6ed52713ba24b5d94e9fe00616491e05 /it | |
parent | 49b3b0bc394ce675356d832e1d12459b9be543bd (diff) | |
download | sonarqube-0242e1da3fea5a96a9f0632156b1cacdd89b9ace.tar.gz sonarqube-0242e1da3fea5a96a9f0632156b1cacdd89b9ace.zip |
SONAR-7135 WS api/measures/component_tree navigate through components and display measures
Diffstat (limited to 'it')
-rw-r--r-- | it/it-tests/src/test/java/it/measure/MeasuresWsTest.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/it/it-tests/src/test/java/it/measure/MeasuresWsTest.java b/it/it-tests/src/test/java/it/measure/MeasuresWsTest.java new file mode 100644 index 00000000000..b62e390e627 --- /dev/null +++ b/it/it-tests/src/test/java/it/measure/MeasuresWsTest.java @@ -0,0 +1,82 @@ +/* + * SonarQube Integration Tests :: Tests + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package it.measure; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.SonarRunner; +import it.Category4Suite; +import java.util.List; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonarqube.ws.WsMeasures; +import org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse; +import org.sonarqube.ws.client.WsClient; +import org.sonarqube.ws.client.measure.ComponentTreeWsRequest; +import util.ItUtils; + +import static com.google.common.collect.Lists.newArrayList; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; +import static util.ItUtils.projectDir; +import static util.ItUtils.setServerProperty; + +public class MeasuresWsTest { + @ClassRule + public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; + private static final String FILE_KEY = "sample:src/main/xoo/sample/Sample.xoo"; + WsClient wsClient; + + @BeforeClass + public static void initPeriods() throws Exception { + setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis"); + setServerProperty(orchestrator, "sonar.timemachine.period2", "30"); + setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_version"); + } + + @AfterClass + public static void resetPeriods() throws Exception { + ItUtils.resetPeriods(orchestrator); + } + + @Before + public void inspectProject() { + orchestrator.resetData(); + orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample"))); + + wsClient = ItUtils.newAdminWsClient(orchestrator); + } + + @Test + public void component_tree() { + ComponentTreeWsResponse response = wsClient.measures().componentTree(new ComponentTreeWsRequest() + .setBaseComponentKey("sample") + .setMetricKeys(singletonList("ncloc")) + .setAdditionalFields(newArrayList("metrics", "periods"))); + + assertThat(response).isNotNull(); + assertThat(response.getMetrics().getMetricsList()).extracting("key").containsOnly("ncloc"); + List<WsMeasures.Component> components = response.getComponentsList(); + assertThat(components).hasSize(2).extracting("key").containsOnly("sample:src/main/xoo/sample", FILE_KEY); + assertThat(components.get(0).getMeasuresList().get(0).getValue()).isEqualTo("13"); + } +} |