コード例 #1
0
  @Test
  public void override_debt() {
    insertDebtCharacteristics(dbSession);
    ruleDao.insert(
        dbSession,
        RuleTesting.newDto(RULE_KEY)
            .setDefaultSubCharacteristicId(hardReliabilityId)
            .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
            .setDefaultRemediationCoefficient("1d")
            .setDefaultRemediationOffset("5min")
            .setSubCharacteristicId(null)
            .setRemediationFunction(null)
            .setRemediationCoefficient(null)
            .setRemediationOffset(null));
    dbSession.commit();

    DefaultDebtRemediationFunction fn =
        new DefaultDebtRemediationFunction(
            DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "1min");
    RuleUpdate update =
        RuleUpdate.createForPluginRule(RULE_KEY)
            .setDebtSubCharacteristic("SOFT_RELIABILITY")
            .setDebtRemediationFunction(fn);
    updater.update(update, userSessionRule);
    dbSession.clearCache();

    // verify debt is overridden
    Rule indexedRule = tester.get(RuleIndex.class).getByKey(RULE_KEY);
    assertThat(indexedRule.debtCharacteristicKey()).isEqualTo("RELIABILITY");
    assertThat(indexedRule.debtSubCharacteristicKey()).isEqualTo("SOFT_RELIABILITY");
    assertThat(indexedRule.debtRemediationFunction().type())
        .isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);
    assertThat(indexedRule.debtRemediationFunction().coefficient()).isNull();
    assertThat(indexedRule.debtRemediationFunction().offset()).isEqualTo("1min");

    assertThat(indexedRule.debtOverloaded()).isTrue();
    assertThat(indexedRule.defaultDebtCharacteristicKey()).isEqualTo("RELIABILITY");
    assertThat(indexedRule.defaultDebtSubCharacteristicKey()).isEqualTo("HARD_RELIABILITY");
    assertThat(indexedRule.defaultDebtRemediationFunction().type())
        .isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
    assertThat(indexedRule.defaultDebtRemediationFunction().coefficient()).isEqualTo("1d");
    assertThat(indexedRule.defaultDebtRemediationFunction().offset()).isEqualTo("5min");
  }
コード例 #2
0
  @Test
  public void reset_debt() {
    insertDebtCharacteristics(dbSession);
    ruleDao.insert(
        dbSession,
        RuleTesting.newDto(RULE_KEY)
            .setDefaultSubCharacteristicId(hardReliabilityId)
            .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR.name())
            .setDefaultRemediationCoefficient("1d")
            .setDefaultRemediationOffset("5min")
            .setSubCharacteristicId(softReliabilityId)
            .setRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE.name())
            .setRemediationCoefficient(null)
            .setRemediationOffset("1min"));
    dbSession.commit();

    RuleUpdate update =
        RuleUpdate.createForPluginRule(RULE_KEY)
            .setDebtSubCharacteristic(RuleUpdate.DEFAULT_DEBT_CHARACTERISTIC);
    updater.update(update, userSessionRule);
    dbSession.clearCache();

    // verify debt is coming from default values
    Rule indexedRule = tester.get(RuleIndex.class).getByKey(RULE_KEY);
    assertThat(indexedRule.debtCharacteristicKey()).isEqualTo("RELIABILITY");
    assertThat(indexedRule.debtSubCharacteristicKey()).isEqualTo("HARD_RELIABILITY");
    assertThat(indexedRule.debtRemediationFunction().type())
        .isEqualTo(DebtRemediationFunction.Type.LINEAR);
    assertThat(indexedRule.debtRemediationFunction().coefficient()).isEqualTo("1d");
    assertThat(indexedRule.debtRemediationFunction().offset()).isEqualTo("5min");

    assertThat(indexedRule.debtOverloaded()).isFalse();
    assertThat(indexedRule.defaultDebtCharacteristicKey()).isEqualTo("RELIABILITY");
    assertThat(indexedRule.defaultDebtSubCharacteristicKey()).isEqualTo("HARD_RELIABILITY");
    assertThat(indexedRule.defaultDebtRemediationFunction().type())
        .isEqualTo(DebtRemediationFunction.Type.LINEAR);
    assertThat(indexedRule.defaultDebtRemediationFunction().coefficient()).isEqualTo("1d");
    assertThat(indexedRule.defaultDebtRemediationFunction().offset()).isEqualTo("5min");
  }