Skip to content

Commit

Permalink
ITs: Use SQ DEV, deduplicate initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-mikula-sonarsource committed Mar 31, 2023
1 parent 1a410d4 commit 94ffff5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
8 changes: 1 addition & 7 deletions its/src/test/java/com/sonar/it/csharp/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.ScannerForMSBuild;
import com.sonar.orchestrator.container.Edition;
import com.sonar.orchestrator.locator.FileLocation;
import com.sonar.orchestrator.locator.MavenLocation;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -76,17 +74,13 @@
public class Tests {

@ClassRule
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(TestUtils.replaceLtsVersion(System.getProperty("sonar.runtimeVersion", "9.9")))
public static final Orchestrator ORCHESTRATOR = TestUtils.prepareOrchestrator()
.addPlugin(TestUtils.getPluginLocation("sonar-csharp-plugin")) // Do not add VB.NET here, use shared project instead
.setEdition(Edition.DEVELOPER)
.restoreProfileAtStartup(FileLocation.of("profiles/no_rule.xml"))
.restoreProfileAtStartup(FileLocation.of("profiles/class_name.xml"))
.restoreProfileAtStartup(FileLocation.of("profiles/template_rule.xml"))
.restoreProfileAtStartup(FileLocation.of("profiles/custom_parameters.xml"))
.restoreProfileAtStartup(FileLocation.of("profiles/custom_complexity.xml"))
.activateLicense()
.build();

public static Path projectDir(TemporaryFolder temp, String projectName) throws IOException {
Expand Down
17 changes: 14 additions & 3 deletions its/src/test/java/com/sonar/it/shared/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
package com.sonar.it.shared;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.OrchestratorBuilder;
import com.sonar.orchestrator.build.Build;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.ScannerForMSBuild;
import com.sonar.orchestrator.container.Edition;
import com.sonar.orchestrator.http.HttpMethod;
import com.sonar.orchestrator.locator.FileLocation;
import com.sonar.orchestrator.locator.Location;
Expand All @@ -49,6 +51,7 @@
import org.slf4j.LoggerFactory;
import org.sonarqube.ws.Ce;
import org.sonarqube.ws.Components;
import org.sonarqube.ws.Duplications.ShowResponse;
import org.sonarqube.ws.Issues;
import org.sonarqube.ws.Measures;
import org.sonarqube.ws.Measures.Measure;
Expand All @@ -58,7 +61,6 @@
import org.sonarqube.ws.client.ce.TaskRequest;
import org.sonarqube.ws.client.components.ShowRequest;
import org.sonarqube.ws.client.measures.ComponentRequest;
import org.sonarqube.ws.Duplications.ShowResponse;

import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -70,6 +72,14 @@ public class TestUtils {
private static final String MSBUILD_PATH = "MSBUILD_PATH";
private static final String MSBUILD_PATH_DEFAULT = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Current\\Bin\\msbuild.exe";

public static OrchestratorBuilder prepareOrchestrator() {
return Orchestrator.builderEnv()
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(replaceLtsVersion(System.getProperty("sonar.runtimeVersion", "DEV")))
.setEdition(Edition.DEVELOPER)
.activateLicense();
}

// Ensure no AnalysisWarning is raised inside the SQ GUI
public static void verifyNoGuiWarnings(Orchestrator orchestrator, BuildResult buildResult) {
Ce.Task task = TestUtils.getAnalysisWarningsTask(orchestrator, buildResult);
Expand Down Expand Up @@ -215,7 +225,8 @@ public static List<Issues.Issue> getIssues(Orchestrator orch, String componentKe
}

public static List<Issues.Issue> getIssues(Orchestrator orch, String componentKey, String pullRequestKey) {
return newWsClient(orch).issues().search(new org.sonarqube.ws.client.issues.SearchRequest().setComponentKeys(Collections.singletonList(componentKey)).setPullRequest(pullRequestKey)).getIssuesList();
return newWsClient(orch).issues()
.search(new org.sonarqube.ws.client.issues.SearchRequest().setComponentKeys(Collections.singletonList(componentKey)).setPullRequest(pullRequestKey)).getIssuesList();
}

public static List<Hotspot> getHotspots(Orchestrator orch, String projectKey) {
Expand All @@ -231,7 +242,7 @@ public static List<Hotspot> getHotspots(Orchestrator orch, String projectKey) {
// The term "latest" refers to the highest version number, not the most recently published version.
public static String replaceLtsVersion(String version) {
if (version != null && version.equals("LTS")) {
return "LATEST_RELEASE[8.9]";
return "LATEST_RELEASE[9.9]";
}
return version;
}
Expand Down
7 changes: 1 addition & 6 deletions its/src/test/java/com/sonar/it/shared/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.ScannerForMSBuild;
import com.sonar.orchestrator.container.Edition;
import com.sonar.orchestrator.locator.MavenLocation;
import java.io.File;
import java.io.IOException;
Expand All @@ -48,15 +47,11 @@
public class Tests {

@ClassRule
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(TestUtils.replaceLtsVersion(System.getProperty("sonar.runtimeVersion", "9.9")))
public static final Orchestrator ORCHESTRATOR = TestUtils.prepareOrchestrator()
.addPlugin(TestUtils.getPluginLocation("sonar-csharp-plugin"))
.addPlugin(TestUtils.getPluginLocation("sonar-vbnet-plugin"))
// ScannerCliTest: Fixed version for the HTML plugin as we don't want to have failures in case of changes there.
.addPlugin(MavenLocation.of("org.sonarsource.html", "sonar-html-plugin", "3.2.0.2082"))
.setEdition(Edition.DEVELOPER)
.activateLicense()
.build();

public static Path projectDir(TemporaryFolder temp, String projectName) throws IOException {
Expand Down
4 changes: 1 addition & 3 deletions its/src/test/java/com/sonar/it/vbnet/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@
public class Tests {

@ClassRule
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(TestUtils.replaceLtsVersion(System.getProperty("sonar.runtimeVersion", "9.9")))
public static final Orchestrator ORCHESTRATOR = TestUtils.prepareOrchestrator()
.addPlugin(TestUtils.getPluginLocation("sonar-vbnet-plugin")) // Do not add C# here, use shared project instead
.restoreProfileAtStartup(FileLocation.of("profiles/vbnet_no_rule.xml"))
.restoreProfileAtStartup(FileLocation.of("profiles/vbnet_class_name.xml"))
Expand Down

0 comments on commit 94ffff5

Please sign in to comment.