Search in sources :

Example 31 with QProfileDto

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

the class QProfileFactoryImplTest method delete_removes_qprofile_edit_permissions.

@Test
public void delete_removes_qprofile_edit_permissions() {
    QProfileDto profile = db.qualityProfiles().insert();
    UserDto user = db.users().insertUser();
    db.qualityProfiles().addUserPermission(profile, user);
    GroupDto group = db.users().insertGroup();
    db.qualityProfiles().addGroupPermission(profile, group);
    underTest.delete(dbSession, asList(profile));
    assertThat(db.countRowsOfTable(dbSession, "qprofile_edit_users")).isZero();
    assertThat(db.countRowsOfTable(dbSession, "qprofile_edit_groups")).isZero();
}
Also used : OrgQProfileDto(org.sonar.db.qualityprofile.OrgQProfileDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 32 with QProfileDto

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

the class QProfileFactoryImplTest method delete_accepts_empty_list_of_keys.

@Test
public void delete_accepts_empty_list_of_keys() {
    QProfileDto profile = createCustomProfile();
    underTest.delete(dbSession, Collections.emptyList());
    verifyZeroInteractions(activeRuleIndexer);
    assertQualityProfileFromDb(profile).isNotNull();
}
Also used : OrgQProfileDto(org.sonar.db.qualityprofile.OrgQProfileDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Test(org.junit.Test)

Example 33 with QProfileDto

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

the class QProfileFactoryImplTest method createCustomProfile.

private QProfileDto createCustomProfile() {
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage("xoo").setIsBuiltIn(false));
    ActiveRuleDto activeRuleDto = db.qualityProfiles().activateRule(profile, rule);
    ActiveRuleParamDto activeRuleParam = new ActiveRuleParamDto().setRulesParameterUuid(ruleParam.getUuid()).setKey("foo").setValue("bar");
    db.getDbClient().activeRuleDao().insertParam(dbSession, activeRuleDto, activeRuleParam);
    db.getDbClient().qProfileChangeDao().insert(dbSession, new QProfileChangeDto().setChangeType(ActiveRuleChange.Type.ACTIVATED.name()).setRulesProfileUuid(profile.getRulesProfileUuid()));
    db.commit();
    return profile;
}
Also used : OrgQProfileDto(org.sonar.db.qualityprofile.OrgQProfileDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QProfileChangeDto(org.sonar.db.qualityprofile.QProfileChangeDto)

Example 34 with QProfileDto

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

the class QProfileFactoryImplTest method delete_builtin_profile_associated_to_project.

@Test
public void delete_builtin_profile_associated_to_project() {
    RulesProfileDto builtInProfile = createBuiltInProfile();
    ProjectDto project = db.components().insertPrivateProjectDto();
    QProfileDto profile = associateBuiltInProfile(builtInProfile);
    db.qualityProfiles().associateWithProject(project, profile);
    assertThat(db.getDbClient().qualityProfileDao().selectAssociatedToProjectAndLanguage(dbSession, project, profile.getLanguage())).isNotNull();
    underTest.delete(dbSession, asList(profile));
    verifyNoCallsActiveRuleIndexerDelete();
    // remove only from org_qprofiles and project_qprofiles
    assertThat(db.getDbClient().qualityProfileDao().selectAll(dbSession)).isEmpty();
    assertThat(db.getDbClient().qualityProfileDao().selectAssociatedToProjectAndLanguage(dbSession, project, profile.getLanguage())).isNull();
    assertThatRulesProfileExists(builtInProfile);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) OrgQProfileDto(org.sonar.db.qualityprofile.OrgQProfileDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RulesProfileDto(org.sonar.db.qualityprofile.RulesProfileDto) Test(org.junit.Test)

Example 35 with QProfileDto

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

the class QProfileFactoryImplTest method delete_removes_custom_profile_from_project_associations.

@Test
public void delete_removes_custom_profile_from_project_associations() {
    QProfileDto profile = createCustomProfile();
    ProjectDto project = db.components().insertPrivateProjectDto();
    db.qualityProfiles().associateWithProject(project, profile);
    underTest.delete(dbSession, asList(profile));
    assertThatCustomProfileDoesNotExist(profile);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) OrgQProfileDto(org.sonar.db.qualityprofile.OrgQProfileDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) 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