]> source.dussan.org Git - sonarqube.git/commitdiff
harden TechnicalDebtMeasure IT 2533/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 20 Sep 2017 08:17:09 +0000 (10:17 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 21 Sep 2017 07:54:23 +0000 (09:54 +0200)
tests/src/test/java/org/sonarqube/tests/Category2Suite.java
tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtAndIssueNewMeasuresTest.java [new file with mode: 0644]
tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtMeasureVariationTest.java [deleted file]

index 832da865d7bb58c3e04019719090a3b7115430d4..c84781c885f434eedc689dde1b190b9733495cc3 100644 (file)
@@ -49,7 +49,7 @@ import org.sonarqube.tests.qualityModel.NewDebtRatioMeasureTest;
 import org.sonarqube.tests.qualityModel.ReliabilityMeasureTest;
 import org.sonarqube.tests.qualityModel.SecurityMeasureTest;
 import org.sonarqube.tests.qualityModel.TechnicalDebtInIssueChangelogTest;
-import org.sonarqube.tests.qualityModel.TechnicalDebtMeasureVariationTest;
+import org.sonarqube.tests.qualityModel.TechnicalDebtAndIssueNewMeasuresTest;
 import org.sonarqube.tests.qualityModel.TechnicalDebtTest;
 import org.sonarqube.tests.scm.ScmTest;
 import org.sonarqube.tests.test.CoverageTest;
@@ -95,7 +95,7 @@ import static util.ItUtils.xooPlugin;
   ReliabilityMeasureTest.class,
   SecurityMeasureTest.class,
   TechnicalDebtInIssueChangelogTest.class,
-  TechnicalDebtMeasureVariationTest.class,
+  TechnicalDebtAndIssueNewMeasuresTest.class,
   TechnicalDebtTest.class,
   // ui
   IssuesPageTest.class,
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtAndIssueNewMeasuresTest.java b/tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtAndIssueNewMeasuresTest.java
new file mode 100644 (file)
index 0000000..fe8d6df
--- /dev/null
@@ -0,0 +1,355 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonarqube.tests.qualityModel;
+
+import com.sonar.orchestrator.Orchestrator;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonarqube.tests.Category2Suite;
+import util.ItUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.getLeakPeriodValue;
+import static util.ItUtils.setServerProperty;
+
+/**
+ * SONAR-4776
+ */
+public class TechnicalDebtAndIssueNewMeasuresTest {
+
+  private static final String DATE_31_DAYS_AGO = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDate.now().minusDays(31));// "2013-01-01";
+
+  @ClassRule
+  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
+
+  @AfterClass
+  public static void resetPeriod() throws Exception {
+    ItUtils.resetPeriod(orchestrator);
+  }
+
+  @Before
+  public void cleanUpAnalysisData() {
+    orchestrator.resetData();
+  }
+
+  @Test
+  public void new_technical_debt_measures_from_new_issues() throws Exception {
+    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+
+    // Execute an analysis in the past to have a past snapshot without any issues
+    provisionSampleProject();
+    setSampleProjectQualityProfile("empty");
+    runSampleProjectAnalysis("sonar.projectDate", DATE_31_DAYS_AGO);
+
+    // Second analysis -> issues will be created
+    defineQualityProfile("one-issue-per-line");
+    setSampleProjectQualityProfile("one-issue-per-line");
+
+    // New technical debt only comes from new issues
+    runSampleProjectAnalysis();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_technical_debt")).isEqualTo(17d);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_violations")).isEqualTo(17);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_code_smells")).isEqualTo(17);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_minor_violations")).isEqualTo(17);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_info_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isEqualTo(17d);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_violations")).isEqualTo(17);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_code_smells")).isEqualTo(17);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_minor_violations")).isEqualTo(17);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_info_violations")).isZero();
+
+    // Third analysis, with exactly the same profile -> no new issues so no new technical debt
+    runSampleProjectAnalysis();
+    // No variation => measure is 0 (best value)
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_technical_debt")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_code_smells")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_minor_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_info_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_code_smells")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_minor_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_info_violations")).isZero();
+  }
+
+  @Test
+  public void new_technical_debt_measures_from_technical_debt_update_since_previous_analysis() throws Exception {
+    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+
+    // Execute twice analysis
+    defineQualityProfile("one-issue-per-file");
+    provisionSampleProject();
+    setSampleProjectQualityProfile("one-issue-per-file");
+    runSampleProjectAnalysis();
+    runSampleProjectAnalysis();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_technical_debt")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_code_smells")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_minor_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_info_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_code_smells")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_minor_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_info_violations")).isZero();
+
+    // Third analysis, existing issues on OneIssuePerFile will have their technical debt updated with the effort to fix
+    runSampleProjectAnalysis("sonar.oneIssuePerFile.effortToFix", "10");
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_technical_debt")).isEqualTo(90);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_code_smells")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_minor_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_info_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isEqualTo(90);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_code_smells")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_minor_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_info_violations")).isZero();
+
+    // Fourth analysis, with exactly the same profile -> no new issues so no new technical debt since previous analysis
+    runSampleProjectAnalysis("sonar.oneIssuePerFile.effortToFix", "10");
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_technical_debt")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_code_smells")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_minor_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_info_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_code_smells")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_minor_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_info_violations")).isZero();
+  }
+
+  @Test
+  public void new_technical_debt_measures_from_technical_debt_update_since_30_days_with_constant_effort() throws Exception {
+    setServerProperty(orchestrator, "sonar.leak.period", "30");
+
+    // Execute an analysis in the past to have a past snapshot without any issues
+    provisionSampleProject();
+    setSampleProjectQualityProfile("empty");
+    runSampleProjectAnalysis("sonar.projectDate", DATE_31_DAYS_AGO);
+
+    // Second analysis -> issues will be created
+    String profileXmlFile = "one-issue-per-file";
+    defineQualityProfile(profileXmlFile);
+    setSampleProjectQualityProfile("one-issue-per-file");
+    runSampleProjectAnalysis();
+
+    // no new issue and no change in debt but still one issue on the leak period (30d)
+    runSampleProjectAnalysis();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_technical_debt")).isEqualTo(10);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_code_smells")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_minor_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_info_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isEqualTo(10);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_code_smells")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_minor_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_info_violations")).isZero();
+
+    // Fourth analysis, with exactly the same profile -> no new issues so no new technical debt since previous analysis but still since 30
+    // days
+    runSampleProjectAnalysis();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_technical_debt")).isEqualTo(10);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_code_smells")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_minor_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_info_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isEqualTo(10);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_code_smells")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_minor_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_info_violations")).isZero();
+  }
+
+  @Test
+  public void new_technical_debt_measures_from_technical_debt_update_since_30_days_with_effort_change() throws Exception {
+    setServerProperty(orchestrator, "sonar.leak.period", "30");
+
+    // Execute an analysis in the past to have a past snapshot without any issues
+    provisionSampleProject();
+    setSampleProjectQualityProfile("empty");
+    runSampleProjectAnalysis("sonar.projectDate", DATE_31_DAYS_AGO);
+
+    // 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");
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_technical_debt")).isEqualTo(100);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_code_smells")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_minor_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_info_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isEqualTo(100);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_code_smells")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_minor_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_info_violations")).isZero();
+
+    // 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(getLeakPeriodValue(orchestrator, "sample", "new_technical_debt")).isEqualTo(100);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_code_smells")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_minor_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample", "new_info_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isEqualTo(100);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_code_smells")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_bugs")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_vulnerabilities")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_blocker_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_critical_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_major_violations")).isZero();
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_minor_violations")).isEqualTo(1);
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_info_violations")).isZero();
+  }
+
+  /**
+   * SONAR-5059
+   */
+  @Test
+  public void new_technical_debt_measures_should_never_be_negative() throws Exception {
+    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+
+    // 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");
+    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isZero();
+  }
+
+  private void setSampleProjectQualityProfile(String qualityProfileKey) {
+    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", qualityProfileKey);
+  }
+
+  private void provisionSampleProject() {
+    orchestrator.getServer().provisionProject("sample", "sample");
+  }
+
+  private void defineQualityProfile(String qualityProfileKey) {
+    ItUtils.restoreProfile(orchestrator, getClass().getResource("/measure/" + qualityProfileKey + ".xml"));
+  }
+
+  private void runSampleProjectAnalysis(String... properties) {
+    ItUtils.runVerboseProjectAnalysis(TechnicalDebtAndIssueNewMeasuresTest.orchestrator, "shared/xoo-sample", properties);
+  }
+
+}
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtMeasureVariationTest.java b/tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtMeasureVariationTest.java
deleted file mode 100644 (file)
index 5ea5264..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonarqube.tests.qualityModel;
-
-import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category2Suite;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import util.ItUtils;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static util.ItUtils.getLeakPeriodValue;
-import static util.ItUtils.setServerProperty;
-
-/**
- * SONAR-4776
- */
-public class TechnicalDebtMeasureVariationTest {
-
-  @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
-
-  @AfterClass
-  public static void resetPeriod() throws Exception {
-    ItUtils.resetPeriod(orchestrator);
-  }
-
-  @Before
-  public void cleanUpAnalysisData() {
-    orchestrator.resetData();
-  }
-
-  @Test
-  public void new_technical_debt_measures_from_new_issues() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
-
-    // 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
-    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(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 {
-    setServerProperty(orchestrator, "sonar.leak.period", "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");
-    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(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 {
-    setServerProperty(orchestrator, "sonar.leak.period", "30");
-
-    // 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");
-    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(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isEqualTo(90);
-  }
-
-  /**
-   * SONAR-5059
-   */
-  @Test
-  public void new_technical_debt_measures_should_never_be_negative() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
-
-    // 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");
-    assertThat(getLeakPeriodValue(orchestrator, "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt")).isZero();
-  }
-
-  private void setSampleProjectQualityProfile(String qualityProfileKey) {
-    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", qualityProfileKey);
-  }
-
-  private void provisionSampleProject() {
-    orchestrator.getServer().provisionProject("sample", "sample");
-  }
-
-  private void defineQualityProfile(String qualityProfileKey) {
-    ItUtils.restoreProfile(orchestrator, getClass().getResource("/measure/" + qualityProfileKey + ".xml"));
-  }
-
-  private void runSampleProjectAnalysis(String... properties) {
-    ItUtils.runVerboseProjectAnalysis(TechnicalDebtMeasureVariationTest.orchestrator, "shared/xoo-sample", properties);
-  }
-
-}