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;
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;
*/
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
@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
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");
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();
}
/**
*/
@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");
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
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);
}
}
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
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;
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;
@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);
}
/**
// 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")
"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
"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) {
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;
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) {
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");
}
/**
// 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);
}
}
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;
@BeforeClass
public static void analyseProjectWithHistory() {
- initPeriods();
+ initPeriod();
orchestrator.resetData();
orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/measureHistory/one-issue-per-line-profile.xml"));
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() {
@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");
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) {
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 {
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);
public static void resetData() throws Exception {
qgClient().setDefault(DEFAULT_QUALITY_GATE);
- resetPeriods(orchestrator);
+ resetPeriod(orchestrator);
resetEmailSettings(orchestrator);
if (smtpServer != null) {
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;
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);
}
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;
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;
@AfterClass
public static void reset() throws Exception {
- resetPeriods(orchestrator);
+ resetPeriod(orchestrator);
}
@Before
@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");
// 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) {
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;
/**
@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
@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();
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");
// 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();
// 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);
}
/**
*/
@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");
// 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) {
"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
}
@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))
}
/**
- * 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
+ 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();
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";
.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))
@Test
public void all() {
List<PropertyDefinition> defs = CorePropertyDefinitions.all();
- assertThat(defs).hasSize(62);
+ assertThat(defs).hasSize(58);
}
@Test