use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class IssueIndexTest method filter_by_rules.
@Test
public void filter_by_rules() {
ComponentDto project = newProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
RuleKey ruleKey = RuleKey.of("repo", "X1");
indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setRuleKey(ruleKey.toString()));
assertThat(underTest.search(IssueQuery.builder().rules(newArrayList(ruleKey)).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().rules(newArrayList(RuleKey.of("rule", "without issue"))).build(), new SearchOptions()).getDocs()).isEmpty();
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class IssueIndexTest method facets_on_languages.
@Test
public void facets_on_languages() {
ComponentDto project = newProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
RuleKey ruleKey = RuleKey.of("repo", "X1");
indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setRuleKey(ruleKey.toString()).setLanguage("xoo"));
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("languages")));
assertThat(result.getFacets().getNames()).containsOnly("languages");
assertThat(result.getFacets().get("languages")).containsOnly(entry("xoo", 1L));
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class QProfileBackuperMediumTest method backup.
@Test
public void backup() throws Exception {
RuleKey blahRuleKey = RuleKey.of("blah", "my-rule");
RuleDto blahRule = newDto(blahRuleKey).setSeverity("INFO").setLanguage("xoo");
db.ruleDao().insert(dbSession, blahRule);
dbSession.commit();
dbSession.clearCache();
ruleIndexer.index();
// create profile P1 with rules x2 and x1 activated
db.qualityProfileDao().insert(dbSession, newXooP1("org-123"));
RuleActivation activation1 = new RuleActivation(XOO_X2).setSeverity("MINOR");
RuleActivation activation2 = new RuleActivation(XOO_X1);
RuleActivation activation3 = new RuleActivation(blahRuleKey);
activation2.setSeverity(Severity.BLOCKER);
activation2.setParameter("max", "7");
tester.get(RuleActivator.class).activate(dbSession, activation1, XOO_P1_NAME);
tester.get(RuleActivator.class).activate(dbSession, activation2, XOO_P1_NAME);
tester.get(RuleActivator.class).activate(dbSession, activation3, XOO_P1_NAME);
dbSession.commit();
dbSession.clearCache();
activeRuleIndexer.index();
StringWriter output = new StringWriter();
tester.get(QProfileBackuper.class).backup(XOO_P1_KEY, output);
String expectedXml = Resources.toString(getClass().getResource("QProfileBackuperMediumTest/expected-backup.xml"), StandardCharsets.UTF_8);
assertThat(output.toString()).isXmlEqualTo(expectedXml);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class QProfileResetMediumTest method reset_language_profile.
@Test
public void reset_language_profile() {
RulesProfile defProfile = RulesProfile.create("Basic", ServerTester.Xoo.KEY);
defProfile.activateRule(org.sonar.api.rules.Rule.create("xoo", "x1").setParams(newArrayList(new RuleParam().setKey("acceptWhitespace"))), RulePriority.CRITICAL).setParameter("acceptWhitespace", "true");
register(new Rules() {
@Override
public void init(RulesDefinition.NewRepository repository) {
RulesDefinition.NewRule x1 = repository.createRule("x1").setName("x1 name").setHtmlDescription("x1 desc").setSeverity(MINOR);
x1.createParam("acceptWhitespace").setDefaultValue("false").setType(RuleParamType.BOOLEAN).setDescription("Accept whitespaces on the line");
}
}, defProfile);
RuleKey ruleKey = RuleKey.of("xoo", "x1");
QualityProfileDto profile = tester.get(QualityProfileDao.class).selectByNameAndLanguage("Basic", ServerTester.Xoo.KEY, dbSession);
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), ruleKey);
// Change the severity and the value of the parameter in the active rule
tester.get(RuleActivator.class).activate(dbSession, new RuleActivation(ruleKey).setSeverity(BLOCKER).setParameter("acceptWhitespace", "false"), profile.getKey());
dbSession.commit();
// Verify severity and param has changed
ActiveRuleDto activeRuleDto = tester.get(ActiveRuleDao.class).selectOrFailByKey(dbSession, activeRuleKey);
assertThat(activeRuleDto.getSeverityString()).isEqualTo(BLOCKER);
List<ActiveRuleParamDto> activeRuleParamDtos = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
assertThat(activeRuleParamDtos.get(0).getKey()).isEqualTo("acceptWhitespace");
assertThat(activeRuleParamDtos.get(0).getValue()).isEqualTo("false");
reset.resetLanguage(ServerTester.Xoo.KEY);
dbSession.commit();
// Severity and parameter value come back to origin after reset
activeRuleDto = tester.get(ActiveRuleDao.class).selectOrFailByKey(dbSession, activeRuleKey);
assertThat(activeRuleDto.getSeverityString()).isEqualTo(CRITICAL);
activeRuleParamDtos = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
assertThat(activeRuleParamDtos.get(0).getKey()).isEqualTo("acceptWhitespace");
assertThat(activeRuleParamDtos.get(0).getValue()).isEqualTo("true");
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RegisterQualityProfilesMediumTest method register_profile_definitions.
@Test
public void register_profile_definitions() {
tester = new ServerTester().withEsIndexes().withStartupTasks().addXoo().addComponents(XooRulesDefinition.class, XooProfileDefinition.class);
tester.start();
dbSession = dbClient().openSession(false);
// Check Profile in DB
QualityProfileDao qualityProfileDao = dbClient().qualityProfileDao();
assertThat(qualityProfileDao.selectAll(dbSession)).hasSize(1);
QualityProfileDto profile = qualityProfileDao.selectByNameAndLanguage("Basic", "xoo", dbSession);
assertThat(profile).isNotNull();
// Check Default Profile
verifyDefaultProfile("xoo", "Basic");
// Check ActiveRules in DB
ActiveRuleDao activeRuleDao = dbClient().activeRuleDao();
assertThat(activeRuleDao.selectByProfileKey(dbSession, profile.getKey())).hasSize(2);
RuleKey ruleKey = RuleKey.of("xoo", "x1");
ActiveRuleDto activeRule = activeRuleDao.selectByKey(dbSession, ActiveRuleKey.of(profile.getKey(), ruleKey)).get();
assertThat(activeRule.getKey().qProfile()).isEqualTo(profile.getKey());
assertThat(activeRule.getKey().ruleKey()).isEqualTo(ruleKey);
assertThat(activeRule.getSeverityString()).isEqualTo(Severity.CRITICAL);
// Check ActiveRuleParameters in DB
Map<String, ActiveRuleParamDto> params = ActiveRuleParamDto.groupByKey(activeRuleDao.selectParamsByActiveRuleId(dbSession, activeRule.getId()));
assertThat(params).hasSize(2);
// set by profile
assertThat(params.get("acceptWhitespace").getValue()).isEqualTo("true");
// default value
assertThat(params.get("max").getValue()).isEqualTo("10");
}
Aggregations