aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--it/it-tests/src/test/java/it/Category4Suite.java4
-rw-r--r--it/it-tests/src/test/java/it/user/OnboardingTest.java163
-rw-r--r--it/it-tests/src/test/java/it/user/SkipOnboardingTest.java57
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/user/ws/CurrentAction.java5
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java6
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java1
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java6
7 files changed, 181 insertions, 61 deletions
diff --git a/it/it-tests/src/test/java/it/Category4Suite.java b/it/it-tests/src/test/java/it/Category4Suite.java
index b9fa1cba83e..4c424d0c862 100644
--- a/it/it-tests/src/test/java/it/Category4Suite.java
+++ b/it/it-tests/src/test/java/it/Category4Suite.java
@@ -46,7 +46,7 @@ import it.user.ForceAuthenticationTest;
import it.user.LocalAuthenticationTest;
import it.user.MyAccountPageTest;
import it.user.OAuth2IdentityProviderTest;
-import it.user.SkipOnboardingTest;
+import it.user.OnboardingTest;
import it.ws.WsLocalCallTest;
import it.ws.WsTest;
import org.junit.ClassRule;
@@ -66,7 +66,7 @@ import static util.ItUtils.xooPlugin;
// user
MyAccountPageTest.class,
FavoritesWsTest.class,
- SkipOnboardingTest.class,
+ OnboardingTest.class,
// authentication
ForceAuthenticationTest.class,
LocalAuthenticationTest.class,
diff --git a/it/it-tests/src/test/java/it/user/OnboardingTest.java b/it/it-tests/src/test/java/it/user/OnboardingTest.java
new file mode 100644
index 00000000000..14a2f99d68c
--- /dev/null
+++ b/it/it-tests/src/test/java/it/user/OnboardingTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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 it.user;
+
+import com.sonar.orchestrator.Orchestrator;
+import it.Category4Suite;
+import java.util.Optional;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonarqube.ws.client.HttpException;
+import org.sonarqube.ws.client.user.UsersService;
+import util.user.UserRule;
+
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.newAdminWsClient;
+import static util.ItUtils.newUserWsClient;
+import static util.ItUtils.resetSettings;
+import static util.ItUtils.setServerProperty;
+
+public class OnboardingTest {
+
+ @ClassRule
+ public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+ @ClassRule
+ public static UserRule userRule = UserRule.from(orchestrator);
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private static final String ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS = "sonar.onboardingTutorial.showToNewUsers";
+
+ private String userLogin;
+
+ @Before
+ public void setUp() throws Exception {
+ resetSettings(orchestrator, null, ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS);
+ }
+
+ @After
+ public void reset() throws Exception {
+ Optional.ofNullable(userLogin).ifPresent(login -> userRule.deactivateUsers(userLogin));
+ resetSettings(orchestrator, null, ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS);
+ }
+
+ @Test
+ public void by_default_new_user_does_not_see_onboarding_tutorial() {
+ createUser();
+
+ assertOnboardingTutorial(false);
+ }
+
+ @Test
+ public void new_user_see_onboarding_tutorial_when_show_onboarding_setting_is_enabled() {
+ setShownOnboardingSetting(true);
+ createUser();
+
+ assertOnboardingTutorial(true);
+ }
+
+ @Test
+ public void new_user_does_not_see_onboarding_tutorial_when_show_onboarding_setting_is_disabled() {
+ setShownOnboardingSetting(false);
+ createUser();
+
+ assertOnboardingTutorial(false);
+ }
+
+ @Test
+ public void new_user_does_not_see_onboarding_tutorial_when_show_onboarding_setting_is_enabled_after_user_creation() {
+ setShownOnboardingSetting(false);
+ // User is created when show onboading is disabled
+ createUser();
+ setShownOnboardingSetting(true);
+
+ // The user doesn't see the tutorial as he was created when the show onboading setting was disabled
+ assertOnboardingTutorial(false);
+ }
+
+ @Test
+ public void skip_onboarding_tutorial() {
+ setShownOnboardingSetting(true);
+ createUser();
+
+ createUsersServiceForUser().skipOnboardingTutorial();
+
+ assertOnboardingTutorial(false);
+ }
+
+ @Test
+ public void skip_onboarding_tutorial_when_show_onboarding_setting_is_disabled() {
+ setShownOnboardingSetting(true);
+ createUser();
+
+ createUsersServiceForUser().skipOnboardingTutorial();
+
+ assertOnboardingTutorial(false);
+ }
+
+ @Test
+ public void anonymous_user_does_not_see_onboarding_tutorial() {
+ setShownOnboardingSetting(true);
+
+ // anonymous should not see the onboarding tutorial
+ assertOnboardingTutorial(false);
+
+ // anonymous should not be able to skip the tutorial
+ expectedException.expect(HttpException.class);
+ createUsersServiceForUser().skipOnboardingTutorial();
+ }
+
+ @Test
+ public void admin_user_see_onboarding_tutorial() {
+ UsersService adminService = newAdminWsClient(orchestrator).users();
+
+ assertThat(adminService.current().getShowOnboardingTutorial()).isEqualTo(true);
+
+ // Onboarding setting has no effect as admin is created at startup
+ setShownOnboardingSetting(false);
+ assertThat(adminService.current().getShowOnboardingTutorial()).isEqualTo(true);
+
+ setShownOnboardingSetting(true);
+ assertThat(adminService.current().getShowOnboardingTutorial()).isEqualTo(true);
+ }
+
+ private void createUser() {
+ userLogin = randomAlphabetic(10).toLowerCase();
+ userRule.createUser(userLogin, userLogin);
+ }
+
+ private static void setShownOnboardingSetting(boolean showOnboardingTutorial) {
+ setServerProperty(orchestrator, ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS, String.valueOf(showOnboardingTutorial));
+ }
+
+ private void assertOnboardingTutorial(boolean expectedOnboardingTutorial) {
+ assertThat(createUsersServiceForUser().current().getShowOnboardingTutorial()).isEqualTo(expectedOnboardingTutorial);
+ }
+
+ private UsersService createUsersServiceForUser() {
+ return newUserWsClient(orchestrator, userLogin, userLogin).users();
+ }
+
+}
diff --git a/it/it-tests/src/test/java/it/user/SkipOnboardingTest.java b/it/it-tests/src/test/java/it/user/SkipOnboardingTest.java
deleted file mode 100644
index 3e1ae3e617e..00000000000
--- a/it/it-tests/src/test/java/it/user/SkipOnboardingTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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 it.user;
-
-import com.sonar.orchestrator.Orchestrator;
-import it.Category4Suite;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.sonarqube.ws.client.WsResponse;
-import util.ItUtils;
-import util.user.UserRule;
-
-import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class SkipOnboardingTest {
-
- @ClassRule
- public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
- @ClassRule
- public static UserRule userRule = UserRule.from(orchestrator);
-
- @Test
- public void should_operate_silently() {
- String login = randomAlphabetic(10).toLowerCase();
- String password = randomAlphabetic(10).toLowerCase();
- userRule.createUser(login, password);
- WsResponse response;
- try {
-
- response = ItUtils.newUserWsClient(orchestrator, null, null).users().skipOnboardingTutorial();
-
- } finally {
- userRule.deactivateUsers(login);
- }
-
- assertThat(response.code()).isEqualTo(204);
- assertThat(response.hasContent()).isFalse();
- }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/CurrentAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/CurrentAction.java
index 6d06d380fc8..2529b920e63 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/CurrentAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/CurrentAction.java
@@ -41,6 +41,7 @@ import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.WsUsers.CurrentWsResponse.Permissions;
import static org.sonarqube.ws.WsUsers.CurrentWsResponse.newBuilder;
+import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_CURRENT;
public class CurrentAction implements UsersWsAction {
private final UserSession userSession;
@@ -55,13 +56,13 @@ public class CurrentAction implements UsersWsAction {
@Override
public void define(NewController context) {
- context.createAction("current")
+ context.createAction(ACTION_CURRENT)
.setDescription("Get the details of the current authenticated user.")
.setHandler(this)
.setInternal(true)
.setResponseExample(getClass().getResource("current-example.json"))
.setSince("5.2")
- .setChangelog(new Change("6.5", "showOnboardingTutorial is now returned in the response"));
+ .setChangelog(new Change("6.5", "showOnboardingTutorial is now returned in the response"));
}
@Override
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java
index 55d75aab734..5c1da476c1a 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java
@@ -21,6 +21,7 @@ package org.sonarqube.ws.client.user;
import java.util.List;
import org.sonarqube.ws.WsUsers.CreateWsResponse;
+import org.sonarqube.ws.WsUsers.CurrentWsResponse;
import org.sonarqube.ws.WsUsers.GroupsWsResponse;
import org.sonarqube.ws.WsUsers.SearchWsResponse;
import org.sonarqube.ws.client.BaseService;
@@ -34,6 +35,7 @@ import static org.sonar.api.server.ws.WebService.Param.PAGE;
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_CREATE;
+import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_CURRENT;
import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_GROUPS;
import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_SEARCH;
import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_SKIP_ONBOARDING_TUTORIAL;
@@ -94,6 +96,10 @@ public class UsersService extends BaseService {
GroupsWsResponse.parser());
}
+ public CurrentWsResponse current() {
+ return call(new GetRequest(path(ACTION_CURRENT)), CurrentWsResponse.parser());
+ }
+
public WsResponse skipOnboardingTutorial() {
return call(new PostRequest(path(ACTION_SKIP_ONBOARDING_TUTORIAL)));
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java
index 6ffecd751b0..2e648e047a5 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java
@@ -28,6 +28,7 @@ public class UsersWsParameters {
public static final String ACTION_UPDATE = "update";
public static final String ACTION_GROUPS = "groups";
public static final String ACTION_SKIP_ONBOARDING_TUTORIAL = "skip_onboarding_tutorial";
+ public static final String ACTION_CURRENT = "current";
public static final String PARAM_ORGANIZATION = "organization";
public static final String PARAM_LOGIN = "login";
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java
index 0933d16b26c..7d26c5f238a 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java
@@ -129,4 +129,10 @@ public class UsersServiceTest {
.andNoOtherParam();
}
+ @Test
+ public void current() {
+ underTest.current();
+
+ assertThat(serviceTester.getGetParser()).isSameAs(WsUsers.CurrentWsResponse.parser());
+ }
}