Search in sources :

Example 1 with DefaultDebtRemediationFunction

use of org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction in project sonarqube by SonarSource.

the class UpdateAction method readDebt.

private void readDebt(Request request, RuleUpdate update) {
    String value = defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_TYPE), request.param(DEPRECATED_PARAM_REMEDIATION_FN_TYPE));
    if (value != null) {
        if (StringUtils.isBlank(value)) {
            update.setDebtRemediationFunction(null);
        } else {
            DebtRemediationFunction fn = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.valueOf(value), defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_GAP_MULTIPLIER), request.param(DEPRECATED_PARAM_REMEDIATION_FN_COEFF)), defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_BASE_EFFORT), request.param(DEPRECATED_PARAM_REMEDIATION_FN_OFFSET)));
            update.setDebtRemediationFunction(fn);
        }
    }
}
Also used : DefaultDebtRemediationFunction(org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction) DebtRemediationFunction(org.sonar.api.server.debt.DebtRemediationFunction) DefaultDebtRemediationFunction(org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction)

Example 2 with DefaultDebtRemediationFunction

use of org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction in project sonarqube by SonarSource.

the class DebtCalculatorTest method default_effort_to_fix_is_one_for_linear_function.

@Test
public void default_effort_to_fix_is_one_for_linear_function() {
    int coefficient = 2;
    rule.setFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, coefficient + "min", null));
    assertThat(underTest.calculate(issue).toMinutes()).isEqualTo(coefficient * 1);
}
Also used : DefaultDebtRemediationFunction(org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction) Test(org.junit.Test)

Example 3 with DefaultDebtRemediationFunction

use of org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction in project sonarqube by SonarSource.

the class DebtCalculatorTest method constant_function.

@Test
public void constant_function() {
    int constant = 2;
    issue.setGap(null);
    rule.setFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, constant + "min"));
    assertThat(underTest.calculate(issue).toMinutes()).isEqualTo(2);
}
Also used : DefaultDebtRemediationFunction(org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction) Test(org.junit.Test)

Example 4 with DefaultDebtRemediationFunction

use of org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction in project sonarqube by SonarSource.

the class DebtCalculatorTest method effort_to_fix_must_not_be_set_with_constant_function.

@Test(expected = IllegalArgumentException.class)
public void effort_to_fix_must_not_be_set_with_constant_function() {
    int constant = 2;
    issue.setGap(3.0);
    rule.setFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, constant + "min"));
    underTest.calculate(issue);
}
Also used : DefaultDebtRemediationFunction(org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction) Test(org.junit.Test)

Example 5 with DefaultDebtRemediationFunction

use of org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction in project sonarqube by SonarSource.

the class DebtCalculatorTest method linear_function.

@Test
public void linear_function() {
    double effortToFix = 3.0;
    int coefficient = 2;
    issue.setGap(effortToFix);
    rule.setFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, coefficient + "min", null));
    assertThat(underTest.calculate(issue).toMinutes()).isEqualTo((int) (coefficient * effortToFix));
}
Also used : DefaultDebtRemediationFunction(org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction) Test(org.junit.Test)

Aggregations

DefaultDebtRemediationFunction (org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction)15 Test (org.junit.Test)13 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)3 RuleDto (org.sonar.db.rule.RuleDto)3 DebtRemediationFunction (org.sonar.api.server.debt.DebtRemediationFunction)2