use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class QProfilesWsMediumTest method reset.
@Test
public void reset() {
QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setLanguage("java");
QProfileDto childProfile = QualityProfileTesting.newQualityProfileDto().setParentKee(profile.getKee()).setLanguage("java");
dbClient.qualityProfileDao().insert(dbSession, profile, childProfile);
RuleDefinitionDto rule = createRule(profile.getLanguage(), "rule");
ActiveRuleDto active1 = ActiveRuleDto.createFor(profile, rule).setSeverity(rule.getSeverityString());
ActiveRuleDto active2 = ActiveRuleDto.createFor(childProfile, rule).setSeverity("MINOR");
dbClient.activeRuleDao().insert(dbSession, active1);
dbClient.activeRuleDao().insert(dbSession, active2);
dbSession.commit();
activeRuleIndexer.indexAll();
// 0. assert rule child rule is minor
Optional<ActiveRuleDto> activeRuleDto = dbClient.activeRuleDao().selectByKey(dbSession, active2.getKey());
assertThat(activeRuleDto).isPresent();
assertThat(activeRuleDto.get().getSeverityString()).isEqualTo(Severity.MINOR);
// 1. reset child rule
wsActivateRule.newRequest().setMethod("POST").setParam(PARAM_KEY, childProfile.getKee()).setParam(PARAM_RULE, rule.getKey().toString()).setParam(PARAM_RESET, "true").execute();
dbSession.clearCache();
// 2. assert rule child rule is NOT minor
activeRuleDto = dbClient.activeRuleDao().selectByKey(dbSession, active2.getKey());
assertThat(activeRuleDto).isPresent();
assertThat(activeRuleDto.get().getSeverityString()).isNotEqualTo(Severity.MINOR);
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class QProfilesWsMediumTest method activate_rule_override_severity.
@Test
public void activate_rule_override_severity() {
QProfileDto profile = createProfile("java");
RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto");
ruleIndexer.commitAndIndex(dbSession, rule.getUuid());
// 0. Assert No Active Rule for profile
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
// 1. Activate Rule
wsActivateRule.newRequest().setMethod("POST").setParam(PARAM_KEY, profile.getKee()).setParam(PARAM_RULE, rule.getKey().toString()).setParam(PARAM_SEVERITY, "MINOR").execute();
dbSession.clearCache();
// 2. Assert ActiveRule in DAO
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile, rule.getKey());
Optional<ActiveRuleDto> activeRuleDto = dbClient.activeRuleDao().selectByKey(dbSession, activeRuleKey);
assertThat(activeRuleDto).isPresent();
assertThat(activeRuleDto.get().getSeverityString()).isEqualTo(Severity.MINOR);
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class QProfilesWsMediumTest method createActiveRule.
private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity(rule.getSeverityString());
dbClient.activeRuleDao().insert(dbSession, activeRule);
return activeRule;
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class ActiveRuleCompleterTest method test_completeShow.
@Test
public void test_completeShow() {
ActiveRuleCompleter underTest = new ActiveRuleCompleter(dbTester.getDbClient(), new Languages());
RuleDefinitionDto rule = dbTester.rules().insert();
QProfileDto qualityProfile = dbTester.qualityProfiles().insert();
ActiveRuleDto activeRule = dbTester.qualityProfiles().activateRule(qualityProfile, rule);
List<Rules.Active> result = underTest.completeShow(dbTester.getSession(), rule);
assertThat(result).extracting(Rules.Active::getQProfile).containsExactlyInAnyOrder(qualityProfile.getKee());
assertThat(result).extracting(Rules.Active::getSeverity).containsExactlyInAnyOrder(activeRule.getSeverityString());
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class ShowActionTest method show_rule_with_activation.
@Test
public void show_rule_with_activation() {
RuleDefinitionDto rule = db.rules().insert();
RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setType("STRING").setDescription("Reg *exp*").setDefaultValue(".*"));
db.rules().insertOrUpdateMetadata(rule, m -> m.setNoteData(null).setNoteUserUuid(null));
QProfileDto qProfile = db.qualityProfiles().insert();
ActiveRuleDto activeRule = db.qualityProfiles().activateRule(qProfile, rule);
db.getDbClient().activeRuleDao().insertParam(db.getSession(), activeRule, new ActiveRuleParamDto().setRulesParameterUuid(ruleParam.getUuid()).setKey(ruleParam.getName()).setValue(".*?"));
db.commit();
ShowResponse result = ws.newRequest().setParam(PARAM_KEY, rule.getKey().toString()).setParam(PARAM_ACTIVES, "true").executeProtobuf(ShowResponse.class);
List<Rules.Active> actives = result.getActivesList();
assertThat(actives).extracting(Rules.Active::getQProfile).containsExactly(qProfile.getKee());
assertThat(actives).extracting(Rules.Active::getSeverity).containsExactly(activeRule.getSeverityString());
assertThat(actives).extracting(Rules.Active::getInherit).containsExactly("NONE");
assertThat(actives.get(0).getParamsList()).extracting(Rules.Active.Param::getKey, Rules.Active.Param::getValue).containsExactlyInAnyOrder(tuple(ruleParam.getName(), ".*?"));
}
Aggregations