From 9366cb85997d872d4656eac38bb9ef835789432d Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 20 Jun 2014 15:18:20 +0200 Subject: SONAR-5329 Add medium test on qprofile activity with author name --- .../src/main/java/org/sonar/core/user/UserDao.java | 7 ++++++ .../main/java/org/sonar/core/user/UserMapper.java | 3 +++ .../resources/org/sonar/core/user/UserMapper.xml | 5 ++++ .../test/java/org/sonar/core/user/UserDaoTest.java | 28 ++++++++++++++++++---- .../sonar/core/user/UserDaoTest/insert-result.xml | 3 +++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/insert-result.xml (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/core/user/UserDao.java b/sonar-core/src/main/java/org/sonar/core/user/UserDao.java index d022ee0c135..afcda180bea 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/UserDao.java +++ b/sonar-core/src/main/java/org/sonar/core/user/UserDao.java @@ -28,6 +28,7 @@ import org.sonar.core.persistence.DaoComponent; import org.sonar.core.persistence.MyBatis; import javax.annotation.CheckForNull; + import java.util.List; /** @@ -101,6 +102,12 @@ public class UserDao implements BatchComponent, ServerComponent, DaoComponent { } } + @CheckForNull + public UserDto insert(SqlSession session, UserDto dto) { + session.getMapper(UserMapper.class).insert(dto); + return dto; + } + /** * Deactivate a user and drops all his preferences. * @return false if the user does not exist, true if the existing user has been deactivated diff --git a/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java b/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java index a2f1dfebe02..6e49630a361 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java @@ -44,6 +44,8 @@ public interface UserMapper { @CheckForNull GroupDto selectGroupByName(String name); + void insert(UserDto userDto); + void removeUserFromGroups(long userId); void deleteUserActiveDashboards(long userId); @@ -63,4 +65,5 @@ public interface UserMapper { void deleteUserRoles(long userId); void deactivateUser(long userId); + } diff --git a/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml b/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml index 3b9c25b8f8d..0a272daa876 100644 --- a/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml @@ -101,4 +101,9 @@ UPDATE users SET active=${_false} WHERE id=#{id} + + INSERT INTO users (login, name, email, active, created_at, updated_at) + VALUES (#{login}, #{name}, #{email}, ${_true}, #{createdAt}, #{updatedAt}) + + diff --git a/sonar-core/src/test/java/org/sonar/core/user/UserDaoTest.java b/sonar-core/src/test/java/org/sonar/core/user/UserDaoTest.java index 2db206ddbf8..981695b23c9 100644 --- a/sonar-core/src/test/java/org/sonar/core/user/UserDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/user/UserDaoTest.java @@ -19,27 +19,35 @@ */ package org.sonar.core.user; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.sonar.api.user.UserQuery; +import org.sonar.api.utils.DateUtils; import org.sonar.core.persistence.AbstractDaoTestCase; +import org.sonar.core.persistence.DbSession; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; import static org.fest.assertions.Assertions.assertThat; public class UserDaoTest extends AbstractDaoTestCase { - private UserDao dao; + UserDao dao; + + DbSession session; @Before public void setUp() { + session = getMyBatis().openSession(false); dao = new UserDao(getMyBatis()); } + @After + public void tearDown() throws Exception { + session.close(); + } + @Test public void selectUserByLogin_ignore_inactive() { setupData("selectActiveUserByLogin"); @@ -156,6 +164,16 @@ public class UserDaoTest extends AbstractDaoTestCase { assertThat(group).isNull(); } + @Test + public void insert_user() { + Date date = DateUtils.parseDate("2014-06-20"); + + UserDto userDto = new UserDto().setId(1L).setLogin("john").setName("John").setEmail("jo@hn.com").setCreatedAt(date).setUpdatedAt(date); + dao.insert(session, userDto); + + checkTables("insert"); + } + @Test public void deactivate_user() { setupData("deactivate_user"); diff --git a/sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/insert-result.xml new file mode 100644 index 00000000000..374d956745d --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/insert-result.xml @@ -0,0 +1,3 @@ + + + -- cgit v1.2.3