use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class BuiltInQProfileUpdateImplTest method assertThatRuleIsActivated.
private void assertThatRuleIsActivated(QProfileDto profile, RuleDefinitionDto rule, @Nullable List<ActiveRuleChange> changes, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) {
OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile).stream().filter(ar -> ar.getRuleKey().equals(rule.getKey())).findFirst().orElseThrow(IllegalStateException::new);
assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity);
assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null);
List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
assertThat(params).hasSize(expectedParams.size());
if (changes != null) {
ActiveRuleChange change = changes.stream().filter(c -> c.getActiveRule().getUuid().equals(activeRule.getUuid())).findFirst().orElseThrow(IllegalStateException::new);
assertThat(change.getInheritance()).isEqualTo(expectedInheritance);
assertThat(change.getSeverity()).isEqualTo(expectedSeverity);
assertThat(change.getType()).isEqualTo(ActiveRuleChange.Type.ACTIVATED);
}
}
use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class ChangeParentActionTest method as_qprofile_editor.
@Test
public void as_qprofile_editor() {
QProfileDto parent1 = createProfile();
QProfileDto parent2 = createProfile();
QProfileDto child = createProfile();
RuleDefinitionDto rule1 = createRule();
RuleDefinitionDto rule2 = createRule();
createActiveRule(rule1, parent1);
createActiveRule(rule2, parent2);
ruleIndexer.commitAndIndex(dbSession, asList(rule1.getUuid(), rule2.getUuid()));
activeRuleIndexer.indexAll();
// Set parent 1
qProfileTree.setParentAndCommit(dbSession, child, parent1);
UserDto user = db.users().insertUser();
db.qualityProfiles().addUserPermission(child, user);
userSession.logIn(user);
ws.newRequest().setMethod("POST").setParam(PARAM_LANGUAGE, child.getLanguage()).setParam(PARAM_QUALITY_PROFILE, child.getName()).setParam(PARAM_PARENT_QUALITY_PROFILE, parent2.getName()).execute();
List<OrgActiveRuleDto> activeRules2 = dbClient.activeRuleDao().selectByProfile(dbSession, child);
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().getRuleKey().rule()).isEqualTo(rule2.getRuleKey());
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).hasSize(1);
}
use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class QualityProfileChangeEventServiceImpl method createRuleChanges.
private List<RuleChange> createRuleChanges(@NotNull QProfileDto profileDto) {
List<RuleChange> ruleChanges = new ArrayList<>();
try (DbSession dbSession = dbClient.openSession(false)) {
List<OrgActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfile(dbSession, profileDto);
List<String> activeRuleUuids = activeRuleDtos.stream().map(ActiveRuleDto::getUuid).collect(Collectors.toList());
Map<String, List<ActiveRuleParamDto>> paramsByActiveRuleUuid = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, activeRuleUuids).stream().collect(Collectors.groupingBy(ActiveRuleParamDto::getActiveRuleUuid));
Map<String, String> activeRuleUuidByRuleUuid = activeRuleDtos.stream().collect(Collectors.toMap(ActiveRuleDto::getRuleUuid, ActiveRuleDto::getUuid));
List<String> ruleUuids = activeRuleDtos.stream().map(ActiveRuleDto::getRuleUuid).collect(Collectors.toList());
List<RuleDto> ruleDtos = dbClient.ruleDao().selectByUuids(dbSession, ruleUuids);
for (RuleDto ruleDto : ruleDtos) {
String activeRuleUuid = activeRuleUuidByRuleUuid.get(ruleDto.getUuid());
List<ActiveRuleParamDto> params = paramsByActiveRuleUuid.getOrDefault(activeRuleUuid, new ArrayList<>());
RuleChange ruleChange = toRuleChange(ruleDto, params);
ruleChanges.add(ruleChange);
}
}
return ruleChanges;
}
use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class QProfileTreeImplTest method assertThatRuleIsUpdated.
private void assertThatRuleIsUpdated(QProfileDto profile, RuleDefinitionDto rule, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) {
OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile).stream().filter(ar -> ar.getRuleKey().equals(rule.getKey())).findFirst().orElseThrow(IllegalStateException::new);
assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity);
assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null);
List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
assertThat(params).hasSize(expectedParams.size());
}
use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class QProfileTreeImplTest method assertThatRuleIsActivated.
private void assertThatRuleIsActivated(QProfileDto profile, RuleDefinitionDto rule, @Nullable List<ActiveRuleChange> changes, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) {
OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile).stream().filter(ar -> ar.getRuleKey().equals(rule.getKey())).findFirst().orElseThrow(IllegalStateException::new);
assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity);
assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null);
List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
assertThat(params).hasSize(expectedParams.size());
if (changes != null) {
ActiveRuleChange change = changes.stream().filter(c -> c.getActiveRule().getUuid().equals(activeRule.getUuid())).findFirst().orElseThrow(IllegalStateException::new);
assertThat(change.getInheritance()).isEqualTo(expectedInheritance);
assertThat(change.getSeverity()).isEqualTo(expectedSeverity);
assertThat(change.getType()).isEqualTo(ActiveRuleChange.Type.ACTIVATED);
}
}
Aggregations