diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-01-17 12:19:23 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-01-18 15:23:40 +0100 |
commit | 5690b112fccf1b3498ed457535cff629609269a2 (patch) | |
tree | 227b350c6c042ed72df1183f680237527760e6a8 /tests | |
parent | 013a9aa964e25e0c70bec60eaa4484d5c7e8683f (diff) | |
download | sonarqube-5690b112fccf1b3498ed457535cff629609269a2.tar.gz sonarqube-5690b112fccf1b3498ed457535cff629609269a2.zip |
SONAR-8574 Replace usage of api/resources/index by api/measures/component in ITs
Diffstat (limited to 'tests')
4 files changed, 44 insertions, 12 deletions
diff --git a/tests/perf/pom.xml b/tests/perf/pom.xml index 7ef689fdb72..d385f5d48fe 100644 --- a/tests/perf/pom.xml +++ b/tests/perf/pom.xml @@ -57,6 +57,12 @@ <version>1.12.1</version> </dependency> <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>sonar-ws</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> diff --git a/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/scanner/suite/DuplicationTest.java b/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/scanner/suite/DuplicationTest.java index b309b7f5b8f..9b700a0b3a8 100644 --- a/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/scanner/suite/DuplicationTest.java +++ b/tests/perf/src/test/java/org/sonarsource/sonarqube/perf/scanner/suite/DuplicationTest.java @@ -22,8 +22,9 @@ package org.sonarsource.sonarqube.perf.scanner.suite; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.MavenBuild; import com.sonar.orchestrator.locator.FileLocation; -import org.sonarsource.sonarqube.perf.PerfTestCase; import java.io.IOException; +import java.util.Map; +import java.util.stream.Collectors; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -31,9 +32,15 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ErrorCollector; import org.junit.rules.TemporaryFolder; -import org.sonar.wsclient.services.Resource; -import org.sonar.wsclient.services.ResourceQuery; +import org.sonarqube.ws.WsMeasures; +import org.sonarqube.ws.client.HttpConnector; +import org.sonarqube.ws.client.WsClient; +import org.sonarqube.ws.client.WsClientFactories; +import org.sonarqube.ws.client.measure.ComponentWsRequest; +import org.sonarsource.sonarqube.perf.PerfTestCase; +import static java.lang.Double.parseDouble; +import static java.util.Arrays.asList; import static org.fest.assertions.Assertions.assertThat; public class DuplicationTest extends PerfTestCase { @@ -68,12 +75,22 @@ public class DuplicationTest extends PerfTestCase { .setProperty("sonar.sourceEncoding", "UTF-8") .setCleanSonarGoals(); orchestrator.executeBuild(build); - Resource file = getResource("com.sonarsource.it.samples:huge-file:src/main/java/huge/HugeFile.java"); - assertThat(file.getMeasureValue("duplicated_lines")).isGreaterThan(50000.0); + Map<String, Double> measure = getMeasures("com.sonarsource.it.samples:huge-file:src/main/java/huge/HugeFile.java"); + assertThat(measure.get("duplicated_lines")).isGreaterThan(50000.0); + } + + private Map<String, Double> getMeasures(String key) { + return newWsClient().measures().component(new ComponentWsRequest() + .setComponentKey(key) + .setMetricKeys(asList("duplicated_lines", "duplicated_blocks", "duplicated_files", "duplicated_lines_density"))) + .getComponent().getMeasuresList() + .stream() + .collect(Collectors.toMap(WsMeasures.Measure::getMetric, measure -> parseDouble(measure.getValue()))); } - private Resource getResource(String key) { - return orchestrator.getServer().getWsClient() - .find(ResourceQuery.createForMetrics(key, "duplicated_lines", "duplicated_blocks", "duplicated_files", "duplicated_lines_density", "useless-duplicated-lines")); + private WsClient newWsClient() { + return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder() + .url(orchestrator.getServer().getUrl()) + .build()); } } diff --git a/tests/upgrade/pom.xml b/tests/upgrade/pom.xml index 59086bf5f6d..eddab9a40ae 100644 --- a/tests/upgrade/pom.xml +++ b/tests/upgrade/pom.xml @@ -18,9 +18,9 @@ <dependencies> <dependency> - <groupId>org.codehaus.sonar</groupId> - <artifactId>sonar-ws-client</artifactId> - <version>5.1</version> + <groupId>org.sonarsource.sonarqube</groupId> + <artifactId>sonar-ws</artifactId> + <version>${project.version}</version> <scope>test</scope> </dependency> <dependency> diff --git a/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java b/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java index bad5a01d7f7..480846415f3 100644 --- a/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java +++ b/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java @@ -32,18 +32,22 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.util.Arrays; +import java.util.Collections; import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Test; import org.sonar.wsclient.services.ResourceQuery; +import org.sonarqube.ws.WsMeasures.Measure; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.HttpConnector; import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.WsClientFactories; import org.sonarqube.ws.client.WsResponse; +import org.sonarqube.ws.client.measure.ComponentWsRequest; import static com.codeborne.selenide.Condition.hasText; import static com.codeborne.selenide.Selenide.$; +import static java.lang.Integer.parseInt; import static org.assertj.core.api.Assertions.assertThat; public class UpgradeTest { @@ -129,7 +133,7 @@ public class UpgradeTest { checkUrlIsReturningOk("/api/system/db_migration_status"); checkUrlIsReturningOk("/api/webservices/list"); // TODO Reactivate when latest Sonarqube version will be in repox -// checkUrlIsReturningOkOnlyForDevVersion("/api/l10n/index", sqVersion); + // checkUrlIsReturningOkOnlyForDevVersion("/api/l10n/index", sqVersion); // These urls should not be available when system requires a migration checkUrlIsReturningNotFound("/api/issues/search?projectKeys=org.apache.struts%3Astruts-core"); @@ -212,6 +216,11 @@ public class UpgradeTest { } private int countFiles(String key) { + if (orchestrator.getConfiguration().getSonarVersion().isGreaterThanOrEquals("5.4")) { + Measure measure = newWsClient(orchestrator).measures().component(new ComponentWsRequest().setComponentKey(key).setMetricKeys(Collections.singletonList("files"))) + .getComponent().getMeasures(0); + return parseInt(measure.getValue()); + } return orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics(key, "files")).getMeasureIntValue("files"); } |