Search in sources :

Example 81 with QProfileDto

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

the class BuiltInQProfileInsertImplTest method existing_default_profile_must_not_be_changed.

@Test
public void existing_default_profile_must_not_be_changed() {
    BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
    NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("the name", "xoo").setDefault(true);
    newQp.done();
    BuiltInQProfile builtIn = builtInQProfileRepository.create(context.profile("xoo", "the name"));
    QProfileDto currentDefault = db.qualityProfiles().insert(p -> p.setLanguage("xoo"));
    db.qualityProfiles().setAsDefault(currentDefault);
    call(builtIn);
    QProfileDto defaultProfile = db.getDbClient().qualityProfileDao().selectDefaultProfile(dbSession, "xoo");
    assertThat(defaultProfile.getKee()).isEqualTo(currentDefault.getKee());
    verifyTableSize("rules_profiles", 2);
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) BuiltInQualityProfilesDefinition(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Test(org.junit.Test)

Example 82 with QProfileDto

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

the class BuiltInQProfileInsertImplTest method verifyProfileInDb.

private QProfileDto verifyProfileInDb(BuiltInQProfile builtIn) {
    QProfileDto profileOnOrg1 = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(dbSession, builtIn.getName(), builtIn.getLanguage());
    assertThat(profileOnOrg1.getLanguage()).isEqualTo(builtIn.getLanguage());
    assertThat(profileOnOrg1.getName()).isEqualTo(builtIn.getName());
    assertThat(profileOnOrg1.getParentKee()).isNull();
    assertThat(profileOnOrg1.getLastUsed()).isNull();
    assertThat(profileOnOrg1.getUserUpdatedAt()).isNull();
    assertThat(profileOnOrg1.getRulesUpdatedAt()).isNotEmpty();
    assertThat(profileOnOrg1.getKee()).isNotEqualTo(profileOnOrg1.getRulesProfileUuid());
    assertThat(profileOnOrg1.getRulesProfileUuid()).isNotNull();
    return profileOnOrg1;
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto)

Example 83 with QProfileDto

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

the class ActivateRulesActionTest method fail_if_built_in_profile.

@Test
public void fail_if_built_in_profile() {
    userSession.logIn().addPermission(ADMINISTER_QUALITY_PROFILES);
    QProfileDto qualityProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true));
    TestRequest request = ws.newRequest().setMethod("POST").setParam(PARAM_TARGET_KEY, qualityProfile.getKee());
    assertThatThrownBy(() -> request.execute()).isInstanceOf(BadRequestException.class);
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 84 with QProfileDto

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

the class ActivateRulesActionTest method as_qprofile_editor.

@Test
public void as_qprofile_editor() {
    UserDto user = db.users().insertUser();
    GroupDto group = db.users().insertGroup();
    QProfileDto qualityProfile = db.qualityProfiles().insert();
    db.qualityProfiles().addGroupPermission(qualityProfile, group);
    userSession.logIn(user).setGroups(group);
    ws.newRequest().setMethod("POST").setParam(PARAM_TARGET_KEY, qualityProfile.getKee()).execute();
    verify(qProfileRules).bulkActivateAndCommit(any(), any(), any(), any());
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 85 with QProfileDto

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

the class ActivateRulesActionTest method as_global_qprofile_admin.

@Test
public void as_global_qprofile_admin() {
    userSession.logIn(db.users().insertUser()).addPermission(ADMINISTER_QUALITY_PROFILES);
    QProfileDto qualityProfile = db.qualityProfiles().insert();
    ws.newRequest().setMethod("POST").setParam(PARAM_TARGET_KEY, qualityProfile.getKee()).execute();
    verify(qProfileRules).bulkActivateAndCommit(any(), any(), any(), any());
}
Also used : 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