set -euo pipefail
+function runCategory {
+ mvn verify \
+ -f tests/pom.xml \
+ -Dcategory=$CATEGORY \
+ -Dorchestrator.configUrl=http://infra.internal.sonarsource.com/jenkins/orch-$DB_ENGINE.properties \
+ -Dorchestrator.workspace=target/$CATEGORY
+ -Dwith-db-drivers \
+ -B -e -V
+}
+
case "$RUN_ACTIVITY" in
run-db-unit-tests-*)
run-db-integration-tests-*)
DB_ENGINE=$(sed "s/run-db-integration-tests-//g" <<< $RUN_ACTIVITY | cut -d \- -f 1)
- CATEGORY=$(sed "s/run-db-integration-tests-//g" <<< $RUN_ACTIVITY | cut -d \- -f 2)
+ CATEGORY_GROUP=$(sed "s/run-db-integration-tests-//g" <<< $RUN_ACTIVITY | cut -d \- -f 2)
+
if [[ "$GITHUB_BRANCH" == "PULLREQUEST-"* ]] && [[ "$DB_ENGINE" != "postgresql93" ]]; then
- exit 0
+ # execute PR QA only on postgres
+ exit 0
else
- ./run-integration-tests.sh "${CATEGORY}" "http://infra.internal.sonarsource.com/jenkins/orch-${DB_ENGINE}.properties"
+ mvn clean package -B -e -V -f tests/plugins/pom.xml
+
+ case "$CATEGORY_GROUP" in
+ Category1)
+ CATEGORY=Category1 && runCategory
+ ;;
+
+ Category2)
+ CATEGORY=Category2 && runCategory
+ ;;
+
+ Category3)
+ CATEGORY=Category3 && runCategory
+ ;;
+
+ Category4)
+ CATEGORY=Category4 && runCategory
+ CATEGORY=duplication && runCategory
+ ;;
+
+ Category5)
+ CATEGORY=Category5 && runCategory
+ ;;
+
+ Category6)
+ CATEGORY=Category6 && runCategory
+ ;;
+
+ *)
+ echo "unknown CATEGORY_GROUP: $CATEGORY_GROUP"
+ exit 1
+ ;;
+ esac
+
fi
;;
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-application</artifactId>
- <version>${project.parent.version}</version>
+ <version>${project.version}</version>
<type>zip</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-qa-util</artifactId>
- <version>${project.parent.version}</version>
+ <version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-process</artifactId>
- <version>${project.parent.version}</version>
+ <version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-ws</artifactId>
- <version>${project.parent.version}</version>
+ <version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
</argLine>
<skipTests>${skipIts}</skipTests>
<includes>
+ <include>*/${category}/*Suite.java</include>
+
+ <!-- deprecated categories -->
<include>*/*${category}Suite.java</include>
</includes>
</configuration>
import org.sonarqube.tests.component.ComponentsWsTest;
import org.sonarqube.tests.component.ProjectsWsTest;
import org.sonarqube.tests.dbCleaner.PurgeTest;
-import org.sonarqube.tests.duplication.CrossProjectDuplicationsOnRemoveFileTest;
-import org.sonarqube.tests.duplication.CrossProjectDuplicationsTest;
-import org.sonarqube.tests.duplication.DuplicationsTest;
-import org.sonarqube.tests.duplication.NewDuplicationsTest;
import org.sonarqube.tests.organization.RootUserTest;
import org.sonarqube.tests.projectEvent.EventTest;
import org.sonarqube.tests.projectEvent.ProjectActivityPageTest;
// analysis exclusion
FileExclusionsTest.class,
IssueExclusionsTest.class,
- // duplication
- CrossProjectDuplicationsTest.class,
- CrossProjectDuplicationsOnRemoveFileTest.class,
- DuplicationsTest.class,
- NewDuplicationsTest.class,
// db cleaner
PurgeTest.class,
// project event
import com.google.common.collect.ImmutableMap;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category4Suite;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonarqube.qa.util.Tester;
import util.ItUtils;
import static org.assertj.core.api.Assertions.assertThat;
private File projectDir;
@ClassRule
- public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = DuplicationSuite.ORCHESTRATOR;
@Rule
public TemporaryFolder temp = new TemporaryFolder();
- @BeforeClass
- public static void analyzeProjects() {
-
- }
+ @Rule
+ public Tester tester = new Tester(orchestrator);
@Before
- public void setUpProject() throws IOException {
- orchestrator.resetData();
+ public void setUp() throws IOException {
ItUtils.restoreProfile(orchestrator, getClass().getResource("/duplication/xoo-duplication-profile.xml"));
FileUtils.copyDirectory(ItUtils.projectDir(PROJECT_DIR), temp.getRoot());
verifyDuplicationMeasures(PROJECT_KEY + ":module2", 0, 0, 0, 0);
}
- private static SonarScanner analyzeProject(File projectDir, String projectKey, boolean create, String... additionalProperties) {
+ private static void analyzeProject(File projectDir, String projectKey, boolean create, String... additionalProperties) {
if (create) {
orchestrator.getServer().provisionProject(projectKey, projectKey);
orchestrator.getServer().associateProjectToQualityProfile(projectKey, "xoo", "xoo-duplication-profile");
builder.put(additionalProperties[i], additionalProperties[i + 1]);
}
SonarScanner scan = sonarRunner.setDebugLogs(true).setProperties(builder.build());
- orchestrator.executeBuild(scan);
- return scan;
- }
+ orchestrator.executeBuild(scan); }
private static void verifyDuplicationMeasures(String componentKey, int duplicatedBlocks, int duplicatedLines, int duplicatedFiles, double duplicatedLinesDensity) {
Map<String, Double> measures = getMeasuresAsDoubleByMetricKey(orchestrator, componentKey, "duplicated_lines", "duplicated_blocks", "duplicated_files", "duplicated_lines_density");
package org.sonarqube.tests.duplication;
import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category4Suite;
import org.apache.commons.io.IOUtils;
-import org.junit.BeforeClass;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
import util.ItUtils;
import static org.assertj.core.api.Assertions.assertThat;
public class CrossProjectDuplicationsOnRemoveFileTest {
- static final String ORIGIN_PROJECT = "origin-project";
- static final String DUPLICATE_PROJECT = "duplicate-project";
- static final String DUPLICATE_FILE = DUPLICATE_PROJECT + ":src/main/xoo/sample/File1.xoo";
+ private static final String ORIGIN_PROJECT = "origin-project";
+ private static final String DUPLICATE_PROJECT = "duplicate-project";
+ private static final String DUPLICATE_FILE = DUPLICATE_PROJECT + ":src/main/xoo/sample/File1.xoo";
@ClassRule
- public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = DuplicationSuite.ORCHESTRATOR;
- @BeforeClass
- public static void analyzeProjects() {
- orchestrator.resetData();
- ItUtils.restoreProfile(orchestrator, CrossProjectDuplicationsOnRemoveFileTest.class.getResource("/duplication/xoo-duplication-profile.xml"));
+ @Rule
+ public Tester tester = new Tester(orchestrator);
+ @Test
+ public void duplications_show_ws_does_not_contain_key_of_deleted_file() throws Exception {
+ // analyze projects
+ ItUtils.restoreProfile(orchestrator, CrossProjectDuplicationsOnRemoveFileTest.class.getResource("/duplication/xoo-duplication-profile.xml"));
analyzeProject(ORIGIN_PROJECT, "duplications/cross-project/origin");
analyzeProject(DUPLICATE_PROJECT, "duplications/cross-project/duplicate");
// Remove origin project
- orchestrator.getServer().adminWsClient().post("api/projects/bulk_delete", "keys", ORIGIN_PROJECT);
+ tester.wsClient().wsConnector().call(new PostRequest("api/projects/bulk_delete").setParam("keys", ORIGIN_PROJECT));
assertThat(getComponent(orchestrator, ORIGIN_PROJECT)).isNull();
- }
-
- @Test
- public void duplications_show_ws_does_not_contain_key_of_deleted_file() throws Exception {
- String duplication = orchestrator.getServer().adminWsClient().get("api/duplications/show", "key", DUPLICATE_FILE);
+ // api/duplications/show does not return the deleted file
+ String json = tester.wsClient().wsConnector().call(new GetRequest("api/duplications/show").setParam("key", DUPLICATE_FILE)).content();
assertEquals(IOUtils.toString(CrossProjectDuplicationsTest.class.getResourceAsStream(
"/duplication/CrossProjectDuplicationsOnRemoveFileTest/duplications_on_removed_file-expected.json"), "UTF-8"),
- duplication, false);
-
+ json, false);
// Only one file should be reference, so the reference 2 on origin-project must not exist
- assertThat(duplication).doesNotContain("\"2\"");
- assertThat(duplication).doesNotContain("origin-project");
- }
+ assertThat(json).doesNotContain("\"2\"");
+ assertThat(json).doesNotContain("origin-project");
- /**
- * SONAR-3277
- */
- @Test
- public void display_message_in_viewer_when_duplications_with_deleted_files_are_found() throws Exception {
- // TODO stas, please replace this IT by a medium test
+ // SONAR-3277 display message in source viewer when duplications on deleted files are found
runSelenese(orchestrator,
"/duplication/CrossProjectDuplicationsOnRemoveFileTest/duplications-with-deleted-project.html");
}
import com.google.common.collect.ObjectArrays;
import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category4Suite;
import java.util.Map;
import org.apache.commons.io.IOUtils;
-import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.issue.SearchWsRequest;
import util.ItUtils;
import static util.ItUtils.getMeasuresAsDoubleByMetricKey;
import static util.ItUtils.newAdminWsClient;
import static util.ItUtils.runProjectAnalysis;
-import static util.ItUtils.setServerProperty;
import static util.selenium.Selenese.runSelenese;
public class CrossProjectDuplicationsTest {
- static final String ORIGIN_PROJECT = "origin-project";
- static final String DUPLICATE_PROJECT = "duplicate-project";
- static final String PROJECT_WITH_EXCLUSION = "project-with-exclusion";
- static final String PROJECT_WITHOUT_ENOUGH_TOKENS = "project_without_enough_tokens";
-
- static final String DUPLICATE_FILE = DUPLICATE_PROJECT + ":src/main/xoo/sample/File1.xoo";
- static final String BRANCH = "with-branch";
-
- static final String ORIGIN_PATH = "duplications/cross-project/origin";
- static final String DUPLICATE_PATH = "duplications/cross-project/duplicate";
+ private static final String ORIGIN_PROJECT = "origin-project";
+ private static final String DUPLICATE_PROJECT = "duplicate-project";
+ private static final String PROJECT_WITH_EXCLUSION = "project-with-exclusion";
+ private static final String PROJECT_WITHOUT_ENOUGH_TOKENS = "project_without_enough_tokens";
+ private static final String DUPLICATE_FILE = DUPLICATE_PROJECT + ":src/main/xoo/sample/File1.xoo";
+ private static final String BRANCH = "with-branch";
+ private static final String ORIGIN_PATH = "duplications/cross-project/origin";
+ private static final String DUPLICATE_PATH = "duplications/cross-project/duplicate";
@ClassRule
- public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = DuplicationSuite.ORCHESTRATOR;
@ClassRule
public static final IssueRule issueRule = IssueRule.from(orchestrator);
+ private static Tester tester = new Tester(orchestrator);
+
+ @ClassRule
+ public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester);
+
@BeforeClass
public static void analyzeProjects() {
- orchestrator.resetData();
ItUtils.restoreProfile(orchestrator, CrossProjectDuplicationsTest.class.getResource("/duplication/xoo-duplication-profile.xml"));
analyzeProject(ORIGIN_PROJECT, ORIGIN_PATH);
analyzeProject(PROJECT_WITH_EXCLUSION, DUPLICATE_PATH, "sonar.cpd.exclusions", "**/File*");
// Set minimum tokens to a big value in order to not get duplications
- setServerProperty(orchestrator, "sonar.cpd.xoo.minimumTokens", "1000");
+ tester.settings().setGlobalSettings("sonar.cpd.xoo.minimumTokens", "1000");
analyzeProject(PROJECT_WITHOUT_ENOUGH_TOKENS, DUPLICATE_PATH);
}
- @AfterClass
- public static void resetServerProperties() throws Exception {
- setServerProperty(orchestrator, "sonar.cpd.xoo.minimumTokens", null);
- }
-
@Test
public void origin_project_has_no_duplication_as_it_has_not_been_analyzed_twice() throws Exception {
assertProjectHasNoDuplication(ORIGIN_PROJECT);
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info 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 org.sonarqube.tests.duplication;
+
+import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+import static util.ItUtils.xooPlugin;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ CrossModuleDuplicationsTest.class,
+ CrossProjectDuplicationsOnRemoveFileTest.class,
+ CrossProjectDuplicationsTest.class,
+ DuplicationsTest.class,
+ NewDuplicationsTest.class,
+})
+public class DuplicationSuite {
+ @ClassRule
+ public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
+ .addPlugin(xooPlugin())
+
+ // reduce Elasticsearch memory
+ .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m")
+
+ .build();
+}
import com.google.common.collect.ObjectArrays;
import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category4Suite;
import java.util.Map;
import org.apache.commons.io.IOUtils;
-import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.WsResponse;
import org.sonarqube.ws.client.issue.SearchWsRequest;
import util.ItUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
import static util.ItUtils.getMeasuresAsDoubleByMetricKey;
-import static util.ItUtils.newAdminWsClient;
import static util.ItUtils.runProjectAnalysis;
-import static util.ItUtils.setServerProperty;
public class DuplicationsTest {
- static final String DUPLICATIONS = "file-duplications";
- static final String DUPLICATIONS_WITH_EXCLUSIONS = "file-duplications-with-exclusions";
- static final String WITHOUT_ENOUGH_TOKENS = "project_without_enough_tokens";
+ private static final String DUPLICATIONS = "file-duplications";
+ private static final String DUPLICATIONS_WITH_EXCLUSIONS = "file-duplications-with-exclusions";
+ private static final String WITHOUT_ENOUGH_TOKENS = "project_without_enough_tokens";
@ClassRule
- public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = DuplicationSuite.ORCHESTRATOR;
@ClassRule
public static final IssueRule issueRule = IssueRule.from(orchestrator);
- private static WsClient adminWsClient;
+ private static Tester tester = new Tester(orchestrator);
+
+ @ClassRule
+ public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester);
@BeforeClass
public static void analyzeProjects() {
- orchestrator.resetData();
-
ItUtils.restoreProfile(orchestrator, DuplicationsTest.class.getResource("/duplication/xoo-duplication-profile.xml"));
analyzeProject(DUPLICATIONS);
analyzeProject(DUPLICATIONS_WITH_EXCLUSIONS, "sonar.cpd.exclusions", "**/File*");
// Set minimum tokens to a big value in order to not get duplications
- setServerProperty(orchestrator, "sonar.cpd.xoo.minimumTokens", "1000");
+ tester.settings().setGlobalSettings("sonar.cpd.xoo.minimumTokens", "1000");
analyzeProject(WITHOUT_ENOUGH_TOKENS);
-
- adminWsClient = newAdminWsClient(orchestrator);
- }
-
- @AfterClass
- public static void resetProperties() throws Exception {
- setServerProperty(orchestrator, "sonar.cpd.xoo.minimumTokens", null);
}
private static Map<String, Double> getMeasures(String key) {
// SONAR-9441
@Test
public void fail_properly_when_no_parameter() {
- WsResponse result = adminWsClient.wsConnector().call(new GetRequest("api/duplications/show"));
+ WsResponse result = tester.wsClient().wsConnector().call(new GetRequest("api/duplications/show"));
assertThat(result.code()).isEqualTo(HTTP_BAD_REQUEST);
assertThat(result.content()).contains("Either 'uuid' or 'key' must be provided");
package org.sonarqube.tests.duplication;
import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category4Suite;
import java.util.Map;
import org.assertj.core.data.Offset;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsMeasures;
import static java.lang.Double.parseDouble;
public class NewDuplicationsTest {
- static final Offset<Double> DEFAULT_OFFSET = Offset.offset(0.1d);
+ private static final Offset<Double> DEFAULT_OFFSET = Offset.offset(0.1d);
@ClassRule
- public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = DuplicationSuite.ORCHESTRATOR;
+
+ private static Tester tester = new Tester(orchestrator);
+
+ @ClassRule
+ public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester);
@BeforeClass
public static void analyzeProjects() {
- orchestrator.resetData();
-
runProjectAnalysis(orchestrator, "duplications/new-duplications-v1",
"sonar.projectDate", "2015-02-01",
"sonar.scm.disabled", "false");
private static Tester tester = new Tester(orchestrator);
@ClassRule
- public static RuleChain ruleChain = RuleChain.outerRule(orchestrator)
- .around(tester);
+ public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester);
@BeforeClass
public static void setUp() {