From: Daniel Schwarz Date: Thu, 1 Jun 2017 16:01:20 +0000 (+0200) Subject: SONAR-9356 new webservice stub for api/users/skipOnboardingTutorial X-Git-Tag: 6.5-M2~133 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=77b6ed8b18023d7a9b52cc54afbc8a0d0032acb7;p=sonarqube.git SONAR-9356 new webservice stub for api/users/skipOnboardingTutorial --- diff --git a/it/it-tests/src/test/java/it/Category4Suite.java b/it/it-tests/src/test/java/it/Category4Suite.java index cbb752d4a71..b9fa1cba83e 100644 --- a/it/it-tests/src/test/java/it/Category4Suite.java +++ b/it/it-tests/src/test/java/it/Category4Suite.java @@ -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 index 00000000000..3e1ae3e617e --- /dev/null +++ b/it/it-tests/src/test/java/it/user/SkipOnboardingTest.java @@ -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 index 00000000000..39359a9f153 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/SkipOnboardingTutorialAction.java @@ -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(); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/UsersWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/UsersWsModule.java index 84f2757dc5d..175615ae5fb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/UsersWsModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/UsersWsModule.java @@ -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 index 00000000000..85985b76ec0 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SkipOnboardingTutorialActionTest.java @@ -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(); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UsersWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UsersWsModuleTest.java index 256506d6b75..c5bf180fda0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UsersWsModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UsersWsModuleTest.java @@ -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); } } 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 8467336d1c0..55d75aab734 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 @@ -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))); + } } 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 6f153218db9..c79994c1a40 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 @@ -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";