Search in sources :

Example 96 with QProfileDto

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

the class QProfileExportersTest method import_xml_return_messages.

@Test
public void import_xml_return_messages() {
    QProfileDto profile = createProfile();
    QProfileResult result = underTest.importXml(profile, "XooProfileImporterWithMessages", toInputStream("<xml/>", UTF_8), db.getSession());
    assertThat(result.infos()).containsOnly("an info");
    assertThat(result.warnings()).containsOnly("a warning");
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Test(org.junit.Test)

Example 97 with QProfileDto

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

the class QProfileExportersTest method export_empty_profile.

@Test
public void export_empty_profile() {
    QProfileDto profile = createProfile();
    StringWriter writer = new StringWriter();
    underTest.export(db.getSession(), profile, "standard", writer);
    assertThat(writer.toString()).isEqualTo("standard -> " + profile.getName() + " -> 0");
    writer = new StringWriter();
    underTest.export(db.getSession(), profile, "xootool", writer);
    assertThat(writer.toString()).isEqualTo("xoo -> " + profile.getName() + " -> 0");
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) StringWriter(java.io.StringWriter) Test(org.junit.Test)

Example 98 with QProfileDto

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

the class AddGroupActionTest method uses_global_permission.

@Test
public void uses_global_permission() {
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
    GroupDto group = db.users().insertGroup();
    userSession.logIn().addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES);
    ws.newRequest().setParam(PARAM_QUALITY_PROFILE, profile.getName()).setParam(PARAM_LANGUAGE, XOO).setParam(PARAM_GROUP, group.getName()).execute();
    assertThat(db.getDbClient().qProfileEditGroupsDao().exists(db.getSession(), profile, group)).isTrue();
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 99 with QProfileDto

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

the class AddGroupActionTest method does_nothing_when_group_can_already_edit_profile.

@Test
public void does_nothing_when_group_can_already_edit_profile() {
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
    GroupDto group = db.users().insertGroup();
    db.qualityProfiles().addGroupPermission(profile, group);
    assertThat(db.getDbClient().qProfileEditGroupsDao().exists(db.getSession(), profile, group)).isTrue();
    userSession.logIn().addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES);
    ws.newRequest().setParam(PARAM_QUALITY_PROFILE, profile.getName()).setParam(PARAM_LANGUAGE, XOO).setParam(PARAM_GROUP, group.getName()).execute();
    assertThat(db.getDbClient().qProfileEditGroupsDao().exists(db.getSession(), profile, group)).isTrue();
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 100 with QProfileDto

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

the class AddGroupActionTest method fail_when_wrong_language.

@Test
public void fail_when_wrong_language() {
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage("unknown"));
    UserDto user = db.users().insertUser();
    userSession.logIn().addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES);
    assertThatThrownBy(() -> {
        ws.newRequest().setParam(PARAM_QUALITY_PROFILE, profile.getName()).setParam(PARAM_LANGUAGE, XOO).setParam(PARAM_GROUP, user.getLogin()).execute();
    }).isInstanceOf(NotFoundException.class).hasMessage(format("Quality Profile for language 'xoo' and name '%s' does not exist", profile.getName()));
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) UserDto(org.sonar.db.user.UserDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) 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