]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6523 Remove user client from sonar-wsclient library
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 13 May 2015 07:58:48 +0000 (09:58 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 18 May 2015 08:26:04 +0000 (10:26 +0200)
server/sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java
server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/UserClient.java [deleted file]
server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/UserParameters.java [deleted file]
server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/UserQuery.java [deleted file]
server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/internal/DefaultUserClient.java [deleted file]
server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/internal/package-info.java [deleted file]
server/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarClientTest.java
server/sonar-ws-client/src/test/java/org/sonar/wsclient/user/DefaultUserClientTest.java [deleted file]
server/sonar-ws-client/src/test/java/org/sonar/wsclient/user/UserQueryTest.java [deleted file]

index 498a4c00cc53eef2691fa7bd2e4a00160ebc8cb7..efd5a2512cbd85e2ecb890b95acc194bf07be273 100644 (file)
@@ -34,8 +34,6 @@ import org.sonar.wsclient.qualitygate.QualityGateClient;
 import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
 import org.sonar.wsclient.system.SystemClient;
 import org.sonar.wsclient.system.internal.DefaultSystemClient;
-import org.sonar.wsclient.user.UserClient;
-import org.sonar.wsclient.user.internal.DefaultUserClient;
 
 import javax.annotation.Nullable;
 
@@ -97,13 +95,6 @@ public class SonarClient {
     return new DefaultActionPlanClient(requestFactory);
   }
 
-  /**
-   * New client to interact with web services related to users
-   */
-  public UserClient userClient() {
-    return new DefaultUserClient(requestFactory);
-  }
-
   /**
    * New client to interact with web services related to users and groups permissions
    */
diff --git a/server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/UserClient.java b/server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/UserClient.java
deleted file mode 100644 (file)
index 2617453..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.user;
-
-import java.util.List;
-
-/**
- * @since 3.6
- */
-public interface UserClient {
-
-  List<User> find(UserQuery query);
-
-  /**
-   * @since 3.7
-   */
-  User create(UserParameters userParameters);
-
-  /**
-   * @since 3.7
-   */
-  User update(UserParameters userParameters);
-
-  /**
-   * @since 3.7
-   */
-  void deactivate(String login);
-}
diff --git a/server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/UserParameters.java b/server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/UserParameters.java
deleted file mode 100644 (file)
index 025cea9..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.user;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class UserParameters {
-
-  private final Map<String, Object> params = new HashMap<>();
-
-  private UserParameters() {
-  }
-
-  public static UserParameters create() {
-    return new UserParameters();
-  }
-
-  public Map<String, Object> urlParams() {
-    return params;
-  }
-
-  public UserParameters login(String s) {
-    params.put("login", s);
-    return this;
-  }
-
-  public UserParameters name(String s) {
-    params.put("name", s);
-    return this;
-  }
-
-  public UserParameters password(String s) {
-    params.put("password", s);
-    return this;
-  }
-
-  public UserParameters passwordConfirmation(String s) {
-    params.put("password_confirmation", s);
-    return this;
-  }
-
-  public UserParameters email(String s) {
-    params.put("email", s);
-    return this;
-  }
-}
diff --git a/server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/UserQuery.java b/server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/UserQuery.java
deleted file mode 100644 (file)
index 2550ef7..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.user;
-
-import org.sonar.wsclient.internal.EncodingUtils;
-
-import javax.annotation.Nullable;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @since 3.6
- */
-public class UserQuery {
-
-  private final Map<String, Object> params = new HashMap<>();
-
-  private UserQuery() {
-  }
-
-  public static UserQuery create() {
-    return new UserQuery();
-  }
-
-  public UserQuery includeDeactivated() {
-    params.put("includeDeactivated", "true");
-    return this;
-  }
-
-  public UserQuery logins(String... s) {
-    params.put("logins", EncodingUtils.toQueryParam(s));
-    return this;
-  }
-
-  public UserQuery searchText(@Nullable String s) {
-    if (s != null) {
-      params.put("s", s);
-    } else {
-      params.remove("s");
-    }
-    return this;
-  }
-
-  public Map<String, Object> urlParams() {
-    return params;
-  }
-}
diff --git a/server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/internal/DefaultUserClient.java b/server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/internal/DefaultUserClient.java
deleted file mode 100644 (file)
index 7b1af27..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.user.internal;
-
-import org.json.simple.JSONValue;
-import org.sonar.wsclient.internal.HttpRequestFactory;
-import org.sonar.wsclient.user.User;
-import org.sonar.wsclient.user.UserClient;
-import org.sonar.wsclient.user.UserParameters;
-import org.sonar.wsclient.user.UserQuery;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Do not instantiate this class, but use {@link org.sonar.wsclient.SonarClient#userClient()}.
- */
-public class DefaultUserClient implements UserClient {
-
-  private static final String BASE_URL = "/api/users/";
-  private static final String SEARCH_URL = BASE_URL + "search";
-  private static final String CREATE_URL = BASE_URL + "create";
-  private static final String UPDATE_URL = BASE_URL + "update";
-  private static final String DEACTIVATE_URL = BASE_URL + "deactivate";
-
-  private final HttpRequestFactory requestFactory;
-
-  /**
-   * For internal use. Use {@link org.sonar.wsclient.SonarClient} to get an instance.
-   */
-  public DefaultUserClient(HttpRequestFactory requestFactory) {
-    this.requestFactory = requestFactory;
-  }
-
-  @Override
-  public List<User> find(UserQuery query) {
-    String json = requestFactory.get(SEARCH_URL, query.urlParams());
-    List<User> result = new ArrayList<>();
-    Map jsonRoot = (Map) JSONValue.parse(json);
-    List<Map> jsonUsers = (List<Map>) jsonRoot.get("users");
-    if (jsonUsers != null) {
-      for (Map jsonUser : jsonUsers) {
-        result.add(new User(jsonUser));
-      }
-    }
-    return result;
-  }
-
-  @Override
-  public User create(UserParameters userParameters) {
-    String json = requestFactory.post(CREATE_URL, userParameters.urlParams());
-    Map jsonRoot = (Map) JSONValue.parse(json);
-    Map jsonUser = (Map) jsonRoot.get("user");
-    return new User(jsonUser);
-  }
-
-  @Override
-  public User update(UserParameters userParameters) {
-    String json = requestFactory.post(UPDATE_URL, userParameters.urlParams());
-    Map jsonRoot = (Map) JSONValue.parse(json);
-    Map jsonUser = (Map) jsonRoot.get("user");
-    return new User(jsonUser);
-  }
-
-  @Override
-  public void deactivate(String login) {
-    Map<String, Object> params = new HashMap<>();
-    params.put("login", login);
-    requestFactory.post(DEACTIVATE_URL, params);
-  }
-}
diff --git a/server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/internal/package-info.java b/server/sonar-ws-client/src/main/java/org/sonar/wsclient/user/internal/package-info.java
deleted file mode 100644 (file)
index 20e56b9..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.
- */
-
-@javax.annotation.ParametersAreNonnullByDefault
-package org.sonar.wsclient.user.internal;
index 7c1ed06d2378665ce2324c93f3281b6f6bee0cec..5b01598674ebcf57d66a92c20d6aae432000ac0c 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.wsclient.project.internal.DefaultProjectClient;
 import org.sonar.wsclient.qprofile.internal.DefaultQProfileClient;
 import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
 import org.sonar.wsclient.system.internal.DefaultSystemClient;
-import org.sonar.wsclient.user.internal.DefaultUserClient;
 
 import java.util.Map;
 
@@ -45,7 +44,6 @@ public class SonarClientTest {
     SonarClient client = SonarClient.create("http://localhost:9000");
     assertThat(client.issueClient()).isNotNull().isInstanceOf(DefaultIssueClient.class);
     assertThat(client.actionPlanClient()).isNotNull().isInstanceOf(DefaultActionPlanClient.class);
-    assertThat(client.userClient()).isNotNull().isInstanceOf(DefaultUserClient.class);
     assertThat(client.permissionClient()).isNotNull().isInstanceOf(DefaultPermissionClient.class);
     assertThat(client.projectClient()).isNotNull().isInstanceOf(DefaultProjectClient.class);
     assertThat(client.qualityGateClient()).isNotNull().isInstanceOf(DefaultQualityGateClient.class);
diff --git a/server/sonar-ws-client/src/test/java/org/sonar/wsclient/user/DefaultUserClientTest.java b/server/sonar-ws-client/src/test/java/org/sonar/wsclient/user/DefaultUserClientTest.java
deleted file mode 100644 (file)
index d521d11..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.user;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.wsclient.MockHttpServerInterceptor;
-import org.sonar.wsclient.internal.HttpRequestFactory;
-import org.sonar.wsclient.user.internal.DefaultUserClient;
-
-import java.util.Arrays;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
-
-public class DefaultUserClientTest {
-
-  HttpRequestFactory requestFactory;
-  DefaultUserClient client;
-
-  @Rule
-  public MockHttpServerInterceptor httpServer = new MockHttpServerInterceptor();
-
-  @Before
-  public void setUp() {
-    requestFactory = new HttpRequestFactory(httpServer.url());
-    client = new DefaultUserClient(requestFactory);
-  }
-
-  @Test
-  public void should_find_issues() {
-    httpServer.stubResponseBody("{\"users\": [{\"login\": \"simon\", \"name\": \"Simon\", \"active\": true}]}");
-
-    UserQuery query = UserQuery.create().logins("simon", "loic");
-    List<User> users = client.find(query);
-
-    assertThatGetRequestUrlContains("/api/users/search?", "logins=simon,loic");
-    assertThat(users).hasSize(1);
-    User simon = users.get(0);
-    assertThat(simon.login()).isEqualTo("simon");
-    assertThat(simon.name()).isEqualTo("Simon");
-    assertThat(simon.email()).isNull();
-    assertThat(simon.active()).isTrue();
-  }
-
-  @Test
-  public void should_create_user() {
-    httpServer.stubResponseBody("{\"user\":{\"login\":\"daveloper\",\"name\":\"daveloper\",\"email\":null}}");
-
-    UserParameters params = UserParameters.create().login("daveloper").password("pass1").passwordConfirmation("pass1");
-    User createdUser = client.create(params);
-
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/users/create");
-    assertThat(httpServer.requestParams()).contains(
-      entry("login", "daveloper"),
-      entry("password", "pass1"),
-      entry("password_confirmation", "pass1")
-      );
-    assertThat(createdUser).isNotNull();
-    assertThat(createdUser.login()).isEqualTo("daveloper");
-    assertThat(createdUser.name()).isEqualTo("daveloper");
-    assertThat(createdUser.email()).isNull();
-  }
-
-  @Test
-  public void should_update_user() {
-    httpServer.stubResponseBody("{\"user\":{\"login\":\"daveloper\",\"name\":\"daveloper\",\"email\":\"new_email\"}}");
-
-    UserParameters params = UserParameters.create().login("daveloper").email("new_email");
-    User updatedUser = client.update(params);
-
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/users/update");
-    assertThat(httpServer.requestParams()).contains(
-      entry("login", "daveloper"),
-      entry("email", "new_email")
-      );
-    assertThat(updatedUser).isNotNull();
-    assertThat(updatedUser.login()).isEqualTo("daveloper");
-    assertThat(updatedUser.name()).isEqualTo("daveloper");
-    assertThat(updatedUser.email()).isEqualTo("new_email");
-  }
-
-  @Test
-  public void should_deactivate_user() {
-    httpServer.stubStatusCode(200);
-
-    client.deactivate("daveloper");
-
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/users/deactivate");
-    assertThat(httpServer.requestParams()).containsEntry("login", "daveloper");
-  }
-
-  private void assertThatGetRequestUrlContains(String baseUrl, String... parameters) {
-    assertThat(httpServer.requestedPath()).startsWith(baseUrl);
-    List<String> requestParameters = Arrays.asList(httpServer.requestedPath().substring(baseUrl.length()).split("&"));
-    assertThat(requestParameters).containsOnly(parameters);
-  }
-}
diff --git a/server/sonar-ws-client/src/test/java/org/sonar/wsclient/user/UserQueryTest.java b/server/sonar-ws-client/src/test/java/org/sonar/wsclient/user/UserQueryTest.java
deleted file mode 100644 (file)
index 5cad471..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.user;
-
-import org.junit.Test;
-
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class UserQueryTest {
-  @Test
-  public void test_params() throws Exception {
-    UserQuery query = UserQuery.create().includeDeactivated().logins("simon", "loic");
-    Map<String, Object> params = query.urlParams();
-
-    assertThat(params.get("includeDeactivated")).isEqualTo("true");
-    assertThat(params.get("logins")).isEqualTo("simon,loic");
-  }
-
-  @Test
-  public void test_empty_params() throws Exception {
-    UserQuery query = UserQuery.create();
-    Map<String, Object> params = query.urlParams();
-
-    assertThat(params).isEmpty();
-  }
-
-  @Test
-  public void should_replace_logins() {
-    UserQuery query = UserQuery.create().logins("simon").logins("loic");
-    assertThat(query.urlParams().get("logins")).isEqualTo("loic");
-  }
-
-  @Test
-  public void should_search_by_text() {
-    UserQuery query = UserQuery.create().searchText("sim");
-    assertThat(query.urlParams().get("s")).isEqualTo("sim");
-
-    query = UserQuery.create().searchText("sim").searchText(null);
-    assertThat(query.urlParams().get("s")).isNull();
-  }
-}