aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-07-06 19:12:26 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-07-06 19:12:26 +0200
commit526e4462a75591804fa560f65e536cf4f9a20b72 (patch)
tree61267a16f04672bd61551e348b2fe3e16759c270 /sonar-core/src
parent612c68f47947000e22fb0c09d73b10561702926e (diff)
downloadsonarqube-526e4462a75591804fa560f65e536cf4f9a20b72.tar.gz
sonarqube-526e4462a75591804fa560f65e536cf4f9a20b72.zip
Add tests to MyBatis RoleMapper
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/user/RoleMapperTest.java79
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/countRoles.xml14
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/deleteRolesByResourceId-result.xml14
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/deleteRolesByResourceId.xml14
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/insertRoles-result.xml11
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/insertRoles.xml5
6 files changed, 137 insertions, 0 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/user/RoleMapperTest.java b/sonar-core/src/test/java/org/sonar/core/user/RoleMapperTest.java
new file mode 100644
index 00000000000..2c269694746
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/user/RoleMapperTest.java
@@ -0,0 +1,79 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.user;
+
+import org.apache.ibatis.session.SqlSession;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.core.persistence.AbstractDaoTestCase;
+import org.sonar.core.persistence.MyBatis;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class RoleMapperTest extends AbstractDaoTestCase {
+
+ private SqlSession session;
+
+ @Before
+ public void openSession() {
+ session = getMyBatis().openSession();
+ }
+
+ @After
+ public void closeSession() {
+ MyBatis.closeQuietly(session);
+ }
+
+ @Test
+ public void countRoles() {
+ setupData("countRoles");
+
+ RoleMapper mapper = session.getMapper(RoleMapper.class);
+ assertThat(mapper.countGroupRoles(123L)).isEqualTo(2);
+ assertThat(mapper.countUserRoles(123L)).isEqualTo(1);
+ }
+
+ @Test
+ public void deleteRolesByResourceId() {
+ setupData("deleteRolesByResourceId");
+
+ RoleMapper mapper = session.getMapper(RoleMapper.class);
+ mapper.deleteGroupRolesByResourceId(123L);
+ mapper.deleteUserRolesByResourceId(123L);
+ session.commit();
+
+
+ checkTables("deleteRolesByResourceId", "group_roles", "user_roles");
+ }
+
+ @Test
+ public void insertRoles() {
+ setupData("insertRoles");
+
+ RoleMapper mapper = session.getMapper(RoleMapper.class);
+ mapper.insertGroupRole(new GroupRoleDto().setRole("admin").setGroupId(100L).setResourceId(123L));
+ mapper.insertGroupRole(new GroupRoleDto().setRole("user").setResourceId(123L));// Anyone
+ mapper.insertUserRole(new UserRoleDto().setRole("codeviewer").setUserId(200L).setResourceId(123L));// Anyone
+ session.commit();
+
+ checkTables("insertRoles", "group_roles", "user_roles");
+ }
+}
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/countRoles.xml b/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/countRoles.xml
new file mode 100644
index 00000000000..ec1ed3b076f
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/countRoles.xml
@@ -0,0 +1,14 @@
+<dataset>
+ <groups id="100" name="sonar-administrators"/>
+ <groups id="101" name="sonar-users"/>
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]"/>
+
+ <group_roles id="1" group_id="100" resource_id="123" role="admin"/>
+ <group_roles id="2" group_id="[null]" resource_id="123" role="user"/>
+ <user_roles id="1" user_id="200" resource_id="123" role="codeviewer"/>
+
+ <!-- other resource -->
+ <group_roles id="3" group_id="101" resource_id="999" role="codeviewer"/>
+ <user_roles id="2" user_id="200" resource_id="999" role="codeviewer"/>
+
+</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/deleteRolesByResourceId-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/deleteRolesByResourceId-result.xml
new file mode 100644
index 00000000000..dae82ddd8f8
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/deleteRolesByResourceId-result.xml
@@ -0,0 +1,14 @@
+<dataset>
+ <groups id="100" name="sonar-administrators"/>
+ <groups id="101" name="sonar-users"/>
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]"/>
+
+ <!--<group_roles id="1" group_id="100" resource_id="123" role="admin"/>-->
+ <!--<group_roles id="2" group_id="[null]" resource_id="123" role="user"/>-->
+ <!--<user_roles id="1" user_id="200" resource_id="123" role="codeviewer"/>-->
+
+ <!-- other resource -->
+ <group_roles id="3" group_id="101" resource_id="999" role="codeviewer"/>
+ <user_roles id="2" user_id="200" resource_id="999" role="codeviewer"/>
+
+</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/deleteRolesByResourceId.xml b/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/deleteRolesByResourceId.xml
new file mode 100644
index 00000000000..ec1ed3b076f
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/deleteRolesByResourceId.xml
@@ -0,0 +1,14 @@
+<dataset>
+ <groups id="100" name="sonar-administrators"/>
+ <groups id="101" name="sonar-users"/>
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]"/>
+
+ <group_roles id="1" group_id="100" resource_id="123" role="admin"/>
+ <group_roles id="2" group_id="[null]" resource_id="123" role="user"/>
+ <user_roles id="1" user_id="200" resource_id="123" role="codeviewer"/>
+
+ <!-- other resource -->
+ <group_roles id="3" group_id="101" resource_id="999" role="codeviewer"/>
+ <user_roles id="2" user_id="200" resource_id="999" role="codeviewer"/>
+
+</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/insertRoles-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/insertRoles-result.xml
new file mode 100644
index 00000000000..7a7e6f8e196
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/insertRoles-result.xml
@@ -0,0 +1,11 @@
+<dataset>
+ <groups id="100" name="sonar-administrators"/>
+ <groups id="101" name="sonar-users"/>
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]"/>
+
+ <group_roles id="1" group_id="100" resource_id="123" role="admin"/>
+ <group_roles id="2" group_id="[null]" resource_id="123" role="user"/>
+ <user_roles id="1" user_id="200" resource_id="123" role="codeviewer"/>
+
+
+</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/insertRoles.xml b/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/insertRoles.xml
new file mode 100644
index 00000000000..b99df83bc15
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/user/RoleMapperTest/insertRoles.xml
@@ -0,0 +1,5 @@
+<dataset>
+ <groups id="100" name="sonar-administrators"/>
+ <groups id="101" name="sonar-users"/>
+ <users id="200" login="marius" name="Marius" email="[null]" active="[true]"/>
+</dataset> \ No newline at end of file