]> source.dussan.org Git - sonarqube.git/commitdiff
Clean-up DefaultUserService
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 18 Jan 2017 18:57:07 +0000 (19:57 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 18 Jan 2017 19:47:59 +0000 (20:47 +0100)
because it's not used anymore from Ruby

server/sonar-server/src/main/java/org/sonar/server/user/DefaultUserService.java
server/sonar-server/src/test/java/org/sonar/server/user/DefaultUserServiceTest.java
server/sonar-web/src/main/webapp/WEB-INF/app/models/api.rb [deleted file]
server/sonar-web/src/main/webapp/WEB-INF/app/models/internal.rb

index bab380415ae341230656ce2cef60257588f74b4c..6100a1e1cd6af11318158d49a27f3ec34c7981dc 100644 (file)
@@ -22,27 +22,17 @@ package org.sonar.server.user;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.CheckForNull;
-import org.apache.commons.lang.StringUtils;
 import org.sonar.api.user.RubyUserService;
 import org.sonar.api.user.User;
 import org.sonar.api.user.UserFinder;
 import org.sonar.api.user.UserQuery;
-import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.user.index.UserDoc;
-import org.sonar.server.user.index.UserIndex;
 import org.sonar.server.util.RubyUtils;
 
-import static org.sonar.server.util.Validation.checkMandatoryParameter;
-
 public class DefaultUserService implements RubyUserService {
 
-  private final UserIndex userIndex;
-  private final UserUpdater userUpdater;
   private final UserFinder finder;
 
-  public DefaultUserService(UserIndex userIndex, UserUpdater userUpdater, UserFinder finder) {
-    this.userIndex = userIndex;
-    this.userUpdater = userUpdater;
+  public DefaultUserService(UserFinder finder) {
     this.finder = finder;
   }
 
@@ -58,7 +48,7 @@ public class DefaultUserService implements RubyUserService {
     return finder.find(query);
   }
 
-  private UserQuery parseQuery(Map<String, Object> params) {
+  private static UserQuery parseQuery(Map<String, Object> params) {
     UserQuery.Builder builder = UserQuery.builder();
     if (RubyUtils.toBoolean(params.get("includeDeactivated")) == Boolean.TRUE) {
       builder.includeDeactivated();
@@ -67,31 +57,4 @@ public class DefaultUserService implements RubyUserService {
     builder.searchText((String) params.get("s"));
     return builder.build();
   }
-
-  @CheckForNull
-  public UserDoc getByLogin(String login) {
-    return userIndex.getNullableByLogin(login);
-  }
-
-  public boolean create(Map<String, Object> params) {
-    String password = (String) params.get("password");
-    String passwordConfirmation = (String) params.get("password_confirmation");
-    checkMandatoryParameter(password, "Password");
-    checkMandatoryParameter(passwordConfirmation, "Password confirmation");
-    if (!StringUtils.equals(password, passwordConfirmation)) {
-      throw new BadRequestException("user.password_doesnt_match_confirmation");
-    }
-
-    NewUser newUser = NewUser.create()
-      .setLogin((String) params.get("login"))
-      .setName((String) params.get("name"))
-      .setEmail((String) params.get("email"))
-      .setScmAccounts(RubyUtils.toStrings(params.get("scm_accounts")))
-      .setPassword(password);
-    return userUpdater.create(newUser);
-  }
-
-  public void index() {
-    userUpdater.index();
-  }
 }
index a184bc7a359b7fcb94032abc46e758f5c582f4b8..4464a8ef1b6819ebbe8d18da60e7e5c40e7facd3 100644 (file)
@@ -21,22 +21,13 @@ package org.sonar.server.user;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
-import java.util.Map;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.mockito.ArgumentCaptor;
 import org.mockito.ArgumentMatcher;
 import org.sonar.api.user.UserFinder;
 import org.sonar.api.user.UserQuery;
-import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.exceptions.Message;
-import org.sonar.server.user.index.UserIndex;
-import org.sonar.server.util.Validation;
 
-import static com.google.common.collect.Lists.newArrayList;
-import static com.google.common.collect.Maps.newHashMap;
-import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.argThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
@@ -44,10 +35,8 @@ import static org.mockito.Mockito.verify;
 
 public class DefaultUserServiceTest {
 
-  private UserIndex userIndex = mock(UserIndex.class);
   private UserFinder finder = mock(UserFinder.class);
-  private UserUpdater userUpdater = mock(UserUpdater.class);
-  private DefaultUserService service = new DefaultUserService(userIndex, userUpdater, finder);
+  private DefaultUserService service = new DefaultUserService(finder);
 
   @Rule
   public ExpectedException thrown = ExpectedException.none();
@@ -82,84 +71,4 @@ public class DefaultUserServiceTest {
       }
     }));
   }
-
-  @Test
-  public void create_user() {
-    Map<String, Object> params = newHashMap();
-    params.put("login", "john");
-    params.put("name", "John");
-    params.put("email", "john@email.com");
-    params.put("password", "123456");
-    params.put("password_confirmation", "123456");
-    params.put("scm_accounts", newArrayList("jn"));
-    service.create(params);
-
-    ArgumentCaptor<NewUser> newUserCaptor = ArgumentCaptor.forClass(NewUser.class);
-    verify(userUpdater).create(newUserCaptor.capture());
-    assertThat(newUserCaptor.getValue().login()).isEqualTo("john");
-    assertThat(newUserCaptor.getValue().name()).isEqualTo("John");
-    assertThat(newUserCaptor.getValue().email()).isEqualTo("john@email.com");
-    assertThat(newUserCaptor.getValue().password()).isEqualTo("123456");
-    assertThat(newUserCaptor.getValue().scmAccounts()).containsOnly("jn");
-  }
-
-  @Test
-  public void fail_to_create_user_when_password_is_empty() throws Exception {
-    Map<String, Object> params = newHashMap();
-    params.put("login", "john");
-    params.put("name", "John");
-    params.put("email", "john@email.com");
-    params.put("password", "");
-    params.put("password_confirmation", "123456");
-
-    try {
-      service.create(params);
-    } catch (BadRequestException e) {
-      assertThat(e.errors().messages()).containsOnly(Message.of(Validation.CANT_BE_EMPTY_MESSAGE, "Password"));
-    }
-  }
-
-  @Test
-  public void fail_to_create_user_when_password_confirmation_is_empty() throws Exception {
-    Map<String, Object> params = newHashMap();
-    params.put("login", "john");
-    params.put("name", "John");
-    params.put("email", "john@email.com");
-    params.put("password", "123456");
-    params.put("password_confirmation", "");
-
-    try {
-      service.create(params);
-    } catch (BadRequestException e) {
-      assertThat(e.errors().messages()).containsOnly(Message.of(Validation.CANT_BE_EMPTY_MESSAGE, "Password confirmation"));
-    }
-  }
-
-  @Test
-  public void fail_to_create_user_when_password_does_not_match_confirmation() throws Exception {
-    Map<String, Object> params = newHashMap();
-    params.put("login", "john");
-    params.put("name", "John");
-    params.put("email", "john@email.com");
-    params.put("password", "123456");
-    params.put("password_confirmation", "654321");
-
-    try {
-      service.create(params);
-    } catch (BadRequestException e) {
-      assertThat(e.errors().messages()).containsOnly(Message.of("user.password_doesnt_match_confirmation"));
-    }
-  }
-
-  @Test
-  public void get_by_login() {
-    service.getByLogin("john");
-    verify(userIndex).getNullableByLogin("john");
-  }
-
-  @Test
-  public void index() {
-    service.index();
-    verify(userUpdater).index();
-  }
 }
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/api.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/api.rb
deleted file mode 100644 (file)
index c9a1f35..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2016 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.
-#
-
-# Entry points to Java API. All other Ruby classes are not considered
-# as an API and can evolve through time.
-class Api
-
-  # See the javadoc of org.sonar.api.user.RubyUserService
-  # Since 3.6
-  def self.users
-    Internal.users_api
-  end
-end
index e0f5c76376fb3311a2dc4089c08d1abc974cb48e..9427cf9aac7c996e8c608a4095f0ed108776af42 100644 (file)
@@ -26,10 +26,6 @@ class Internal
     component(Java::OrgSonarServerIssue::InternalRubyIssueService.java_class)
   end
 
-  def self.users_api
-    component(Java::OrgSonarApiUser::RubyUserService.java_class)
-  end
-
   def self.component_api
     component(Java::OrgSonarApiComponent::RubyComponentService.java_class)
   end