use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_activation_and_inheritance.
@Test
public void search_by_activation_and_inheritance() {
RuleDefinitionDto rule1 = createJavaRule();
RuleDefinitionDto rule2 = createJavaRule();
RuleDefinitionDto rule3 = createJavaRule();
RuleDefinitionDto rule4 = createJavaRule();
QProfileDto parent = createJavaProfile();
QProfileDto child = createJavaProfile();
db.qualityProfiles().activateRule(parent, rule1);
db.qualityProfiles().activateRule(parent, rule2);
db.qualityProfiles().activateRule(parent, rule3);
db.qualityProfiles().activateRule(child, rule1, ar -> ar.setInheritance(INHERITED.name()));
db.qualityProfiles().activateRule(child, rule2, ar -> ar.setInheritance(OVERRIDES.name()));
db.qualityProfiles().activateRule(child, rule3, ar -> ar.setInheritance(INHERITED.name()));
index();
// all rules
verifySearch(newRuleQuery(), rule1, rule2, rule3, rule4);
// inherited/overrides rules on parent
verifyEmptySearch(newRuleQuery().setActivation(true).setQProfile(parent).setInheritance(of(INHERITED.name())));
verifyEmptySearch(newRuleQuery().setActivation(true).setQProfile(parent).setInheritance(of(OVERRIDES.name())));
// inherited/overrides rules on child
verifySearch(newRuleQuery().setActivation(true).setQProfile(child).setInheritance(of(INHERITED.name())), rule1, rule3);
verifySearch(newRuleQuery().setActivation(true).setQProfile(child).setInheritance(of(OVERRIDES.name())), rule2);
// inherited AND overridden on parent
verifyEmptySearch(newRuleQuery().setActivation(true).setQProfile(parent).setInheritance(of(INHERITED.name(), OVERRIDES.name())));
// inherited AND overridden on child
verifySearch(newRuleQuery().setActivation(true).setQProfile(child).setInheritance(of(INHERITED.name(), OVERRIDES.name())), rule1, rule2, rule3);
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QualityProfileChangeEventServiceImplTest method distributeRuleChangeEvent.
@Test
public void distributeRuleChangeEvent() {
QProfileDto qualityProfileDto = QualityProfileTesting.newQualityProfileDto();
// Template rule
RuleDto templateRule = newTemplateRule(RuleKey.of("xoo", "template-key"));
db.rules().insert(templateRule.getDefinition());
// Custom rule
RuleDefinitionDto rule1 = newCustomRule(templateRule.getDefinition()).setLanguage("xoo").setDescription("<div>line1\nline2</div>").setDescriptionFormat(MARKDOWN);
db.rules().insert(rule1);
ActiveRuleDto activeRuleDto = ActiveRuleDto.createFor(qualityProfileDto, rule1);
ActiveRuleChange activeRuleChange = new ActiveRuleChange(ACTIVATED, activeRuleDto, rule1);
activeRuleChange.setParameter("paramChangeKey", "paramChangeValue");
Collection<QProfileDto> profiles = Collections.singleton(qualityProfileDto);
ProjectDto project = db.components().insertPrivateProjectDto();
db.qualityProfiles().associateWithProject(project, qualityProfileDto);
underTest.distributeRuleChangeEvent(profiles, of(activeRuleChange), "xoo");
ArgumentCaptor<RuleSetChangedEvent> eventCaptor = ArgumentCaptor.forClass(RuleSetChangedEvent.class);
verify(eventsDistributor).pushEvent(eventCaptor.capture());
RuleSetChangedEvent ruleSetChangedEvent = eventCaptor.getValue();
assertThat(ruleSetChangedEvent).isNotNull();
assertThat(ruleSetChangedEvent).extracting(RuleSetChangedEvent::getEvent, RuleSetChangedEvent::getLanguage, RuleSetChangedEvent::getProjects).containsExactly("RuleSetChanged", "xoo", new String[] { project.getKey() });
assertThat(ruleSetChangedEvent.getActivatedRules()).extracting(RuleChange::getKey, RuleChange::getLanguage, RuleChange::getSeverity, RuleChange::getTemplateKey).containsExactly(tuple(rule1.getRuleKey(), "xoo", null, "template-key"));
assertThat(ruleSetChangedEvent.getActivatedRules()[0].getParams()).hasSize(1);
ParamChange actualParamChange = ruleSetChangedEvent.getActivatedRules()[0].getParams()[0];
assertThat(actualParamChange).extracting(ParamChange::getKey, ParamChange::getValue).containsExactly("paramChangeKey", "paramChangeValue");
assertThat(ruleSetChangedEvent.getDeactivatedRules()).isEmpty();
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class UpdateQualityProfilesLastUsedDateStepTest method ancestor_profiles_are_updated.
@Test
public void ancestor_profiles_are_updated() {
// Parent profiles should be updated
QProfileDto rootProfile = newProfile("root");
QProfileDto parentProfile = newProfile("parent").setParentKee(rootProfile.getKee());
// Current profile => should be updated
QProfileDto currentProfile = newProfile("current").setParentKee(parentProfile.getKee());
// Child of current profile => should not be updated
QProfileDto childProfile = newProfile("child").setParentKee(currentProfile.getKee());
qualityProfileDb.insert(rootProfile, parentProfile, currentProfile, childProfile);
measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(toJson(currentProfile.getKee())));
underTest.execute(new TestComputationStepContext());
assertQualityProfileIsUpdated(rootProfile);
assertQualityProfileIsUpdated(parentProfile);
assertQualityProfileIsUpdated(currentProfile);
assertQualityProfileIsTheSame(childProfile);
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class ActiveRuleChangeTest method toDto.
@Test
public void toDto() {
QProfileDto profile = newQualityProfileDto();
ActiveRuleKey key = ActiveRuleKey.of(profile, RuleKey.of("P1", "R1"));
String ruleUuid = Uuids.createFast();
ActiveRuleChange underTest = new ActiveRuleChange(ACTIVATED, key, new RuleDefinitionDto().setUuid(ruleUuid));
QProfileChangeDto result = underTest.toDto(A_USER_UUID);
assertThat(result.getChangeType()).isEqualTo(ACTIVATED.name());
assertThat(result.getRulesProfileUuid()).isEqualTo(profile.getRulesProfileUuid());
assertThat(result.getUserUuid()).isEqualTo(A_USER_UUID);
assertThat(result.getDataAsMap()).containsEntry("ruleUuid", ruleUuid);
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileFactoryImpl method checkAndCreateCustom.
@Override
public QProfileDto checkAndCreateCustom(DbSession dbSession, QProfileName name) {
QProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(dbSession, name.getName(), name.getLanguage());
checkRequest(dto == null, "Quality profile already exists: %s", name);
return doCreate(dbSession, name, null, false, false);
}
Aggregations