Search in sources :

Example 46 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class QProfileTreeImplTest method set_then_unset_parent.

@Test
public void set_then_unset_parent() {
    RuleDefinitionDto rule1 = createJavaRule();
    RuleDefinitionDto rule2 = createJavaRule();
    QProfileDto profile1 = createProfile(rule1);
    List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getUuid()));
    assertThat(changes).hasSize(1);
    QProfileDto profile2 = createProfile(rule2);
    changes = activate(profile2, RuleActivation.create(rule2.getUuid()));
    assertThat(changes).hasSize(1);
    changes = underTest.setParentAndCommit(db.getSession(), profile2, profile1);
    assertThat(changes).hasSize(1);
    assertThatRuleIsActivated(profile2, rule1, changes, rule1.getSeverityString(), INHERITED, emptyMap());
    assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
    verify(qualityProfileChangeEventService, times(2)).distributeRuleChangeEvent(any(), any(), eq(profile2.getLanguage()));
    changes = underTest.removeParentAndCommit(db.getSession(), profile2);
    assertThat(changes).hasSize(1);
    assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
    assertThatRuleIsNotPresent(profile2, rule1);
    verify(qualityProfileChangeEventService, times(2)).distributeRuleChangeEvent(any(), any(), eq(profile2.getLanguage()));
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 47 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class QProfileTreeImplTest method activation_errors_are_ignored_when_setting_a_parent.

@Test
public void activation_errors_are_ignored_when_setting_a_parent() {
    RuleDefinitionDto rule1 = createJavaRule();
    RuleDefinitionDto rule2 = createJavaRule();
    QProfileDto parentProfile = createProfile(rule1);
    activate(parentProfile, RuleActivation.create(rule1.getUuid()));
    activate(parentProfile, RuleActivation.create(rule2.getUuid()));
    rule1.setStatus(RuleStatus.REMOVED);
    db.rules().update(rule1);
    QProfileDto childProfile = createProfile(rule1);
    List<ActiveRuleChange> changes = underTest.setParentAndCommit(db.getSession(), childProfile, parentProfile);
    verify(qualityProfileChangeEventService, times(2)).distributeRuleChangeEvent(any(), any(), eq(childProfile.getLanguage()));
    assertThatRuleIsNotPresent(childProfile, rule1);
    assertThatRuleIsActivated(childProfile, rule2, changes, rule2.getSeverityString(), INHERITED, emptyMap());
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 48 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class QProfileTreeImplTest method set_itself_as_parent_fails.

@Test
public void set_itself_as_parent_fails() {
    RuleDefinitionDto rule = createRule();
    QProfileDto profile = createProfile(rule);
    assertThatThrownBy(() -> underTest.setParentAndCommit(db.getSession(), profile, profile)).isInstanceOf(BadRequestException.class).hasMessageContaining(" can not be selected as parent of ");
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) BadRequestException(org.sonar.server.exceptions.BadRequestException) Test(org.junit.Test)

Example 49 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class QProfileTreeImplTest method set_then_unset_parent_keep_overridden_rules.

@Test
public void set_then_unset_parent_keep_overridden_rules() {
    RuleDefinitionDto rule1 = createJavaRule();
    RuleDefinitionDto rule2 = createJavaRule();
    QProfileDto profile1 = createProfile(rule1);
    List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getUuid()));
    assertThat(changes).hasSize(1);
    QProfileDto profile2 = createProfile(rule2);
    changes = activate(profile2, RuleActivation.create(rule2.getUuid()));
    assertThat(changes).hasSize(1);
    changes = underTest.setParentAndCommit(db.getSession(), profile2, profile1);
    assertThat(changes).hasSize(1);
    assertThatRuleIsActivated(profile2, rule1, changes, rule1.getSeverityString(), INHERITED, emptyMap());
    assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
    verify(qualityProfileChangeEventService, times(2)).distributeRuleChangeEvent(any(), any(), eq(profile2.getLanguage()));
    RuleActivation activation = RuleActivation.create(rule1.getUuid(), BLOCKER, null);
    changes = activate(profile2, activation);
    assertThat(changes).hasSize(1);
    assertThatRuleIsUpdated(profile2, rule1, BLOCKER, ActiveRuleInheritance.OVERRIDES, emptyMap());
    assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
    changes = underTest.removeParentAndCommit(db.getSession(), profile2);
    assertThat(changes).hasSize(1);
    // Not testing changes here since severity is not set in changelog
    assertThatRuleIsActivated(profile2, rule1, null, BLOCKER, null, emptyMap());
    assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
    verify(qualityProfileChangeEventService, times(3)).distributeRuleChangeEvent(anyList(), any(), eq(profile2.getLanguage()));
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 50 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class QProfileTreeImplTest method set_child_as_parent_fails.

@Test
public void set_child_as_parent_fails() {
    RuleDefinitionDto rule = createRule();
    QProfileDto parentProfile = createProfile(rule);
    QProfileDto childProfile = createChildProfile(parentProfile);
    assertThatThrownBy(() -> underTest.setParentAndCommit(db.getSession(), parentProfile, childProfile)).isInstanceOf(BadRequestException.class).hasMessageContaining(" can not be selected as parent of ");
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) BadRequestException(org.sonar.server.exceptions.BadRequestException) Test(org.junit.Test)

Aggregations

QProfileDto (org.sonar.db.qualityprofile.QProfileDto)389 Test (org.junit.Test)329 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)139 UserDto (org.sonar.db.user.UserDto)72 DbSession (org.sonar.db.DbSession)38 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)38 ProjectDto (org.sonar.db.project.ProjectDto)36 RuleParamDto (org.sonar.db.rule.RuleParamDto)36 GroupDto (org.sonar.db.user.GroupDto)35 NotFoundException (org.sonar.server.exceptions.NotFoundException)31 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)23 TestRequest (org.sonar.server.ws.TestRequest)23 System2 (org.sonar.api.utils.System2)22 RuleQuery (org.sonar.server.rule.index.RuleQuery)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)21 DbTester (org.sonar.db.DbTester)21 BadRequestException (org.sonar.server.exceptions.BadRequestException)20 UserSessionRule (org.sonar.server.tester.UserSessionRule)20 List (java.util.List)19 Rule (org.junit.Rule)19