diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2018-02-12 12:03:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-12 12:03:26 +0100 |
commit | 4a85b3c8960f0e448319ffbe8de894e0146ff5a5 (patch) | |
tree | 53db67d4251665a54ccd63b577224e035757c982 /tests | |
parent | 3ba0210407680ae481d91658f0b623d5353a2663 (diff) | |
download | sonarqube-4a85b3c8960f0e448319ffbe8de894e0146ff5a5.tar.gz sonarqube-4a85b3c8960f0e448319ffbe8de894e0146ff5a5.zip |
SONAR-8964 Drop overall notifications not related to the current user on SonarCloud
* SONAR-8964 Remove some global notifications in api/notifications/list on SonarCloud
* SONAR-8964 Remove some global notifications in api/notifications/add on SonarCloud
* In WebServiceEngine, define web services in start()
* SONAR-8964 Remove some global notifications in api/notifications/remove on SonarCloud
* Move some user ITs to their own suite
* SONAR-8964 Add ITs on notifications (not for SonarCloud)
* SONAR-8964 Add ITs on notifications for SonarCloud
Diffstat (limited to 'tests')
14 files changed, 365 insertions, 46 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java index b29280ba12f..89368b1488a 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java @@ -28,7 +28,6 @@ import org.sonarqube.tests.settings.DeprecatedPropertiesWsTest; import org.sonarqube.tests.settings.EmailsTest; import org.sonarqube.tests.settings.PropertySetsTest; import org.sonarqube.tests.settings.SettingsTest; -import org.sonarqube.tests.user.UsersPageTest; import static util.ItUtils.pluginArtifact; import static util.ItUtils.xooPlugin; @@ -40,7 +39,6 @@ import static util.ItUtils.xooPlugin; @Deprecated @RunWith(Suite.class) @Suite.SuiteClasses({ - UsersPageTest.class, BackgroundTasksTest.class, DeprecatedPropertiesWsTest.class, EmailsTest.class, @@ -61,7 +59,6 @@ public class Category1Suite { // Used in SettingsTest.should_get_settings_default_value .addPlugin(pluginArtifact("server-plugin")) - // Used in I18nTest .addPlugin(pluginArtifact("l10n-fr-pack")) diff --git a/tests/src/test/java/org/sonarqube/tests/Category4Suite.java b/tests/src/test/java/org/sonarqube/tests/Category4Suite.java index 3745186d27a..332ef87afe1 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category4Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category4Suite.java @@ -36,13 +36,6 @@ import org.sonarqube.tests.serverSystem.ServerSystemTest; import org.sonarqube.tests.serverSystem.SystemInfoTest; import org.sonarqube.tests.ui.UiExtensionsTest; import org.sonarqube.tests.ui.UiTest; -import org.sonarqube.tests.user.BaseIdentityProviderTest; -import org.sonarqube.tests.user.FavoritesWsTest; -import org.sonarqube.tests.user.ForceAuthenticationTest; -import org.sonarqube.tests.user.LocalAuthenticationTest; -import org.sonarqube.tests.user.MyAccountPageTest; -import org.sonarqube.tests.user.OAuth2IdentityProviderTest; -import org.sonarqube.tests.user.RootUserInStandaloneModeTest; import org.sonarqube.tests.ws.WsLocalCallTest; import org.sonarqube.tests.ws.WsTest; @@ -56,20 +49,10 @@ import static util.ItUtils.xooPlugin; @Deprecated @RunWith(Suite.class) @Suite.SuiteClasses({ - // organization - RootUserInStandaloneModeTest.class, // server system ServerSystemTest.class, SystemInfoTest.class, PingTest.class, - // user - MyAccountPageTest.class, - FavoritesWsTest.class, - // authentication - ForceAuthenticationTest.class, - LocalAuthenticationTest.class, - BaseIdentityProviderTest.class, - OAuth2IdentityProviderTest.class, // analysis exclusion FileExclusionsTest.class, IssueExclusionsTest.class, @@ -95,12 +78,6 @@ public class Category4Suite { public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() .addPlugin(xooPlugin()) - // Used in BaseIdentityProviderTest - .addPlugin(pluginArtifact("base-auth-plugin")) - - // Used in OAuth2IdentityProviderTest - .addPlugin(pluginArtifact("oauth2-auth-plugin")) - // Used in UiExtensionsTest .addPlugin(pluginArtifact("ui-extensions-plugin")) @@ -113,7 +90,5 @@ public class Category4Suite { // reduce memory for Elasticsearch to 128M .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") - .setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8001") - .build(); } diff --git a/tests/src/test/java/org/sonarqube/tests/user/BaseIdentityProviderTest.java b/tests/src/test/java/org/sonarqube/tests/user/BaseIdentityProviderTest.java index e445488536d..9ecf5aa4e3a 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/BaseIdentityProviderTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/BaseIdentityProviderTest.java @@ -31,7 +31,6 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.RuleChain; import org.sonarqube.qa.util.pageobjects.Navigation; -import org.sonarqube.tests.Category4Suite; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.users.CreateRequest; @@ -51,7 +50,7 @@ import static util.selenium.Selenese.runSelenese; public class BaseIdentityProviderTest { @ClassRule - public static Orchestrator ORCHESTRATOR = Category4Suite.ORCHESTRATOR; + public static Orchestrator ORCHESTRATOR = UserSuite.ORCHESTRATOR; private static UserRule userRule = UserRule.from(ORCHESTRATOR); diff --git a/tests/src/test/java/org/sonarqube/tests/user/FavoritesWsTest.java b/tests/src/test/java/org/sonarqube/tests/user/FavoritesWsTest.java index 55b09ea4b64..0dac746ecd9 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/FavoritesWsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/FavoritesWsTest.java @@ -25,7 +25,6 @@ import java.util.List; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; -import org.sonarqube.tests.Category4Suite; import org.sonarqube.ws.Favorites.Favorite; import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.favorites.AddRequest; @@ -42,7 +41,8 @@ import static util.ItUtils.projectDir; public class FavoritesWsTest { @ClassRule - public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; + public static final Orchestrator orchestrator = UserSuite.ORCHESTRATOR; + private static WsClient adminClient; @Before diff --git a/tests/src/test/java/org/sonarqube/tests/user/ForceAuthenticationTest.java b/tests/src/test/java/org/sonarqube/tests/user/ForceAuthenticationTest.java index d3a4cb71cb7..4bf5885476c 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/ForceAuthenticationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/ForceAuthenticationTest.java @@ -20,13 +20,13 @@ package org.sonarqube.tests.user; import com.sonar.orchestrator.Orchestrator; -import org.sonarqube.tests.Category4Suite; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.sonarqube.qa.util.Tester; +import org.sonarqube.qa.util.pageobjects.Navigation; import org.sonarqube.ws.Users.CreateWsResponse.User; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.PostRequest; @@ -34,7 +34,6 @@ import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.WsConnector; import org.sonarqube.ws.client.WsRequest; import org.sonarqube.ws.client.WsResponse; -import org.sonarqube.qa.util.pageobjects.Navigation; import static org.assertj.core.api.Assertions.assertThat; import static org.sonarqube.ws.client.WsRequest.Method.GET; @@ -45,7 +44,7 @@ import static util.ItUtils.setServerProperty; public class ForceAuthenticationTest { @ClassRule - public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; + public static final Orchestrator orchestrator = UserSuite.ORCHESTRATOR; @Rule public Tester tester = new Tester(orchestrator).disableOrganizations(); diff --git a/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java b/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java index fc3707f322e..3f56905e7b2 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java @@ -29,7 +29,6 @@ import org.junit.Test; import org.sonarqube.qa.util.Tester; import org.sonarqube.qa.util.pageobjects.LoginPage; import org.sonarqube.qa.util.pageobjects.Navigation; -import org.sonarqube.tests.Category4Suite; import org.sonarqube.ws.UserTokens; import org.sonarqube.ws.Users; import org.sonarqube.ws.Users.CreateWsResponse.User; @@ -56,7 +55,7 @@ import static util.ItUtils.setServerProperty; public class LocalAuthenticationTest { @ClassRule - public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = UserSuite.ORCHESTRATOR; @Rule public Tester tester = new Tester(orchestrator).disableOrganizations(); diff --git a/tests/src/test/java/org/sonarqube/tests/user/MyAccountPageTest.java b/tests/src/test/java/org/sonarqube/tests/user/MyAccountPageTest.java index 226082b75b1..ec7ddee7474 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/MyAccountPageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/MyAccountPageTest.java @@ -25,9 +25,8 @@ import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.sonarqube.qa.util.pageobjects.Navigation; -import org.sonarqube.tests.Category4Suite; import org.sonarqube.qa.util.Tester; +import org.sonarqube.qa.util.pageobjects.Navigation; import org.sonarqube.ws.Users.CreateWsResponse.User; import org.sonarqube.ws.client.PostRequest; @@ -40,7 +39,7 @@ import static util.selenium.Selenese.runSelenese; public class MyAccountPageTest { @ClassRule - public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = UserSuite.ORCHESTRATOR; @Rule public Tester tester = new Tester(orchestrator).disableOrganizations(); diff --git a/tests/src/test/java/org/sonarqube/tests/user/NotificationsWsTest.java b/tests/src/test/java/org/sonarqube/tests/user/NotificationsWsTest.java new file mode 100644 index 00000000000..2dc9de4022c --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/user/NotificationsWsTest.java @@ -0,0 +1,137 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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.user; + +import com.sonar.orchestrator.Orchestrator; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.qa.util.Tester; +import org.sonarqube.ws.Notifications; +import org.sonarqube.ws.Notifications.Notification; +import org.sonarqube.ws.Projects; +import org.sonarqube.ws.Users; +import org.sonarqube.ws.client.notifications.AddRequest; +import org.sonarqube.ws.client.notifications.ListRequest; +import org.sonarqube.ws.client.notifications.RemoveRequest; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +public class NotificationsWsTest { + + @ClassRule + public static final Orchestrator orchestrator = UserSuite.ORCHESTRATOR; + + @Rule + public Tester tester = new Tester(orchestrator).disableOrganizations(); + + @Test + public void list_notifications() { + Users.CreateWsResponse.User user = tester.users().generate(); + + Notifications.ListResponse list = tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()); + + assertThat(list.getNotificationsList()).isEmpty(); + assertThat(list.getChannelsList()).containsExactlyInAnyOrder("EmailNotificationChannel"); + assertThat(list.getGlobalTypesList()).containsExactlyInAnyOrder( + "CeReportTaskFailure", "ChangesOnMyIssue", "NewAlerts", "NewFalsePositiveIssue", "NewIssues", "SQ-MyNewIssues"); + assertThat(list.getPerProjectTypesList()).containsExactlyInAnyOrder( + "CeReportTaskFailure", "ChangesOnMyIssue", "NewAlerts", "NewFalsePositiveIssue", "NewIssues", "SQ-MyNewIssues"); + } + + @Test + public void add_global_and_project_notifications() { + Users.CreateWsResponse.User user = tester.users().generate(); + assertThat(tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()).getNotificationsList()).isEmpty(); + Projects.CreateWsResponse.Project project = tester.projects().provision(); + + tester.as(user.getLogin()).wsClient().notifications().add(new AddRequest().setChannel("EmailNotificationChannel").setType("ChangesOnMyIssue")); + tester.as(user.getLogin()).wsClient().notifications().add(new AddRequest().setChannel("EmailNotificationChannel").setType("NewIssues").setProject(project.getKey())); + + assertThat(tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()).getNotificationsList()) + .extracting(Notification::getChannel, Notification::getType, Notification::getProject, Notification::getProjectName) + .containsExactlyInAnyOrder( + tuple("EmailNotificationChannel", "ChangesOnMyIssue", "", ""), + tuple("EmailNotificationChannel", "NewIssues", project.getKey(), project.getName())); + } + + @Test + public void remove_global_and_project_notifications() { + Users.CreateWsResponse.User user = tester.users().generate(); + assertThat(tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()).getNotificationsList()).isEmpty(); + Projects.CreateWsResponse.Project project = tester.projects().provision(); + // These 2 notifications will be removed + tester.as(user.getLogin()).wsClient().notifications().add(new AddRequest().setChannel("EmailNotificationChannel").setType("ChangesOnMyIssue")); + tester.as(user.getLogin()).wsClient().notifications().add(new AddRequest().setChannel("EmailNotificationChannel").setType("NewIssues").setProject(project.getKey())); + // These 2 notifications will not be removed + tester.as(user.getLogin()).wsClient().notifications().add(new AddRequest().setChannel("EmailNotificationChannel").setType("NewAlerts")); + tester.as(user.getLogin()).wsClient().notifications().add(new AddRequest().setChannel("EmailNotificationChannel").setType("SQ-MyNewIssues").setProject(project.getKey())); + + tester.as(user.getLogin()).wsClient().notifications().remove(new RemoveRequest().setChannel("EmailNotificationChannel").setType("ChangesOnMyIssue")); + tester.as(user.getLogin()).wsClient().notifications().remove(new RemoveRequest().setChannel("EmailNotificationChannel").setType("NewIssues").setProject(project.getKey())); + + assertThat(tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()).getNotificationsList()) + .extracting(Notification::getType, Notification::getProject) + .containsExactlyInAnyOrder( + tuple("NewAlerts", ""), + tuple("SQ-MyNewIssues", project.getKey())); + } + + @Test + public void add_global_and_project_notifications_on_another_user_as_a_system_administrator() { + Users.CreateWsResponse.User admin = tester.users().generateAdministratorOnDefaultOrganization(); + Users.CreateWsResponse.User user = tester.users().generate(); + assertThat(tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()).getNotificationsList()).isEmpty(); + Projects.CreateWsResponse.Project project = tester.projects().provision(); + + tester.as(admin.getLogin()).wsClient().notifications().add(new AddRequest().setLogin(user.getLogin()).setChannel("EmailNotificationChannel").setType("ChangesOnMyIssue")); + tester.as(admin.getLogin()).wsClient().notifications().add(new AddRequest().setLogin(user.getLogin()).setChannel("EmailNotificationChannel").setType("NewIssues").setProject(project.getKey())); + + assertThat(tester.as(admin.getLogin()).wsClient().notifications().list(new ListRequest().setLogin(user.getLogin())).getNotificationsList()) + .extracting(Notification::getChannel, Notification::getType, Notification::getProject, Notification::getProjectName) + .containsExactlyInAnyOrder( + tuple("EmailNotificationChannel", "ChangesOnMyIssue", "", ""), + tuple("EmailNotificationChannel", "NewIssues", project.getKey(), project.getName())); + } + + @Test + public void remove_global_and_project_notifications_on_another_user_as_a_system_administrator() { + Users.CreateWsResponse.User admin = tester.users().generateAdministratorOnDefaultOrganization(); + Users.CreateWsResponse.User user = tester.users().generate(); + assertThat(tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()).getNotificationsList()).isEmpty(); + Projects.CreateWsResponse.Project project = tester.projects().provision(); + // These 2 notifications will be removed + tester.as(admin.getLogin()).wsClient().notifications().add(new AddRequest().setLogin(user.getLogin()).setChannel("EmailNotificationChannel").setType("ChangesOnMyIssue")); + tester.as(admin.getLogin()).wsClient().notifications().add(new AddRequest().setLogin(user.getLogin()).setChannel("EmailNotificationChannel").setType("NewIssues").setProject(project.getKey())); + // These 2 notifications will not be removed + tester.as(admin.getLogin()).wsClient().notifications().add(new AddRequest().setLogin(user.getLogin()).setChannel("EmailNotificationChannel").setType("NewAlerts")); + tester.as(admin.getLogin()).wsClient().notifications().add(new AddRequest().setLogin(user.getLogin()).setChannel("EmailNotificationChannel").setType("SQ-MyNewIssues").setProject(project.getKey())); + + tester.as(admin.getLogin()).wsClient().notifications().remove(new RemoveRequest().setLogin(user.getLogin()).setChannel("EmailNotificationChannel").setType("ChangesOnMyIssue")); + tester.as(admin.getLogin()).wsClient().notifications().remove(new RemoveRequest().setLogin(user.getLogin()).setChannel("EmailNotificationChannel").setType("NewIssues").setProject(project.getKey())); + + assertThat(tester.as(admin.getLogin()).wsClient().notifications().list(new ListRequest().setLogin(user.getLogin())).getNotificationsList()) + .extracting(Notification::getType, Notification::getProject) + .containsExactlyInAnyOrder( + tuple("NewAlerts", ""), + tuple("SQ-MyNewIssues", project.getKey())); + } +} diff --git a/tests/src/test/java/org/sonarqube/tests/user/OAuth2IdentityProviderTest.java b/tests/src/test/java/org/sonarqube/tests/user/OAuth2IdentityProviderTest.java index 9ad8f1a79cc..103b634ccd7 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/OAuth2IdentityProviderTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/OAuth2IdentityProviderTest.java @@ -33,7 +33,6 @@ import org.junit.Rule; import org.junit.Test; import org.sonarqube.qa.util.Tester; import org.sonarqube.qa.util.pageobjects.Navigation; -import org.sonarqube.tests.Category4Suite; import org.sonarqube.ws.Users.SearchWsResponse.User; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.permissions.AddUserRequest; @@ -50,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class OAuth2IdentityProviderTest { @ClassRule - public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = UserSuite.ORCHESTRATOR; private static String FAKE_PROVIDER_KEY = "fake-oauth2-id-provider"; diff --git a/tests/src/test/java/org/sonarqube/tests/user/RootUserInStandaloneModeTest.java b/tests/src/test/java/org/sonarqube/tests/user/RootUserInStandaloneModeTest.java index fcb1d62c868..bb5fe85f6b3 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/RootUserInStandaloneModeTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/RootUserInStandaloneModeTest.java @@ -20,7 +20,6 @@ package org.sonarqube.tests.user; import com.sonar.orchestrator.Orchestrator; -import org.sonarqube.tests.Category4Suite; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; @@ -31,7 +30,7 @@ import static util.ItUtils.expectForbiddenError; public class RootUserInStandaloneModeTest { @ClassRule - public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = UserSuite.ORCHESTRATOR; @Rule public Tester tester = new Tester(orchestrator).disableOrganizations(); diff --git a/tests/src/test/java/org/sonarqube/tests/user/SonarCloudNotificationsWsTest.java b/tests/src/test/java/org/sonarqube/tests/user/SonarCloudNotificationsWsTest.java new file mode 100644 index 00000000000..f6426b48981 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/user/SonarCloudNotificationsWsTest.java @@ -0,0 +1,110 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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.user; + +import com.sonar.orchestrator.Orchestrator; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.qa.util.Tester; +import org.sonarqube.ws.Notifications; +import org.sonarqube.ws.Notifications.Notification; +import org.sonarqube.ws.Projects; +import org.sonarqube.ws.Users; +import org.sonarqube.ws.client.notifications.AddRequest; +import org.sonarqube.ws.client.notifications.ListRequest; +import org.sonarqube.ws.client.notifications.RemoveRequest; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; +import static util.ItUtils.expectHttpError; + +public class SonarCloudNotificationsWsTest { + + @ClassRule + public static final Orchestrator orchestrator = SonarCloudUserSuite.ORCHESTRATOR; + + @Rule + public Tester tester = new Tester(orchestrator); + + @Test + public void list_notifications() { + Users.CreateWsResponse.User user = tester.users().generate(); + + Notifications.ListResponse list = tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()); + + assertThat(list.getNotificationsList()).isEmpty(); + assertThat(list.getChannelsList()).containsExactlyInAnyOrder("EmailNotificationChannel"); + assertThat(list.getGlobalTypesList()) + .containsExactlyInAnyOrder( + "CeReportTaskFailure", "ChangesOnMyIssue", "SQ-MyNewIssues") + .doesNotContain("NewAlerts", "NewFalsePositiveIssue", "NewIssues"); + assertThat(list.getPerProjectTypesList()).containsExactlyInAnyOrder( + "CeReportTaskFailure", "ChangesOnMyIssue", "NewAlerts", "NewFalsePositiveIssue", "NewIssues", "SQ-MyNewIssues"); + } + + @Test + public void add_global_and_project_notifications() { + Users.CreateWsResponse.User user = tester.users().generate(); + assertThat(tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()).getNotificationsList()).isEmpty(); + Projects.CreateWsResponse.Project project = tester.projects().provision(); + + tester.as(user.getLogin()).wsClient().notifications().add(new AddRequest().setChannel("EmailNotificationChannel").setType("ChangesOnMyIssue")); + tester.as(user.getLogin()).wsClient().notifications().add(new AddRequest().setChannel("EmailNotificationChannel").setType("NewIssues").setProject(project.getKey())); + + assertThat(tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()).getNotificationsList()) + .extracting(Notification::getChannel, Notification::getType, Notification::getProject, Notification::getProjectName) + .containsExactlyInAnyOrder( + tuple("EmailNotificationChannel", "ChangesOnMyIssue", "", ""), + tuple("EmailNotificationChannel", "NewIssues", project.getKey(), project.getName())); + } + + @Test + public void remove_global_and_project_notifications() { + Users.CreateWsResponse.User user = tester.users().generate(); + assertThat(tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()).getNotificationsList()).isEmpty(); + Projects.CreateWsResponse.Project project = tester.projects().provision(); + tester.as(user.getLogin()).wsClient().notifications().add(new AddRequest().setChannel("EmailNotificationChannel").setType("ChangesOnMyIssue")); + tester.as(user.getLogin()).wsClient().notifications().add(new AddRequest().setChannel("EmailNotificationChannel").setType("NewIssues").setProject(project.getKey())); + + tester.as(user.getLogin()).wsClient().notifications().remove(new RemoveRequest().setChannel("EmailNotificationChannel").setType("ChangesOnMyIssue")); + tester.as(user.getLogin()).wsClient().notifications().remove(new RemoveRequest().setChannel("EmailNotificationChannel").setType("NewIssues").setProject(project.getKey())); + + assertThat(tester.as(user.getLogin()).wsClient().notifications().list(new ListRequest()).getNotificationsList()).isEmpty(); + } + + @Test + public void fail_to_add_global_new_issues_notification() { + Users.CreateWsResponse.User user = tester.users().generate(); + + expectHttpError(400, + "Value of parameter 'type' (NewIssues) must be one of: [CeReportTaskFailure, ChangesOnMyIssue, SQ-MyNewIssues]", + () -> tester.as(user.getLogin()).wsClient().notifications().add(new AddRequest().setChannel("EmailNotificationChannel").setType("NewIssues"))); + } + + @Test + public void fail_to_remove_global_new_issues_notification() { + Users.CreateWsResponse.User user = tester.users().generate(); + + expectHttpError(400, + "Value of parameter 'type' (NewIssues) must be one of: [CeReportTaskFailure, ChangesOnMyIssue, SQ-MyNewIssues]", + () -> tester.as(user.getLogin()).wsClient().notifications().remove(new RemoveRequest().setChannel("EmailNotificationChannel").setType("NewIssues"))); + } +} diff --git a/tests/src/test/java/org/sonarqube/tests/user/SonarCloudUserSuite.java b/tests/src/test/java/org/sonarqube/tests/user/SonarCloudUserSuite.java new file mode 100644 index 00000000000..b14ad6da627 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/user/SonarCloudUserSuite.java @@ -0,0 +1,47 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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.user; + +import com.sonar.orchestrator.Orchestrator; +import org.junit.ClassRule; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import static util.ItUtils.xooPlugin; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + SonarCloudNotificationsWsTest.class +}) +public class SonarCloudUserSuite { + + @ClassRule + public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() + .addPlugin(xooPlugin()) + + .setServerProperty("sonar.sonarcloud.enabled", "true") + + // reduce memory for Elasticsearch + .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") + + .build(); + +} diff --git a/tests/src/test/java/org/sonarqube/tests/user/UserSuite.java b/tests/src/test/java/org/sonarqube/tests/user/UserSuite.java new file mode 100644 index 00000000000..d6b4ddb36ed --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/user/UserSuite.java @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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.user; + +import com.sonar.orchestrator.Orchestrator; +import org.junit.ClassRule; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import static util.ItUtils.pluginArtifact; +import static util.ItUtils.xooPlugin; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + BaseIdentityProviderTest.class, + FavoritesWsTest.class, + ForceAuthenticationTest.class, + LocalAuthenticationTest.class, + MyAccountPageTest.class, + NotificationsWsTest.class, + OAuth2IdentityProviderTest.class, + RootUserInStandaloneModeTest.class, + UsersPageTest.class +}) +public class UserSuite { + + @ClassRule + public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() + .addPlugin(xooPlugin()) + + // Used in BaseIdentityProviderTest + .addPlugin(pluginArtifact("base-auth-plugin")) + + // Used in OAuth2IdentityProviderTest + .addPlugin(pluginArtifact("oauth2-auth-plugin")) + + // reduce memory for Elasticsearch + .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") + + .build(); + +} diff --git a/tests/src/test/java/org/sonarqube/tests/user/UsersPageTest.java b/tests/src/test/java/org/sonarqube/tests/user/UsersPageTest.java index a71f4305511..072d9d0bfd3 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/UsersPageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/UsersPageTest.java @@ -28,7 +28,6 @@ import org.junit.Rule; import org.junit.Test; import org.sonarqube.qa.util.Tester; import org.sonarqube.qa.util.pageobjects.UsersManagementPage; -import org.sonarqube.tests.Category1Suite; import org.sonarqube.ws.Users; import org.sonarqube.ws.Users.CreateWsResponse.User; import org.sonarqube.ws.client.users.GroupsRequest; @@ -42,7 +41,7 @@ public class UsersPageTest { private User adminUser; @ClassRule - public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = UserSuite.ORCHESTRATOR; @Rule public UserRule userRule = UserRule.from(orchestrator); |