use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class InheritanceActionMediumTest method inheritance_nominal.
@Test
public void inheritance_nominal() throws Exception {
RuleDto rule1 = createRule("xoo", "rule1");
RuleDto rule2 = createRule("xoo", "rule2");
RuleDto rule3 = createRule("xoo", "rule3");
/*
* groupWide (2) <- companyWide (2) <- buWide (2, 1 overriding) <- (forProject1 (2), forProject2 (2))
*/
QualityProfileDto groupWide = createProfile("xoo", "My Group Profile", "xoo-my-group-profile-01234");
createActiveRule(rule1, groupWide);
createActiveRule(rule2, groupWide);
session.commit();
ruleIndexer.index();
activeRuleIndexer.index();
QualityProfileDto companyWide = createProfile("xoo", "My Company Profile", "xoo-my-company-profile-12345");
setParent(groupWide, companyWide);
QualityProfileDto buWide = createProfile("xoo", "My BU Profile", "xoo-my-bu-profile-23456");
setParent(companyWide, buWide);
overrideActiveRuleSeverity(rule1, buWide, Severity.CRITICAL);
QualityProfileDto forProject1 = createProfile("xoo", "For Project One", "xoo-for-project-one-34567");
setParent(buWide, forProject1);
createActiveRule(rule3, forProject1);
session.commit();
activeRuleIndexer.index();
QualityProfileDto forProject2 = createProfile("xoo", "For Project Two", "xoo-for-project-two-45678");
setParent(buWide, forProject2);
overrideActiveRuleSeverity(rule2, forProject2, Severity.CRITICAL);
wsTester.newGetRequest("api/qualityprofiles", "inheritance").setParam("profileKey", buWide.getKee()).execute().assertJson(getClass(), "inheritance-buWide.json");
}
use of org.sonar.db.rule.RuleDto 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.db.rule.RuleDto in project sonarqube by SonarSource.
the class ChangeParentActionMediumTest method replace_existing_parent.
@Test
public void replace_existing_parent() throws Exception {
QualityProfileDto parent1 = createProfile("xoo", "Parent 1");
QualityProfileDto parent2 = createProfile("xoo", "Parent 2");
QualityProfileDto child = createProfile("xoo", "Child");
RuleDto rule1 = createRule("xoo", "rule1");
RuleDto rule2 = createRule("xoo", "rule2");
createActiveRule(rule1, parent1);
createActiveRule(rule2, parent2);
session.commit();
ruleIndexer.index();
activeRuleIndexer.index();
// Set parent 1
tester.get(RuleActivator.class).setParent(session, child.getKey(), parent1.getKey());
session.clearCache();
// Set parent 2 through WS
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent").setParam(QProfileRef.PARAM_PROFILE_KEY, child.getKey()).setParam("parentKey", parent2.getKey()).execute();
session.clearCache();
// Check rule 2 enabled
List<ActiveRuleDto> activeRules2 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().ruleKey().rule()).isEqualTo("rule2");
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).hasSize(1);
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class ChangeParentActionMediumTest method createRule.
private RuleDto createRule(String lang, String id) {
RuleDto rule = RuleTesting.newDto(RuleKey.of("blah", id)).setLanguage(lang).setSeverity(Severity.BLOCKER).setStatus(RuleStatus.READY);
db.ruleDao().insert(session, rule);
return rule;
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class ChangelogLoaderTest method insertRule.
private void insertRule(RuleKey key, String name) {
RuleDto dto = RuleTesting.newDto(key).setName(name);
dbTester.getDbClient().ruleDao().insert(dbTester.getSession(), dto);
dbTester.getSession().commit();
}
Aggregations