Esempio n. 1
0
  /** Reset from provided model */
  public void reset() {
    checkPermission();

    Date updateDate = new Date(system2.now());
    DbSession session = dbClient.openSession(false);
    try {
      // Restore characteristics
      List<CharacteristicDto> allCharacteristicDtos =
          restoreCharacteristics(
              loadModelFromPlugin(DebtModelPluginRepository.DEFAULT_MODEL), updateDate, session);

      // Restore rules
      List<RuleDto> ruleDtos = dbClient.ruleDao().selectEnabledAndNonManual(session);
      if (!ruleDtos.isEmpty()) {

        // Load default rule definitions
        RulesDefinition.Context context = defLoader.load();
        List<RulesDefinition.Rule> rules = newArrayList();
        for (RulesDefinition.Repository repoDef : context.repositories()) {
          rules.addAll(repoDef.rules());
        }

        resetRules(ruleDtos, rules, allCharacteristicDtos, updateDate, session);
      }

      session.commit();
    } finally {
      MyBatis.closeQuietly(session);
    }
  }
  @Test
  public void define_xoo_rules() {
    XooRulesDefinition def = new XooRulesDefinition();
    RulesDefinition.Context context = new RulesDefinition.Context();
    def.define(context);

    RulesDefinition.Repository repo = context.repository("xoo");
    assertThat(repo).isNotNull();
    assertThat(repo.name()).isEqualTo("Xoo");
    assertThat(repo.language()).isEqualTo("xoo");
    assertThat(repo.rules()).hasSize(1);

    RulesDefinition.Rule x1 = repo.rule("x1");
    assertThat(x1.key()).isEqualTo("x1");
    assertThat(x1.tags()).containsOnly("style", "security");
    assertThat(x1.htmlDescription()).isNotEmpty();

    assertThat(x1.debtSubCharacteristic())
        .isEqualTo(RulesDefinition.SubCharacteristics.INTEGRATION_TESTABILITY);
    assertThat(x1.debtRemediationFunction().type())
        .isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
    assertThat(x1.debtRemediationFunction().coefficient()).isEqualTo("1h");
    assertThat(x1.debtRemediationFunction().offset()).isEqualTo("30min");
    assertThat(x1.effortToFixDescription()).isEqualTo("Effort to fix issue on one line");
  }
  @Test
  public void test() {
    RulesDefinition.Context context = new RulesDefinition.Context();
    ErlangChecksRuleDefinition ruleDefinition = new ErlangChecksRuleDefinition();

    ruleDefinition.define(context);

    RulesDefinition.Repository repository = context.repository(CheckList.REPOSITORY_KEY);

    assertThat(repository.name()).isEqualTo(CheckList.REPOSITORY_NAME);

    List<RulesDefinition.Rule> rules = repository.rules();

    assertThat(rules.size()).isEqualTo(CheckList.getChecks().size());
  }