aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src/test
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-08-11 11:50:20 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-08-11 11:50:28 +0200
commit0e52cad9c679bda4ba5bd2a1487d441a732d2d7b (patch)
tree9fd9a9c04efadd8e684cd25a3f1818f554fad174 /sonar-core/src/test
parentf4f68fce0f7c2fbe9cc8ff08555327f2618e483a (diff)
downloadsonarqube-0e52cad9c679bda4ba5bd2a1487d441a732d2d7b.tar.gz
sonarqube-0e52cad9c679bda4ba5bd2a1487d441a732d2d7b.zip
SONAR-5175 When deleting a group, rows related to this group in perm_templates_groups table should be deleted
Diffstat (limited to 'sonar-core/src/test')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java21
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/remove_by_group-result.xml5
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/remove_by_group.xml7
3 files changed, 30 insertions, 3 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java b/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java
index 5a71651c35e..0bb6f825edd 100644
--- a/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java
@@ -20,6 +20,7 @@
package org.sonar.core.permission;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.utils.System2;
@@ -33,23 +34,28 @@ import java.util.Date;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
Date now;
PermissionTemplateDao permissionTemplateDao;
+ DbSession session;
System2 system = mock(System2.class);
@Before
public void setUpDao() throws ParseException {
+ session = getMyBatis().openSession(false);
now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2013-01-02 01:04:05");
when(system.now()).thenReturn(now.getTime());
permissionTemplateDao = new PermissionTemplateDao(getMyBatis(), system);
}
+ @After
+ public void after() {
+ this.session.close();
+ }
+
@Test
public void should_create_permission_template() throws Exception {
setupData("createPermissionTemplate");
@@ -207,6 +213,15 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
}
@Test
+ public void remove_by_group() throws Exception {
+ setupData("remove_by_group");
+ permissionTemplateDao.removeByGroup(2L, session);
+ session.commit();
+
+ checkTable("remove_by_group", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
+ }
+
+ @Test
public void should_add_group_permission_with_null_name() throws Exception {
setupData("addNullGroupPermissionToTemplate");
permissionTemplateDao.addGroupPermission(1L, null, "new_permission");
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/remove_by_group-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/remove_by_group-result.xml
new file mode 100644
index 00000000000..94ab2fde7ed
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/remove_by_group-result.xml
@@ -0,0 +1,5 @@
+<dataset>
+ <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+ <perm_templates_users/>
+ <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/remove_by_group.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/remove_by_group.xml
new file mode 100644
index 00000000000..2ff5815d855
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionTemplateDaoTest/remove_by_group.xml
@@ -0,0 +1,7 @@
+<dataset>
+ <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+ <perm_templates_users/>
+ <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+ <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="permission_to_remove"/>
+ <perm_templates_groups id="3" template_id="1" group_id="2" permission_reference="permission_to_remove2"/>
+</dataset>