@Test
  public void reactivate_disabled_rules() {
    verifyRulesInDb();

    // Disable plugin X1
    rulesDefinition.includeX1 = false;
    tester.get(Platform.class).executeStartupTasks();

    RuleDto rule = db.ruleDao().getByKey(dbSession, RuleTesting.XOO_X1);
    assertThat(rule.getStatus()).isEqualTo(RuleStatus.REMOVED);
    dbSession.clearCache();

    // Reactivate plugin X1
    rulesDefinition.includeX1 = true;
    tester.get(Platform.class).executeStartupTasks();

    RuleDto ruleReloaded = db.ruleDao().getByKey(dbSession, RuleTesting.XOO_X1);
    assertThat(ruleReloaded.getStatus()).isEqualTo(RuleStatus.READY);
  }
  @Test
  public void mark_rule_as_removed() throws Exception {
    verifyRulesInDb();

    rulesDefinition.includeX2 = false;
    tester.get(Platform.class).executeStartupTasks();

    verifyRulesInDb();
    RuleDto rule = db.ruleDao().getByKey(dbSession, RuleKey.of("xoo", "x2"));
    assertThat(rule.getStatus()).isEqualTo(RuleStatus.REMOVED);
  }
Example #3
0
 private void updateExistingRule(RuleDto ruleDto, NewRule newRule, DbSession dbSession) {
   if (ruleDto.getStatus().equals(RuleStatus.REMOVED)) {
     if (newRule.isPreventReactivation()) {
       throw new ReactivationException(
           String.format(
               "A removed rule with the key '%s' already exists", ruleDto.getKey().rule()),
           ruleDto.getKey());
     } else {
       ruleDto.setStatus(RuleStatus.READY);
       dbClient.ruleDao().update(dbSession, ruleDto);
     }
   } else {
     throw new IllegalArgumentException(
         String.format("A rule with the key '%s' already exists", ruleDto.getKey().rule()));
   }
 }
 void verifyForActivation() {
   if (RuleStatus.REMOVED == rule.getStatus()) {
     throw new BadRequestException("Rule was removed: " + rule.getKey());
   }
   if (rule.isTemplate()) {
     throw new BadRequestException(
         "Rule template can't be activated on a Quality profile: " + rule.getKey());
   }
   if (rule.getKey().isManual()) {
     throw new BadRequestException(
         "Manual rule can't be activated on a Quality profile: " + rule.getKey());
   }
   if (!profile.getLanguage().equals(rule.getLanguage())) {
     throw new BadRequestException(
         String.format(
             "Rule %s and profile %s have different languages", rule.getKey(), profile.getKey()));
   }
 }