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;
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
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
}
@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);
}
"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) {