Skip to content

Commit

Permalink
Fix QA with SQ 9.8
Browse files Browse the repository at this point in the history
After SONAR-17524, the default main branch name is "main". To simplify our tests on different versions, we will
revert to "master".
  • Loading branch information
henryju committed Nov 2, 2022
1 parent 3749cc7 commit ce414c9
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 61 deletions.
13 changes: 13 additions & 0 deletions its/tests/src/test/java/its/AbstractConnectedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.collect.Maps;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.MavenBuild;
import com.sonar.orchestrator.http.HttpMethod;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -67,6 +68,7 @@
public abstract class AbstractConnectedTest {
protected static final String SONARLINT_USER = "sonarlint";
protected static final String SONARLINT_PWD = "sonarlintpwd";
protected static final String MAIN_BRANCH_NAME = "master";

protected static final OkHttpClient CLIENT_NO_AUTH = new OkHttpClient.Builder()
.addNetworkInterceptor(new UserAgentInterceptor("SonarLint ITs"))
Expand Down Expand Up @@ -386,4 +388,15 @@ protected static void changeIssueStatus(WsClient adminWsClient, String issueKey,
}
}

protected static void provisionProject(Orchestrator orchestrator, String projectKey, String projectName) {
orchestrator.getServer()
.newHttpCall("/api/projects/create")
.setMethod(HttpMethod.POST)
.setAdminCredentials()
.setParam("project", projectKey)
.setParam("name", projectName)
.setParam("mainBranch", MAIN_BRANCH_NAME)
.execute();
}

}
8 changes: 4 additions & 4 deletions its/tests/src/test/java/its/CommercialAnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public static void prepare() throws Exception {

adminWsClient.users().create(new CreateRequest().setLogin(SONARLINT_USER).setPassword(SONARLINT_PWD).setName("SonarLint"));

ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_C, "Sample C");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_COBOL, "Sample Cobol");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_TSQL, "Sample TSQL");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_APEX, "Sample APEX");
provisionProject(ORCHESTRATOR, PROJECT_KEY_C, "Sample C");
provisionProject(ORCHESTRATOR, PROJECT_KEY_COBOL, "Sample Cobol");
provisionProject(ORCHESTRATOR, PROJECT_KEY_TSQL, "Sample TSQL");
provisionProject(ORCHESTRATOR, PROJECT_KEY_APEX, "Sample APEX");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY_C, "c", "SonarLint IT C");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY_COBOL, "cobol", "SonarLint IT Cobol");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY_TSQL, "tsql", "SonarLint IT TSQL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void prepare() {
var adminWsClient = newAdminWsClient(ORCHESTRATOR);
adminWsClient.users().create(new CreateRequest().setLogin(SONARLINT_USER).setPassword(SONARLINT_PWD).setName("SonarLint"));

ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY, "Sample Xoo");
provisionProject(ORCHESTRATOR, PROJECT_KEY, "Sample Xoo");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "SonarLint IT Xoo");

analyzeProject("sample-xoo-v1");
Expand Down Expand Up @@ -137,17 +137,17 @@ public void stop() {
public void download_all_issues_not_limited_to_10k() {
engine.updateProject(endpointParams(ORCHESTRATOR), sqHttpClient(), PROJECT_KEY, null);

engine.downloadAllServerIssues(endpointParams(ORCHESTRATOR), sqHttpClient(), PROJECT_KEY, "master", null);
engine.downloadAllServerIssues(endpointParams(ORCHESTRATOR), sqHttpClient(), PROJECT_KEY, MAIN_BRANCH_NAME, null);

var file1Issues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), "master", "src/500lines.xoo");
var file2Issues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), "master", "src/10000lines.xoo");
var file1Issues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), MAIN_BRANCH_NAME, "src/500lines.xoo");
var file2Issues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), MAIN_BRANCH_NAME, "src/10000lines.xoo");

// Number of issues is not limited to 10k
assertThat(file1Issues.size() + file2Issues.size()).isEqualTo(10_500);

Map<String, ServerIssue> allIssues = new HashMap<>();
engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), "master", "src/500lines.xoo").forEach(i -> allIssues.put(i.getKey(), i));
engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), "master", "src/10000lines.xoo").forEach(i -> allIssues.put(i.getKey(), i));
engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), MAIN_BRANCH_NAME, "src/500lines.xoo").forEach(i -> allIssues.put(i.getKey(), i));
engine.getServerIssues(new ProjectBinding(PROJECT_KEY, "", ""), MAIN_BRANCH_NAME, "src/10000lines.xoo").forEach(i -> allIssues.put(i.getKey(), i));

assertThat(allIssues).hasSize(10_500);
assertThat(allIssues.get(wfIssue.getKey()).isResolved()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static void prepare() throws IOException {
.setExtraProperties(new HashMap<>())
.build());

ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY, "Sample Xoo");
provisionProject(ORCHESTRATOR, PROJECT_KEY, "Sample Xoo");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "SonarLint IT Xoo");

engine.updateProject(endpointParams(ORCHESTRATOR), sqHttpClient(), PROJECT_KEY, null);
Expand Down Expand Up @@ -150,11 +150,11 @@ public void sync_all_project_branches() {

// Starting from SQ 8.1, concept of short vs long living branch has been removed
if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(8, 1)) {
assertThat(engine.getServerBranches(PROJECT_KEY).getBranchNames()).containsOnly("master", LONG_BRANCH, SHORT_BRANCH);
assertThat(engine.getServerBranches(PROJECT_KEY).getBranchNames()).containsOnly(MAIN_BRANCH_NAME, LONG_BRANCH, SHORT_BRANCH);
} else {
assertThat(engine.getServerBranches(PROJECT_KEY).getBranchNames()).containsOnly("master", LONG_BRANCH);
assertThat(engine.getServerBranches(PROJECT_KEY).getBranchNames()).containsOnly(MAIN_BRANCH_NAME, LONG_BRANCH);
}
assertThat(engine.getServerBranches(PROJECT_KEY).getMainBranchName()).isEqualTo("master");
assertThat(engine.getServerBranches(PROJECT_KEY).getMainBranchName()).isEqualTo(MAIN_BRANCH_NAME);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void prepare() throws Exception {

adminWsClient.users().create(new CreateRequest().setLogin(SONARLINT_USER).setPassword(SONARLINT_PWD).setName("SonarLint"));

ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_C, "Sample C");
provisionProject(ORCHESTRATOR, PROJECT_KEY_C, "Sample C");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY_C, "c", "SonarLint IT C");
}

Expand Down
17 changes: 9 additions & 8 deletions its/tests/src/test/java/its/ConnectedFileMatchingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ConnectedFileMatchingTest extends AbstractConnectedTest {
.defaultForceAuthentication()
.setSonarVersion(SONAR_VERSION)
.keepBundledPlugins()
.setServerProperty("sonar.projectCreation.mainBranchName", MAIN_BRANCH_NAME)
.build();

@Rule
Expand Down Expand Up @@ -108,19 +109,19 @@ public void should_match_files_when_importing_entire_project() throws IOExceptio
assertThat(projectBinding.serverPathPrefix()).isEmpty();
assertThat(projectBinding.idePathPrefix()).isEmpty();
engine.downloadAllServerIssuesForFile(endpointParams(ORCHESTRATOR), sqHttpClient(), projectBinding,
"module_b/module_b1/src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java", "master", null);
var serverIssues = engine.getServerIssues(projectBinding, "master", "module_b/module_b1/src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java");
"module_b/module_b1/src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java", MAIN_BRANCH_NAME, null);
var serverIssues = engine.getServerIssues(projectBinding, MAIN_BRANCH_NAME, "module_b/module_b1/src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java");
if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(9, 6)) {
assertThat(serverIssues).isEmpty();
assertThat(logs).contains("Skip downloading file issues on SonarQube 9.6+");
} else {
assertThat(serverIssues).hasSize(2);
}
engine.syncServerIssues(endpointParams(ORCHESTRATOR), sqHttpClient(), PROJECT_KEY, "master", null);
engine.syncServerIssues(endpointParams(ORCHESTRATOR), sqHttpClient(), PROJECT_KEY, MAIN_BRANCH_NAME, null);
if (!ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(9, 6)) {
assertThat(logs).contains("Incremental issue sync is not supported. Skipping.");
}
serverIssues = engine.getServerIssues(projectBinding, "master", "module_b/module_b1/src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java");
serverIssues = engine.getServerIssues(projectBinding, MAIN_BRANCH_NAME, "module_b/module_b1/src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java");
assertThat(serverIssues).hasSize(2);
}

Expand All @@ -138,19 +139,19 @@ public void should_match_files_when_importing_module() throws IOException {
assertThat(projectBinding.serverPathPrefix()).isEqualTo("module_b/module_b1");
assertThat(projectBinding.idePathPrefix()).isEmpty();
engine.downloadAllServerIssuesForFile(endpointParams(ORCHESTRATOR), sqHttpClient(), projectBinding,
"src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java", "master", null);
var serverIssues = engine.getServerIssues(projectBinding, "master", "src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java");
"src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java", MAIN_BRANCH_NAME, null);
var serverIssues = engine.getServerIssues(projectBinding, MAIN_BRANCH_NAME, "src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java");
if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(9, 6)) {
assertThat(serverIssues).isEmpty();
assertThat(logs).contains("Skip downloading file issues on SonarQube 9.6+");
} else {
assertThat(serverIssues).hasSize(2);
}
engine.syncServerIssues(endpointParams(ORCHESTRATOR), sqHttpClient(), PROJECT_KEY, "master", null);
engine.syncServerIssues(endpointParams(ORCHESTRATOR), sqHttpClient(), PROJECT_KEY, MAIN_BRANCH_NAME, null);
if (!ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(9, 6)) {
assertThat(logs).contains("Incremental issue sync is not supported. Skipping.");
}
serverIssues = engine.getServerIssues(projectBinding, "master", "src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java");
serverIssues = engine.getServerIssues(projectBinding, MAIN_BRANCH_NAME, "src/main/java/com/sonar/it/samples/modules/b1/HelloB1.java");
assertThat(serverIssues).hasSize(2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public static void prepare() throws Exception {

newAdminWsClient(ORCHESTRATOR).users().create(new CreateRequest().setLogin(SONARLINT_USER).setPassword(SONARLINT_PWD).setName("SonarLint"));

ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_JAVASCRIPT, "Sample Javascript");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_TYPESCRIPT, "Sample Typescript");
provisionProject(ORCHESTRATOR, PROJECT_KEY_JAVASCRIPT, "Sample Javascript");
provisionProject(ORCHESTRATOR, PROJECT_KEY_TYPESCRIPT, "Sample Typescript");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY_JAVASCRIPT, "js", "SonarLint IT Javascript");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY_TYPESCRIPT, "ts", "SonarLint IT Typescript");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void prepare() throws IOException {
var adminWsClient = newAdminWsClient(ORCHESTRATOR);
adminWsClient.users().create(new CreateRequest().setLogin(SONARLINT_USER).setPassword(SONARLINT_PWD).setName("SonarLint"));

ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_LANGUAGE_MIX, "Sample Language Mix");
provisionProject(ORCHESTRATOR, PROJECT_KEY_LANGUAGE_MIX, "Sample Language Mix");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY_LANGUAGE_MIX, "java", "SonarLint IT Java");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY_LANGUAGE_MIX, "py", "SonarLint IT Python");

Expand Down Expand Up @@ -96,10 +96,10 @@ public void sync_all_issues_of_enabled_languages() {
assumeTrue("SonarQube should support pulling issues",
ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(9, 6));

engine.syncServerIssues(endpointParams(ORCHESTRATOR), sqHttpClient(), PROJECT_KEY_LANGUAGE_MIX, "master", null);
engine.syncServerIssues(endpointParams(ORCHESTRATOR), sqHttpClient(), PROJECT_KEY_LANGUAGE_MIX, MAIN_BRANCH_NAME, null);

var javaIssues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY_LANGUAGE_MIX, "", ""), "master", "src/main/java/foo/Foo.java");
var pythonIssues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY_LANGUAGE_MIX, "", ""), "master", "src/main/java/foo/main.py");
var javaIssues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY_LANGUAGE_MIX, "", ""), MAIN_BRANCH_NAME, "src/main/java/foo/Foo.java");
var pythonIssues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY_LANGUAGE_MIX, "", ""), MAIN_BRANCH_NAME, "src/main/java/foo/main.py");

assertThat(javaIssues).hasSize(2);
assertThat(pythonIssues).isEmpty();
Expand Down
39 changes: 20 additions & 19 deletions its/tests/src/test/java/its/ConnectedModeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private static String javaRuleKey(String key) {
.setServerProperty("sonar.pushevents.polling.initial.delay", "2")
.setServerProperty("sonar.pushevents.polling.period", "1")
.setServerProperty("sonar.pushevents.polling.last.timestamp", "1")
.setServerProperty("sonar.projectCreation.mainBranchName", MAIN_BRANCH_NAME)
.build();

@ClassRule
Expand All @@ -155,22 +156,22 @@ public static void prepare() throws Exception {

adminWsClient.users().create(new CreateRequest().setLogin(SONARLINT_USER).setPassword(SONARLINT_PWD).setName("SonarLint"));

ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_JAVA, "Sample Java");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_JAVA_PACKAGE, "Sample Java Package");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_JAVA_HOTSPOT, "Sample Java Hotspot");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_JAVA_EMPTY, "Sample Java Empty");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_JAVA_MARKDOWN, "Sample Java Markdown");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_PHP, "Sample PHP");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_JAVASCRIPT, "Sample Javascript");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_JAVA_CUSTOM, "Sample Java Custom");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_PYTHON, "Sample Python");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_WEB, "Sample Web");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_JAVA_CUSTOM_SENSOR, "Sample Java Custom");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_GLOBAL_EXTENSION, "Sample Global Extension");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_RUBY, "Sample Ruby");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_KOTLIN, "Sample Kotlin");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_SCALA, "Sample Scala");
ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY_XML, "Sample XML");
provisionProject(ORCHESTRATOR, PROJECT_KEY_JAVA, "Sample Java");
provisionProject(ORCHESTRATOR, PROJECT_KEY_JAVA_PACKAGE, "Sample Java Package");
provisionProject(ORCHESTRATOR, PROJECT_KEY_JAVA_HOTSPOT, "Sample Java Hotspot");
provisionProject(ORCHESTRATOR, PROJECT_KEY_JAVA_EMPTY, "Sample Java Empty");
provisionProject(ORCHESTRATOR, PROJECT_KEY_JAVA_MARKDOWN, "Sample Java Markdown");
provisionProject(ORCHESTRATOR, PROJECT_KEY_PHP, "Sample PHP");
provisionProject(ORCHESTRATOR, PROJECT_KEY_JAVASCRIPT, "Sample Javascript");
provisionProject(ORCHESTRATOR, PROJECT_KEY_JAVA_CUSTOM, "Sample Java Custom");
provisionProject(ORCHESTRATOR, PROJECT_KEY_PYTHON, "Sample Python");
provisionProject(ORCHESTRATOR, PROJECT_KEY_WEB, "Sample Web");
provisionProject(ORCHESTRATOR, PROJECT_KEY_JAVA_CUSTOM_SENSOR, "Sample Java Custom");
provisionProject(ORCHESTRATOR, PROJECT_KEY_GLOBAL_EXTENSION, "Sample Global Extension");
provisionProject(ORCHESTRATOR, PROJECT_KEY_RUBY, "Sample Ruby");
provisionProject(ORCHESTRATOR, PROJECT_KEY_KOTLIN, "Sample Kotlin");
provisionProject(ORCHESTRATOR, PROJECT_KEY_SCALA, "Sample Scala");
provisionProject(ORCHESTRATOR, PROJECT_KEY_XML, "Sample XML");

ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY_JAVA, "java", "SonarLint IT Java");
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY_JAVA_PACKAGE, "java", "SonarLint IT Java Package");
Expand Down Expand Up @@ -243,7 +244,7 @@ public void stop() {

@Test
public void downloadProjects() {
ORCHESTRATOR.getServer().provisionProject("foo-bar", "Foo");
provisionProject(ORCHESTRATOR, "foo-bar", "Foo");
assertThat(engine.downloadAllProjects(endpointParams(ORCHESTRATOR), sqHttpClient(), null)).hasSize(17).containsKeys("foo-bar", PROJECT_KEY_JAVA, PROJECT_KEY_PHP);
}

Expand Down Expand Up @@ -685,7 +686,7 @@ public void updatesStorageWhenIssueResolvedOnServer() throws InterruptedExceptio
});
});

var serverIssues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY_JAVA, "", ""), "master", "src/main/java/foo/Foo.java");
var serverIssues = engine.getServerIssues(new ProjectBinding(PROJECT_KEY_JAVA, "", ""), MAIN_BRANCH_NAME, "src/main/java/foo/Foo.java");

assertThat(serverIssues)
.extracting(ServerIssue::getRuleKey, ServerIssue::isResolved)
Expand All @@ -702,7 +703,7 @@ private void setSettingsMultiValue(@Nullable String moduleKey, String key, Strin
private void updateProject(String projectKey) {
engine.updateProject(endpointParams(ORCHESTRATOR), sqHttpClient(), projectKey, null);
engine.sync(endpointParams(ORCHESTRATOR), sqHttpClient(), Set.of(projectKey), null);
engine.syncServerIssues(endpointParams(ORCHESTRATOR), sqHttpClient(), projectKey, "master", null);
engine.syncServerIssues(endpointParams(ORCHESTRATOR), sqHttpClient(), projectKey, MAIN_BRANCH_NAME, null);
}

private static void analyzeMavenProject(String projectKey, String projectDirName) {
Expand Down
Loading

0 comments on commit ce414c9

Please sign in to comment.