use of org.sonar.db.qualityprofile.QualityProfileDto 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.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method assertProfileHasBeenUpdatedAutomatically.
private void assertProfileHasBeenUpdatedAutomatically(String profileKey) {
QualityProfileDto profile = db.qualityProfileDao().selectByKey(dbSession, profileKey);
assertThat(profile.getRulesUpdatedAt()).isNotEmpty();
assertThat(profile.getUserUpdatedAt()).isNull();
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class ChangeParentActionMediumTest method fail_if_parent_key_and_name_both_set.
@Test(expected = IllegalArgumentException.class)
public void fail_if_parent_key_and_name_both_set() throws Exception {
QualityProfileDto child = createProfile("xoo", "Child");
session.commit();
assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent").setParam(QProfileRef.PARAM_PROFILE_KEY, child.getKee()).setParam("parentName", "polop").setParam("parentKey", "palap").execute();
}
use of org.sonar.db.qualityprofile.QualityProfileDto 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.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class ChangeParentActionMediumTest method createProfile.
private QualityProfileDto createProfile(String lang, String name) {
QualityProfileDto profile = QProfileTesting.newQProfileDto("org-123", new QProfileName(lang, name), "p" + lang + "-" + name.toLowerCase());
db.qualityProfileDao().insert(session, profile);
return profile;
}
Aggregations