From 492cd3de03d14aaf91b54e96531d77079c0db7f1 Mon Sep 17 00:00:00 2001 From: Guillaume Jambet Date: Wed, 13 Dec 2017 11:07:16 +0100 Subject: [PATCH] SONAR-10183 Create api/users/set_homepage stub --- .../sonar/server/user/ws/HomepageTypes.java | 34 ++++++++++ .../server/user/ws/SetHomepageAction.java | 59 +++++++++++++++++ .../sonar/server/user/ws/UsersWsModule.java | 3 +- .../server/user/ws/SetHomepageActionTest.java | 65 +++++++++++++++++++ .../server/user/ws/UsersWsModuleTest.java | 2 +- 5 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypes.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/user/ws/SetHomepageActionTest.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypes.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypes.java new file mode 100644 index 00000000000..fd7142a399c --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypes.java @@ -0,0 +1,34 @@ +/* + * 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 java.util.List; + +import static java.util.Arrays.stream; +import static java.util.stream.Collectors.toList; + +public enum HomepageTypes { + + PROJECT, ORGANIZATION, MY_PROJECTS, MY_ISSUES; + + public static List keys() { + return stream(values()).map(Enum::toString).collect(toList()); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java new file mode 100644 index 00000000000..1adb81b82e8 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java @@ -0,0 +1,59 @@ +/* + * 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 SetHomepageAction implements UsersWsAction { + + private static final String PARAM_TYPE = "type"; + private static final String PARAM_VALUE = "value"; + private static final String ACTION = "set_homepage"; + + + @Override + public void define(WebService.NewController controller) { + WebService.NewAction action = controller.createAction(ACTION) + .setPost(true) + .setDescription("Set Homepage of current user.
Requires authentication.") + .setSince("7.0") + .setHandler(this); + + action.createParam(PARAM_TYPE) + .setDescription("Type of the requested page") + .setRequired(true) + .setPossibleValues(HomepageTypes.keys()); + + action.createParam(PARAM_VALUE) + .setDescription("Additional information to filter the page (project or organization key)") + .setExampleValue("my-project-key"); + + } + + @Override + public void handle(Request request, Response response) throws Exception { + + // WIP : Not implemented yet. + 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 175615ae5fb..c99e0a6b4b7 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 @@ -36,6 +36,7 @@ public class UsersWsModule extends Module { IdentityProvidersAction.class, UserPropertiesWs.class, UserJsonWriter.class, - SkipOnboardingTutorialAction.class); + SkipOnboardingTutorialAction.class, + SetHomepageAction.class); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SetHomepageActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SetHomepageActionTest.java new file mode 100644 index 00000000000..c84786f4d19 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SetHomepageActionTest.java @@ -0,0 +1,65 @@ +/* + * 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.WsActionTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SetHomepageActionTest { + + private SetHomepageAction underTest = new SetHomepageAction(); + private WsActionTester wsTester = new WsActionTester(underTest); + + @Test + public void verify_definition() { + WebService.Action action = wsTester.getDef(); + assertThat(action.key()).isEqualTo("set_homepage"); + assertThat(action.isInternal()).isFalse(); + assertThat(action.isPost()).isTrue(); + assertThat(action.since()).isEqualTo("7.0"); + assertThat(action.description()).isEqualTo("Set Homepage of current user.
Requires authentication."); + assertThat(action.responseExample()).isNull(); + assertThat(action.deprecatedKey()).isNull(); + assertThat(action.deprecatedSince()).isNull(); + assertThat(action.handler()).isSameAs(underTest); + assertThat(action.params()).hasSize(2); + + WebService.Param typeParam = action.param("type"); + assertThat(typeParam.isRequired()).isTrue(); + assertThat(typeParam.description()).isEqualTo("Type of the requested page"); + assertThat(typeParam.defaultValue()).isNull(); + assertThat(typeParam.possibleValues()).containsExactlyInAnyOrder("PROJECT", "ORGANIZATION", "MY_PROJECTS", "MY_ISSUES"); + assertThat(typeParam.deprecatedSince()).isNull(); + assertThat(typeParam.deprecatedKey()).isNull(); + + WebService.Param keyParam = action.param("value"); + assertThat(keyParam.isRequired()).isFalse(); + assertThat(keyParam.description()).isEqualTo("Additional information to filter the page (project or organization key)"); + assertThat(keyParam.exampleValue()).isEqualTo("my-project-key"); + assertThat(keyParam.defaultValue()).isNull(); + assertThat(keyParam.deprecatedSince()).isNull(); + assertThat(keyParam.deprecatedKey()).isNull(); + } + + +} \ No newline at end of file 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 c5bf180fda0..5e7074d7c26 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 + 12); + assertThat(container.size()).isEqualTo(2 + 13); } } -- 2.39.5