use of org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult in project sonarqube by SonarSource.
the class QProfileComparisonMediumTest method compare_same.
@Test
public void compare_same() {
RuleActivation commonActivation = new RuleActivation(xooRule1.getKey()).setSeverity(Severity.CRITICAL).setParameter("min", "7").setParameter("max", "42");
ruleActivator.activate(dbSession, commonActivation, left);
ruleActivator.activate(dbSession, commonActivation, right);
dbSession.commit();
QProfileComparisonResult result = comparison.compare(left.getKey(), right.getKey());
assertThat(result.left().getKey()).isEqualTo(left.getKey());
assertThat(result.right().getKey()).isEqualTo(right.getKey());
assertThat(result.same()).isNotEmpty().containsOnlyKeys(xooRule1.getKey());
assertThat(result.inLeft()).isEmpty();
assertThat(result.inRight()).isEmpty();
assertThat(result.modified()).isEmpty();
assertThat(result.collectRuleKeys()).containsOnly(xooRule1.getKey());
}
use of org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult in project sonarqube by SonarSource.
the class CompareAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String leftKey = request.mandatoryParam(PARAM_LEFT_KEY);
String rightKey = request.mandatoryParam(PARAM_RIGHT_KEY);
QProfileComparisonResult result = comparator.compare(leftKey, rightKey);
try (DbSession dbSession = dbClient.openSession(false)) {
List<RuleDto> referencedRules = dbClient.ruleDao().selectByKeys(dbSession, new ArrayList<>(result.collectRuleKeys()));
Map<RuleKey, RuleDto> rulesByKey = Maps.uniqueIndex(referencedRules, RuleDtoToRuleKey.INSTANCE);
Map<String, RuleRepositoryDto> repositoriesByKey = Maps.uniqueIndex(dbClient.ruleRepositoryDao().selectAll(dbSession), RuleRepositoryDto::getKey);
writeResult(response.newJsonWriter(), result, rulesByKey, repositoriesByKey);
}
}
use of org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult in project sonarqube by SonarSource.
the class QProfileComparisonMediumTest method compare_modified_severity.
@Test
public void compare_modified_severity() {
ruleActivator.activate(dbSession, new RuleActivation(xooRule1.getKey()).setSeverity(Severity.CRITICAL), left);
ruleActivator.activate(dbSession, new RuleActivation(xooRule1.getKey()).setSeverity(Severity.BLOCKER), right);
dbSession.commit();
QProfileComparisonResult result = comparison.compare(left.getKey(), right.getKey());
assertThat(result.left().getKey()).isEqualTo(left.getKey());
assertThat(result.right().getKey()).isEqualTo(right.getKey());
assertThat(result.same()).isEmpty();
assertThat(result.inLeft()).isEmpty();
assertThat(result.inRight()).isEmpty();
assertThat(result.modified()).isNotEmpty().containsOnlyKeys(xooRule1.getKey());
assertThat(result.collectRuleKeys()).containsOnly(xooRule1.getKey());
ActiveRuleDiff activeRuleDiff = result.modified().get(xooRule1.getKey());
assertThat(activeRuleDiff.leftSeverity()).isEqualTo(Severity.CRITICAL);
assertThat(activeRuleDiff.rightSeverity()).isEqualTo(Severity.BLOCKER);
assertThat(activeRuleDiff.paramDifference().areEqual()).isTrue();
}
use of org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult in project sonarqube by SonarSource.
the class QProfileComparisonMediumTest method compare_empty_profiles.
@Test
public void compare_empty_profiles() {
QProfileComparisonResult result = comparison.compare(left.getKey(), right.getKey());
assertThat(result.left().getKey()).isEqualTo(left.getKey());
assertThat(result.right().getKey()).isEqualTo(right.getKey());
assertThat(result.same()).isEmpty();
assertThat(result.inLeft()).isEmpty();
assertThat(result.inRight()).isEmpty();
assertThat(result.modified()).isEmpty();
assertThat(result.collectRuleKeys()).isEmpty();
}
Aggregations