]> source.dussan.org Git - sonarqube.git/commitdiff
Fix NewDebtRatioMeasureTest
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 16 Sep 2016 08:19:14 +0000 (10:19 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 16 Sep 2016 08:19:44 +0000 (10:19 +0200)
it/it-projects/measure/xoo-new-debt-ratio-v1/src/main/xoo/sample/Sample.xoo.scm
it/it-projects/measure/xoo-new-debt-ratio-v2/src/main/xoo/sample/Sample.xoo.scm
it/it-projects/measure/xoo-new-debt-ratio-v3/src/main/xoo/sample/Sample.xoo.scm
it/it-tests/src/test/java/it/qualityModel/NewDebtRatioMeasureTest.java

index 9f1974d8cba71ec12e9891b68256c1fba1fdf848..c838f29021fb8243365ea90957de668b8c23697c 100644 (file)
@@ -1,14 +1,14 @@
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
-1,user1,2015-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
+1,user1,2016-08-01
index 280b7d64326e8dd6bea6b87dc5cc4280aecdf47e..bc69cd71308eed36b8e34cb4222541c8ba1c2fce 100644 (file)
@@ -1,18 +1,18 @@
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-2,user2,2015-09-17
-2,user2,2015-09-17
-2,user2,2015-09-17
-2,user2,2015-09-17
-1,user1,2015-09-01
-1,user1,2015-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+2,user2,2016-09-17
+2,user2,2016-09-17
+2,user2,2016-09-17
+2,user2,2016-09-17
+1,user1,2016-09-01
+1,user1,2016-09-01
index 4b429f3c1522c2f7b3e7ea1ddb27b1aa22c05d2f..09a256f652799eff53dbfe9487c3efb35229f23f 100644 (file)
@@ -1,23 +1,23 @@
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-1,user1,2015-09-01
-2,user2,2015-09-17
-2,user2,2015-09-17
-2,user2,2015-09-17
-2,user2,2015-09-17
-3,user2,2015-09-20
-3,user2,2015-09-20
-3,user2,2015-09-20
-3,user2,2015-09-20
-3,user2,2015-09-20
-1,user1,2015-09-01
-1,user1,2015-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+1,user1,2016-09-01
+2,user2,2016-09-17
+2,user2,2016-09-17
+2,user2,2016-09-17
+2,user2,2016-09-17
+3,user2,2016-09-20
+3,user2,2016-09-20
+3,user2,2016-09-20
+3,user2,2016-09-20
+3,user2,2016-09-20
+1,user1,2016-09-01
+1,user1,2016-09-01
index ae4f6a9e7e77b3ccb404e0357f70152541ef4a50..05e96062aedd17bbd2319af23379c319b6b4a880 100644 (file)
@@ -22,11 +22,11 @@ package it.qualityModel;
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.locator.FileLocation;
 import it.Category2Suite;
+import java.util.Date;
 import java.util.List;
 import javax.annotation.Nullable;
 import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.sonar.wsclient.services.Measure;
@@ -34,9 +34,13 @@ import org.sonar.wsclient.services.Resource;
 import org.sonar.wsclient.services.ResourceQuery;
 import util.ItUtils;
 
+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.resetPeriods;
 import static util.ItUtils.setServerProperty;
+import static util.ItUtils.toDate;
 
 /**
  * SONAR-5876
@@ -45,19 +49,16 @@ public class NewDebtRatioMeasureTest {
 
   private static final String NEW_DEBT_RATIO_METRIC_KEY = "new_sqale_debt_ratio";
 
+  private static final Date FIRST_COMMIT_DATE = toDate("2016-09-01");
+  private static final Date SECOND_COMMIT_DATE = toDate("2016-09-17");
+  private static final Date THIRD_COMMIT_DATE = toDate("2016-09-20");
+
   @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_version");
-  }
-
   @AfterClass
-  public static void resetPeriods() throws Exception {
-    ItUtils.resetPeriods(orchestrator);
+  public static void reset() throws Exception {
+    resetPeriods(orchestrator);
   }
 
   @Before
@@ -66,27 +67,27 @@ public class NewDebtRatioMeasureTest {
   }
 
   @Test
-  public void new_debt_ratio_is_computed_from_nes_debt_and_new_ncloc_count_per_file() throws Exception {
-    // This test assumes that period 1 is "since previous analysis" and 2 is "over 30 days"
+  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 (2015-09-01), with 'one-issue-per-line' profile
-    // => some issues at date 2015-09-02
+    // 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", "2015-09-02");
+    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 (2015-09-17) 'one-issue-per-line' profile*
-    // => 3 new issues will be created at date 2015-09-18
-    runSampleProjectAnalysis("v2", "sonar.projectDate", "2015-09-18");
+    // 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);
 
-    // run analysis on the day after of third commit (2015-09-20) 'one-issue-per-line' profile*
-    // => 4 new issues will be created at date 2015-09-21
-    runSampleProjectAnalysis("v3", "sonar.projectDate", "2015-09-21");
+    // 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);
   }
 
@@ -119,8 +120,7 @@ public class NewDebtRatioMeasureTest {
       "measure/xoo-new-debt-ratio-" + projectVersion,
       ItUtils.concat(properties,
         // disable standard scm support so that it does not interfere with Xoo Scm sensor
-        "sonar.scm.disabled", "false")
-      );
+        "sonar.scm.disabled", "false"));
   }
 
   private Resource getFileResourceWithVariations(String metricKey) {