Search in sources :

Example 1 with ActiveRuleDiff

use of org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff in project sonarqube by SonarSource.

the class QProfileComparisonMediumTest method compare_different_params.

@Test
public void compare_different_params() {
    ruleActivator.activate(dbSession, new RuleActivation(xooRule1.getKey()).setParameter("max", "20"), left);
    ruleActivator.activate(dbSession, new RuleActivation(xooRule1.getKey()).setParameter("min", "5"), 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(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"));
}
Also used : ActiveRuleDiff(org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff) QProfileComparisonResult(org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult) Test(org.junit.Test)

Example 2 with ActiveRuleDiff

use of org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff in project sonarqube by SonarSource.

the class QProfileComparisonMediumTest method compare_modified_param.

@Test
public void compare_modified_param() {
    ruleActivator.activate(dbSession, new RuleActivation(xooRule1.getKey()).setParameter("max", "20"), left);
    ruleActivator.activate(dbSession, new RuleActivation(xooRule1.getKey()).setParameter("max", "30"), 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(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");
}
Also used : ActiveRuleDiff(org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff) QProfileComparisonResult(org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult) Test(org.junit.Test)

Example 3 with ActiveRuleDiff

use of org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff in project sonarqube by SonarSource.

the class QProfileComparisonTest method compare_modified_severity.

@Test
public void compare_modified_severity() {
    qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getUuid(), Severity.CRITICAL, null)));
    qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getUuid(), Severity.BLOCKER, null)));
    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(Severity.CRITICAL);
    assertThat(activeRuleDiff.rightSeverity()).isEqualTo(Severity.BLOCKER);
    assertThat(activeRuleDiff.paramDifference().areEqual()).isTrue();
}
Also used : ActiveRuleDiff(org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff) QProfileComparisonResult(org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult) Test(org.junit.Test)

Example 4 with ActiveRuleDiff

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, RuleDto> rulesByKey, Map<String, RuleRepositoryDto> repositoriesByKey) {
    json.beginArray();
    for (Entry<RuleKey, ActiveRuleDiff> diffEntry : modified.entrySet()) {
        RuleKey key = diffEntry.getKey();
        ActiveRuleDiff value = diffEntry.getValue();
        json.beginObject();
        RuleDto 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();
}
Also used : ActiveRuleDiff(org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff) RuleKey(org.sonar.api.rule.RuleKey) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ValueDifference(com.google.common.collect.MapDifference.ValueDifference)

Example 5 with ActiveRuleDiff

use of org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff 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();
}
Also used : ActiveRuleDiff(org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff) QProfileComparisonResult(org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult) Test(org.junit.Test)

Aggregations

ActiveRuleDiff (org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff)8 Test (org.junit.Test)6 QProfileComparisonResult (org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult)6 ValueDifference (com.google.common.collect.MapDifference.ValueDifference)2 RuleKey (org.sonar.api.rule.RuleKey)2 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)1 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)1 RuleDto (org.sonar.db.rule.RuleDto)1