]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9356 Add ITs on onboardning
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 12 Jun 2017 12:12:28 +0000 (14:12 +0200)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 20 Jun 2017 11:10:53 +0000 (04:10 -0700)
it/it-tests/src/test/java/it/Category4Suite.java
it/it-tests/src/test/java/it/user/OnboardingTest.java [new file with mode: 0644]
it/it-tests/src/test/java/it/user/SkipOnboardingTest.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/user/ws/CurrentAction.java
sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java
sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java
sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java

index b9fa1cba83e1bd4ab2a74c8486db3cc1b490c9bc..4c424d0c862d68560e6bef2944cdbfe079fbbe35 100644 (file)
@@ -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 (file)
index 0000000..14a2f99
--- /dev/null
@@ -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 (file)
index 3e1ae3e..0000000
+++ /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();
-  }
-}
index 6d06d380fc89f6c9d2f57edbf36b91cbcab17d30..2529b920e6312c52586ab6a38a75c071f9564f5f 100644 (file)
@@ -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
index 55d75aab734d58bf97446242f7ce4863cddb8583..5c1da476c1a2883a4819b9b97d496eb0791a347c 100644 (file)
@@ -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)));
   }
index 6ffecd751b0ce0f1604f0c9c4e15b1f44afbcab7..2e648e047a57408938684a4a30556845b9411f15 100644 (file)
@@ -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";
index 0933d16b26c25cf53217ac642c809b12fc825b7b..7d26c5f238aedae8914aeba6cebe0d5eef7b6cdd 100644 (file)
@@ -129,4 +129,10 @@ public class UsersServiceTest {
       .andNoOtherParam();
   }
 
+  @Test
+  public void current() {
+    underTest.current();
+
+    assertThat(serviceTester.getGetParser()).isSameAs(WsUsers.CurrentWsResponse.parser());
+  }
 }