aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--it/it-tests/src/test/java/analysis/suite/AnalysisTestSuite.java2
-rw-r--r--it/it-tests/src/test/java/analysis/suite/measure/DifferentialPeriodsTest.java88
-rw-r--r--it/it-tests/src/test/resources/measure/suite/DifferentialPeriodsTest/one-issue-per-line.xml12
3 files changed, 102 insertions, 0 deletions
diff --git a/it/it-tests/src/test/java/analysis/suite/AnalysisTestSuite.java b/it/it-tests/src/test/java/analysis/suite/AnalysisTestSuite.java
index 06d0efefbde..d2c9250a0a5 100644
--- a/it/it-tests/src/test/java/analysis/suite/AnalysisTestSuite.java
+++ b/it/it-tests/src/test/java/analysis/suite/AnalysisTestSuite.java
@@ -20,6 +20,7 @@
package analysis.suite;
import analysis.suite.measure.CustomMeasuresTest;
+import analysis.suite.measure.DifferentialPeriodsTest;
import analysis.suite.measure.MeasureFiltersTest;
import analysis.suite.measure.TimeMachineTest;
import analysis.suite.testing.CoverageTest;
@@ -35,6 +36,7 @@ import util.ItUtils;
@RunWith(Suite.class)
@Suite.SuiteClasses({
CustomMeasuresTest.class,
+ DifferentialPeriodsTest.class,
MeasureFiltersTest.class,
TimeMachineTest.class,
CoverageTrackingTest.class,
diff --git a/it/it-tests/src/test/java/analysis/suite/measure/DifferentialPeriodsTest.java b/it/it-tests/src/test/java/analysis/suite/measure/DifferentialPeriodsTest.java
new file mode 100644
index 00000000000..f7b73764f39
--- /dev/null
+++ b/it/it-tests/src/test/java/analysis/suite/measure/DifferentialPeriodsTest.java
@@ -0,0 +1,88 @@
+package analysis.suite.measure;
+
+import analysis.suite.AnalysisTestSuite;
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarRunner;
+import com.sonar.orchestrator.locator.FileLocation;
+import java.util.List;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.wsclient.services.Measure;
+import org.sonar.wsclient.services.Resource;
+import org.sonar.wsclient.services.ResourceQuery;
+import util.ItUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class DifferentialPeriodsTest {
+
+ @ClassRule
+ public static final Orchestrator orchestrator = AnalysisTestSuite.ORCHESTRATOR;
+
+ @Before
+ public void cleanUpAnalysisData() {
+ orchestrator.resetData();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ String propertyKey = "sonar.timemachine.period4";
+ unsetProperty(propertyKey);
+ unsetProperty("sonar.timemachine.period5");
+ }
+
+ /**
+ * SONAR-6787
+ */
+ @Test
+ public void ensure_differential_period_4_and_5_defined_at_project_level_is_taken_into_account() throws Exception {
+ setProperty("sonar.timemachine.period4", "30");
+ setProperty("sonar.timemachine.period5", "previous_analysis");
+
+ // Execute an analysis in the past to have a past snapshot without any issues
+ orchestrator.getServer().provisionProject("sample", "sample");
+ orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "empty");
+ orchestrator.executeBuild(SonarRunner.create(ItUtils.projectDir("shared/xoo-sample"))
+ .setProperty("sonar.projectDate", "2013-01-01"));
+
+ // Second analysis -> issues will be created
+ orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/measure/suite/DifferentialPeriodsTest/one-issue-per-line.xml"));
+ orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
+ orchestrator.executeBuild(SonarRunner.create(ItUtils.projectDir("shared/xoo-sample")));
+
+ // New technical debt only comes from new issues
+ Resource newTechnicalDebt = orchestrator.getServer().getWsClient()
+ .find(ResourceQuery.createForMetrics("sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt").setIncludeTrends(true));
+ List<Measure> measures = newTechnicalDebt.getMeasures();
+ assertThat(measures.get(0).getVariation4()).isEqualTo(17);
+ assertThat(measures.get(0).getVariation5()).isEqualTo(17);
+
+ // Third analysis, with exactly the same profile -> no new issues so no new technical debt
+ orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
+ orchestrator.executeBuild(SonarRunner.create(ItUtils.projectDir("shared/xoo-sample")));
+
+ newTechnicalDebt = orchestrator.getServer().getWsClient().find(
+ ResourceQuery.createForMetrics("sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt").setIncludeTrends(true)
+ );
+
+ // No variation => measure is purged
+ assertThat(newTechnicalDebt).isNull();
+ }
+
+ private static void unsetProperty(String propertyKey) {
+ setProperty(propertyKey, "");
+ }
+
+ private static void setProperty(String propertyKey, String propertyValue) {
+ orchestrator.getServer().adminWsClient().post(
+ "/api/properties?",
+ "id", propertyKey,
+ "value", propertyValue
+ );
+ }
+
+}
+
diff --git a/it/it-tests/src/test/resources/measure/suite/DifferentialPeriodsTest/one-issue-per-line.xml b/it/it-tests/src/test/resources/measure/suite/DifferentialPeriodsTest/one-issue-per-line.xml
new file mode 100644
index 00000000000..365aa896a73
--- /dev/null
+++ b/it/it-tests/src/test/resources/measure/suite/DifferentialPeriodsTest/one-issue-per-line.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<profile>
+ <name>one-issue-per-line</name>
+ <language>xoo</language>
+ <rules>
+ <rule>
+ <repositoryKey>xoo</repositoryKey>
+ <key>OneIssuePerLine</key>
+ <priority>MINOR</priority>
+ </rule>
+ </rules>
+</profile>