use of org.sonar.core.util.ParamChange in project sonarqube by SonarSource.
the class QualityProfileChangeEventServiceImplTest method publishRuleActivationToSonarLintClients.
@Test
public void publishRuleActivationToSonarLintClients() {
ProjectDto projectDao = new ProjectDto();
QProfileDto activatedQualityProfile = QualityProfileTesting.newQualityProfileDto();
db.qualityProfiles().insert(activatedQualityProfile);
RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo"));
RuleParamDto rule1Param = db.rules().insertRuleParam(rule1);
ActiveRuleDto activeRule1 = db.qualityProfiles().activateRule(activatedQualityProfile, rule1);
ActiveRuleParamDto activeRuleParam1 = ActiveRuleParamDto.createFor(rule1Param).setValue(randomAlphanumeric(20));
db.getDbClient().activeRuleDao().insertParam(db.getSession(), activeRule1, activeRuleParam1);
db.getSession().commit();
QProfileDto deactivatedQualityProfile = QualityProfileTesting.newQualityProfileDto();
db.qualityProfiles().insert(deactivatedQualityProfile);
RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("xoo"));
RuleParamDto rule2Param = db.rules().insertRuleParam(rule2);
ActiveRuleDto activeRule2 = db.qualityProfiles().activateRule(deactivatedQualityProfile, rule2);
ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(rule2Param).setValue(randomAlphanumeric(20));
db.getDbClient().activeRuleDao().insertParam(db.getSession(), activeRule2, activeRuleParam2);
db.getSession().commit();
underTest.publishRuleActivationToSonarLintClients(projectDao, activatedQualityProfile, deactivatedQualityProfile);
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[] { null });
// activated rule
assertThat(ruleSetChangedEvent.getActivatedRules()).extracting(RuleChange::getKey, RuleChange::getLanguage, RuleChange::getSeverity, RuleChange::getTemplateKey).containsExactly(tuple(rule1.getRuleKey(), "xoo", rule1.getSeverityString(), null));
assertThat(ruleSetChangedEvent.getActivatedRules()[0].getParams()).hasSize(1);
ParamChange actualParamChange = ruleSetChangedEvent.getActivatedRules()[0].getParams()[0];
assertThat(actualParamChange).extracting(ParamChange::getKey, ParamChange::getValue).containsExactly(activeRuleParam1.getKey(), activeRuleParam1.getValue());
// deactivated rule
assertThat(ruleSetChangedEvent.getDeactivatedRules()).extracting(RuleChange::getKey, RuleChange::getLanguage, RuleChange::getSeverity, RuleChange::getTemplateKey).containsExactly(tuple(rule2.getRuleKey(), "xoo", rule2.getSeverityString(), null));
assertThat(ruleSetChangedEvent.getDeactivatedRules()[0].getParams()).hasSize(1);
ParamChange actualParamChangeDeactivated = ruleSetChangedEvent.getDeactivatedRules()[0].getParams()[0];
assertThat(actualParamChangeDeactivated).extracting(ParamChange::getKey, ParamChange::getValue).containsExactly(activeRuleParam2.getKey(), activeRuleParam2.getValue());
}
Aggregations