]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8190 SONAR-8191 SONAR-8206 rename api/root/* to api/roots/* 1287/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 12 Oct 2016 08:44:02 +0000 (10:44 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 12 Oct 2016 10:24:33 +0000 (12:24 +0200)
24 files changed:
server/sonar-server/src/main/java/org/sonar/server/root/ws/RootWs.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/root/ws/RootWsAction.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/root/ws/RootWsModule.java
server/sonar-server/src/main/java/org/sonar/server/root/ws/RootsWs.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/root/ws/RootsWsAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/root/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/root/ws/SetRootAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/root/ws/SetRootWsAction.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/root/ws/UnsetRootAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/root/ws/UnsetRootWsAction.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/root/ws/RootWsModuleTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/root/ws/RootWsTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/root/ws/RootsWsModuleTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/root/ws/RootsWsTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/root/ws/SetRootActionTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/root/ws/SetRootWsActionTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/root/ws/UnsetRootActionTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/root/ws/UnsetRootWsActionTest.java [deleted file]
sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java
sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
sonar-ws/src/main/java/org/sonarqube/ws/client/root/RootService.java [deleted file]
sonar-ws/src/main/java/org/sonarqube/ws/client/root/RootsService.java [new file with mode: 0644]
sonar-ws/src/test/java/org/sonarqube/ws/client/root/RootServiceTest.java [deleted file]
sonar-ws/src/test/java/org/sonarqube/ws/client/root/RootsServiceTest.java [new file with mode: 0644]

diff --git a/server/sonar-server/src/main/java/org/sonar/server/root/ws/RootWs.java b/server/sonar-server/src/main/java/org/sonar/server/root/ws/RootWs.java
deleted file mode 100644 (file)
index 3687cc3..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.root.ws;
-
-import org.sonar.api.server.ws.WebService;
-
-public class RootWs implements WebService {
-  private final RootWsAction[] actions;
-
-  public RootWs(RootWsAction... actions) {
-    this.actions = actions;
-  }
-
-  @Override
-  public void define(Context context) {
-    NewController controller = context.createController("api/root")
-        .setSince("6.2")
-        .setDescription("Manage root users");
-
-    for (RootWsAction action : actions) {
-      action.define(controller);
-    }
-
-    controller.done();
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/root/ws/RootWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/root/ws/RootWsAction.java
deleted file mode 100644 (file)
index 131c438..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.root.ws;
-
-import org.sonar.server.ws.WsAction;
-
-public interface RootWsAction extends WsAction {
-
-}
index 4e49416f721ce8665836dbb27e66a2abd874019d..56ae76a4a72dfb10dfb80465feae6b36fd53343c 100644 (file)
@@ -24,9 +24,9 @@ import org.sonar.core.platform.Module;
 public class RootWsModule extends Module {
   @Override
   protected void configureModule() {
-    add(RootWs.class,
-      SetRootWsAction.class,
-      UnsetRootWsAction.class,
+    add(RootsWs.class,
+      SetRootAction.class,
+      UnsetRootAction.class,
       SearchAction.class);
   }
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/root/ws/RootsWs.java b/server/sonar-server/src/main/java/org/sonar/server/root/ws/RootsWs.java
new file mode 100644 (file)
index 0000000..b1b74d2
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.root.ws;
+
+import org.sonar.api.server.ws.WebService;
+
+public class RootsWs implements WebService {
+  private final RootsWsAction[] actions;
+
+  public RootsWs(RootsWsAction... actions) {
+    this.actions = actions;
+  }
+
+  @Override
+  public void define(Context context) {
+    NewController controller = context.createController("api/roots")
+        .setSince("6.2")
+        .setDescription("Manage root users");
+
+    for (RootsWsAction action : actions) {
+      action.define(controller);
+    }
+
+    controller.done();
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/root/ws/RootsWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/root/ws/RootsWsAction.java
new file mode 100644 (file)
index 0000000..b49f464
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.root.ws;
+
+import org.sonar.server.ws.WsAction;
+
+public interface RootsWsAction extends WsAction {
+
+}
index 35b4c02cf65ca55d836894443555ba1f6e427ea5..76fe456ea9e02918bb5888bd8fadf5e6382fcaea 100644 (file)
@@ -32,7 +32,7 @@ import org.sonarqube.ws.WsRoot;
 
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
-public class SearchAction implements RootWsAction {
+public class SearchAction implements RootsWsAction {
   private final UserSession userSession;
   private final DbClient dbClient;
 
diff --git a/server/sonar-server/src/main/java/org/sonar/server/root/ws/SetRootAction.java b/server/sonar-server/src/main/java/org/sonar/server/root/ws/SetRootAction.java
new file mode 100644 (file)
index 0000000..fa8df89
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.root.ws;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.user.UserDto;
+import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.user.UserSession;
+
+import static java.lang.String.format;
+
+public class SetRootAction implements RootsWsAction {
+  private static final String PARAM_LOGIN = "login";
+
+  private final UserSession userSession;
+  private final DbClient dbClient;
+
+  public SetRootAction(UserSession userSession, DbClient dbClient) {
+    this.userSession = userSession;
+    this.dbClient = dbClient;
+  }
+
+  @Override
+  public void define(WebService.NewController controller) {
+    WebService.NewAction action = controller.createAction("set_root")
+      .setInternal(true)
+      .setPost(true)
+      .setDescription("Make the specified user root.<br/>" +
+        "Requires to be root.")
+      .setSince("6.2")
+      .setHandler(this);
+
+    action.createParam(PARAM_LOGIN)
+      .setDescription("A user login")
+      .setExampleValue("admin")
+      .setRequired(true)
+      .setSince("6.2");
+  }
+
+  @Override
+  public void handle(Request request, Response response) throws Exception {
+    userSession.checkIsRoot();
+
+    String login = request.mandatoryParam(PARAM_LOGIN);
+    try (DbSession dbSession = dbClient.openSession(false)) {
+      UserDto userDto = dbClient.userDao().selectByLogin(dbSession, login);
+      if (userDto == null || !userDto.isActive()) {
+        throw new NotFoundException(format("User with login '%s' not found", login));
+      }
+
+      if (!userDto.isRoot()) {
+        dbClient.userDao().setRoot(dbSession, login, true);
+        dbSession.commit();
+      }
+    }
+    response.noContent();
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/root/ws/SetRootWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/root/ws/SetRootWsAction.java
deleted file mode 100644 (file)
index 81121b2..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.root.ws;
-
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.user.UserDto;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.user.UserSession;
-
-import static java.lang.String.format;
-
-public class SetRootWsAction implements RootWsAction {
-  private static final String PARAM_LOGIN = "login";
-
-  private final UserSession userSession;
-  private final DbClient dbClient;
-
-  public SetRootWsAction(UserSession userSession, DbClient dbClient) {
-    this.userSession = userSession;
-    this.dbClient = dbClient;
-  }
-
-  @Override
-  public void define(WebService.NewController controller) {
-    WebService.NewAction action = controller.createAction("set_root")
-      .setInternal(true)
-      .setPost(true)
-      .setDescription("Make the specified user root.<br/>" +
-        "Requires to be root.")
-      .setSince("6.2")
-      .setHandler(this);
-
-    action.createParam(PARAM_LOGIN)
-      .setDescription("A user login")
-      .setExampleValue("admin")
-      .setRequired(true)
-      .setSince("6.2");
-  }
-
-  @Override
-  public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
-
-    String login = request.mandatoryParam(PARAM_LOGIN);
-    try (DbSession dbSession = dbClient.openSession(false)) {
-      UserDto userDto = dbClient.userDao().selectByLogin(dbSession, login);
-      if (userDto == null || !userDto.isActive()) {
-        throw new NotFoundException(format("User with login '%s' not found", login));
-      }
-
-      if (!userDto.isRoot()) {
-        dbClient.userDao().setRoot(dbSession, login, true);
-        dbSession.commit();
-      }
-    }
-    response.noContent();
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/root/ws/UnsetRootAction.java b/server/sonar-server/src/main/java/org/sonar/server/root/ws/UnsetRootAction.java
new file mode 100644 (file)
index 0000000..d842fa2
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.root.ws;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.user.UserDto;
+import org.sonar.server.exceptions.BadRequestException;
+import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.user.UserSession;
+
+import static java.lang.String.format;
+
+public class UnsetRootAction implements RootsWsAction {
+  private static final String PARAM_LOGIN = "login";
+
+  private final UserSession userSession;
+  private final DbClient dbClient;
+
+  public UnsetRootAction(UserSession userSession, DbClient dbClient) {
+    this.userSession = userSession;
+    this.dbClient = dbClient;
+  }
+
+  @Override
+  public void define(WebService.NewController controller) {
+    WebService.NewAction action = controller.createAction("unset_root")
+      .setInternal(true)
+      .setPost(true)
+      .setDescription("Make the specified user not root.<br/>" +
+        "Requires to be root.")
+      .setSince("6.2")
+      .setHandler(this);
+
+    action.createParam(PARAM_LOGIN)
+      .setDescription("A user login")
+      .setExampleValue("admin")
+      .setRequired(true)
+      .setSince("6.2");
+  }
+
+  @Override
+  public void handle(Request request, Response response) throws Exception {
+    userSession.checkIsRoot();
+
+    String login = request.mandatoryParam(PARAM_LOGIN);
+    try (DbSession dbSession = dbClient.openSession(false)) {
+      UserDto userDto = dbClient.userDao().selectByLogin(dbSession, login);
+      if (userDto == null || !userDto.isActive()) {
+        throw new NotFoundException(format("User with login '%s' not found", login));
+      }
+
+      if (dbClient.userDao().countRootUsersButLogin(dbSession, login) == 0) {
+        throw new BadRequestException("Last root can't be unset");
+      }
+      if (userDto.isRoot()) {
+        dbClient.userDao().setRoot(dbSession, login, false);
+        dbSession.commit();
+      }
+    }
+    response.noContent();
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/root/ws/UnsetRootWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/root/ws/UnsetRootWsAction.java
deleted file mode 100644 (file)
index bb09571..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.root.ws;
-
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.user.UserDto;
-import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.user.UserSession;
-
-import static java.lang.String.format;
-
-public class UnsetRootWsAction implements RootWsAction {
-  private static final String PARAM_LOGIN = "login";
-
-  private final UserSession userSession;
-  private final DbClient dbClient;
-
-  public UnsetRootWsAction(UserSession userSession, DbClient dbClient) {
-    this.userSession = userSession;
-    this.dbClient = dbClient;
-  }
-
-  @Override
-  public void define(WebService.NewController controller) {
-    WebService.NewAction action = controller.createAction("unset_root")
-      .setInternal(true)
-      .setPost(true)
-      .setDescription("Make the specified user not root.<br/>" +
-        "Requires to be root.")
-      .setSince("6.2")
-      .setHandler(this);
-
-    action.createParam(PARAM_LOGIN)
-      .setDescription("A user login")
-      .setExampleValue("admin")
-      .setRequired(true)
-      .setSince("6.2");
-  }
-
-  @Override
-  public void handle(Request request, Response response) throws Exception {
-    userSession.checkIsRoot();
-
-    String login = request.mandatoryParam(PARAM_LOGIN);
-    try (DbSession dbSession = dbClient.openSession(false)) {
-      UserDto userDto = dbClient.userDao().selectByLogin(dbSession, login);
-      if (userDto == null || !userDto.isActive()) {
-        throw new NotFoundException(format("User with login '%s' not found", login));
-      }
-
-      if (dbClient.userDao().countRootUsersButLogin(dbSession, login) == 0) {
-        throw new BadRequestException("Last root can't be unset");
-      }
-      if (userDto.isRoot()) {
-        dbClient.userDao().setRoot(dbSession, login, false);
-        dbSession.commit();
-      }
-    }
-    response.noContent();
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/root/ws/RootWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/root/ws/RootWsModuleTest.java
deleted file mode 100644 (file)
index 2333777..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.root.ws;
-
-import org.junit.Test;
-import org.sonar.core.platform.ComponentContainer;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class RootWsModuleTest {
-  private static final int ADAPTERS_IN_EMPTY_CONTAINER = 2;
-
-  private RootWsModule underTest = new RootWsModule();
-
-  @Test
-  public void verify_number_of_components_added_by_module() {
-    ComponentContainer container = new ComponentContainer();
-
-    underTest.configure(container);
-
-    assertThat(container.getPicoContainer().getComponentAdapters()).hasSize(ADAPTERS_IN_EMPTY_CONTAINER + 4);
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/root/ws/RootWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/root/ws/RootWsTest.java
deleted file mode 100644 (file)
index 2c90a6a..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.root.ws;
-
-import org.junit.Test;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.server.ws.WsTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class RootWsTest {
-  private RootWs underTest = new RootWs(new DummyRootWsAction());
-  private WsTester wsTester = new WsTester(underTest);
-
-  @Test
-  public void verify_definition() {
-    assertThat(wsTester.context().controllers()).hasSize(1);
-    WebService.Controller controller = wsTester.context().controller("api/root");
-    assertThat(controller.description()).isEqualTo("Manage root users");
-    assertThat(controller.since()).isEqualTo("6.2");
-  }
-
-  private static class DummyRootWsAction implements RootWsAction {
-    @Override
-    public void define(WebService.NewController context) {
-      context.createAction("ooo").setHandler(this);
-    }
-
-    @Override
-    public void handle(Request request, Response response) throws Exception {
-
-    }
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/root/ws/RootsWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/root/ws/RootsWsModuleTest.java
new file mode 100644 (file)
index 0000000..0cb39fd
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.root.ws;
+
+import org.junit.Test;
+import org.sonar.core.platform.ComponentContainer;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class RootsWsModuleTest {
+  private static final int ADAPTERS_IN_EMPTY_CONTAINER = 2;
+
+  private RootWsModule underTest = new RootWsModule();
+
+  @Test
+  public void verify_number_of_components_added_by_module() {
+    ComponentContainer container = new ComponentContainer();
+
+    underTest.configure(container);
+
+    assertThat(container.getPicoContainer().getComponentAdapters()).hasSize(ADAPTERS_IN_EMPTY_CONTAINER + 4);
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/root/ws/RootsWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/root/ws/RootsWsTest.java
new file mode 100644 (file)
index 0000000..0d27539
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.root.ws;
+
+import org.junit.Test;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.ws.WsTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class RootsWsTest {
+  private RootsWs underTest = new RootsWs(new DummyRootsWsAction());
+  private WsTester wsTester = new WsTester(underTest);
+
+  @Test
+  public void verify_definition() {
+    assertThat(wsTester.context().controllers()).hasSize(1);
+    WebService.Controller controller = wsTester.context().controller("api/roots");
+    assertThat(controller.description()).isEqualTo("Manage root users");
+    assertThat(controller.since()).isEqualTo("6.2");
+  }
+
+  private static class DummyRootsWsAction implements RootsWsAction {
+    @Override
+    public void define(WebService.NewController context) {
+      context.createAction("ooo").setHandler(this);
+    }
+
+    @Override
+    public void handle(Request request, Response response) throws Exception {
+
+    }
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/root/ws/SetRootActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/root/ws/SetRootActionTest.java
new file mode 100644 (file)
index 0000000..1115022
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.root.ws;
+
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.user.UserDao;
+import org.sonar.db.user.UserDto;
+import org.sonar.db.user.UserTesting;
+import org.sonar.server.exceptions.ForbiddenException;
+import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.TestRequest;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SetRootActionTest {
+  private static final String SOME_LOGIN = "johndoe";
+
+  @Rule
+  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  @Rule
+  public UserSessionRule userSessionRule = UserSessionRule.standalone();
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private UserDao userDao = dbTester.getDbClient().userDao();
+  private DbSession dbSession = dbTester.getSession();
+  private SetRootAction underTest = new SetRootAction(userSessionRule, dbTester.getDbClient());
+  private WsActionTester wsTester = new WsActionTester(underTest);
+
+  @Test
+  public void verify_definition() {
+    WebService.Action action = wsTester.getDef();
+    assertThat(action.key()).isEqualTo("set_root");
+    assertThat(action.isInternal()).isTrue();
+    assertThat(action.isPost()).isTrue();
+    assertThat(action.since()).isEqualTo("6.2");
+    assertThat(action.description()).isEqualTo("Make the specified user root.<br/>" +
+      "Requires to be root.");
+    assertThat(action.responseExample()).isNull();
+    assertThat(action.deprecatedKey()).isNull();
+    assertThat(action.deprecatedSince()).isNull();
+    assertThat(action.handler()).isSameAs(underTest);
+    assertThat(action.params()).hasSize(1);
+
+    WebService.Param param = action.param("login");
+    assertThat(param.isRequired()).isTrue();
+    assertThat(param.description()).isEqualTo("A user login");
+    assertThat(param.defaultValue()).isNull();
+    assertThat(param.deprecatedSince()).isNull();
+    assertThat(param.deprecatedKey()).isNull();
+    assertThat(param.exampleValue()).isEqualTo("admin");
+  }
+
+  @Test
+  public void execute_fails_with_ForbiddenException_when_user_is_not_logged_in() {
+    expectInsufficientPrivilegesForbiddenException();
+
+    executeRequest(SOME_LOGIN);
+  }
+
+  @Test
+  public void execute_fails_with_ForbiddenException_when_user_is_not_root() {
+    userSessionRule.login();
+
+    expectInsufficientPrivilegesForbiddenException();
+
+    executeRequest(SOME_LOGIN);
+  }
+
+  @Test
+  public void execute_fails_with_IAE_when_login_param_is_not_provided() {
+    makeAuthenticatedUserRoot();
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("The 'login' parameter is missing");
+
+    executeRequest(null);
+  }
+
+  @Test
+  public void execute_makes_user_with_specified_login_root_when_it_is_not() {
+    UserDto otherUser = UserTesting.newUserDto();
+    userDao.insert(dbSession, otherUser);
+    userDao.insert(dbSession, UserTesting.newUserDto(SOME_LOGIN, "name", "email"));
+    dbSession.commit();
+    makeAuthenticatedUserRoot();
+
+    executeRequest(SOME_LOGIN);
+
+    assertThat(userDao.selectByLogin(dbSession, SOME_LOGIN).isRoot()).isTrue();
+    assertThat(userDao.selectByLogin(dbSession, otherUser.getLogin()).isRoot()).isFalse();
+  }
+
+  @Test
+  public void execute_has_no_effect_when_user_is_already_root() {
+    UserDto otherUser = UserTesting.newUserDto();
+    userDao.insert(dbSession, otherUser);
+    userDao.insert(dbSession, UserTesting.newUserDto(SOME_LOGIN, "name", "email"));
+    userDao.setRoot(dbSession, SOME_LOGIN, true);
+    dbSession.commit();
+    makeAuthenticatedUserRoot();
+
+    executeRequest(SOME_LOGIN);
+
+    assertThat(userDao.selectByLogin(dbSession, SOME_LOGIN).isRoot()).isTrue();
+    assertThat(userDao.selectByLogin(dbSession, otherUser.getLogin()).isRoot()).isFalse();
+  }
+
+  @Test
+  public void execute_fails_with_NotFoundException_when_user_for_specified_login_does_not_exist() {
+    makeAuthenticatedUserRoot();
+
+    expectedException.expect(NotFoundException.class);
+    expectedException.expectMessage("User with login 'foo_bar' not found");
+    
+    executeRequest("foo_bar");
+  }
+
+  @Test
+  public void execute_fails_with_NotFoundException_when_user_for_specified_login_is_not_active() {
+    UserDto userDto = UserTesting.newUserDto().setActive(false);
+    userDao.insert(dbSession, userDto);
+    dbSession.commit();
+    makeAuthenticatedUserRoot();
+
+    expectedException.expect(NotFoundException.class);
+    expectedException.expectMessage("User with login '" + userDto.getLogin() + "' not found");
+
+    executeRequest(userDto.getLogin());
+  }
+
+  private void makeAuthenticatedUserRoot() {
+    userSessionRule.login().setRoot();
+  }
+
+  private void expectInsufficientPrivilegesForbiddenException() {
+    expectedException.expect(ForbiddenException.class);
+    expectedException.expectMessage("Insufficient privileges");
+  }
+
+  private int executeRequest(@Nullable String login) {
+    TestRequest request = wsTester.newRequest();
+    if (login != null) {
+      request.setParam("login", login);
+    }
+    return request
+      .execute()
+      .getStatus();
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/root/ws/SetRootWsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/root/ws/SetRootWsActionTest.java
deleted file mode 100644 (file)
index e111dda..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.root.ws;
-
-import javax.annotation.Nullable;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.user.UserDao;
-import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserTesting;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.tester.UserSessionRule;
-import org.sonar.server.ws.TestRequest;
-import org.sonar.server.ws.WsActionTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class SetRootWsActionTest {
-  private static final String SOME_LOGIN = "johndoe";
-
-  @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
-  @Rule
-  public UserSessionRule userSessionRule = UserSessionRule.standalone();
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
-  private UserDao userDao = dbTester.getDbClient().userDao();
-  private DbSession dbSession = dbTester.getSession();
-  private SetRootWsAction underTest = new SetRootWsAction(userSessionRule, dbTester.getDbClient());
-  private WsActionTester wsTester = new WsActionTester(underTest);
-
-  @Test
-  public void verify_definition() {
-    WebService.Action action = wsTester.getDef();
-    assertThat(action.key()).isEqualTo("set_root");
-    assertThat(action.isInternal()).isTrue();
-    assertThat(action.isPost()).isTrue();
-    assertThat(action.since()).isEqualTo("6.2");
-    assertThat(action.description()).isEqualTo("Make the specified user root.<br/>" +
-      "Requires to be root.");
-    assertThat(action.responseExample()).isNull();
-    assertThat(action.deprecatedKey()).isNull();
-    assertThat(action.deprecatedSince()).isNull();
-    assertThat(action.handler()).isSameAs(underTest);
-    assertThat(action.params()).hasSize(1);
-
-    WebService.Param param = action.param("login");
-    assertThat(param.isRequired()).isTrue();
-    assertThat(param.description()).isEqualTo("A user login");
-    assertThat(param.defaultValue()).isNull();
-    assertThat(param.deprecatedSince()).isNull();
-    assertThat(param.deprecatedKey()).isNull();
-    assertThat(param.exampleValue()).isEqualTo("admin");
-  }
-
-  @Test
-  public void execute_fails_with_ForbiddenException_when_user_is_not_logged_in() {
-    expectInsufficientPrivilegesForbiddenException();
-
-    executeRequest(SOME_LOGIN);
-  }
-
-  @Test
-  public void execute_fails_with_ForbiddenException_when_user_is_not_root() {
-    userSessionRule.login();
-
-    expectInsufficientPrivilegesForbiddenException();
-
-    executeRequest(SOME_LOGIN);
-  }
-
-  @Test
-  public void execute_fails_with_IAE_when_login_param_is_not_provided() {
-    makeAuthenticatedUserRoot();
-
-    expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("The 'login' parameter is missing");
-
-    executeRequest(null);
-  }
-
-  @Test
-  public void execute_makes_user_with_specified_login_root_when_it_is_not() {
-    UserDto otherUser = UserTesting.newUserDto();
-    userDao.insert(dbSession, otherUser);
-    userDao.insert(dbSession, UserTesting.newUserDto(SOME_LOGIN, "name", "email"));
-    dbSession.commit();
-    makeAuthenticatedUserRoot();
-
-    executeRequest(SOME_LOGIN);
-
-    assertThat(userDao.selectByLogin(dbSession, SOME_LOGIN).isRoot()).isTrue();
-    assertThat(userDao.selectByLogin(dbSession, otherUser.getLogin()).isRoot()).isFalse();
-  }
-
-  @Test
-  public void execute_has_no_effect_when_user_is_already_root() {
-    UserDto otherUser = UserTesting.newUserDto();
-    userDao.insert(dbSession, otherUser);
-    userDao.insert(dbSession, UserTesting.newUserDto(SOME_LOGIN, "name", "email"));
-    userDao.setRoot(dbSession, SOME_LOGIN, true);
-    dbSession.commit();
-    makeAuthenticatedUserRoot();
-
-    executeRequest(SOME_LOGIN);
-
-    assertThat(userDao.selectByLogin(dbSession, SOME_LOGIN).isRoot()).isTrue();
-    assertThat(userDao.selectByLogin(dbSession, otherUser.getLogin()).isRoot()).isFalse();
-  }
-
-  @Test
-  public void execute_fails_with_NotFoundException_when_user_for_specified_login_does_not_exist() {
-    makeAuthenticatedUserRoot();
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage("User with login 'foo_bar' not found");
-    
-    executeRequest("foo_bar");
-  }
-
-  @Test
-  public void execute_fails_with_NotFoundException_when_user_for_specified_login_is_not_active() {
-    UserDto userDto = UserTesting.newUserDto().setActive(false);
-    userDao.insert(dbSession, userDto);
-    dbSession.commit();
-    makeAuthenticatedUserRoot();
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage("User with login '" + userDto.getLogin() + "' not found");
-
-    executeRequest(userDto.getLogin());
-  }
-
-  private void makeAuthenticatedUserRoot() {
-    userSessionRule.login().setRoot();
-  }
-
-  private void expectInsufficientPrivilegesForbiddenException() {
-    expectedException.expect(ForbiddenException.class);
-    expectedException.expectMessage("Insufficient privileges");
-  }
-
-  private int executeRequest(@Nullable String login) {
-    TestRequest request = wsTester.newRequest();
-    if (login != null) {
-      request.setParam("login", login);
-    }
-    return request
-      .execute()
-      .getStatus();
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/root/ws/UnsetRootActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/root/ws/UnsetRootActionTest.java
new file mode 100644 (file)
index 0000000..4901f70
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.root.ws;
+
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.user.UserDao;
+import org.sonar.db.user.UserDto;
+import org.sonar.server.exceptions.BadRequestException;
+import org.sonar.server.exceptions.ForbiddenException;
+import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.TestRequest;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.db.user.UserTesting.newUserDto;
+
+public class UnsetRootActionTest {
+  private static final String SOME_LOGIN = "johndoe";
+
+  @Rule
+  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  @Rule
+  public UserSessionRule userSessionRule = UserSessionRule.standalone();
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private UserDao userDao = dbTester.getDbClient().userDao();
+  private DbSession dbSession = dbTester.getSession();
+  private UnsetRootAction underTest = new UnsetRootAction(userSessionRule, dbTester.getDbClient());
+  private WsActionTester wsTester = new WsActionTester(underTest);
+
+  @Test
+  public void verify_definition() {
+    WebService.Action action = wsTester.getDef();
+    assertThat(action.key()).isEqualTo("unset_root");
+    assertThat(action.isInternal()).isTrue();
+    assertThat(action.isPost()).isTrue();
+    assertThat(action.since()).isEqualTo("6.2");
+    assertThat(action.description()).isEqualTo("Make the specified user not root.<br/>" +
+      "Requires to be root.");
+    assertThat(action.responseExample()).isNull();
+    assertThat(action.deprecatedKey()).isNull();
+    assertThat(action.deprecatedSince()).isNull();
+    assertThat(action.handler()).isSameAs(underTest);
+    assertThat(action.params()).hasSize(1);
+
+    WebService.Param param = action.param("login");
+    assertThat(param.isRequired()).isTrue();
+    assertThat(param.description()).isEqualTo("A user login");
+    assertThat(param.defaultValue()).isNull();
+    assertThat(param.deprecatedSince()).isNull();
+    assertThat(param.deprecatedKey()).isNull();
+    assertThat(param.exampleValue()).isEqualTo("admin");
+  }
+
+  @Test
+  public void execute_fails_with_ForbiddenException_when_user_is_not_logged_in() {
+    expectInsufficientPrivilegesForbiddenException();
+
+    executeRequest(SOME_LOGIN);
+  }
+
+  @Test
+  public void execute_fails_with_ForbiddenException_when_user_is_not_root() {
+    userSessionRule.login();
+
+    expectInsufficientPrivilegesForbiddenException();
+
+    executeRequest(SOME_LOGIN);
+  }
+
+  @Test
+  public void execute_fails_with_IAE_when_login_param_is_not_provided() {
+    makeAuthenticatedUserRoot();
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("The 'login' parameter is missing");
+
+    executeRequest(null);
+  }
+
+  @Test
+  public void execute_makes_user_with_specified_login_not_root_when_it_is() {
+    UserDto otherUser = insertRootUser(newUserDto());
+    insertRootUser(newUserDto(SOME_LOGIN, "name", "email"));
+    makeAuthenticatedUserRoot();
+
+    executeRequest(SOME_LOGIN);
+
+    assertThat(userDao.selectByLogin(dbSession, SOME_LOGIN).isRoot()).isFalse();
+    assertThat(userDao.selectByLogin(dbSession, otherUser.getLogin()).isRoot()).isTrue();
+  }
+
+  @Test
+  public void execute_has_no_effect_when_user_is_already_not_root() {
+    UserDto otherUser = insertRootUser(newUserDto());
+    insertNonRootUser(newUserDto(SOME_LOGIN, "name", "email"));
+    makeAuthenticatedUserRoot();
+
+    executeRequest(SOME_LOGIN);
+
+    assertThat(userDao.selectByLogin(dbSession, SOME_LOGIN).isRoot()).isFalse();
+    assertThat(userDao.selectByLogin(dbSession, otherUser.getLogin()).isRoot()).isTrue();
+  }
+
+  @Test
+  public void execute_fails_with_BadRequestException_when_attempting_to_unset_root_on_last_root_user() {
+    insertRootUser(newUserDto(SOME_LOGIN, "name", "email"));
+    insertNonRootUser(newUserDto());
+    makeAuthenticatedUserRoot();
+
+    expectedException.expect(BadRequestException.class);
+    expectedException.expectMessage("Last root can't be unset");
+    
+    executeRequest(SOME_LOGIN);
+  }
+
+  @Test
+  public void execute_fails_with_BadRequestException_when_attempting_to_unset_non_root_and_there_is_no_root_at_all() {
+    UserDto userDto1 = newUserDto(SOME_LOGIN, "name", "email");
+    insertNonRootUser(userDto1);
+    makeAuthenticatedUserRoot();
+
+    expectedException.expect(BadRequestException.class);
+    expectedException.expectMessage("Last root can't be unset");
+
+    executeRequest(userDto1.getLogin());
+  }
+
+  @Test
+  public void execute_fails_with_NotFoundException_when_user_for_specified_login_does_not_exist() {
+    makeAuthenticatedUserRoot();
+
+    expectedException.expect(NotFoundException.class);
+    expectedException.expectMessage("User with login 'bar_foo' not found");
+
+    executeRequest("bar_foo");
+  }
+
+  @Test
+  public void execute_fails_with_NotFoundException_when_user_for_specified_login_is_inactive() {
+    UserDto userDto = insertRootUser(newUserDto().setActive(false));
+    makeAuthenticatedUserRoot();
+
+    expectedException.expect(NotFoundException.class);
+    expectedException.expectMessage("User with login '" + userDto.getLogin() + "' not found");
+
+    executeRequest(userDto.getLogin());
+  }
+
+  private UserDto insertNonRootUser(UserDto dto) {
+    userDao.insert(dbSession, dto);
+    dbSession.commit();
+    return dto;
+  }
+
+  private UserDto insertRootUser(UserDto dto) {
+    insertNonRootUser(dto);
+    userDao.setRoot(dbSession, dto.getLogin(), true);
+    dbSession.commit();
+    return dto;
+  }
+
+  private void makeAuthenticatedUserRoot() {
+    userSessionRule.login().setRoot();
+  }
+
+  private void expectInsufficientPrivilegesForbiddenException() {
+    expectedException.expect(ForbiddenException.class);
+    expectedException.expectMessage("Insufficient privileges");
+  }
+
+  private int executeRequest(@Nullable String login) {
+    TestRequest request = wsTester.newRequest();
+    if (login != null) {
+      request.setParam("login", login);
+    }
+    return request
+      .execute()
+      .getStatus();
+  }
+
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/root/ws/UnsetRootWsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/root/ws/UnsetRootWsActionTest.java
deleted file mode 100644 (file)
index 21bc0de..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.root.ws;
-
-import javax.annotation.Nullable;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.user.UserDao;
-import org.sonar.db.user.UserDto;
-import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.tester.UserSessionRule;
-import org.sonar.server.ws.TestRequest;
-import org.sonar.server.ws.WsActionTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.user.UserTesting.newUserDto;
-
-public class UnsetRootWsActionTest {
-  private static final String SOME_LOGIN = "johndoe";
-
-  @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
-  @Rule
-  public UserSessionRule userSessionRule = UserSessionRule.standalone();
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
-  private UserDao userDao = dbTester.getDbClient().userDao();
-  private DbSession dbSession = dbTester.getSession();
-  private UnsetRootWsAction underTest = new UnsetRootWsAction(userSessionRule, dbTester.getDbClient());
-  private WsActionTester wsTester = new WsActionTester(underTest);
-
-  @Test
-  public void verify_definition() {
-    WebService.Action action = wsTester.getDef();
-    assertThat(action.key()).isEqualTo("unset_root");
-    assertThat(action.isInternal()).isTrue();
-    assertThat(action.isPost()).isTrue();
-    assertThat(action.since()).isEqualTo("6.2");
-    assertThat(action.description()).isEqualTo("Make the specified user not root.<br/>" +
-      "Requires to be root.");
-    assertThat(action.responseExample()).isNull();
-    assertThat(action.deprecatedKey()).isNull();
-    assertThat(action.deprecatedSince()).isNull();
-    assertThat(action.handler()).isSameAs(underTest);
-    assertThat(action.params()).hasSize(1);
-
-    WebService.Param param = action.param("login");
-    assertThat(param.isRequired()).isTrue();
-    assertThat(param.description()).isEqualTo("A user login");
-    assertThat(param.defaultValue()).isNull();
-    assertThat(param.deprecatedSince()).isNull();
-    assertThat(param.deprecatedKey()).isNull();
-    assertThat(param.exampleValue()).isEqualTo("admin");
-  }
-
-  @Test
-  public void execute_fails_with_ForbiddenException_when_user_is_not_logged_in() {
-    expectInsufficientPrivilegesForbiddenException();
-
-    executeRequest(SOME_LOGIN);
-  }
-
-  @Test
-  public void execute_fails_with_ForbiddenException_when_user_is_not_root() {
-    userSessionRule.login();
-
-    expectInsufficientPrivilegesForbiddenException();
-
-    executeRequest(SOME_LOGIN);
-  }
-
-  @Test
-  public void execute_fails_with_IAE_when_login_param_is_not_provided() {
-    makeAuthenticatedUserRoot();
-
-    expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("The 'login' parameter is missing");
-
-    executeRequest(null);
-  }
-
-  @Test
-  public void execute_makes_user_with_specified_login_not_root_when_it_is() {
-    UserDto otherUser = insertRootUser(newUserDto());
-    insertRootUser(newUserDto(SOME_LOGIN, "name", "email"));
-    makeAuthenticatedUserRoot();
-
-    executeRequest(SOME_LOGIN);
-
-    assertThat(userDao.selectByLogin(dbSession, SOME_LOGIN).isRoot()).isFalse();
-    assertThat(userDao.selectByLogin(dbSession, otherUser.getLogin()).isRoot()).isTrue();
-  }
-
-  @Test
-  public void execute_has_no_effect_when_user_is_already_not_root() {
-    UserDto otherUser = insertRootUser(newUserDto());
-    insertNonRootUser(newUserDto(SOME_LOGIN, "name", "email"));
-    makeAuthenticatedUserRoot();
-
-    executeRequest(SOME_LOGIN);
-
-    assertThat(userDao.selectByLogin(dbSession, SOME_LOGIN).isRoot()).isFalse();
-    assertThat(userDao.selectByLogin(dbSession, otherUser.getLogin()).isRoot()).isTrue();
-  }
-
-  @Test
-  public void execute_fails_with_BadRequestException_when_attempting_to_unset_root_on_last_root_user() {
-    insertRootUser(newUserDto(SOME_LOGIN, "name", "email"));
-    insertNonRootUser(newUserDto());
-    makeAuthenticatedUserRoot();
-
-    expectedException.expect(BadRequestException.class);
-    expectedException.expectMessage("Last root can't be unset");
-    
-    executeRequest(SOME_LOGIN);
-  }
-
-  @Test
-  public void execute_fails_with_BadRequestException_when_attempting_to_unset_non_root_and_there_is_no_root_at_all() {
-    UserDto userDto1 = newUserDto(SOME_LOGIN, "name", "email");
-    insertNonRootUser(userDto1);
-    makeAuthenticatedUserRoot();
-
-    expectedException.expect(BadRequestException.class);
-    expectedException.expectMessage("Last root can't be unset");
-
-    executeRequest(userDto1.getLogin());
-  }
-
-  @Test
-  public void execute_fails_with_NotFoundException_when_user_for_specified_login_does_not_exist() {
-    makeAuthenticatedUserRoot();
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage("User with login 'bar_foo' not found");
-
-    executeRequest("bar_foo");
-  }
-
-  @Test
-  public void execute_fails_with_NotFoundException_when_user_for_specified_login_is_inactive() {
-    UserDto userDto = insertRootUser(newUserDto().setActive(false));
-    makeAuthenticatedUserRoot();
-
-    expectedException.expect(NotFoundException.class);
-    expectedException.expectMessage("User with login '" + userDto.getLogin() + "' not found");
-
-    executeRequest(userDto.getLogin());
-  }
-
-  private UserDto insertNonRootUser(UserDto dto) {
-    userDao.insert(dbSession, dto);
-    dbSession.commit();
-    return dto;
-  }
-
-  private UserDto insertRootUser(UserDto dto) {
-    insertNonRootUser(dto);
-    userDao.setRoot(dbSession, dto.getLogin(), true);
-    dbSession.commit();
-    return dto;
-  }
-
-  private void makeAuthenticatedUserRoot() {
-    userSessionRule.login().setRoot();
-  }
-
-  private void expectInsufficientPrivilegesForbiddenException() {
-    expectedException.expect(ForbiddenException.class);
-    expectedException.expectMessage("Insufficient privileges");
-  }
-
-  private int executeRequest(@Nullable String login) {
-    TestRequest request = wsTester.newRequest();
-    if (login != null) {
-      request.setParam("login", login);
-    }
-    return request
-      .execute()
-      .getStatus();
-  }
-
-}
index 8f96d055746e61a75719b848cd4d9e7e783e9a2b..eff30072e0df4339835baed378442613ac6d0460 100644 (file)
@@ -29,7 +29,7 @@ import org.sonarqube.ws.client.project.ProjectsService;
 import org.sonarqube.ws.client.projectlinks.ProjectLinksService;
 import org.sonarqube.ws.client.qualitygate.QualityGatesService;
 import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
-import org.sonarqube.ws.client.root.RootService;
+import org.sonarqube.ws.client.root.RootsService;
 import org.sonarqube.ws.client.rule.RulesService;
 import org.sonarqube.ws.client.setting.SettingsService;
 import org.sonarqube.ws.client.system.SystemService;
@@ -58,7 +58,7 @@ class DefaultWsClient implements WsClient {
   private final ProjectsService projectsService;
   private final ProjectLinksService projectLinksService;
   private final SettingsService settingsService;
-  private final RootService rootService;
+  private final RootsService rootsService;
 
   DefaultWsClient(WsConnector wsConnector) {
     this.wsConnector = wsConnector;
@@ -76,7 +76,7 @@ class DefaultWsClient implements WsClient {
     this.projectsService = new ProjectsService(wsConnector);
     this.projectLinksService = new ProjectLinksService(wsConnector);
     this.settingsService = new SettingsService(wsConnector);
-    this.rootService = new RootService(wsConnector);
+    this.rootsService = new RootsService(wsConnector);
   }
 
   @Override
@@ -155,7 +155,7 @@ class DefaultWsClient implements WsClient {
   }
 
   @Override
-  public RootService rootService() {
-    return rootService;
+  public RootsService rootService() {
+    return rootsService;
   }
 }
index 4514f55ec2dc21e02558e7726db817206169db25..add8512bca2aebce5c749000b0501a9a9bab4e41 100644 (file)
@@ -29,7 +29,7 @@ import org.sonarqube.ws.client.project.ProjectsService;
 import org.sonarqube.ws.client.projectlinks.ProjectLinksService;
 import org.sonarqube.ws.client.qualitygate.QualityGatesService;
 import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
-import org.sonarqube.ws.client.root.RootService;
+import org.sonarqube.ws.client.root.RootsService;
 import org.sonarqube.ws.client.rule.RulesService;
 import org.sonarqube.ws.client.setting.SettingsService;
 import org.sonarqube.ws.client.system.SystemService;
@@ -96,5 +96,5 @@ public interface WsClient {
   /**
    * @since 6.2
    */
-  RootService rootService();
+  RootsService rootService();
 }
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/root/RootService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/root/RootService.java
deleted file mode 100644 (file)
index 90d4d5e..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.sonarqube.ws.client.root;
-
-import org.sonarqube.ws.WsRoot;
-import org.sonarqube.ws.client.BaseService;
-import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.client.PostRequest;
-import org.sonarqube.ws.client.WsConnector;
-
-public class RootService extends BaseService {
-  public RootService(WsConnector wsConnector) {
-    super(wsConnector, "api/root");
-  }
-
-  public WsRoot.SearchWsResponse search() {
-    return call(new GetRequest(path("search")), WsRoot.SearchWsResponse.parser());
-  }
-
-  public void setRoot(String login) {
-    PostRequest post = new PostRequest(path("set_root"))
-      .setParam("login", login);
-
-    call(post);
-  }
-
-  public void unsetRoot(String login) {
-    PostRequest post = new PostRequest(path("unset_root"))
-      .setParam("login", login);
-
-    call(post);
-  }
-}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/root/RootsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/root/RootsService.java
new file mode 100644 (file)
index 0000000..2e9853d
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.sonarqube.ws.client.root;
+
+import org.sonarqube.ws.WsRoot;
+import org.sonarqube.ws.client.BaseService;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.WsConnector;
+
+public class RootsService extends BaseService {
+  public RootsService(WsConnector wsConnector) {
+    super(wsConnector, "api/roots");
+  }
+
+  public WsRoot.SearchWsResponse search() {
+    return call(new GetRequest(path("search")), WsRoot.SearchWsResponse.parser());
+  }
+
+  public void setRoot(String login) {
+    PostRequest post = new PostRequest(path("set_root"))
+      .setParam("login", login);
+
+    call(post);
+  }
+
+  public void unsetRoot(String login) {
+    PostRequest post = new PostRequest(path("unset_root"))
+      .setParam("login", login);
+
+    call(post);
+  }
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/root/RootServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/root/RootServiceTest.java
deleted file mode 100644 (file)
index 616c6eb..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.sonarqube.ws.client.root;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonarqube.ws.client.ServiceTester;
-import org.sonarqube.ws.client.WsConnector;
-
-import static org.mockito.Mockito.mock;
-
-public class RootServiceTest {
-  private static final String SOME_LOGIN = "johnDoe";
-
-  @Rule
-  public ServiceTester<RootService> serviceTester = new ServiceTester<>(new RootService(mock(WsConnector.class)));
-
-  private RootService underTest = serviceTester.getInstanceUnderTest();
-
-  @Test
-  public void search() {
-    underTest.search();
-
-    serviceTester.assertThat(serviceTester.getGetRequest())
-      .hasPath("search")
-      .andNoOtherParam();
-  }
-
-  @Test
-  public void setRoot() {
-    underTest.setRoot(SOME_LOGIN);
-
-    serviceTester.assertThat(serviceTester.getPostRequest())
-      .hasPath("set_root")
-      .hasParam("login", SOME_LOGIN)
-      .andNoOtherParam();
-  }
-
-  @Test
-  public void unsetRoot() {
-    underTest.unsetRoot(SOME_LOGIN);
-
-    serviceTester.assertThat(serviceTester.getPostRequest())
-      .hasPath("unset_root")
-      .hasParam("login", SOME_LOGIN)
-      .andNoOtherParam();
-  }
-}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/root/RootsServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/root/RootsServiceTest.java
new file mode 100644 (file)
index 0000000..9eec001
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.sonarqube.ws.client.root;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.ws.client.ServiceTester;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.mockito.Mockito.mock;
+
+public class RootsServiceTest {
+  private static final String SOME_LOGIN = "johnDoe";
+
+  @Rule
+  public ServiceTester<RootsService> serviceTester = new ServiceTester<>(new RootsService(mock(WsConnector.class)));
+
+  private RootsService underTest = serviceTester.getInstanceUnderTest();
+
+  @Test
+  public void search() {
+    underTest.search();
+
+    serviceTester.assertThat(serviceTester.getGetRequest())
+      .hasPath("search")
+      .andNoOtherParam();
+  }
+
+  @Test
+  public void setRoot() {
+    underTest.setRoot(SOME_LOGIN);
+
+    serviceTester.assertThat(serviceTester.getPostRequest())
+      .hasPath("set_root")
+      .hasParam("login", SOME_LOGIN)
+      .andNoOtherParam();
+  }
+
+  @Test
+  public void unsetRoot() {
+    underTest.unsetRoot(SOME_LOGIN);
+
+    serviceTester.assertThat(serviceTester.getPostRequest())
+      .hasPath("unset_root")
+      .hasParam("login", SOME_LOGIN)
+      .andNoOtherParam();
+  }
+}