summaryrefslogtreecommitdiffstats
path: root/it
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-09-18 09:36:04 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-09-22 17:20:56 +0200
commitcdc80719e43bf7c899697c30c3bff802f567089f (patch)
tree351d811eca51662fe4a10e3abcc784d2e9f4fe5e /it
parent2d4280fc1cdafa8c7fb37239819d58cd580b9f2b (diff)
downloadsonarqube-cdc80719e43bf7c899697c30c3bff802f567089f.tar.gz
sonarqube-cdc80719e43bf7c899697c30c3bff802f567089f.zip
move IT NewTechnicalDebtMeasureTest to SQ repo
and rename it TechnicalDebtMeasureVariationTest
Diffstat (limited to 'it')
-rw-r--r--it/it-tests/src/test/java/analysis/suite/AnalysisTestSuite.java4
-rw-r--r--it/it-tests/src/test/java/analysis/suite/measure/DifferentialPeriodsTest.java2
-rw-r--r--it/it-tests/src/test/java/analysis/suite/measure/TechnicalDebtMeasureVariationTest.java157
-rw-r--r--it/it-tests/src/test/java/util/ItUtils.java13
-rw-r--r--it/it-tests/src/test/resources/measure/suite/one-issue-per-file.xml12
-rw-r--r--it/it-tests/src/test/resources/measure/suite/one-issue-per-line.xml (renamed from it/it-tests/src/test/resources/measure/suite/DifferentialPeriodsTest/one-issue-per-line.xml)0
6 files changed, 186 insertions, 2 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 d2c9250a0a5..ef43f3e535a 100644
--- a/it/it-tests/src/test/java/analysis/suite/AnalysisTestSuite.java
+++ b/it/it-tests/src/test/java/analysis/suite/AnalysisTestSuite.java
@@ -22,6 +22,7 @@ package analysis.suite;
import analysis.suite.measure.CustomMeasuresTest;
import analysis.suite.measure.DifferentialPeriodsTest;
import analysis.suite.measure.MeasureFiltersTest;
+import analysis.suite.measure.TechnicalDebtMeasureVariationTest;
import analysis.suite.measure.TimeMachineTest;
import analysis.suite.testing.CoverageTest;
import analysis.suite.testing.CoverageTrackingTest;
@@ -42,7 +43,8 @@ import util.ItUtils;
CoverageTrackingTest.class,
CoverageTest.class,
NewCoverageTest.class,
- TestExecutionTest.class
+ TestExecutionTest.class,
+ TechnicalDebtMeasureVariationTest.class
})
public class AnalysisTestSuite {
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
index f7b73764f39..b1119b7e7b6 100644
--- a/it/it-tests/src/test/java/analysis/suite/measure/DifferentialPeriodsTest.java
+++ b/it/it-tests/src/test/java/analysis/suite/measure/DifferentialPeriodsTest.java
@@ -49,7 +49,7 @@ public class DifferentialPeriodsTest {
.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().restoreProfile(FileLocation.ofClasspath("/measure/suite/one-issue-per-line.xml"));
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
orchestrator.executeBuild(SonarRunner.create(ItUtils.projectDir("shared/xoo-sample")));
diff --git a/it/it-tests/src/test/java/analysis/suite/measure/TechnicalDebtMeasureVariationTest.java b/it/it-tests/src/test/java/analysis/suite/measure/TechnicalDebtMeasureVariationTest.java
new file mode 100644
index 00000000000..24b78ebebb4
--- /dev/null
+++ b/it/it-tests/src/test/java/analysis/suite/measure/TechnicalDebtMeasureVariationTest.java
@@ -0,0 +1,157 @@
+package analysis.suite.measure;
+
+import analysis.suite.AnalysisTestSuite;
+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.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;
+
+
+/**
+ * SONAR-4776
+ */
+public class TechnicalDebtMeasureVariationTest {
+
+ @ClassRule
+ public static Orchestrator orchestrator = AnalysisTestSuite.ORCHESTRATOR;
+
+ @Before
+ public void cleanUpAnalysisData() {
+ orchestrator.resetData();
+ }
+
+ @Test
+ public void new_technical_debt_measures_from_new_issues() throws Exception {
+ // This test assumes that period 1 is "since previous analysis" and 2 is "over x days"
+
+ // Execute an analysis in the past to have a past snapshot without any issues
+ provisionSampleProject();
+ setSampleProjectQualityProfile("empty");
+ runSampleProjectAnalysis("sonar.projectDate", "2013-01-01");
+
+ // Second analysis -> issues will be created
+ defineQualityProfile("one-issue-per-line");
+ setSampleProjectQualityProfile("one-issue-per-line");
+ runSampleProjectAnalysis();
+
+ // New technical debt only comes from new issues
+ Resource newTechnicalDebt = getSampleProjectResourceWithVariations("new_technical_debt");
+ List<Measure> measures = newTechnicalDebt.getMeasures();
+ assertThat(measures.get(0).getVariation1()).isEqualTo(17);
+ assertThat(measures.get(0).getVariation2()).isEqualTo(17);
+
+ // Third analysis, with exactly the same profile -> no new issues so no new technical debt
+ runSampleProjectAnalysis();
+
+ 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();
+ }
+
+ @Test
+ public void new_technical_debt_measures_from_technical_debt_update_since_previous_analysis() throws Exception {
+ // This test assumes that period 1 is "since previous analysis"
+
+ // Execute twice analysis
+ defineQualityProfile("one-issue-per-file");
+ provisionSampleProject();
+ setSampleProjectQualityProfile("one-issue-per-file");
+ runSampleProjectAnalysis();
+ runSampleProjectAnalysis();
+
+ // Third analysis, existing issues on OneIssuePerFile will have their technical debt updated with the effort to fix
+ runSampleProjectAnalysis("sonar.oneIssuePerFile.effortToFix", "10");
+
+ Resource newTechnicalDebt = getSampleProjectResourceWithVariations("new_technical_debt");
+ List<Measure> measures = newTechnicalDebt.getMeasures();
+ assertThat(measures.get(0).getVariation1()).isEqualTo(90);
+
+ // Fourth analysis, with exactly the same profile -> no new issues so no new technical debt since previous analysis
+ runSampleProjectAnalysis("sonar.oneIssuePerFile.effortToFix", "10");
+
+ newTechnicalDebt = getSampleProjectResourceWithVariations("new_technical_debt");
+ measures = newTechnicalDebt.getMeasures();
+ assertThat(measures.get(0).getVariation1()).isEqualTo(0);
+ }
+
+ @Test
+ public void new_technical_debt_measures_from_technical_debt_update_since_30_days() throws Exception {
+ // This test assumes that period 2 is "over x days"
+
+ // Execute an analysis in the past to have a past snapshot without any issues
+ provisionSampleProject();
+ setSampleProjectQualityProfile("empty");
+ runSampleProjectAnalysis("sonar.projectDate", "2013-01-01");
+
+ // Second analysis -> issues will be created
+ String profileXmlFile = "one-issue-per-file";
+ defineQualityProfile(profileXmlFile);
+ setSampleProjectQualityProfile("one-issue-per-file");
+ runSampleProjectAnalysis();
+
+ // Third analysis, existing issues on OneIssuePerFile will have their technical debt updated with the effort to fix
+ runSampleProjectAnalysis("sonar.oneIssuePerFile.effortToFix", "10");
+
+ Resource newTechnicalDebt = getSampleProjectResourceWithVariations("new_technical_debt");
+ List<Measure> measures = newTechnicalDebt.getMeasures();
+ assertThat(measures.get(0).getVariation2()).isEqualTo(90);
+
+ // Fourth analysis, with exactly the same profile -> no new issues so no new technical debt since previous analysis but still since 30 days
+ runSampleProjectAnalysis("sonar.oneIssuePerFile.effortToFix", "10");
+
+ newTechnicalDebt = getSampleProjectResourceWithVariations("new_technical_debt");
+ measures = newTechnicalDebt.getMeasures();
+ assertThat(measures.get(0).getVariation2()).isEqualTo(90);
+ }
+
+ /**
+ * SONAR-5059
+ */
+ @Test
+ public void new_technical_debt_measures_should_never_be_negative() throws Exception {
+ // This test assumes that period 1 is "since previous analysis" and 2 is "over x days"
+
+ // Execute an analysis with a big effort to fix
+ defineQualityProfile("one-issue-per-file");
+ provisionSampleProject();
+ setSampleProjectQualityProfile("one-issue-per-file");
+ runSampleProjectAnalysis("sonar.oneIssuePerFile.effortToFix", "100");
+
+ // Execute a second analysis with a smaller effort to fix -> Added technical debt should be 0, not negative
+ runSampleProjectAnalysis("sonar.oneIssuePerFile.effortToFix", "10");
+
+ Resource newTechnicalDebt = getSampleProjectResourceWithVariations("new_technical_debt");
+ assertThat(newTechnicalDebt).isNull();
+ }
+
+ private void setSampleProjectQualityProfile(String qualityProfileKey) {
+ orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", qualityProfileKey);
+ }
+
+ private void provisionSampleProject() {
+ orchestrator.getServer().provisionProject("sample", "sample");
+ }
+
+ private void defineQualityProfile(String qualityProfileKey) {
+ orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/measure/suite/" + qualityProfileKey + ".xml"));
+ }
+
+ private void runSampleProjectAnalysis(String... properties) {
+ ItUtils.runProjectAnalysis(TechnicalDebtMeasureVariationTest.orchestrator, "shared/xoo-sample", properties);
+ }
+
+ private Resource getSampleProjectResourceWithVariations(String metricKey) {
+ return orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("sample:src/main/xoo/sample/Sample.xoo", metricKey).setIncludeTrends(true));
+ }
+
+}
+
diff --git a/it/it-tests/src/test/java/util/ItUtils.java b/it/it-tests/src/test/java/util/ItUtils.java
index 322fabb9117..4e299355a75 100644
--- a/it/it-tests/src/test/java/util/ItUtils.java
+++ b/it/it-tests/src/test/java/util/ItUtils.java
@@ -4,7 +4,10 @@ package util;/*
* mailto:contact AT sonarsource DOT com
*/
+import com.google.common.collect.ImmutableMap;
+import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
+import com.sonar.orchestrator.build.SonarRunner;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
@@ -125,4 +128,14 @@ public class ItUtils {
}
return count;
}
+
+ public static void runProjectAnalysis(Orchestrator orchestrator, String projectRelativePath, String... properties) {
+ SonarRunner sonarRunner = SonarRunner.create(projectDir(projectRelativePath));
+ ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
+ for (int i = 0; i < properties.length; i++) {
+ builder.put(properties[i], properties[i+1]);
+ i+=2;
+ }
+ orchestrator.executeBuild(sonarRunner.setProperties(builder.build()));
+ }
}
diff --git a/it/it-tests/src/test/resources/measure/suite/one-issue-per-file.xml b/it/it-tests/src/test/resources/measure/suite/one-issue-per-file.xml
new file mode 100644
index 00000000000..7193ebfd779
--- /dev/null
+++ b/it/it-tests/src/test/resources/measure/suite/one-issue-per-file.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<profile>
+ <name>one-issue-per-file</name>
+ <language>xoo</language>
+ <rules>
+ <rule>
+ <repositoryKey>xoo</repositoryKey>
+ <key>OneIssuePerFile</key>
+ <priority>MINOR</priority>
+ </rule>
+ </rules>
+</profile>
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/one-issue-per-line.xml
index 365aa896a73..365aa896a73 100644
--- a/it/it-tests/src/test/resources/measure/suite/DifferentialPeriodsTest/one-issue-per-line.xml
+++ b/it/it-tests/src/test/resources/measure/suite/one-issue-per-line.xml