use of org.sonar.db.rule.RuleMetadataDto in project sonarqube by SonarSource.
the class SearchActionTest method insertMetadata.
@SafeVarargs
private final RuleMetadataDto insertMetadata(RuleDefinitionDto rule, Consumer<RuleMetadataDto>... populaters) {
RuleMetadataDto metadata = db.rules().insertOrUpdateMetadata(rule, populaters);
ruleIndexer.commitAndIndex(db.getSession(), rule.getUuid());
return metadata;
}
use of org.sonar.db.rule.RuleMetadataDto in project sonarqube by SonarSource.
the class UpdateActionTest method update_rule_remediation_function.
@Test
public void update_rule_remediation_function() {
logInAsQProfileAdministrator();
RuleDefinitionDto rule = db.rules().insert(r -> r.setDefRemediationFunction(LINEAR.toString()), r -> r.setDefRemediationGapMultiplier("10d"), r -> r.setDefRemediationBaseEffort(null));
String newOffset = LINEAR_OFFSET.toString();
String newMultiplier = "15d";
String newEffort = "5min";
Rules.UpdateResponse result = ws.newRequest().setMethod("POST").setParam("key", rule.getKey().toString()).setParam(PARAM_REMEDIATION_FN_TYPE, newOffset).setParam(PARAM_REMEDIATION_FN_GAP_MULTIPLIER, newMultiplier).setParam(PARAM_REMEDIATION_FN_BASE_EFFORT, newEffort).executeProtobuf(Rules.UpdateResponse.class);
Rules.Rule updatedRule = result.getRule();
assertThat(updatedRule).isNotNull();
assertThat(updatedRule.getKey()).isEqualTo(rule.getKey().toString());
assertThat(updatedRule.getDefaultRemFnType()).isEqualTo(rule.getDefRemediationFunction());
assertThat(updatedRule.getDefaultRemFnGapMultiplier()).isEqualTo(rule.getDefRemediationGapMultiplier());
assertThat(updatedRule.getDefaultRemFnBaseEffort()).isEmpty();
assertThat(updatedRule.getGapDescription()).isEqualTo(rule.getGapDescription());
assertThat(updatedRule.getRemFnType()).isEqualTo(newOffset);
assertThat(updatedRule.getRemFnGapMultiplier()).isEqualTo(newMultiplier);
assertThat(updatedRule.getRemFnBaseEffort()).isEqualTo(newEffort);
// check database
RuleMetadataDto metadataOfSpecificOrg = db.getDbClient().ruleDao().selectMetadataByKey(db.getSession(), rule.getKey()).orElseThrow(() -> new IllegalStateException("Cannot load metadata"));
assertThat(metadataOfSpecificOrg.getRemediationFunction()).isEqualTo(newOffset);
assertThat(metadataOfSpecificOrg.getRemediationGapMultiplier()).isEqualTo(newMultiplier);
assertThat(metadataOfSpecificOrg.getRemediationBaseEffort()).isEqualTo(newEffort);
}
use of org.sonar.db.rule.RuleMetadataDto in project sonarqube by SonarSource.
the class UpdateActionTest method update_note.
@Test
public void update_note() {
RuleDefinitionDto rule = db.rules().insert();
UserDto userHavingUpdatingNote = db.users().insertUser();
db.rules().insertOrUpdateMetadata(rule, userHavingUpdatingNote, m -> m.setNoteData("old data"));
UserDto userAuthenticated = db.users().insertUser();
userSession.logIn(userAuthenticated).addPermission(ADMINISTER_QUALITY_PROFILES);
Rules.UpdateResponse result = ws.newRequest().setMethod("POST").setParam(PARAM_KEY, rule.getKey().toString()).setParam(PARAM_MARKDOWN_NOTE, "new data").executeProtobuf(Rules.UpdateResponse.class);
Rules.Rule updatedRule = result.getRule();
// check response
assertThat(updatedRule.getMdNote()).isEqualTo("new data");
assertThat(updatedRule.getNoteLogin()).isEqualTo(userAuthenticated.getLogin());
// check database
RuleMetadataDto metadataOfSpecificOrg = db.getDbClient().ruleDao().selectMetadataByKey(db.getSession(), rule.getKey()).get();
assertThat(metadataOfSpecificOrg.getNoteData()).isEqualTo("new data");
assertThat(metadataOfSpecificOrg.getNoteUserUuid()).isEqualTo(userAuthenticated.getUuid());
}
use of org.sonar.db.rule.RuleMetadataDto in project sonarqube by SonarSource.
the class ShowActionTest method show_adhoc_rule.
@Test
public void show_adhoc_rule() {
RuleDefinitionDto externalRule = db.rules().insert(r -> r.setIsExternal(true).setIsAdHoc(true));
RuleMetadataDto metadata = db.rules().insertOrUpdateMetadata(externalRule, m -> m.setAdHocName("adhoc name").setAdHocDescription("<div>desc</div>").setAdHocSeverity(Severity.BLOCKER).setAdHocType(RuleType.VULNERABILITY).setNoteData(null).setNoteUserUuid(null));
doReturn("<div>desc2</div>").when(macroInterpreter).interpret(metadata.getAdHocDescription());
ShowResponse result = ws.newRequest().setParam(PARAM_KEY, externalRule.getKey().toString()).executeProtobuf(ShowResponse.class);
Rule resultRule = result.getRule();
assertThat(resultRule).extracting(Rule::getName, Rule::getHtmlDesc, Rule::getSeverity, Rule::getType).containsExactlyInAnyOrder("adhoc name", "<div>desc2</div>", Severity.BLOCKER, VULNERABILITY);
}
use of org.sonar.db.rule.RuleMetadataDto in project sonarqube by SonarSource.
the class SearchActionTest method search_debt_rules_with_default_linear_offset_and_overridden_constant_debt.
@Test
public void search_debt_rules_with_default_linear_offset_and_overridden_constant_debt() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java").setDefRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name()).setDefRemediationGapMultiplier("1h").setDefRemediationBaseEffort("15min"));
RuleMetadataDto metadata = insertMetadata(rule, r -> r.setRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE.name()).setRemediationGapMultiplier(null).setRemediationBaseEffort("5min"));
indexRules();
SearchResponse result = ws.newRequest().setParam("f", "debtRemFn,debtOverloaded,defaultDebtRemFn").executeProtobuf(SearchResponse.class);
assertThat(result.getTotal()).isOne();
assertThat(result.getRulesCount()).isOne();
Rule searchedRule = result.getRules(0);
assertThat(searchedRule).isNotNull();
assertThat(searchedRule.getDefaultDebtRemFnCoeff()).isEqualTo("1h");
assertThat(searchedRule.getDefaultDebtRemFnOffset()).isEqualTo("15min");
assertThat(searchedRule.getDefaultDebtRemFnType()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET.name());
assertThat(searchedRule.getDefaultRemFnBaseEffort()).isEqualTo("15min");
assertThat(searchedRule.getDefaultRemFnGapMultiplier()).isEqualTo("1h");
assertThat(searchedRule.getDefaultRemFnType()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET.name());
assertThat(searchedRule.getDebtOverloaded()).isTrue();
assertThat(searchedRule.getDebtRemFnCoeff()).isEmpty();
assertThat(searchedRule.getDebtRemFnOffset()).isEqualTo("5min");
assertThat(searchedRule.getDebtRemFnType()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE.name());
}
Aggregations