]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9356 new webservice stub for api/users/skipOnboardingTutorial
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Thu, 1 Jun 2017 16:01:20 +0000 (18:01 +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/SkipOnboardingTest.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/user/ws/SkipOnboardingTutorialAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/user/ws/UsersWsModule.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/SkipOnboardingTutorialActionTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/user/ws/UsersWsModuleTest.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

index cbb752d4a711528e93d8019964e98ca366a91ede..b9fa1cba83e1bd4ab2a74c8486db3cc1b490c9bc 100644 (file)
@@ -46,6 +46,7 @@ import it.user.ForceAuthenticationTest;
 import it.user.LocalAuthenticationTest;
 import it.user.MyAccountPageTest;
 import it.user.OAuth2IdentityProviderTest;
+import it.user.SkipOnboardingTest;
 import it.ws.WsLocalCallTest;
 import it.ws.WsTest;
 import org.junit.ClassRule;
@@ -65,6 +66,7 @@ import static util.ItUtils.xooPlugin;
   // user
   MyAccountPageTest.class,
   FavoritesWsTest.class,
+  SkipOnboardingTest.class,
   // authentication
   ForceAuthenticationTest.class,
   LocalAuthenticationTest.class,
diff --git a/it/it-tests/src/test/java/it/user/SkipOnboardingTest.java b/it/it-tests/src/test/java/it/user/SkipOnboardingTest.java
new file mode 100644 (file)
index 0000000..3e1ae3e
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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/SkipOnboardingTutorialAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/SkipOnboardingTutorialAction.java
new file mode 100644 (file)
index 0000000..39359a9
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.sonar.server.user.ws;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+
+public class SkipOnboardingTutorialAction implements UsersWsAction {
+
+  @Override
+  public void define(WebService.NewController context) {
+    context.createAction("skipOnboardingTutorial")
+      .setPost(true)
+      .setInternal(true)
+      .setDescription("Stores that the user has skipped the onboarding tutorial and does not want to see it after future logins." +
+        " Calling this webservice several times will silently ignore subsequent requests.")
+      .setSince("6.5")
+      .setHandler(this);
+  }
+
+  @Override
+  public void handle(Request request, Response response) throws Exception {
+    response.noContent();
+  }
+}
index 84f2757dc5dc8e2722cfd21acdaef3ee2d106b84..175615ae5fbcf5d8359900cf98a0c885813577de 100644 (file)
@@ -35,6 +35,7 @@ public class UsersWsModule extends Module {
       GroupsAction.class,
       IdentityProvidersAction.class,
       UserPropertiesWs.class,
-      UserJsonWriter.class);
+      UserJsonWriter.class,
+      SkipOnboardingTutorialAction.class);
   }
 }
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SkipOnboardingTutorialActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SkipOnboardingTutorialActionTest.java
new file mode 100644 (file)
index 0000000..85985b7
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.sonar.server.user.ws;
+
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.ws.TestResponse;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SkipOnboardingTutorialActionTest {
+
+  @Test
+  public void should_have_a_good_definition() {
+    WsActionTester ws = new WsActionTester(new SkipOnboardingTutorialAction());
+    WebService.Action def = ws.getDef();
+    assertThat(def.isPost()).isTrue();
+    assertThat(def.isInternal()).isTrue();
+    assertThat(def.since()).isEqualTo("6.5");
+    assertThat(def.params()).isEmpty();
+  }
+
+  @Test
+  public void should_return_silently() {
+    WsActionTester ws = new WsActionTester(new SkipOnboardingTutorialAction());
+    TestResponse response = ws.newRequest().setMethod("POST").execute();
+    assertThat(response.getStatus()).isEqualTo(204);
+    assertThat(response.getInput()).isEmpty();
+  }
+}
index 256506d6b75ea4e976cb55ee06c304dc2c631795..c5bf180fda067b7d3bc1ba31b97fc11f7947c205 100644 (file)
@@ -29,6 +29,6 @@ public class UsersWsModuleTest {
   public void verify_count_of_added_components() {
     ComponentContainer container = new ComponentContainer();
     new UsersWsModule().configure(container);
-    assertThat(container.size()).isEqualTo(2 + 11);
+    assertThat(container.size()).isEqualTo(2 + 12);
   }
 }
index 8467336d1c05d6dc5719f058d75fe68dc6069cff..55d75aab734d58bf97446242f7ce4863cddb8583 100644 (file)
@@ -27,6 +27,7 @@ import org.sonarqube.ws.client.BaseService;
 import org.sonarqube.ws.client.GetRequest;
 import org.sonarqube.ws.client.PostRequest;
 import org.sonarqube.ws.client.WsConnector;
+import org.sonarqube.ws.client.WsResponse;
 
 import static org.sonar.api.server.ws.WebService.Param.FIELDS;
 import static org.sonar.api.server.ws.WebService.Param.PAGE;
@@ -35,6 +36,7 @@ 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_GROUPS;
 import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_SEARCH;
+import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_SKIP_ONBOARDING_TUTORIAL;
 import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_UPDATE;
 import static org.sonarqube.ws.client.user.UsersWsParameters.CONTROLLER_USERS;
 import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_EMAIL;
@@ -92,4 +94,7 @@ public class UsersService extends BaseService {
       GroupsWsResponse.parser());
   }
 
+  public WsResponse skipOnboardingTutorial() {
+    return call(new PostRequest(path(ACTION_SKIP_ONBOARDING_TUTORIAL)));
+  }
 }
index 6f153218db998eba940f40229a43c27026e8d4ab..c79994c1a40a1f511526ac6568454a584428eca3 100644 (file)
@@ -27,6 +27,7 @@ public class UsersWsParameters {
   public static final String ACTION_CREATE = "create";
   public static final String ACTION_UPDATE = "update";
   public static final String ACTION_GROUPS = "groups";
+  public static final String ACTION_SKIP_ONBOARDING_TUTORIAL = "skipOnboardingTutorial";
 
   public static final String PARAM_ORGANIZATION = "organization";
   public static final String PARAM_LOGIN = "login";