use of org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff in project sonarqube by SonarSource.
the class CompareAction method writeDifferences.
private void writeDifferences(JsonWriter json, Map<RuleKey, ActiveRuleDiff> modified, Map<RuleKey, RuleDefinitionDto> rulesByKey, Map<String, RuleRepositoryDto> repositoriesByKey) {
json.beginArray();
for (Entry<RuleKey, ActiveRuleDiff> diffEntry : modified.entrySet()) {
RuleKey key = diffEntry.getKey();
ActiveRuleDiff value = diffEntry.getValue();
json.beginObject();
RuleDefinitionDto rule = rulesByKey.get(key);
writeRule(json, rule, repositoriesByKey.get(rule.getRepositoryKey()));
json.name(ATTRIBUTE_LEFT).beginObject();
json.prop(ATTRIBUTE_SEVERITY, value.leftSeverity());
json.name(ATTRIBUTE_PARAMS).beginObject();
for (Entry<String, ValueDifference<String>> valueDiff : value.paramDifference().entriesDiffering().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue().leftValue());
}
for (Entry<String, String> valueDiff : value.paramDifference().entriesOnlyOnLeft().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue());
}
// params
json.endObject();
// left
json.endObject();
json.name(ATTRIBUTE_RIGHT).beginObject();
json.prop(ATTRIBUTE_SEVERITY, value.rightSeverity());
json.name(ATTRIBUTE_PARAMS).beginObject();
for (Entry<String, ValueDifference<String>> valueDiff : value.paramDifference().entriesDiffering().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue().rightValue());
}
for (Entry<String, String> valueDiff : value.paramDifference().entriesOnlyOnRight().entrySet()) {
json.prop(valueDiff.getKey(), valueDiff.getValue());
}
// params
json.endObject();
// right
json.endObject();
// rule
json.endObject();
}
json.endArray();
}
use of org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff in project sonarqube by SonarSource.
the class QProfileComparisonTest method compare_modified_param.
@Test
public void compare_modified_param() {
qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getUuid(), null, ImmutableMap.of("max", "20"))));
qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getUuid(), null, ImmutableMap.of("max", "30"))));
QProfileComparisonResult result = comparison.compare(dbSession, left, right);
assertThat(result.left().getKee()).isEqualTo(left.getKee());
assertThat(result.right().getKee()).isEqualTo(right.getKee());
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(activeRuleDiff.rightSeverity()).isEqualTo(xooRule1.getSeverityString());
assertThat(activeRuleDiff.paramDifference().areEqual()).isFalse();
assertThat(activeRuleDiff.paramDifference().entriesDiffering()).isNotEmpty();
ValueDifference<String> paramDiff = activeRuleDiff.paramDifference().entriesDiffering().get("max");
assertThat(paramDiff.leftValue()).isEqualTo("20");
assertThat(paramDiff.rightValue()).isEqualTo("30");
}
use of org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff in project sonarqube by SonarSource.
the class QProfileComparisonTest method compare_different_params.
@Test
public void compare_different_params() {
qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getUuid(), null, ImmutableMap.of("max", "20"))));
qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getUuid(), null, ImmutableMap.of("min", "5"))));
QProfileComparisonResult result = comparison.compare(dbSession, left, right);
assertThat(result.left().getKee()).isEqualTo(left.getKee());
assertThat(result.right().getKee()).isEqualTo(right.getKee());
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(activeRuleDiff.rightSeverity()).isEqualTo(xooRule1.getSeverityString());
assertThat(activeRuleDiff.paramDifference().areEqual()).isFalse();
assertThat(activeRuleDiff.paramDifference().entriesDiffering()).isEmpty();
assertThat(activeRuleDiff.paramDifference().entriesOnlyOnLeft()).containsExactly(MapEntry.entry("max", "20"));
assertThat(activeRuleDiff.paramDifference().entriesOnlyOnRight()).containsExactly(MapEntry.entry("min", "5"));
}
Aggregations