Search in sources :

Example 91 with QProfileDto

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

the class AddProjectActionTest method as_qprofile_editor.

@Test
public void as_qprofile_editor() {
    UserDto user = db.users().insertUser();
    QProfileDto qualityProfile = db.qualityProfiles().insert(qp -> qp.setLanguage(LANGUAGE_1));
    db.qualityProfiles().addUserPermission(qualityProfile, user);
    ProjectDto project = db.components().insertPrivateProjectDto();
    userSession.logIn(user);
    call(project, qualityProfile);
    assertProjectIsAssociatedToProfile(project, qualityProfile);
    verify(qualityProfileChangeEventService).publishRuleActivationToSonarLintClients(project, qualityProfile, null);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 92 with QProfileDto

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

the class AddProjectActionTest method assertProjectIsAssociatedToProfile.

private void assertProjectIsAssociatedToProfile(ProjectDto project, QProfileDto profile) {
    QProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage());
    assertThat(loaded.getKee()).isEqualTo(profile.getKee());
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto)

Example 93 with QProfileDto

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

the class AddProjectActionTest method changing_association_does_not_change_other_language_associations.

@Test
public void changing_association_does_not_change_other_language_associations() {
    logInAsProfileAdmin();
    ProjectDto project = db.components().insertPrivateProjectDto();
    QProfileDto profile1Language1 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
    QProfileDto profile2Language2 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_2));
    QProfileDto profile3Language1 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
    db.qualityProfiles().associateWithProject(project, profile1Language1, profile2Language2);
    call(project, profile3Language1);
    assertProjectIsAssociatedToProfile(project, profile3Language1);
    assertProjectIsAssociatedToProfile(project, profile2Language2);
    verify(qualityProfileChangeEventService).publishRuleActivationToSonarLintClients(project, profile3Language1, profile1Language1);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Test(org.junit.Test)

Example 94 with QProfileDto

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

the class ActivateRuleActionTest method fail_activate_if_built_in_profile.

@Test
public void fail_activate_if_built_in_profile() {
    userSession.logIn(db.users().insertUser()).addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES);
    QProfileDto qualityProfile = db.qualityProfiles().insert(profile -> profile.setIsBuiltIn(true).setName("Xoo profile").setLanguage("xoo"));
    TestRequest request = ws.newRequest().setMethod("POST").setParam(PARAM_RULE, RuleTesting.newRule().getKey().toString()).setParam(PARAM_KEY, qualityProfile.getKee());
    assertThatThrownBy(() -> request.execute()).isInstanceOf(BadRequestException.class).hasMessage("Operation forbidden for built-in Quality Profile 'Xoo profile' with language 'xoo'");
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) BadRequestException(org.sonar.server.exceptions.BadRequestException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 95 with QProfileDto

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

the class QProfileExportersTest method fail_to_import_xml_on_unknown_importer.

@Test
public void fail_to_import_xml_on_unknown_importer() {
    QProfileDto qProfileDto = newQualityProfileDto();
    InputStream inputStream = toInputStream("<xml/>", UTF_8);
    DbSession dbSession = db.getSession();
    assertThatThrownBy(() -> underTest.importXml(qProfileDto, "Unknown", inputStream, dbSession)).isInstanceOf(BadRequestException.class).hasMessage("No such importer : Unknown");
}
Also used : DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) IOUtils.toInputStream(org.apache.commons.io.IOUtils.toInputStream) InputStream(java.io.InputStream) 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