]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10183 Create api/users/set_homepage stub
authorGuillaume Jambet <guillaume.jambet@sonarsource.com>
Wed, 13 Dec 2017 10:07:16 +0000 (11:07 +0100)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 2 Jan 2018 09:38:10 +0000 (10:38 +0100)
server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypes.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/user/ws/SetHomepageAction.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/SetHomepageActionTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/user/ws/UsersWsModuleTest.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 (file)
index 0000000..fd7142a
--- /dev/null
@@ -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<String> 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 (file)
index 0000000..1adb81b
--- /dev/null
@@ -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.<br> 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();
+
+  }
+}
index 175615ae5fbcf5d8359900cf98a0c885813577de..c99e0a6b4b739102f1988945c03696a6cfa5edf3 100644 (file)
@@ -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 (file)
index 0000000..c84786f
--- /dev/null
@@ -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.<br> 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
index c5bf180fda067b7d3bc1ba31b97fc11f7947c205..5e7074d7c268975a44594d7a0bb34c5a3a74ec89 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 + 12);
+    assertThat(container.size()).isEqualTo(2 + 13);
   }
 }