aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-06-17 19:20:13 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-06-17 20:46:57 +0200
commitc0e82d3ac6b1ceae1053b7139f608d86e90faf32 (patch)
tree313245ea5b7959abf920fab1f72e56a083cc53e1 /sonar-core
parent183b104dadd5b350d4d00a1ef2336094755e5f4f (diff)
downloadsonarqube-c0e82d3ac6b1ceae1053b7139f608d86e90faf32.tar.gz
sonarqube-c0e82d3ac6b1ceae1053b7139f608d86e90faf32.zip
Remove ability to get users from batch
+ drop Hibernate model "User"
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/user/DeprecatedUserFinder.java (renamed from sonar-core/src/main/java/org/sonar/core/user/HibernateUserFinder.java)26
-rw-r--r--sonar-core/src/main/resources/META-INF/persistence.xml1
-rw-r--r--sonar-core/src/test/java/org/sonar/core/user/DeprecatedUserFinderTest.java (renamed from sonar-core/src/test/java/org/sonar/core/user/HibernateUserFinderTest.java)37
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/user/DeprecatedUserFinderTest/fixture.xml (renamed from sonar-core/src/test/resources/org/sonar/core/user/HibernateUserFinderTest/fixture.xml)0
4 files changed, 38 insertions, 26 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/user/HibernateUserFinder.java b/sonar-core/src/main/java/org/sonar/core/user/DeprecatedUserFinder.java
index 4cc42aacccc..7a180bb7d54 100644
--- a/sonar-core/src/main/java/org/sonar/core/user/HibernateUserFinder.java
+++ b/sonar-core/src/main/java/org/sonar/core/user/DeprecatedUserFinder.java
@@ -19,32 +19,38 @@
*/
package org.sonar.core.user;
-import org.sonar.api.database.DatabaseSession;
+import javax.annotation.Nullable;
import org.sonar.api.database.model.User;
import org.sonar.api.security.UserFinder;
-import org.sonar.jpa.session.DatabaseSessionFactory;
/**
* @since 2.10
*/
-public class HibernateUserFinder implements UserFinder {
+public class DeprecatedUserFinder implements UserFinder {
- private DatabaseSessionFactory sessionFactory;
+ private final UserDao userDao;
- public HibernateUserFinder(DatabaseSessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
+ public DeprecatedUserFinder(UserDao userDao) {
+ this.userDao = userDao;
}
@Override
public User findById(int id) {
- DatabaseSession session = sessionFactory.getSession();
- return session.getSingleResult(User.class, "id", id);
+ return copy(userDao.getUser(id));
}
@Override
public User findByLogin(String login) {
- DatabaseSession session = sessionFactory.getSession();
- return session.getSingleResult(User.class, "login", login);
+ return copy(userDao.selectActiveUserByLogin(login));
+ }
+
+ private User copy(@Nullable UserDto dto) {
+ if (dto != null) {
+ User user = new User().setEmail(dto.getEmail()).setLogin(dto.getLogin()).setName(dto.getName());
+ user.setId(dto.getId().intValue());
+ return user;
+ }
+ return null;
}
}
diff --git a/sonar-core/src/main/resources/META-INF/persistence.xml b/sonar-core/src/main/resources/META-INF/persistence.xml
index d8b0e5613fd..543cc5e66c4 100644
--- a/sonar-core/src/main/resources/META-INF/persistence.xml
+++ b/sonar-core/src/main/resources/META-INF/persistence.xml
@@ -6,7 +6,6 @@
<persistence-unit name="sonar" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
- <class>org.sonar.api.database.model.User</class>
<class>org.sonar.api.database.model.Snapshot</class>
<class>org.sonar.api.measures.Metric</class>
<class>org.sonar.api.database.model.ResourceModel</class>
diff --git a/sonar-core/src/test/java/org/sonar/core/user/HibernateUserFinderTest.java b/sonar-core/src/test/java/org/sonar/core/user/DeprecatedUserFinderTest.java
index f685c4ccecf..b0fa938476d 100644
--- a/sonar-core/src/test/java/org/sonar/core/user/HibernateUserFinderTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/user/DeprecatedUserFinderTest.java
@@ -19,59 +19,66 @@
*/
package org.sonar.core.user;
-import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.sonar.api.database.model.User;
-import org.sonar.api.security.UserFinder;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.test.DbTests;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
-public class HibernateUserFinderTest extends AbstractDbUnitTestCase {
+@Category(DbTests.class)
+public class DeprecatedUserFinderTest {
- private UserFinder userFinder;
+ @ClassRule
+ public static final DbTester dbTester = new DbTester();
- @Before
- public void setUp() {
- setupData("fixture");
- userFinder = new HibernateUserFinder(getSessionFactory());
+ @BeforeClass
+ public static void init() {
+ dbTester.prepareDbUnit(DeprecatedUserFinderTest.class, "fixture.xml");
}
@Test
public void shouldFindUserByLogin() {
- User user = userFinder.findByLogin("simon");
+ DeprecatedUserFinder finder = new DeprecatedUserFinder(new UserDao(dbTester.myBatis(), mock(System2.class)));
+ User user = finder.findByLogin("simon");
assertThat(user.getId(), is(1));
assertThat(user.getLogin(), is("simon"));
assertThat(user.getName(), is("Simon Brandhof"));
assertThat(user.getEmail(), is("simon.brandhof@sonarsource.com"));
- user = userFinder.findByLogin("godin");
+ user = finder.findByLogin("godin");
assertThat(user.getId(), is(2));
assertThat(user.getLogin(), is("godin"));
assertThat(user.getName(), is("Evgeny Mandrikov"));
assertThat(user.getEmail(), is("evgeny.mandrikov@sonarsource.com"));
- user = userFinder.findByLogin("user");
+ user = finder.findByLogin("user");
assertThat(user, nullValue());
}
@Test
public void shouldFindUserById() {
- User user = userFinder.findById(1);
+ DeprecatedUserFinder finder = new DeprecatedUserFinder(new UserDao(dbTester.myBatis(), mock(System2.class)));
+ User user = finder.findById(1);
assertThat(user.getId(), is(1));
assertThat(user.getLogin(), is("simon"));
assertThat(user.getName(), is("Simon Brandhof"));
assertThat(user.getEmail(), is("simon.brandhof@sonarsource.com"));
- user = userFinder.findById(2);
+ user = finder.findById(2);
assertThat(user.getId(), is(2));
assertThat(user.getLogin(), is("godin"));
assertThat(user.getName(), is("Evgeny Mandrikov"));
assertThat(user.getEmail(), is("evgeny.mandrikov@sonarsource.com"));
- user = userFinder.findById(3);
+ user = finder.findById(3);
assertThat(user, nullValue());
}
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/HibernateUserFinderTest/fixture.xml b/sonar-core/src/test/resources/org/sonar/core/user/DeprecatedUserFinderTest/fixture.xml
index 456f9305802..456f9305802 100644
--- a/sonar-core/src/test/resources/org/sonar/core/user/HibernateUserFinderTest/fixture.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/user/DeprecatedUserFinderTest/fixture.xml