aboutsummaryrefslogtreecommitdiffstats
path: root/it/it-tests
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-02-08 12:17:32 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2017-02-09 12:15:11 +0100
commitb86ac25293e0779aa47ab40e822c422264241078 (patch)
tree9fe6af98108985d02c16736b50530b295b9a543b /it/it-tests
parentac37b5725ac884aad4f7e35d73a2fce4ac61aa89 (diff)
downloadsonarqube-b86ac25293e0779aa47ab40e822c422264241078.tar.gz
sonarqube-b86ac25293e0779aa47ab40e822c422264241078.zip
SONAR-8758 Remove settings related to periods 2 to 5
Diffstat (limited to 'it/it-tests')
-rw-r--r--it/it-tests/src/test/java/it/issue/NewIssuesMeasureTest.java37
-rw-r--r--it/it-tests/src/test/java/it/measure/MeasuresWsTest.java8
-rw-r--r--it/it-tests/src/test/java/it/measureHistory/DifferentialPeriodsTest.java54
-rw-r--r--it/it-tests/src/test/java/it/measureHistory/SincePreviousVersionHistoryTest.java31
-rw-r--r--it/it-tests/src/test/java/it/measureHistory/SinceXDaysHistoryTest.java26
-rw-r--r--it/it-tests/src/test/java/it/measureHistory/TimeMachineTest.java10
-rw-r--r--it/it-tests/src/test/java/it/qualityGate/QualityGateNotificationTest.java6
-rw-r--r--it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java8
-rw-r--r--it/it-tests/src/test/java/it/qualityModel/NewDebtRatioMeasureTest.java44
-rw-r--r--it/it-tests/src/test/java/it/qualityModel/TechnicalDebtMeasureVariationTest.java44
-rw-r--r--it/it-tests/src/test/java/util/ItUtils.java15
11 files changed, 111 insertions, 172 deletions
diff --git a/it/it-tests/src/test/java/it/issue/NewIssuesMeasureTest.java b/it/it-tests/src/test/java/it/issue/NewIssuesMeasureTest.java
index b28d7db8b2d..2f8956cef45 100644
--- a/it/it-tests/src/test/java/it/issue/NewIssuesMeasureTest.java
+++ b/it/it-tests/src/test/java/it/issue/NewIssuesMeasureTest.java
@@ -24,7 +24,6 @@ import com.sonar.orchestrator.locator.FileLocation;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.sonar.wsclient.issue.IssueQuery;
import org.sonarqube.ws.WsMeasures;
@@ -33,8 +32,8 @@ import util.ItUtils;
import static java.lang.Integer.parseInt;
import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.getLeakPeriodValue;
import static util.ItUtils.getMeasuresWithVariationsByMetricKey;
-import static util.ItUtils.getPeriodMeasureValuesByIndex;
import static util.ItUtils.projectDir;
import static util.ItUtils.setServerProperty;
@@ -43,16 +42,9 @@ import static util.ItUtils.setServerProperty;
*/
public class NewIssuesMeasureTest extends AbstractIssueTest {
- @BeforeClass
- public static void preparePeriodsAndQProfiles() {
- setServerProperty(ORCHESTRATOR, "sonar.timemachine.period1", "previous_analysis");
- setServerProperty(ORCHESTRATOR, "sonar.timemachine.period2", "30");
- setServerProperty(ORCHESTRATOR, "sonar.timemachine.period3", "previous_analysis");
- }
-
@AfterClass
- public static void resetPeriods() {
- ItUtils.resetPeriods(ORCHESTRATOR);
+ public static void resetPeriod() {
+ ItUtils.resetPeriod(ORCHESTRATOR);
}
@Before
@@ -62,6 +54,7 @@ public class NewIssuesMeasureTest extends AbstractIssueTest {
@Test
public void new_issues_measures() throws Exception {
+ setServerProperty(ORCHESTRATOR, "sonar.timemachine.period1", "previous_analysis");
ORCHESTRATOR.getServer().provisionProject("sample", "Sample");
// Execute an analysis in the past with no issue to have a past snapshot
@@ -74,19 +67,18 @@ public class NewIssuesMeasureTest extends AbstractIssueTest {
ORCHESTRATOR.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
assertThat(ORCHESTRATOR.getServer().wsClient().issueClient().find(IssueQuery.create()).list()).isNotEmpty();
- Map<Integer, Double> newIssues = getPeriodMeasureValuesByIndex(ORCHESTRATOR, "sample:src/main/xoo/sample/Sample.xoo", "new_violations");
- assertThat(newIssues.get(1)).isEqualTo(17);
- assertThat(newIssues.get(2)).isEqualTo(17);
+ assertThat(getLeakPeriodValue(ORCHESTRATOR, "sample:src/main/xoo/sample/Sample.xoo", "new_violations")).isEqualTo(17);
// second analysis, with exactly the same profile -> no new issues
ORCHESTRATOR.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
assertThat(ORCHESTRATOR.getServer().wsClient().issueClient().find(IssueQuery.create()).list()).isNotEmpty();
- assertThat(getPeriodMeasureValuesByIndex(ORCHESTRATOR, "sample:src/main/xoo/sample/Sample.xoo", "new_violations").values()).containsOnly(0d, 0d, 0d);
+ assertThat(getLeakPeriodValue(ORCHESTRATOR, "sample:src/main/xoo/sample/Sample.xoo", "new_violations")).isZero();
}
@Test
public void new_issues_measures_should_be_zero_on_project_when_no_new_issues_since_x_days() throws Exception {
+ setServerProperty(ORCHESTRATOR, "sonar.timemachine.period1", "30");
ORCHESTRATOR.getServer().provisionProject("sample", "Sample");
ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/issue/one-issue-per-line-profile.xml"));
ORCHESTRATOR.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line-profile");
@@ -97,9 +89,7 @@ public class NewIssuesMeasureTest extends AbstractIssueTest {
ORCHESTRATOR.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
// new issues measures should be to 0 on project on 2 periods as new issues has been created
- Map<Integer, Double> measures = getPeriodMeasureValuesByIndex(ORCHESTRATOR, "sample", "new_violations");
- assertThat(measures.get(1)).isZero();
- assertThat(measures.get(2)).isZero();
+ assertThat(getLeakPeriodValue(ORCHESTRATOR, "sample", "new_violations")).isZero();
}
/**
@@ -107,6 +97,7 @@ public class NewIssuesMeasureTest extends AbstractIssueTest {
*/
@Test
public void new_issues_measures_consistent_with_variations() throws Exception {
+ setServerProperty(ORCHESTRATOR, "sonar.timemachine.period1", "previous_analysis");
ORCHESTRATOR.getServer().provisionProject("sample", "Sample");
ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/issue/one-issue-per-line-profile.xml"));
ORCHESTRATOR.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line-profile");
@@ -121,19 +112,20 @@ public class NewIssuesMeasureTest extends AbstractIssueTest {
assertThat(ORCHESTRATOR.getServer().wsClient().issueClient().find(IssueQuery.create()).list()).isNotEmpty();
Map<String, Measure> measures = getMeasuresWithVariationsByMetricKey(ORCHESTRATOR, "sample", "new_violations", "violations", "ncloc");
- assertThat(measures.get("new_violations").getPeriods().getPeriodsValueList()).extracting(WsMeasures.PeriodValue::getValue).containsOnly("17", "17", "17");
+ assertThat(measures.get("new_violations").getPeriods().getPeriodsValueList()).extracting(WsMeasures.PeriodValue::getValue).containsOnly("17");
Measure violations = measures.get("violations");
assertThat(parseInt(violations.getValue())).isEqualTo(43);
- assertThat(violations.getPeriods().getPeriodsValueList()).extracting(periodValue -> parseInt(periodValue.getValue())).containsOnly(17, 17, 17);
+ assertThat(violations.getPeriods().getPeriodsValueList()).extracting(periodValue -> parseInt(periodValue.getValue())).containsOnly(17);
Measure ncloc = measures.get("ncloc");
assertThat(parseInt(ncloc.getValue())).isEqualTo(40);
- assertThat(ncloc.getPeriods().getPeriodsValueList()).extracting(periodValue -> parseInt(periodValue.getValue())).containsOnly(16, 16, 16);
+ assertThat(ncloc.getPeriods().getPeriodsValueList()).extracting(periodValue -> parseInt(periodValue.getValue())).containsOnly(16);
}
@Test
public void new_issues_measures_should_be_correctly_calculated_when_adding_a_new_module() throws Exception {
+ setServerProperty(ORCHESTRATOR, "sonar.timemachine.period1", "previous_analysis");
ORCHESTRATOR.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "com.sonarsource.it.samples:multi-modules-sample");
// First analysis without module b
@@ -147,8 +139,7 @@ public class NewIssuesMeasureTest extends AbstractIssueTest {
ORCHESTRATOR.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-sample", "xoo", "profile2");
ORCHESTRATOR.executeBuild(SonarScanner.create(projectDir("shared/xoo-multi-modules-sample")));
- Map<Integer, Double> periodMeasures = getPeriodMeasureValuesByIndex(ORCHESTRATOR, "com.sonarsource.it.samples:multi-modules-sample", "new_violations");
- assertThat(periodMeasures.get(1)).isEqualTo(65);
+ assertThat(getLeakPeriodValue(ORCHESTRATOR, "com.sonarsource.it.samples:multi-modules-sample", "new_violations")).isEqualTo(65);
}
}
diff --git a/it/it-tests/src/test/java/it/measure/MeasuresWsTest.java b/it/it-tests/src/test/java/it/measure/MeasuresWsTest.java
index 84eda2908bf..a6de412dc65 100644
--- a/it/it-tests/src/test/java/it/measure/MeasuresWsTest.java
+++ b/it/it-tests/src/test/java/it/measure/MeasuresWsTest.java
@@ -51,15 +51,13 @@ public class MeasuresWsTest {
WsClient wsClient;
@BeforeClass
- public static void initPeriods() throws Exception {
+ public static void initPeriod() throws Exception {
setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
- setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
- setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_version");
}
@AfterClass
- public static void resetPeriods() throws Exception {
- ItUtils.resetPeriods(orchestrator);
+ public static void resetPeriod() throws Exception {
+ ItUtils.resetPeriod(orchestrator);
}
@Before
diff --git a/it/it-tests/src/test/java/it/measureHistory/DifferentialPeriodsTest.java b/it/it-tests/src/test/java/it/measureHistory/DifferentialPeriodsTest.java
index 50904a35831..14d6aaf8f56 100644
--- a/it/it-tests/src/test/java/it/measureHistory/DifferentialPeriodsTest.java
+++ b/it/it-tests/src/test/java/it/measureHistory/DifferentialPeriodsTest.java
@@ -23,7 +23,6 @@ import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.locator.FileLocation;
import it.Category1Suite;
import java.util.Date;
-import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -35,11 +34,10 @@ import pageobjects.Navigation;
import static org.apache.commons.lang.time.DateUtils.addDays;
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.formatDate;
-import static util.ItUtils.getMeasure;
+import static util.ItUtils.getLeakPeriodValue;
import static util.ItUtils.getMeasuresAsDoubleByMetricKey;
-import static util.ItUtils.getPeriodMeasureValuesByIndex;
import static util.ItUtils.newAdminWsClient;
-import static util.ItUtils.resetPeriods;
+import static util.ItUtils.resetPeriod;
import static util.ItUtils.runProjectAnalysis;
import static util.ItUtils.setServerProperty;
@@ -65,41 +63,7 @@ public class DifferentialPeriodsTest {
@After
public void reset() throws Exception {
- resetPeriods(orchestrator);
- }
-
- /**
- * SONAR-6787
- */
- @Test
- public void ensure_differential_period_4_and_5_defined_at_project_level_is_taken_into_account() throws Exception {
- orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
- setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
- setServerProperty(orchestrator, "sonar.timemachine.period2", "previous_analysis");
- setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_analysis");
- setServerProperty(orchestrator, PROJECT_KEY, "sonar.timemachine.period4", "30");
- setServerProperty(orchestrator, PROJECT_KEY, "sonar.timemachine.period5", "previous_analysis");
-
- // Execute an analysis 60 days ago to have a past snapshot without any issues
- orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "empty");
- runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.projectDate", formatDate(addDays(new Date(), -60)));
-
- // Second analysis, 20 days ago, issues will be created
- orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/measureHistory/one-issue-per-line-profile.xml"));
- orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "one-issue-per-line");
- runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.projectDate", formatDate(addDays(new Date(), -20)));
-
- // New technical debt only comes from new issues
- Map<Integer, Double> periodsMeasure = getPeriodMeasureValuesByIndex(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt");
- assertThat(periodsMeasure.get(4)).isEqualTo(17);
- assertThat(periodsMeasure.get(5)).isEqualTo(17);
-
- // Third analysis, today, with exactly the same profile -> no new issues so no new technical debt
- orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "one-issue-per-line");
- runProjectAnalysis(orchestrator, "shared/xoo-sample");
-
- // No variation => measure is purged
- assertThat(getMeasure(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isNull();
+ resetPeriod(orchestrator);
}
/**
@@ -125,9 +89,8 @@ public class DifferentialPeriodsTest {
// Third analysis -> There's no new issue from previous analysis
runProjectAnalysis(orchestrator, "shared/xoo-sample");
- // Project should have 17 new issues for period 1
- Map<Integer, Double> periodsMeasure = getPeriodMeasureValuesByIndex(orchestrator, PROJECT_KEY, "violations");
- assertThat(periodsMeasure.get(1)).isEqualTo(17);
+ // Project should have 17 new issues for leak period
+ assertThat(getLeakPeriodValue(orchestrator, PROJECT_KEY, "violations")).isEqualTo(17);
// Check on ui that it's possible to define leak period on project
Navigation.get(orchestrator).openHomepage().logIn().asAdmin().openSettings("sample")
@@ -156,8 +119,7 @@ public class DifferentialPeriodsTest {
"sonar.modules", "module_a,module_b");
// Variation on module b should exist
- Map<Integer, Double> periodsMeasure = getPeriodMeasureValuesByIndex(orchestrator, MULTI_MODULE_PROJECT_KEY + ":module_b", "ncloc");
- assertThat(periodsMeasure.get(1)).isEqualTo(24);
+ assertThat(getLeakPeriodValue(orchestrator, MULTI_MODULE_PROJECT_KEY + ":module_b", "ncloc")).isEqualTo(24);
}
@Test
@@ -197,8 +159,8 @@ public class DifferentialPeriodsTest {
"sonar.scm.provider", "xoo", "sonar.scm.disabled", "false");
// New lines measures is zero
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, projectKey, "new_lines").get(1)).isEqualTo(0);
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, projectKey, "new_lines_to_cover").get(1)).isEqualTo(0);
+ assertThat(getLeakPeriodValue(orchestrator, projectKey, "new_lines")).isEqualTo(0);
+ assertThat(getLeakPeriodValue(orchestrator, projectKey, "new_lines_to_cover")).isEqualTo(0);
}
private void assertNoMeasures(String projectKey, String... metrics) {
diff --git a/it/it-tests/src/test/java/it/measureHistory/SincePreviousVersionHistoryTest.java b/it/it-tests/src/test/java/it/measureHistory/SincePreviousVersionHistoryTest.java
index 5fccc477dd5..d217b889362 100644
--- a/it/it-tests/src/test/java/it/measureHistory/SincePreviousVersionHistoryTest.java
+++ b/it/it-tests/src/test/java/it/measureHistory/SincePreviousVersionHistoryTest.java
@@ -35,11 +35,10 @@ import util.ItUtils;
import static java.lang.Integer.parseInt;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.groups.Tuple.tuple;
import static org.sonarqube.ws.WsMeasures.Measure;
import static org.sonarqube.ws.WsMeasures.PeriodValue;
-import static util.ItUtils.getMeasureWithVariations;
-import static util.ItUtils.getPeriodMeasureValuesByIndex;
+import static util.ItUtils.getLeakPeriodValue;
+import static util.ItUtils.getMeasureWithVariation;
import static util.ItUtils.projectDir;
import static util.ItUtils.setServerProperty;
@@ -50,15 +49,13 @@ public class SincePreviousVersionHistoryTest {
public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
@BeforeClass
- public static void initPeriods() throws Exception {
- setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
- setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
- setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_version");
+ public static void initPeriod() throws Exception {
+ setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_version");
}
@AfterClass
- public static void resetPeriods() throws Exception {
- ItUtils.resetPeriods(orchestrator);
+ public static void resetPeriod() throws Exception {
+ ItUtils.resetPeriod(orchestrator);
}
private static void analyzeProject(String version) {
@@ -104,16 +101,12 @@ public class SincePreviousVersionHistoryTest {
analyzeProject("1.0-SNAPSHOT");
analyzeProject("1.0-SNAPSHOT");
- Measure measure = getMeasureWithVariations(orchestrator, PROJECT, "files");
+ Measure measure = getMeasureWithVariation(orchestrator, PROJECT, "files");
// There are 4 files
assertThat(parseInt(measure.getValue())).isEqualTo(4);
- assertThat(measure.getPeriods().getPeriodsValueList()).extracting(PeriodValue::getIndex, PeriodValue::getValue)
- .contains(
- // nothing changed in the previous analysis
- tuple(1, "0"),
- // but 2 files were added since the first analysis which was version 0.9
- tuple(3, "2"));
+ // 2 files were added since the first analysis which was version 0.9
+ assertThat(measure.getPeriods().getPeriodsValueList()).extracting(PeriodValue::getValue).contains("2");
}
/**
@@ -126,15 +119,15 @@ public class SincePreviousVersionHistoryTest {
// Analyze project by excluding some files
analyzeProject("1.0-SNAPSHOT", "**/*2.xoo", toStringDate(DateUtils.addDays(now, -2)));
// No difference measure after first analysis
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, PROJECT, "files").get(3)).isNull();
+ assertThat(getLeakPeriodValue(orchestrator, PROJECT, "files")).isNull();
analyzeProjectWithDate("1.0-SNAPSHOT", toStringDate(DateUtils.addDays(now, -1)));
// No new version, first analysis is used -> 2 new files
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, PROJECT, "files").get(3)).isEqualTo(2);
+ assertThat(getLeakPeriodValue(orchestrator, PROJECT, "files")).isEqualTo(2);
analyzeProjectWithDate("1.0-SNAPSHOT", toStringDate(now));
// Still no new version, first analysis is used -> 2 new files
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, PROJECT, "files").get(3)).isEqualTo(2);
+ assertThat(getLeakPeriodValue(orchestrator, PROJECT, "files")).isEqualTo(2);
}
}
diff --git a/it/it-tests/src/test/java/it/measureHistory/SinceXDaysHistoryTest.java b/it/it-tests/src/test/java/it/measureHistory/SinceXDaysHistoryTest.java
index dd2dc29143c..890180c1a78 100644
--- a/it/it-tests/src/test/java/it/measureHistory/SinceXDaysHistoryTest.java
+++ b/it/it-tests/src/test/java/it/measureHistory/SinceXDaysHistoryTest.java
@@ -36,8 +36,7 @@ import util.ItUtils;
import static java.lang.Integer.parseInt;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.groups.Tuple.tuple;
-import static util.ItUtils.getMeasureWithVariations;
+import static util.ItUtils.getMeasureWithVariation;
import static util.ItUtils.projectDir;
import static util.ItUtils.setServerProperty;
@@ -50,7 +49,7 @@ public class SinceXDaysHistoryTest {
@BeforeClass
public static void analyseProjectWithHistory() {
- initPeriods();
+ initPeriod();
orchestrator.resetData();
orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/measureHistory/one-issue-per-line-profile.xml"));
@@ -70,36 +69,33 @@ public class SinceXDaysHistoryTest {
analyzeProject();
}
- public static void initPeriods() {
- setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
- setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
- setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_version");
+ private static void initPeriod() {
+ setServerProperty(orchestrator, "sonar.timemachine.period1", "30");
}
@AfterClass
public static void resetPeriods() throws Exception {
- ItUtils.resetPeriods(orchestrator);
+ ItUtils.resetPeriod(orchestrator);
}
@Test
public void check_files_variation() throws Exception {
- checkMeasure("files", 2, 3);
+ checkMeasure("files", 3);
}
@Test
public void check_issues_variation() throws Exception {
- checkMeasure("violations", 24, 45);
+ checkMeasure("violations", 45);
}
@Test
public void check_new_issues_measures() throws Exception {
- checkMeasure("new_violations", 24, 45);
+ checkMeasure("new_violations", 45);
}
- private void checkMeasure(String metric, int variation1, int variation2) {
- WsMeasures.Measure measure = getMeasureWithVariations(orchestrator, PROJECT, metric);
- assertThat(measure.getPeriods().getPeriodsValueList()).extracting(WsMeasures.PeriodValue::getIndex, periodValue -> parseInt(periodValue.getValue()))
- .contains(tuple(1, variation1), tuple(2, variation2));
+ private void checkMeasure(String metric, int variation) {
+ WsMeasures.Measure measure = getMeasureWithVariation(orchestrator, PROJECT, metric);
+ assertThat(measure.getPeriods().getPeriodsValueList()).extracting(periodValue -> parseInt(periodValue.getValue())).containsOnly(variation);
}
private static void analyzeProject() {
diff --git a/it/it-tests/src/test/java/it/measureHistory/TimeMachineTest.java b/it/it-tests/src/test/java/it/measureHistory/TimeMachineTest.java
index 7c1434c68a2..879432820e3 100644
--- a/it/it-tests/src/test/java/it/measureHistory/TimeMachineTest.java
+++ b/it/it-tests/src/test/java/it/measureHistory/TimeMachineTest.java
@@ -62,7 +62,7 @@ public class TimeMachineTest {
@BeforeClass
public static void initialize() {
orchestrator.resetData();
- initPeriods();
+ initPeriod();
orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/measureHistory/one-issue-per-line-profile.xml"));
orchestrator.getServer().provisionProject("sample", "Sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
@@ -72,15 +72,13 @@ public class TimeMachineTest {
wsMeasures = newAdminWsClient(orchestrator).measures();
}
- public static void initPeriods() {
+ private static void initPeriod() {
setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
- setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
- setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_version");
}
@AfterClass
- public static void resetPeriods() throws Exception {
- ItUtils.resetPeriods(orchestrator);
+ public static void resetPeriod() throws Exception {
+ ItUtils.resetPeriod(orchestrator);
}
private static BuildResult analyzeProject(String path, String date) {
diff --git a/it/it-tests/src/test/java/it/qualityGate/QualityGateNotificationTest.java b/it/it-tests/src/test/java/it/qualityGate/QualityGateNotificationTest.java
index 17fa0e3829a..ac043c0885b 100644
--- a/it/it-tests/src/test/java/it/qualityGate/QualityGateNotificationTest.java
+++ b/it/it-tests/src/test/java/it/qualityGate/QualityGateNotificationTest.java
@@ -45,7 +45,7 @@ import static util.ItUtils.newAdminWsClient;
import static util.ItUtils.newUserWsClient;
import static util.ItUtils.projectDir;
import static util.ItUtils.resetEmailSettings;
-import static util.ItUtils.resetPeriods;
+import static util.ItUtils.resetPeriod;
import static util.ItUtils.setServerProperty;
public class QualityGateNotificationTest {
@@ -67,8 +67,6 @@ public class QualityGateNotificationTest {
DEFAULT_QUALITY_GATE = qgClient().list().defaultGate().id();
setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
- setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
- setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_version");
resetEmailSettings(orchestrator);
smtpServer = new Wiser(0);
@@ -79,7 +77,7 @@ public class QualityGateNotificationTest {
public static void resetData() throws Exception {
qgClient().setDefault(DEFAULT_QUALITY_GATE);
- resetPeriods(orchestrator);
+ resetPeriod(orchestrator);
resetEmailSettings(orchestrator);
if (smtpServer != null) {
diff --git a/it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java b/it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java
index 6048ff9d076..deb62bf4899 100644
--- a/it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java
+++ b/it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java
@@ -37,10 +37,10 @@ import org.sonar.wsclient.qualitygate.QualityGateCondition;
import org.sonar.wsclient.qualitygate.UpdateCondition;
import pageobjects.Navigation;
import pageobjects.ProjectActivityPage;
-import util.ItUtils;
import static org.apache.commons.lang.time.DateUtils.addDays;
import static util.ItUtils.projectDir;
+import static util.ItUtils.resetPeriod;
import static util.ItUtils.setServerProperty;
import static util.selenium.Selenese.runSelenese;
@@ -52,16 +52,14 @@ public class QualityGateUiTest {
private static long DEFAULT_QUALITY_GATE;
@BeforeClass
- public static void initPeriods() throws Exception {
+ public static void initPeriod() throws Exception {
setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
- setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
- setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_version");
DEFAULT_QUALITY_GATE = qgClient().list().defaultGate().id();
}
@AfterClass
public static void resetData() throws Exception {
- ItUtils.resetPeriods(orchestrator);
+ resetPeriod(orchestrator);
qgClient().setDefault(DEFAULT_QUALITY_GATE);
}
diff --git a/it/it-tests/src/test/java/it/qualityModel/NewDebtRatioMeasureTest.java b/it/it-tests/src/test/java/it/qualityModel/NewDebtRatioMeasureTest.java
index afac1617362..14c08f755de 100644
--- a/it/it-tests/src/test/java/it/qualityModel/NewDebtRatioMeasureTest.java
+++ b/it/it-tests/src/test/java/it/qualityModel/NewDebtRatioMeasureTest.java
@@ -23,7 +23,6 @@ import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.locator.FileLocation;
import it.Category2Suite;
import java.util.Date;
-import java.util.Map;
import javax.annotation.Nullable;
import org.junit.AfterClass;
import org.junit.Before;
@@ -35,8 +34,8 @@ import static org.apache.commons.lang.time.DateUtils.addDays;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.within;
import static util.ItUtils.formatDate;
-import static util.ItUtils.getPeriodMeasureValuesByIndex;
-import static util.ItUtils.resetPeriods;
+import static util.ItUtils.getLeakPeriodValue;
+import static util.ItUtils.resetPeriod;
import static util.ItUtils.setServerProperty;
import static util.ItUtils.toDate;
@@ -56,7 +55,7 @@ public class NewDebtRatioMeasureTest {
@AfterClass
public static void reset() throws Exception {
- resetPeriods(orchestrator);
+ resetPeriod(orchestrator);
}
@Before
@@ -67,7 +66,6 @@ public class NewDebtRatioMeasureTest {
@Test
public void new_debt_ratio_is_computed_from_new_debt_and_new_ncloc_count_per_file() throws Exception {
setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
- setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
// run analysis on the day of after the first commit, with 'one-issue-per-line' profile
defineQualityProfile("one-issue-per-line");
@@ -81,22 +79,44 @@ public class NewDebtRatioMeasureTest {
// run analysis on the day after of second commit 'one-issue-per-line' profile*
// => 3 new issues will be created
runSampleProjectAnalysis("v2", "sonar.projectDate", formatDate(addDays(SECOND_COMMIT_DATE, 1)));
- assertNewDebtRatio(4.44, 4.44);
+ assertNewDebtRatio(4.44);
// run analysis on the day after of third commit 'one-issue-per-line' profile*
// => 4 new issues will be created
runSampleProjectAnalysis("v3", "sonar.projectDate", formatDate(addDays(THIRD_COMMIT_DATE, 1)));
- assertNewDebtRatio(4.17, 4.28);
+ assertNewDebtRatio(4.17);
+ }
+
+ @Test
+ public void compute_new_debt_ratio_using_number_days_in_leak_period() throws Exception {
+ setServerProperty(orchestrator, "sonar.timemachine.period1", "30");
+
+ // run analysis on the day of after the first commit, with 'one-issue-per-line' profile
+ defineQualityProfile("one-issue-per-line");
+ provisionSampleProject();
+ setSampleProjectQualityProfile("one-issue-per-line");
+ runSampleProjectAnalysis("v1", "sonar.projectDate", formatDate(addDays(FIRST_COMMIT_DATE, 1)));
+
+ // first analysis, no previous snapshot => periods not resolved => no value
+ assertNoNewDebtRatio();
+
+ // run analysis on the day after of second commit 'one-issue-per-line' profile*
+ // => 3 new issues will be created
+ runSampleProjectAnalysis("v2", "sonar.projectDate", formatDate(addDays(SECOND_COMMIT_DATE, 1)));
+ assertNewDebtRatio(4.44);
+
+ // run analysis on the day after of third commit 'one-issue-per-line' profile*
+ // => previous 3 issues plus 4 new issues will be taking into account
+ runSampleProjectAnalysis("v3", "sonar.projectDate", formatDate(addDays(THIRD_COMMIT_DATE, 1)));
+ assertNewDebtRatio(4.28);
}
private void assertNoNewDebtRatio() {
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", NEW_DEBT_RATIO_METRIC_KEY)).isEmpty();
+ assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", NEW_DEBT_RATIO_METRIC_KEY)).isZero();
}
- private void assertNewDebtRatio(@Nullable Double valuePeriod1, @Nullable Double valuePeriod2) {
- Map<Integer, Double> newTechnicalDebt = getPeriodMeasureValuesByIndex(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", NEW_DEBT_RATIO_METRIC_KEY);
- assertThat(newTechnicalDebt.get(1)).isEqualTo(valuePeriod1, within(0.01));
- assertThat(newTechnicalDebt.get(2)).isEqualTo(valuePeriod2, within(0.01));
+ private void assertNewDebtRatio(@Nullable Double valuePeriod) {
+ assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", NEW_DEBT_RATIO_METRIC_KEY)).isEqualTo(valuePeriod, within(0.01));
}
private void setSampleProjectQualityProfile(String qualityProfileKey) {
diff --git a/it/it-tests/src/test/java/it/qualityModel/TechnicalDebtMeasureVariationTest.java b/it/it-tests/src/test/java/it/qualityModel/TechnicalDebtMeasureVariationTest.java
index c0281aec65d..e85bbef5414 100644
--- a/it/it-tests/src/test/java/it/qualityModel/TechnicalDebtMeasureVariationTest.java
+++ b/it/it-tests/src/test/java/it/qualityModel/TechnicalDebtMeasureVariationTest.java
@@ -24,14 +24,12 @@ import com.sonar.orchestrator.locator.FileLocation;
import it.Category2Suite;
import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import util.ItUtils;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
-import static util.ItUtils.getPeriodMeasureValuesByIndex;
+import static util.ItUtils.getLeakPeriodValue;
import static util.ItUtils.setServerProperty;
/**
@@ -42,16 +40,9 @@ public class TechnicalDebtMeasureVariationTest {
@ClassRule
public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
- @BeforeClass
- public static void initPeriods() throws Exception {
- setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
- setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
- setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_analysis");
- }
-
@AfterClass
- public static void resetPeriods() throws Exception {
- ItUtils.resetPeriods(orchestrator);
+ public static void resetPeriod() throws Exception {
+ ItUtils.resetPeriod(orchestrator);
}
@Before
@@ -61,7 +52,7 @@ public class TechnicalDebtMeasureVariationTest {
@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"
+ setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
// Execute an analysis in the past to have a past snapshot without any issues
provisionSampleProject();
@@ -74,19 +65,17 @@ public class TechnicalDebtMeasureVariationTest {
runSampleProjectAnalysis();
// New technical debt only comes from new issues
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt"))
- .contains(entry(1, 17d), entry(2, 17d));
+ assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isEqualTo(17d);
// Third analysis, with exactly the same profile -> no new issues so no new technical debt
runSampleProjectAnalysis();
// No variation => measure is 0 (best value)
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt"))
- .contains(entry(1, 0d), entry(2, 0d));
+ assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isZero();
}
@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"
+ setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
// Execute twice analysis
defineQualityProfile("one-issue-per-file");
@@ -97,18 +86,16 @@ public class TechnicalDebtMeasureVariationTest {
// Third analysis, existing issues on OneIssuePerFile will have their technical debt updated with the effort to fix
runSampleProjectAnalysis("sonar.oneIssuePerFile.effortToFix", "10");
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")
- .get(1)).isEqualTo(90);
+ assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).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");
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")
- .get(1)).isZero();
+ assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isZero();
}
@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"
+ setServerProperty(orchestrator, "sonar.timemachine.period1", "30");
// Execute an analysis in the past to have a past snapshot without any issues
provisionSampleProject();
@@ -123,14 +110,12 @@ public class TechnicalDebtMeasureVariationTest {
// Third analysis, existing issues on OneIssuePerFile will have their technical debt updated with the effort to fix
runSampleProjectAnalysis("sonar.oneIssuePerFile.effortToFix", "10");
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")
- .get(2)).isEqualTo(90);
+ assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).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");
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")
- .get(2)).isEqualTo(90);
+ assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isEqualTo(90);
}
/**
@@ -138,7 +123,7 @@ public class TechnicalDebtMeasureVariationTest {
*/
@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"
+ setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
// Execute an analysis with a big effort to fix
defineQualityProfile("one-issue-per-file");
@@ -148,8 +133,7 @@ public class TechnicalDebtMeasureVariationTest {
// Execute a second analysis with a smaller effort to fix -> Added technical debt should be 0, not negative
runSampleProjectAnalysis("sonar.oneIssuePerFile.effortToFix", "10");
- assertThat(getPeriodMeasureValuesByIndex(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt"))
- .contains(entry(1, 0d), entry(2, 0d));
+ assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isZero();
}
private void setSampleProjectQualityProfile(String qualityProfileKey) {
diff --git a/it/it-tests/src/test/java/util/ItUtils.java b/it/it-tests/src/test/java/util/ItUtils.java
index 3fc95321bac..63174c69983 100644
--- a/it/it-tests/src/test/java/util/ItUtils.java
+++ b/it/it-tests/src/test/java/util/ItUtils.java
@@ -251,8 +251,8 @@ public class ItUtils {
"email.smtp_password.secured", "email.from", "email.prefix");
}
- public static void resetPeriods(Orchestrator orchestrator) {
- resetSettings(orchestrator, null, "sonar.timemachine.period1", "sonar.timemachine.period2", "sonar.timemachine.period3");
+ public static void resetPeriod(Orchestrator orchestrator) {
+ resetSettings(orchestrator, null, "sonar.timemachine.period1");
}
@CheckForNull
@@ -287,7 +287,7 @@ public class ItUtils {
}
@CheckForNull
- public static Measure getMeasureWithVariations(Orchestrator orchestrator, String componentKey, String metricKey) {
+ public static Measure getMeasureWithVariation(Orchestrator orchestrator, String componentKey, String metricKey) {
WsMeasures.ComponentWsResponse response = newWsClient(orchestrator).measures().component(new ComponentWsRequest()
.setComponentKey(componentKey)
.setMetricKeys(singletonList(metricKey))
@@ -307,11 +307,12 @@ public class ItUtils {
}
/**
- * Return period values as string by period index (from 1 to 5)
+ * Return leak period value
*/
- public static Map<Integer, Double> getPeriodMeasureValuesByIndex(Orchestrator orchestrator, String componentKey, String metricKey) {
- return getMeasureWithVariations(orchestrator, componentKey, metricKey).getPeriods().getPeriodsValueList().stream()
- .collect(Collectors.toMap(WsMeasures.PeriodValue::getIndex, measure -> parseDouble(measure.getValue())));
+ @CheckForNull
+ public static Double getLeakPeriodValue(Orchestrator orchestrator, String componentKey, String metricKey) {
+ List<WsMeasures.PeriodValue> periodsValueList = getMeasureWithVariation(orchestrator, componentKey, metricKey).getPeriods().getPeriodsValueList();
+ return periodsValueList.size() > 0 ? Double.parseDouble(periodsValueList.get(0).getValue()) : null;
}
@CheckForNull