use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RuleIndexTest method sort_by_name.
@Test
public void sort_by_name() {
indexRules(newDoc(RuleKey.of("java", "S001")).setName("abcd"), newDoc(RuleKey.of("java", "S002")).setName("ABC"), newDoc(RuleKey.of("java", "S003")).setName("FGH"));
// ascending
RuleQuery query = new RuleQuery().setSortField(RuleIndexDefinition.FIELD_RULE_NAME);
SearchIdResult<RuleKey> results = index.search(query, new SearchOptions());
assertThat(results.getIds()).containsExactly(RuleKey.of("java", "S002"), RuleKey.of("java", "S001"), RuleKey.of("java", "S003"));
// descending
query = new RuleQuery().setSortField(RuleIndexDefinition.FIELD_RULE_NAME).setAscendingSort(false);
results = index.search(query, new SearchOptions());
assertThat(results.getIds()).containsExactly(RuleKey.of("java", "S003"), RuleKey.of("java", "S001"), RuleKey.of("java", "S002"));
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RuleIndexTest method default_sort_is_by_updated_at_desc.
@Test
public void default_sort_is_by_updated_at_desc() {
indexRules(newDoc(RuleKey.of("java", "S001")).setCreatedAt(1000L).setUpdatedAt(1000L), newDoc(RuleKey.of("java", "S002")).setCreatedAt(1000L).setUpdatedAt(3000L), newDoc(RuleKey.of("java", "S003")).setCreatedAt(1000L).setUpdatedAt(2000L));
SearchIdResult<RuleKey> results = index.search(new RuleQuery(), new SearchOptions());
assertThat(results.getIds()).containsExactly(RuleKey.of("java", "S002"), RuleKey.of("java", "S003"), RuleKey.of("java", "S001"));
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RuleCreatorMediumTest method create_custom_rule_with_no_parameter_value.
@Test
public void create_custom_rule_with_no_parameter_value() {
// insert template rule
RuleDto templateRule = createTemplateRuleWithIntArrayParam();
NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()).setName("My custom").setHtmlDescription("Some description").setSeverity(Severity.MAJOR).setStatus(RuleStatus.READY);
RuleKey customRuleKey = creator.create(newRule);
dbSession.clearCache();
List<RuleParamDto> params = db.ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
assertThat(params).hasSize(1);
RuleParamDto param = params.get(0);
assertThat(param.getName()).isEqualTo("myIntegers");
assertThat(param.getDescription()).isEqualTo("My Integers");
assertThat(param.getType()).isEqualTo("INTEGER,multiple=true,values=1;2;3");
assertThat(param.getDefaultValue()).isNull();
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class ShowActionMediumTest method encode_html_description_of_custom_rule.
@Test
public void encode_html_description_of_custom_rule() throws Exception {
// Template rule
RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001"));
ruleDao.insert(session, templateRule);
session.commit();
// Custom rule
NewCustomRule customRule = NewCustomRule.createForCustomRule("MY_CUSTOM", templateRule.getKey()).setName("My custom").setSeverity(MINOR).setStatus(RuleStatus.READY).setMarkdownDescription("<div>line1\nline2</div>");
RuleKey customRuleKey = tester.get(RuleCreator.class).create(customRule);
session.clearCache();
WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show").setParam("key", customRuleKey.toString());
request.execute().assertJson(getClass(), "encode_html_description_of_custom_rule.json");
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RegisterQualityProfiles method register.
private List<ActiveRuleChange> register(QProfileName name, Collection<RulesProfile> profiles, DbSession session) {
LOGGER.info("Register profile " + name);
List<ActiveRuleChange> changes = new ArrayList<>();
QualityProfileDto profileDto = dbClient.qualityProfileDao().selectByNameAndLanguage(name.getName(), name.getLanguage(), session);
if (profileDto != null) {
changes.addAll(profileFactory.delete(session, profileDto.getKey(), true));
}
profileFactory.create(session, name);
for (RulesProfile profile : profiles) {
for (org.sonar.api.rules.ActiveRule activeRule : profile.getActiveRules()) {
RuleKey ruleKey = RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey());
RuleActivation activation = new RuleActivation(ruleKey);
activation.setSeverity(activeRule.getSeverity() != null ? activeRule.getSeverity().name() : null);
for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
activation.setParameter(param.getKey(), param.getValue());
}
changes.addAll(ruleActivator.activate(session, activation, name));
}
}
LoadedTemplateDto template = new LoadedTemplateDto(templateKey(name), LoadedTemplateDto.QUALITY_PROFILE_TYPE);
dbClient.loadedTemplateDao().insert(template, session);
session.commit();
return changes;
}
Aggregations