Search in sources :

Example 16 with SearchWsResponse

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method filter_on_project_key.

@Test
public void filter_on_project_key() {
    ProjectDto project = db.components().insertPrivateProjectDto();
    QProfileDto profileOnXoo1 = db.qualityProfiles().insert(q -> q.setLanguage(XOO1.getKey()));
    QProfileDto defaultProfileOnXoo1 = db.qualityProfiles().insert(q -> q.setLanguage(XOO1.getKey()));
    QProfileDto defaultProfileOnXoo2 = db.qualityProfiles().insert(q -> q.setLanguage(XOO2.getKey()));
    db.qualityProfiles().associateWithProject(project, profileOnXoo1);
    db.qualityProfiles().setAsDefault(defaultProfileOnXoo1, defaultProfileOnXoo2);
    SearchWsResponse result = call(ws.newRequest().setParam(PARAM_PROJECT, project.getKey()));
    assertThat(result.getProfilesList()).extracting(QualityProfile::getKey).containsExactlyInAnyOrder(profileOnXoo1.getKee(), defaultProfileOnXoo2.getKee()).doesNotContain(defaultProfileOnXoo1.getKee());
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) QualityProfile(org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile) SearchWsResponse(org.sonarqube.ws.Qualityprofiles.SearchWsResponse) Test(org.junit.Test)

Example 17 with SearchWsResponse

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method actions_when_user_is_global_qprofile_administer.

@Test
public void actions_when_user_is_global_qprofile_administer() {
    QProfileDto customProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    QProfileDto builtInProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()).setIsBuiltIn(true));
    QProfileDto defaultProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    db.qualityProfiles().setAsDefault(defaultProfile);
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES);
    SearchWsResponse result = call(ws.newRequest());
    assertThat(result.getProfilesList()).extracting(QualityProfile::getKey, qp -> qp.getActions().getEdit(), qp -> qp.getActions().getCopy(), qp -> qp.getActions().getSetAsDefault(), qp -> qp.getActions().getDelete(), qp -> qp.getActions().getAssociateProjects()).containsExactlyInAnyOrder(tuple(customProfile.getKee(), true, true, true, true, true), tuple(builtInProfile.getKee(), false, true, true, false, true), tuple(defaultProfile.getKee(), true, true, false, false, false));
    assertThat(result.getActions().getCreate()).isTrue();
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) SearchWsResponse(org.sonarqube.ws.Qualityprofiles.SearchWsResponse) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) IntStream.range(java.util.stream.IntStream.range) GlobalPermission(org.sonar.db.permission.GlobalPermission) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Languages(org.sonar.api.resources.Languages) QualityProfileDbTester(org.sonar.db.qualityprofile.QualityProfileDbTester) PARAM_PROJECT(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT) WebService(org.sonar.api.server.ws.WebService) DateUtils(org.sonar.api.utils.DateUtils) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PARAM_LANGUAGE(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE) PARAM_DEFAULTS(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_DEFAULTS) MediaTypes(org.sonarqube.ws.MediaTypes) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Language(org.sonar.api.resources.Language) PARAM_QUALITY_PROFILE(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE) PARAM_PROJECT_KEY(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_KEY) GroupDto(org.sonar.db.user.GroupDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) QualityProfile(org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) QualityProfileTesting.newQualityProfileDto(org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto) LanguageTesting.newLanguage(org.sonar.server.language.LanguageTesting.newLanguage) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) DEPRECATED(org.sonar.api.rule.RuleStatus.DEPRECATED) NotFoundException(org.sonar.server.exceptions.NotFoundException) DbClient(org.sonar.db.DbClient) List(java.util.List) Rule(org.junit.Rule) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Change(org.sonar.api.server.ws.Change) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) UserDto(org.sonar.db.user.UserDto) SearchWsResponse(org.sonarqube.ws.Qualityprofiles.SearchWsResponse) Test(org.junit.Test)

Example 18 with SearchWsResponse

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method statistics_on_projects.

@Test
public void statistics_on_projects() {
    ProjectDto project1 = db.components().insertPrivateProjectDto();
    ProjectDto project2 = db.components().insertPrivateProjectDto();
    QProfileDto profileOnXoo1 = db.qualityProfiles().insert(q -> q.setLanguage(XOO1.getKey()));
    QProfileDto defaultProfileOnXoo1 = db.qualityProfiles().insert(q -> q.setLanguage(XOO1.getKey()));
    db.qualityProfiles().associateWithProject(project1, profileOnXoo1);
    db.qualityProfiles().associateWithProject(project2, profileOnXoo1);
    db.qualityProfiles().setAsDefault(defaultProfileOnXoo1);
    SearchWsResponse result = call(ws.newRequest());
    assertThat(result.getProfilesList()).extracting(QualityProfile::hasProjectCount, QualityProfile::getProjectCount).containsExactlyInAnyOrder(tuple(true, 2L), tuple(false, 0L));
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) SearchWsResponse(org.sonarqube.ws.Qualityprofiles.SearchWsResponse) Test(org.junit.Test)

Example 19 with SearchWsResponse

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method filter_on_project_key_and_default.

@Test
public void filter_on_project_key_and_default() {
    ProjectDto project = db.components().insertPrivateProjectDto();
    QProfileDto profileOnXoo1 = db.qualityProfiles().insert(q -> q.setLanguage(XOO1.getKey()));
    QProfileDto defaultProfileOnXoo1 = db.qualityProfiles().insert(q -> q.setLanguage(XOO1.getKey()));
    QProfileDto defaultProfileOnXoo2 = db.qualityProfiles().insert(q -> q.setLanguage(XOO2.getKey()));
    db.qualityProfiles().associateWithProject(project, profileOnXoo1);
    db.qualityProfiles().setAsDefault(defaultProfileOnXoo1, defaultProfileOnXoo2);
    SearchWsResponse result = call(ws.newRequest().setParam(PARAM_PROJECT, project.getKey()).setParam(PARAM_DEFAULTS, "true"));
    assertThat(result.getProfilesList()).extracting(QualityProfile::getKey).containsExactlyInAnyOrder(defaultProfileOnXoo2.getKee()).doesNotContain(defaultProfileOnXoo1.getKee(), profileOnXoo1.getKee());
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) QualityProfile(org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile) SearchWsResponse(org.sonarqube.ws.Qualityprofiles.SearchWsResponse) Test(org.junit.Test)

Example 20 with SearchWsResponse

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method filter_on_default_profile.

@Test
public void filter_on_default_profile() {
    QProfileDto defaultProfile1 = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    QProfileDto defaultProfile2 = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
    QProfileDto nonDefaultProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    db.qualityProfiles().setAsDefault(defaultProfile1, defaultProfile2);
    SearchWsResponse result = call(ws.newRequest().setParam(PARAM_DEFAULTS, "true"));
    assertThat(result.getProfilesList()).extracting(QualityProfile::getKey).containsExactlyInAnyOrder(defaultProfile1.getKee(), defaultProfile2.getKee()).doesNotContain(nonDefaultProfile.getKee());
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) QualityProfile(org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile) SearchWsResponse(org.sonarqube.ws.Qualityprofiles.SearchWsResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 SearchWsResponse (org.sonarqube.ws.Qualityprofiles.SearchWsResponse)21 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)16 QualityProfile (org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile)14 ProjectDto (org.sonar.db.project.ProjectDto)9 Languages (org.sonar.api.resources.Languages)6 ComponentFinder (org.sonar.server.component.ComponentFinder)6 WsActionTester (org.sonar.server.ws.WsActionTester)6 SearchWsResponse (org.sonarqube.ws.QualityProfiles.SearchWsResponse)6 List (java.util.List)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Assertions.tuple (org.assertj.core.api.Assertions.tuple)5 Rule (org.junit.Rule)5 QualityProfileTesting.newQualityProfileDto (org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 IntStream.range (java.util.stream.IntStream.range)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)4 Language (org.sonar.api.resources.Language)4 DEPRECATED (org.sonar.api.rule.RuleStatus.DEPRECATED)4