]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8758 Remove settings related to periods 2 to 5
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 8 Feb 2017 11:17:32 +0000 (12:17 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 9 Feb 2017 11:15:11 +0000 (12:15 +0100)
14 files changed:
it/it-tests/src/test/java/it/issue/NewIssuesMeasureTest.java
it/it-tests/src/test/java/it/measure/MeasuresWsTest.java
it/it-tests/src/test/java/it/measureHistory/DifferentialPeriodsTest.java
it/it-tests/src/test/java/it/measureHistory/SincePreviousVersionHistoryTest.java
it/it-tests/src/test/java/it/measureHistory/SinceXDaysHistoryTest.java
it/it-tests/src/test/java/it/measureHistory/TimeMachineTest.java
it/it-tests/src/test/java/it/qualityGate/QualityGateNotificationTest.java
it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java
it/it-tests/src/test/java/it/qualityModel/NewDebtRatioMeasureTest.java
it/it-tests/src/test/java/it/qualityModel/TechnicalDebtMeasureVariationTest.java
it/it-tests/src/test/java/util/ItUtils.java
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java

index b28d7db8b2d92d412ac3f8e3baa7045eee85a50b..2f8956cef45fefaeb050592bc7036af2e81e69bd 100644 (file)
@@ -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);
   }
 
 }
index 84eda2908bfc04fe6dca1ed660a17d896f56cb47..a6de412dc656a311c44081746ac770ed4c0a3c2a 100644 (file)
@@ -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
index 50904a3583138ccf1452534d289a84990d07c076..14d6aaf8f569f98be43cfef501821494d9dc0da0 100644 (file)
@@ -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) {
index 5fccc477dd50c4578e0cabb14aaac6999b943905..d217b8893626da871d107554c0284d09efac904d 100644 (file)
@@ -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);
   }
 
 }
index dd2dc29143c102fa6be65719191ae0e311fc9ee6..890180c1a78cecad04940900e1545e08dea4312b 100644 (file)
@@ -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() {
index 7c1434c68a292a83ff8cb31eeae2d60899983100..879432820e3ca34871f3096e70c8b88fa3181a7f 100644 (file)
@@ -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) {
index 17fa0e3829a051a7060d0f59953d8b84380d5081..ac043c0885bf4a82231b75ef6e3cb87b20febc6f 100644 (file)
@@ -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) {
index 6048ff9d076afd48a2ac53c11927b3b2bf95b16c..deb62bf489961cc93a56e67156b96d06bea18c61 100644 (file)
@@ -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);
   }
 
index afac16173622e58858052a715ced18ede6294680..14c08f755de1ea1f0436ce3290c07cd0e776c601 100644 (file)
@@ -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) {
index c0281aec65dcd8113e71c238f007e15af71a4b23..e85bbef54140ad226dfbce001d394f92f485d13c 100644 (file)
@@ -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) {
index 3fc95321bac8fd7630ba54d7f8cddc0cb90803ef..63174c6998394f545d94ebb7f487dddf346342f3 100644 (file)
@@ -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
index 391e632c06336f6ec5e71d5857ee728c824f55c5..3c0fa861b980b1d81c6e80992edd93a517b8ee19 100644 (file)
@@ -109,7 +109,7 @@ public class ComputeEngineContainerImplTest {
         + 25 // level 1
         + 47 // content of DaoModule
         + 3 // content of EsSearchModule
-        + 60 // content of CorePropertyDefinitions
+        + 56 // content of CorePropertyDefinitions
         + 1 // content of CePropertyDefinitions
     );
     assertThat(picoContainer.getParent().getParent().getParent().getParent()).isNull();
index 7553822770a33e7b6887c5da93c1421dbba7c1fa..fa1bb12cda1fdd690d804233eeb73364d8701126 100644 (file)
@@ -42,10 +42,6 @@ public class CorePropertyDefinitions {
   public static final String TIMEMACHINE_MODE_PREVIOUS_VERSION = "previous_version";
 
   private static final String TIMEMACHINE_DEFAULT_PERIOD_1 = TIMEMACHINE_MODE_PREVIOUS_VERSION;
-  private static final String TIMEMACHINE_DEFAULT_PERIOD_2 = TIMEMACHINE_MODE_PREVIOUS_ANALYSIS;
-  private static final String TIMEMACHINE_DEFAULT_PERIOD_3 = "30";
-  private static final String TIMEMACHINE_DEFAULT_PERIOD_4 = "";
-  private static final String TIMEMACHINE_DEFAULT_PERIOD_5 = "";
 
   private static final String CATEGORY_ORGANIZATIONS = "organizations";
   public static final String ORGANIZATIONS_ANYONE_CAN_CREATE = "sonar.organizations.anyoneCanCreate";
@@ -226,45 +222,6 @@ public class CorePropertyDefinitions {
         .onQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW)
         .build(),
 
-      PropertyDefinition.builder(TIMEMACHINE_PERIOD_PREFIX + 2)
-        .name("Period 2")
-        .description("See the property 'Leak Period'")
-        .defaultValue(TIMEMACHINE_DEFAULT_PERIOD_2)
-        .category(CoreProperties.CATEGORY_GENERAL)
-        .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS)
-        .build(),
-
-      PropertyDefinition.builder(TIMEMACHINE_PERIOD_PREFIX + 3)
-        .name("Period 3")
-        .description("See the property 'Leak Period'")
-        .defaultValue(TIMEMACHINE_DEFAULT_PERIOD_3)
-        .category(CoreProperties.CATEGORY_GENERAL)
-        .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS)
-        .build(),
-
-      PropertyDefinition.builder(TIMEMACHINE_PERIOD_PREFIX + 4)
-        .name("Period 4")
-        .description("Period used to compare measures and track new issues. This property is specific to the project. Values are : " +
-          "<ul class='bullet'><li>Number of days before analysis, for example 5.</li><li>A custom date. Format is yyyy-MM-dd, " +
-          "for example 2010-12-25</li><li>'previous_analysis' to compare to previous analysis</li>" +
-          "<li>'previous_version' to compare to the previous version in the project history</li><li>A version, for example '1.2' or 'BASELINE'</li></ul>" +
-          "<p>When specifying a number of days or a date, the snapshot selected for comparison is the first one available inside the corresponding time range. </p>" +
-          "<p>Changing this property only takes effect after subsequent project inspections.<p/>")
-        .defaultValue(TIMEMACHINE_DEFAULT_PERIOD_4)
-        .onlyOnQualifiers(Qualifiers.PROJECT)
-        .category(CoreProperties.CATEGORY_GENERAL)
-        .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS)
-        .build(),
-
-      PropertyDefinition.builder(TIMEMACHINE_PERIOD_PREFIX + 5)
-        .name("Period 5")
-        .description("See the property 'Period 4'")
-        .defaultValue(TIMEMACHINE_DEFAULT_PERIOD_5)
-        .onlyOnQualifiers(Qualifiers.PROJECT)
-        .category(CoreProperties.CATEGORY_GENERAL)
-        .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS)
-        .build(),
-
       // CPD
       PropertyDefinition.builder(CoreProperties.CPD_CROSS_PROJECT)
         .defaultValue(Boolean.toString(CoreProperties.CPD_CROSS_PROJECT_DEFAULT_VALUE))
index 01f3d1bf9d222a156b2fc82a436e0d846e558f2b..d89d8db60fcd9f2fe98810881c357f3d8525cedc 100644 (file)
@@ -33,7 +33,7 @@ public class CorePropertyDefinitionsTest {
   @Test
   public void all() {
     List<PropertyDefinition> defs = CorePropertyDefinitions.all();
-    assertThat(defs).hasSize(62);
+    assertThat(defs).hasSize(58);
   }
 
   @Test