aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/test/java/org
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-08-08 19:22:52 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-09-07 08:33:31 +0200
commit0c9958691ea0fb870762e77384555d2a63ec635a (patch)
tree338792fb8a3f6c29165ecba62e8da99271a08442 /tests/src/test/java/org
parentad5e52729d542dc2ee5fc7b4a90ced2f69eaed9b (diff)
downloadsonarqube-0c9958691ea0fb870762e77384555d2a63ec635a.tar.gz
sonarqube-0c9958691ea0fb870762e77384555d2a63ec635a.zip
SONAR-9661 Add IT for issue backdating on plugin update
Diffstat (limited to 'tests/src/test/java/org')
-rw-r--r--tests/src/test/java/org/sonarqube/tests/Category2Suite.java8
-rw-r--r--tests/src/test/java/org/sonarqube/tests/Category5Suite.java5
-rw-r--r--tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java123
-rw-r--r--tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDateQPChangedTest.java (renamed from tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDateTest.java)24
4 files changed, 140 insertions, 20 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category2Suite.java b/tests/src/test/java/org/sonarqube/tests/Category2Suite.java
index c3b8a749925..244ca12aa36 100644
--- a/tests/src/test/java/org/sonarqube/tests/Category2Suite.java
+++ b/tests/src/test/java/org/sonarqube/tests/Category2Suite.java
@@ -20,12 +20,16 @@
package org.sonarqube.tests;
import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
import org.sonarqube.tests.issue.AutoAssignTest;
import org.sonarqube.tests.issue.CommonRulesTest;
import org.sonarqube.tests.issue.CustomRulesTest;
import org.sonarqube.tests.issue.IssueActionTest;
import org.sonarqube.tests.issue.IssueBulkChangeTest;
import org.sonarqube.tests.issue.IssueChangelogTest;
+import org.sonarqube.tests.issue.IssueCreationDateQPChangedTest;
import org.sonarqube.tests.issue.IssueCreationTest;
import org.sonarqube.tests.issue.IssueFilterExtensionTest;
import org.sonarqube.tests.issue.IssueFilterOnCommonRulesTest;
@@ -51,9 +55,6 @@ import org.sonarqube.tests.test.CoverageTest;
import org.sonarqube.tests.test.CoverageTrackingTest;
import org.sonarqube.tests.test.NewCoverageTest;
import org.sonarqube.tests.test.TestExecutionTest;
-import org.junit.ClassRule;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
import static util.ItUtils.pluginArtifact;
import static util.ItUtils.xooPlugin;
@@ -85,6 +86,7 @@ import static util.ItUtils.xooPlugin;
IssueTrackingTest.class,
IssueWorkflowTest.class,
NewIssuesMeasureTest.class,
+ IssueCreationDateQPChangedTest.class,
// debt
MaintainabilityMeasureTest.class,
MaintainabilityRatingMeasureTest.class,
diff --git a/tests/src/test/java/org/sonarqube/tests/Category5Suite.java b/tests/src/test/java/org/sonarqube/tests/Category5Suite.java
index 7bc3331d1d3..9ef6a74a20f 100644
--- a/tests/src/test/java/org/sonarqube/tests/Category5Suite.java
+++ b/tests/src/test/java/org/sonarqube/tests/Category5Suite.java
@@ -23,10 +23,11 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.sonarqube.tests.ce.CeShutdownTest;
import org.sonarqube.tests.ce.CeWorkersTest;
+import org.sonarqube.tests.cluster.ClusterTest;
+import org.sonarqube.tests.issue.IssueCreationDatePluginChangedTest;
import org.sonarqube.tests.qualityProfile.ActiveRuleEsResilienceTest;
import org.sonarqube.tests.qualityProfile.BuiltInQualityProfilesNotificationTest;
import org.sonarqube.tests.rule.RuleEsResilienceTest;
-import org.sonarqube.tests.cluster.ClusterTest;
import org.sonarqube.tests.serverSystem.RestartTest;
import org.sonarqube.tests.serverSystem.ServerSystemRestartingOrchestrator;
import org.sonarqube.tests.settings.ElasticsearchSettingsTest;
@@ -66,6 +67,8 @@ import org.sonarqube.tests.user.UserEsResilienceTest;
// ce
CeShutdownTest.class,
CeWorkersTest.class,
+ // issues
+ IssueCreationDatePluginChangedTest.class,
// elasticsearch
ElasticsearchSettingsTest.class
diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java
new file mode 100644
index 00000000000..e5bd0a3d55c
--- /dev/null
+++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDatePluginChangedTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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.issue;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarScanner;
+import java.io.File;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.wsclient.issue.Issue;
+import org.sonar.wsclient.issue.IssueQuery;
+import org.sonarqube.ws.client.PostRequest;
+import util.ItUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+import static util.ItUtils.pluginArtifact;
+import static util.ItUtils.projectDir;
+import static util.ItUtils.xooPlugin;
+
+/**
+ * @see <a href="https://jira.sonarsource.com/browse/MMF-766">MMF-766</a>
+ */
+public class IssueCreationDatePluginChangedTest {
+
+ private static final String ISSUE_STATUS_OPEN = "OPEN";
+
+ private static final String LANGUAGE_XOO = "xoo";
+
+ private static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
+
+ private static final String SAMPLE_PROJECT_KEY = "creation-date-sample";
+ private static final String SAMPLE_PROJECT_NAME = "Creation date sample";
+ private static final String SAMPLE_QUALITY_PROFILE_NAME = "creation-date-plugin";
+
+ @ClassRule
+ public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
+ .addPlugin(xooPlugin())
+ .addPlugin(ItUtils.pluginArtifact("backdating-plugin-v1"))
+ .build();
+
+ @Before
+ public void cleanup() {
+ ORCHESTRATOR.resetData();
+ }
+
+ @Test
+ public void should_use_scm_date_for_new_issues_if_plugin_updated() {
+ ItUtils.restoreProfile(ORCHESTRATOR, getClass().getResource("/issue/IssueCreationDatePluginChangedTest/one-rule.xml"));
+
+ ORCHESTRATOR.getServer().provisionProject(SAMPLE_PROJECT_KEY, SAMPLE_PROJECT_NAME);
+ ORCHESTRATOR.getServer().associateProjectToQualityProfile(SAMPLE_PROJECT_KEY, LANGUAGE_XOO, SAMPLE_QUALITY_PROFILE_NAME);
+
+ // First analysis
+ SonarScanner scanner = SonarScanner.create(projectDir("issue/creationDatePluginChanged"))
+ .setProperty("sonar.scm.provider", "xoo")
+ .setProperty("sonar.scm.disabled", "false");
+ ORCHESTRATOR.executeBuild(scanner);
+
+ List<Issue> issues = getIssues(issueQuery().components("creation-date-sample:src/main/xoo/sample/Sample.xoo"));
+
+ // Check that issue is backdated to SCM (because it is the first analysis)
+ assertThat(issues)
+ .extracting(Issue::line, Issue::creationDate)
+ .containsExactly(tuple(1, dateTimeParse("2005-01-01T00:00:00+0000")));
+
+ // Update the plugin
+ // uninstall plugin V1
+ ItUtils.newAdminWsClient(ORCHESTRATOR).wsConnector().call(new PostRequest("api/plugins/uninstall").setParam("key", "backdating")).failIfNotSuccessful();
+ // install plugin V2
+ File pluginsDir = new File(ORCHESTRATOR.getServer().getHome() + "/extensions/plugins");
+ ORCHESTRATOR.getConfiguration().fileSystem().copyToDirectory(pluginArtifact("backdating-plugin-v2"), pluginsDir);
+
+ ORCHESTRATOR.restartServer();
+
+ // New analysis that should raise a new issue
+ ORCHESTRATOR.executeBuild(scanner);
+ issues = getIssues(issueQuery().components("creation-date-sample:src/main/xoo/sample/Sample.xoo"));
+ assertThat(issues)
+ .extracting(Issue::line, Issue::creationDate)
+ .containsExactly(tuple(1, dateTimeParse("2005-01-01T00:00:00+0000")),
+ tuple(2, dateTimeParse("2005-01-01T00:00:00+0000")));
+ }
+
+ private static List<Issue> getIssues(IssueQuery query) {
+ return ORCHESTRATOR.getServer().wsClient().issueClient().find(query).list();
+ }
+
+ private static IssueQuery issueQuery() {
+ return IssueQuery.create().statuses(ISSUE_STATUS_OPEN);
+ }
+
+ private static Date dateTimeParse(String expectedDate) {
+ try {
+ return new SimpleDateFormat(DATETIME_FORMAT).parse(expectedDate);
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDateTest.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDateQPChangedTest.java
index 47ce6e5ac9f..c454ab681da 100644
--- a/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDateTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationDateQPChangedTest.java
@@ -24,6 +24,7 @@ import com.sonar.orchestrator.container.Server;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
+import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Date;
@@ -45,14 +46,13 @@ import static util.ItUtils.projectDir;
/**
* @see <a href="https://jira.sonarsource.com/browse/MMF-567">MMF-567</a>
*/
-public class IssueCreationDateTest extends AbstractIssueTest {
+public class IssueCreationDateQPChangedTest extends AbstractIssueTest {
private static final String ISSUE_STATUS_OPEN = "OPEN";
private static final String LANGUAGE_XOO = "xoo";
private static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
- private static final String DATE_FORMAT = "yyyy-MM-dd";
private static final String SAMPLE_PROJECT_KEY = "creation-date-sample";
private static final String SAMPLE_PROJECT_NAME = "Creation date sample";
@@ -232,16 +232,8 @@ public class IssueCreationDateTest extends AbstractIssueTest {
}
}
- private static Date dateParse(String expectedDate) {
- try {
- return new SimpleDateFormat(DATE_FORMAT).parse(expectedDate);
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }
-
private static String todayMinusDays(int numberOfDays) {
- return DateTimeFormatter.ofPattern(DATE_FORMAT).format(LocalDate.now().atStartOfDay().minusDays(numberOfDays));
+ return DateTimeFormatter.ofPattern(DATETIME_FORMAT).format(LocalDate.now().atStartOfDay().minusDays(numberOfDays).atZone(ZoneId.systemDefault()));
}
private enum SourceCode {
@@ -277,8 +269,8 @@ public class IssueCreationDateTest extends AbstractIssueTest {
private static final Component[] COMPONENTS_OF_SOURCE_CHANGED = {Component.ForeverAndModified, Component.ForeverAndUnmodified, Component.OnlyInChanged};
private enum QProfile {
- ONE_RULE("/issue/IssueCreationDateTest/one-rule.xml"),
- NO_RULES("/issue/IssueCreationDateTest/no-rules.xml"),
+ ONE_RULE("/issue/IssueCreationDateQPChangedTest/one-rule.xml"),
+ NO_RULES("/issue/IssueCreationDateQPChangedTest/no-rules.xml"),
;
private final String path;
@@ -323,8 +315,8 @@ public class IssueCreationDateTest extends AbstractIssueTest {
ForeverAndModified_R1(dateTimeParse("2003-01-01T00:00:00+0000")),
ForeverAndModified_R2(dateTimeParse("2004-01-01T00:00:00+0000")),
OnlyInChanged_R1(dateTimeParse("2005-01-01T00:00:00+0000")),
- EXPLICIT_DATE_1(dateParse(SAMPLE_EXPLICIT_DATE_1)),
- EXPLICIT_DATE_2(dateParse(SAMPLE_EXPLICIT_DATE_2)),
+ EXPLICIT_DATE_1(dateTimeParse(SAMPLE_EXPLICIT_DATE_1)),
+ EXPLICIT_DATE_2(dateTimeParse(SAMPLE_EXPLICIT_DATE_2)),
FIRST_ANALYSIS {
@Override
Date getDate() {
@@ -371,7 +363,7 @@ public class IssueCreationDateTest extends AbstractIssueTest {
.getAnalysesList())
.flatMap(chooseItem)
.map(ProjectAnalyses.Analysis::getDate)
- .map(IssueCreationDateTest::dateTimeParse)
+ .map(IssueCreationDateQPChangedTest::dateTimeParse)
.orElseThrow(() -> new IllegalStateException("There is no analysis"));
}
}