diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-09-22 17:34:34 +0200 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-10-02 17:18:15 +0200 |
commit | f96f99021d99319b935e8c620396743f7ce197a7 (patch) | |
tree | 40a11b82048ca4e4b363c9272b4ed37ba90a870c /tests/src/test | |
parent | 4c0d81eb984640587557787892ee3f1cbdcc193b (diff) | |
download | sonarqube-f96f99021d99319b935e8c620396743f7ce197a7.tar.gz sonarqube-f96f99021d99319b935e8c620396743f7ce197a7.zip |
SONAR-1330 Search for user allowed to edit single quality profile
Diffstat (limited to 'tests/src/test')
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/Category6Suite.java | 2 | ||||
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfilesEditTest.java | 126 |
2 files changed, 128 insertions, 0 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java index 660ff241cd1..8fc6f4f49b5 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java @@ -47,6 +47,7 @@ import org.sonarqube.tests.qualityGate.OrganizationQualityGateUiTest; import org.sonarqube.tests.qualityProfile.BuiltInQualityProfilesTest; import org.sonarqube.tests.qualityProfile.CustomQualityProfilesTest; import org.sonarqube.tests.qualityProfile.OrganizationQualityProfilesUiTest; +import org.sonarqube.tests.qualityProfile.QualityProfilesEditTest; import org.sonarqube.tests.qualityProfile.QualityProfilesWsTest; import org.sonarqube.tests.rule.RulesWsTest; import org.sonarqube.tests.ui.OrganizationUiExtensionsTest; @@ -72,6 +73,7 @@ import static util.ItUtils.xooPlugin; OrganizationUiExtensionsTest.class, PersonalOrganizationTest.class, BuiltInQualityProfilesTest.class, + QualityProfilesEditTest.class, QualityProfilesWsTest.class, CustomQualityProfilesTest.class, BillingTest.class, diff --git a/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfilesEditTest.java b/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfilesEditTest.java new file mode 100644 index 00000000000..cb56d80ab8b --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfilesEditTest.java @@ -0,0 +1,126 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonarqube.tests.qualityProfile; + +import com.sonar.orchestrator.Orchestrator; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.tests.Category6Suite; +import org.sonarqube.tests.Tester; +import org.sonarqube.ws.Common; +import org.sonarqube.ws.Organizations.Organization; +import org.sonarqube.ws.QualityProfiles.CreateWsResponse; +import org.sonarqube.ws.QualityProfiles.SearchUsersResponse; +import org.sonarqube.ws.WsUsers; +import org.sonarqube.ws.client.qualityprofile.AddUserRequest; +import org.sonarqube.ws.client.qualityprofile.RemoveUserRequest; +import org.sonarqube.ws.client.qualityprofile.SearchUsersRequest; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +public class QualityProfilesEditTest { + + @ClassRule + public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; + + @Rule + public Tester tester = new Tester(orchestrator); + + @Test + public void search_users_allowed_to_edit_a_profile() { + Organization organization = tester.organizations().generate(); + WsUsers.CreateWsResponse.User user1 = tester.users().generateMember(organization, u -> u.setEmail("user1@email.com")); + WsUsers.CreateWsResponse.User user2 = tester.users().generateMember(organization, u -> u.setEmail("user2@email.com")); + CreateWsResponse.QualityProfile xooProfile = tester.qProfiles().createXooProfile(organization); + tester.qProfiles().service().addUser(AddUserRequest.builder() + .setOrganization(organization.getKey()) + .setQualityProfile(xooProfile.getName()) + .setLanguage(xooProfile.getLanguage()) + .setUserLogin(user1.getLogin()) + .build()); + + SearchUsersResponse users = tester.qProfiles().service().searchUsers(SearchUsersRequest.builder() + .setOrganization(organization.getKey()) + .setQualityProfile(xooProfile.getName()) + .setLanguage(xooProfile.getLanguage()) + .setSelected("all") + .build()); + + assertThat(users.getUsersList()).extracting(SearchUsersResponse.User::getLogin, SearchUsersResponse.User::getName, SearchUsersResponse.User::getAvatar, SearchUsersResponse.User::getSelected) + .containsExactlyInAnyOrder( + tuple(user1.getLogin(), user1.getName(), "3acc837f898bdaa338b7cd7a9ab6dd5b", true), + tuple(user2.getLogin(), user2.getName(), "fd6926c24d76d650a365ae350784e048", false), + tuple("admin", "Administrator", "d41d8cd98f00b204e9800998ecf8427e", false)); + assertThat(users.getPaging()).extracting(Common.Paging::getPageIndex, Common.Paging::getPageSize, Common.Paging::getTotal) + .containsExactlyInAnyOrder(1, 25, 3); + } + + @Test + public void add_and_remove_user() { + Organization organization = tester.organizations().generate(); + WsUsers.CreateWsResponse.User user1 = tester.users().generateMember(organization); + WsUsers.CreateWsResponse.User user2 = tester.users().generateMember(organization); + CreateWsResponse.QualityProfile xooProfile = tester.qProfiles().createXooProfile(organization); + + // No user added + assertThat(tester.qProfiles().service().searchUsers(SearchUsersRequest.builder() + .setOrganization(organization.getKey()) + .setQualityProfile(xooProfile.getName()) + .setLanguage(xooProfile.getLanguage()) + .setSelected("selected") + .build()).getUsersList()) + .extracting(SearchUsersResponse.User::getLogin) + .isEmpty(); + + // Add user 1 + tester.qProfiles().service().addUser(AddUserRequest.builder() + .setOrganization(organization.getKey()) + .setQualityProfile(xooProfile.getName()) + .setLanguage(xooProfile.getLanguage()) + .setUserLogin(user1.getLogin()) + .build()); + assertThat(tester.qProfiles().service().searchUsers(SearchUsersRequest.builder() + .setOrganization(organization.getKey()) + .setQualityProfile(xooProfile.getName()) + .setLanguage(xooProfile.getLanguage()) + .setSelected("selected") + .build()).getUsersList()) + .extracting(SearchUsersResponse.User::getLogin) + .containsExactlyInAnyOrder(user1.getLogin()); + + // Remove user 1 + tester.qProfiles().service().removeUser(RemoveUserRequest.builder() + .setOrganization(organization.getKey()) + .setQualityProfile(xooProfile.getName()) + .setLanguage(xooProfile.getLanguage()) + .setUserLogin(user1.getLogin()) + .build()); + assertThat(tester.qProfiles().service().searchUsers(SearchUsersRequest.builder() + .setOrganization(organization.getKey()) + .setQualityProfile(xooProfile.getName()) + .setLanguage(xooProfile.getLanguage()) + .setSelected("selected") + .build()).getUsersList()) + .extracting(SearchUsersResponse.User::getLogin) + .isEmpty(); + } +} |