aboutsummaryrefslogtreecommitdiffstats
path: root/it
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-10-20 18:05:58 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-10-23 10:44:16 +0200
commit417e7c62ce4993b66f1fc740a6973aee2c704e53 (patch)
tree7d61ce9da130033ff4aec954d43dcb14f9b3d8be /it
parent0235ff6fffe8a45bfb5b82eb4c6d8aeb2b7eccf9 (diff)
downloadsonarqube-417e7c62ce4993b66f1fc740a6973aee2c704e53.tar.gz
sonarqube-417e7c62ce4993b66f1fc740a6973aee2c704e53.zip
move IssuePurgeTest from it-cores to SQ sources
Diffstat (limited to 'it')
-rw-r--r--it/it-tests/src/test/java/issue/suite/IssuePurgeTest.java131
-rw-r--r--it/it-tests/src/test/java/issue/suite/IssueTestSuite.java5
-rw-r--r--it/it-tests/src/test/resources/issue/suite/IssuePurgeTest/with-many-rules.xml32
3 files changed, 166 insertions, 2 deletions
diff --git a/it/it-tests/src/test/java/issue/suite/IssuePurgeTest.java b/it/it-tests/src/test/java/issue/suite/IssuePurgeTest.java
new file mode 100644
index 00000000000..f7a89303d53
--- /dev/null
+++ b/it/it-tests/src/test/java/issue/suite/IssuePurgeTest.java
@@ -0,0 +1,131 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 issue.suite;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.locator.FileLocation;
+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 static issue.suite.IssueTestSuite.ORCHESTRATOR;
+import static issue.suite.IssueTestSuite.searchIssues;
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.runProjectAnalysis;
+import static util.ItUtils.setServerProperty;
+
+public class IssuePurgeTest {
+
+ @ClassRule
+ public static Orchestrator orchestrator = ORCHESTRATOR;
+
+ @Before
+ public void deleteAnalysisData() {
+ orchestrator.resetData();
+ // reset settings before test
+ setServerProperty(orchestrator, "sonar.dbcleaner.daysBeforeDeletingClosedIssues", null);
+ orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/issue/suite/IssuePurgeTest/with-many-rules.xml"));
+ }
+
+ /**
+ * SONAR-4308
+ */
+ @Test
+ public void purge_old_closed_issues() throws Exception {
+ setServerProperty(orchestrator, "sonar.dbcleaner.daysBeforeDeletingClosedIssues", "5000");
+
+ // Generate some issues
+ orchestrator.getServer().provisionProject("sample", "Sample");
+ orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "with-many-rules");
+ runProjectAnalysis(orchestrator, "shared/xoo-sample",
+ "sonar.dynamicAnalysis", "false",
+ "sonar.projectDate", "2014-10-01");
+
+ // All the issues are open
+ List<Issue> issues = searchIssues();
+ for (Issue issue : issues) {
+ assertThat(issue.resolution()).isNull();
+ }
+
+ // Second scan with empty profile -> all issues are resolved and closed
+ // -> Not deleted because less than 5000 days long
+ orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "empty");
+ runProjectAnalysis(orchestrator, "shared/xoo-sample",
+ "sonar.dynamicAnalysis", "false",
+ "sonar.projectDate", "2014-10-15");
+ issues = searchIssues();
+ assertThat(issues).isNotEmpty();
+ for (Issue issue : issues) {
+ assertThat(issue.resolution()).isNotNull();
+ assertThat(issue.status()).isEqualTo("CLOSED");
+ }
+
+ // Third scan -> closed issues are deleted
+ setServerProperty(orchestrator, "sonar.dbcleaner.daysBeforeDeletingClosedIssues", "1");
+
+ runProjectAnalysis(orchestrator, "shared/xoo-sample",
+ "sonar.dynamicAnalysis", "false",
+ "sonar.projectDate", "2014-10-20");
+ assertThat(searchIssues(IssueQuery.create())).isEmpty();
+ }
+
+ /**
+ * SONAR-5200
+ */
+ @Test
+ public void resolve_issues_when_removing_module() throws Exception {
+ orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "Sonar :: Integration Tests :: Multi-modules Sample");
+ orchestrator.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-sample", "xoo", "with-many-rules");
+
+ // Generate some issues
+ runProjectAnalysis(orchestrator, "shared/xoo-multi-modules-sample",
+ "sonar.dynamicAnalysis", "false");
+
+ // All the issues are open
+ List<Issue> issues = searchIssues();
+ for (Issue issue : issues) {
+ assertThat(issue.resolution()).isNull();
+ }
+ Issue issue = issues.get(0);
+
+ int issuesOnModuleB = searchIssues(IssueQuery.create().componentRoots("com.sonarsource.it.samples:multi-modules-sample:module_b")).size();
+ assertThat(issuesOnModuleB).isEqualTo(28);
+
+ // Second scan without module B -> issues on module B are resolved as removed and closed
+ runProjectAnalysis(orchestrator, "shared/xoo-multi-modules-sample",
+ "sonar.dynamicAnalysis", "false",
+ "sonar.modules", "module_a");
+
+ // Resolved should should all be mark as REMOVED and affect to module b
+ List<Issue> reloadedIssues = searchIssues(IssueQuery.create().resolved(true));
+ assertThat(reloadedIssues).hasSize(issuesOnModuleB);
+ for (Issue reloadedIssue : reloadedIssues) {
+ assertThat(reloadedIssue.resolution()).isEqualTo("FIXED");
+ assertThat(reloadedIssue.status()).isEqualTo("CLOSED");
+ assertThat(reloadedIssue.componentKey()).contains("com.sonarsource.it.samples:multi-modules-sample:module_b");
+ assertThat(reloadedIssue.updateDate().before(issue.updateDate())).isFalse();
+ assertThat(reloadedIssue.closeDate()).isNotNull();
+ assertThat(reloadedIssue.closeDate().before(reloadedIssue.creationDate())).isFalse();
+ }
+ }
+}
diff --git a/it/it-tests/src/test/java/issue/suite/IssueTestSuite.java b/it/it-tests/src/test/java/issue/suite/IssueTestSuite.java
index 5f730418629..bcd494ea20d 100644
--- a/it/it-tests/src/test/java/issue/suite/IssueTestSuite.java
+++ b/it/it-tests/src/test/java/issue/suite/IssueTestSuite.java
@@ -27,7 +27,8 @@ import static util.ItUtils.xooPlugin;
CustomRulesTest.class,
IssueActionTest.class,
IssueChangelogTest.class,
- IssueBulkChangeTest.class
+ IssueBulkChangeTest.class,
+ IssuePurgeTest.class
})
public class IssueTestSuite {
@@ -67,7 +68,7 @@ public class IssueTestSuite {
}
static List<Issue> searchIssues(String issueKey, boolean withComments) {
- return searchIssues(new String[] { issueKey }, withComments);
+ return searchIssues(new String[] {issueKey}, withComments);
}
static List<Issue> searchIssues(String[] issueKeys, boolean withComments) {
diff --git a/it/it-tests/src/test/resources/issue/suite/IssuePurgeTest/with-many-rules.xml b/it/it-tests/src/test/resources/issue/suite/IssuePurgeTest/with-many-rules.xml
new file mode 100644
index 00000000000..f3d0baf0616
--- /dev/null
+++ b/it/it-tests/src/test/resources/issue/suite/IssuePurgeTest/with-many-rules.xml
@@ -0,0 +1,32 @@
+<profile>
+ <name>with-many-rules</name>
+ <language>xoo</language>
+ <rules>
+ <rule>
+ <repositoryKey>xoo</repositoryKey>
+ <key>OneIssuePerLine</key>
+ <priority>MINOR</priority>
+ </rule>
+ <rule>
+ <repositoryKey>xoo</repositoryKey>
+ <key>OneIssuePerFile</key>
+ <priority>MAJOR</priority>
+ </rule>
+ <rule>
+ <repositoryKey>xoo</repositoryKey>
+ <key>OneIssuePerModule</key>
+ <priority>CRITICAL</priority>
+ </rule>
+ <rule>
+ <repositoryKey>xoo</repositoryKey>
+ <key>HasTag</key>
+ <priority>INFO</priority>
+ <parameters>
+ <parameter>
+ <key>tag</key>
+ <value>xoo</value>
+ </parameter>
+ </parameters>
+ </rule>
+ </rules>
+</profile> \ No newline at end of file