diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-09-17 12:22:59 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-09-17 12:23:56 +0200 |
commit | a4a4d9f3e97c4b753aaf5a9b5f9379adea5c838b (patch) | |
tree | 92f19f185462da11af14722a4168992fc7e417e6 /it/it-tests/src/test | |
parent | e7b45f77f155d73d1563c1c06e0b91b871ea65c8 (diff) | |
download | sonarqube-a4a4d9f3e97c4b753aaf5a9b5f9379adea5c838b.tar.gz sonarqube-a4a4d9f3e97c4b753aaf5a9b5f9379adea5c838b.zip |
SONAR-6787 add IT ensuring periods 4&5 @ project level are supported
Diffstat (limited to 'it/it-tests/src/test')
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> |