Search in sources :

Example 6 with QProfileComparisonResult

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

Example 7 with QProfileComparisonResult

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) RuleKey(org.sonar.api.rule.RuleKey) RuleRepositoryDto(org.sonar.db.rule.RuleRepositoryDto) QProfileComparisonResult(org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult)

Example 8 with QProfileComparisonResult

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

Example 9 with QProfileComparisonResult

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

Aggregations

QProfileComparisonResult (org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult)9 Test (org.junit.Test)8 ActiveRuleDiff (org.sonar.server.qualityprofile.QProfileComparison.ActiveRuleDiff)3 RuleKey (org.sonar.api.rule.RuleKey)1 DbSession (org.sonar.db.DbSession)1 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)1 RuleDto (org.sonar.db.rule.RuleDto)1 RuleRepositoryDto (org.sonar.db.rule.RuleRepositoryDto)1