diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-06-20 15:18:20 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-06-20 15:21:23 +0200 |
commit | 9366cb85997d872d4656eac38bb9ef835789432d (patch) | |
tree | f665ecceb7377276bece5b9b085be491f81a5394 /sonar-core | |
parent | 16029c289bdc8f9eb100a4881c766e2a5949837b (diff) | |
download | sonarqube-9366cb85997d872d4656eac38bb9ef835789432d.tar.gz sonarqube-9366cb85997d872d4656eac38bb9ef835789432d.zip |
SONAR-5329 Add medium test on qprofile activity with author name
Diffstat (limited to 'sonar-core')
5 files changed, 41 insertions, 5 deletions
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} </update> + <insert id="insert" parameterType="User" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> + INSERT INTO users (login, name, email, active, created_at, updated_at) + VALUES (#{login}, #{name}, #{email}, ${_true}, #{createdAt}, #{updatedAt}) + </insert> + </mapper> 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"); @@ -157,6 +165,16 @@ public class UserDaoTest extends AbstractDaoTestCase { } @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 @@ +<dataset> + <users id="1" login="john" name="John" email="jo@hn.com" created_at="2014-06-20" updated_at="2014-06-20" active="[true]"/> +</dataset> |