Search in sources :

Example 6 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 7 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)

Example 8 with DefaultDebtRemediationFunction

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

the class RuleUpdaterMediumTest method override_debt_only_offset.

@Test
public void override_debt_only_offset() {
    ruleDao.insert(dbSession, RuleTesting.newDto(RULE_KEY).setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR.name()).setDefaultRemediationGapMultiplier("1d").setDefaultRemediationBaseEffort(null).setRemediationFunction(null).setRemediationGapMultiplier(null).setRemediationBaseEffort(null));
    dbSession.commit();
    RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setDebtRemediationFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "2d", null));
    underTest.update(update, userSessionRule);
    dbSession.clearCache();
    // verify debt is overridden
    RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
    assertThat(rule.getRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
    assertThat(rule.getRemediationGapMultiplier()).isEqualTo("2d");
    assertThat(rule.getRemediationBaseEffort()).isNull();
    assertThat(rule.getDefaultRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
    assertThat(rule.getDefaultRemediationGapMultiplier()).isEqualTo("1d");
    assertThat(rule.getDefaultRemediationBaseEffort()).isNull();
}
Also used : ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) DefaultDebtRemediationFunction(org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction) Test(org.junit.Test)

Example 9 with DefaultDebtRemediationFunction

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

the class RuleMapper method setDefaultDebtRemediationFunctionFields.

private static void setDefaultDebtRemediationFunctionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
    if (shouldReturnField(fieldsToReturn, FIELD_DEFAULT_DEBT_REM_FUNCTION) || shouldReturnField(fieldsToReturn, FIELD_DEFAULT_REM_FUNCTION)) {
        DebtRemediationFunction defaultDebtRemediationFunction = defaultDebtRemediationFunction(ruleDto);
        if (defaultDebtRemediationFunction != null) {
            String gapMultiplier = defaultDebtRemediationFunction.gapMultiplier();
            if (gapMultiplier != null) {
                ruleResponse.setDefaultRemFnGapMultiplier(gapMultiplier);
                // Set deprecated field
                ruleResponse.setDefaultDebtRemFnCoeff(gapMultiplier);
            }
            String baseEffort = defaultDebtRemediationFunction.baseEffort();
            if (baseEffort != null) {
                ruleResponse.setDefaultRemFnBaseEffort(baseEffort);
                // Set deprecated field
                ruleResponse.setDefaultDebtRemFnOffset(baseEffort);
            }
            if (defaultDebtRemediationFunction.type() != null) {
                ruleResponse.setDefaultRemFnType(defaultDebtRemediationFunction.type().name());
                // Set deprecated field
                ruleResponse.setDefaultDebtRemFnType(defaultDebtRemediationFunction.type().name());
            }
        }
    }
}
Also used : DefaultDebtRemediationFunction(org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction) DebtRemediationFunction(org.sonar.api.server.debt.DebtRemediationFunction)

Example 10 with DefaultDebtRemediationFunction

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

the class DebtCalculatorTest method linear_with_offset_function.

@Test
public void linear_with_offset_function() {
    double effortToFix = 3.0;
    int coefficient = 2;
    int offset = 5;
    issue.setGap(effortToFix);
    rule.setFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, coefficient + "min", offset + "min"));
    assertThat(underTest.calculate(issue).toMinutes()).isEqualTo((int) ((coefficient * effortToFix) + offset));
}
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