Added UserGroupDao methods and tests.
Change-Id: I71d224c5d236cc57ef74749e06d4b28d0bc2cc6a
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/RolePrivilegeDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/RolePrivilegeDaoTest.java
index c16b2c3..4c956ae 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/RolePrivilegeDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/RolePrivilegeDaoTest.java
@@ -33,7 +33,7 @@
@Test
public void createDeleteRole () {
- String roleName = "VC editor";
+ String roleName = "vc editor";
List<PrivilegeType> privileges = new ArrayList<PrivilegeType>();
privileges.add(PrivilegeType.READ);
@@ -50,12 +50,12 @@
@Test
public void updateRole () {
Role role = roleDao.retrieveRoleByName("group member");
- roleDao.updateRoleName(role.getId(), "group member role");
+ roleDao.editRoleName(role.getId(), "group member role");
role = roleDao.retrieveRoleById(role.getId());
assertEquals("group member role", role.getName());
- roleDao.updateRoleName(role.getId(), "group member");
+ roleDao.editRoleName(role.getId(), "group member");
role = roleDao.retrieveRoleById(role.getId());
assertEquals("group member", role.getName());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
index 64521dd..e978e49 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
@@ -1,33 +1,147 @@
package de.ids_mannheim.korap.dao;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.List;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import de.ids_mannheim.korap.constant.GroupMemberStatus;
+import de.ids_mannheim.korap.constant.PredefinedRole;
+import de.ids_mannheim.korap.constant.UserGroupStatus;
+import de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
+import de.ids_mannheim.korap.constant.VirtualCorpusType;
+import de.ids_mannheim.korap.entity.Role;
+import de.ids_mannheim.korap.entity.UserGroup;
import de.ids_mannheim.korap.entity.UserGroupMember;
+import de.ids_mannheim.korap.entity.VirtualCorpus;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.user.User.CorpusAccess;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:test-config.xml")
public class UserGroupDaoTest {
@Autowired
- private UserGroupDao dao;
-
+ private UserGroupDao userGroupDao;
@Autowired
- protected ApplicationContext context;
+ private VirtualCorpusDao virtualCorpusDao;
+ @Autowired
+ private RoleDao roleDao;
@Rule
public ExpectedException thrown = ExpectedException.none();
-
+
+
@Test
- public void testNewGroup () {
+ public void createDeleteNewUserGroup () throws KustvaktException {
+ String groupName = "test group";
+ String createdBy = "test class";
+ // create group
+ int groupId = userGroupDao.createGroup(groupName, createdBy,
+ UserGroupStatus.ACTIVE);
-
+ // retrieve group
+ UserGroup group = userGroupDao.retrieveGroupWithMemberById(groupId);
+ assertEquals(groupName, group.getName());
+ assertEquals(createdBy, group.getCreatedBy());
+ assertEquals(UserGroupStatus.ACTIVE, group.getStatus());
+ assertNull(group.getDeletedBy());
+ // group member
+ List<UserGroupMember> members = group.getMembers();
+ assertEquals(1, members.size());
+ UserGroupMember m = members.get(0);
+ assertEquals(GroupMemberStatus.ACTIVE, m.getStatus());
+ assertEquals(createdBy, m.getCreatedBy());
+ assertEquals(createdBy, m.getUserId());
+
+ // member roles
+ List<Role> roles = roleDao.retrieveRoleByGroupMemberId(m.getId());
+ assertEquals(2, roles.size());
+ assertEquals(PredefinedRole.GROUP_ADMIN.getId(), roles.get(0).getId());
+ assertEquals(PredefinedRole.VC_ADMIN.getId(), roles.get(1).getId());
+
+ //retrieve VC by group
+ List<VirtualCorpus> vc = virtualCorpusDao.retrieveVCByGroup(groupId);
+ assertEquals(0, vc.size());
+
+ // soft delete group
+ userGroupDao.deleteGroup(groupId, createdBy, true);
+ group = userGroupDao.retrieveGroupById(groupId);
+ assertEquals(UserGroupStatus.DELETED, group.getStatus());
+
+ // hard delete
+ userGroupDao.deleteGroup(groupId, createdBy, false);
+ thrown.expect(KustvaktException.class);
+ group = userGroupDao.retrieveGroupById(groupId);
+ }
+
+ @Test
+ public void retrieveGroupWithMembers () throws KustvaktException {
+ List<UserGroupMember> members =
+ userGroupDao.retrieveGroupWithMemberById(1).getMembers();
+ assertEquals(4, members.size());
+
+ UserGroupMember m = members.get(1);
+ List<Role> roles = m.getRoles();
+ assertEquals(2, roles.size());
+ assertEquals(PredefinedRole.GROUP_MEMBER.getId(), roles.get(0).getId());
+ assertEquals(PredefinedRole.VC_MEMBER.getId(), roles.get(1).getId());
+ }
+
+ @Test
+ public void retrieveGroupByUserId () throws KustvaktException {
+ List<UserGroup> group = userGroupDao.retrieveGroupByUserId("dory");
+ assertEquals(1, group.size());
+
+ group = userGroupDao.retrieveGroupByUserId("pearl");
+ assertEquals(0, group.size());
+ }
+
+ @Test
+ public void editExistingGroupName () throws KustvaktException {
+ UserGroup group = userGroupDao.retrieveGroupById(1);
+ String name = group.getName();
+ String newName = "new vc name";
+ userGroupDao.editGroupName(1, newName);
+ group = userGroupDao.retrieveGroupById(1);
+ assertEquals(newName, group.getName());
+
+ userGroupDao.editGroupName(1, name);
+ group = userGroupDao.retrieveGroupById(1);
+ assertEquals(name, group.getName());
+ }
+
+ @Test
+ public void addVCToGroup () throws KustvaktException {
+ // dory group
+ int groupId = 1;
+
+ UserGroup group = userGroupDao.retrieveGroupById(groupId);
+ String createdBy = "dory";
+ String name = "dory new vc";
+ int id = virtualCorpusDao.createVirtualCorpus(name, VirtualCorpusType.PROJECT,
+ CorpusAccess.PUB, "corpusSigle=WPD15", "", "", "", createdBy);
+
+ VirtualCorpus virtualCorpus = virtualCorpusDao.retrieveVCById(id);
+ userGroupDao.addVCToGroup(virtualCorpus, createdBy,
+ VirtualCorpusAccessStatus.ACTIVE, group);
+
+ List<VirtualCorpus> vc = virtualCorpusDao.retrieveVCByGroup(groupId);
+ assertEquals(2, vc.size());
+ assertEquals(name, vc.get(1).getName());
+
+ userGroupDao.deleteVCFromGroup(virtualCorpus.getId(), groupId);
+
+ vc = virtualCorpusDao.retrieveVCByGroup(groupId);
+ assertEquals(1, vc.size());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
index 9774865..d80c454 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
@@ -11,14 +11,13 @@
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import de.ids_mannheim.korap.constant.VirtualCorpusType;
-import de.ids_mannheim.korap.dao.VirtualCorpusDao;
import de.ids_mannheim.korap.entity.VirtualCorpus;
import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.user.User;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:test-config.xml")
@@ -26,8 +25,6 @@
@Autowired
private VirtualCorpusDao dao;
- @Autowired
- protected ApplicationContext context;
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -36,13 +33,9 @@
@Test
public void testPredefinedVC () throws KustvaktException {
// insert vc
- VirtualCorpus vc = new VirtualCorpus();
- vc.setName("predefined VC");
- vc.setCreatedBy("test class");
- vc.setCollectionQuery("corpusSigle=GOE");
- vc.setRequiredAccess("free");
- vc.setType(VirtualCorpusType.PREDEFINED);
- dao.storeVirtualCorpus(vc);
+ int id = dao.createVirtualCorpus("predefined VC", VirtualCorpusType.PREDEFINED,
+ User.CorpusAccess.FREE, "corpusSigle=GOE", "definition",
+ "description", "experimental", "test class");
// select vc
List<VirtualCorpus> vcList =
@@ -50,11 +43,11 @@
assertEquals(2, vcList.size());
// delete vc
- dao.deleteVirtualCorpus(vc.getId());
+ dao.deleteVirtualCorpus(id);
// check if vc has been deleted
thrown.expect(KustvaktException.class);
- vc = dao.retrieveVCById(vc.getId());
+ dao.retrieveVCById(id);
}
diff --git a/full/src/test/resources/test-jdbc.properties b/full/src/test/resources/test-jdbc.properties
index c106656..db40081 100644
--- a/full/src/test/resources/test-jdbc.properties
+++ b/full/src/test/resources/test-jdbc.properties
@@ -8,4 +8,4 @@
jdbc.username=pc
jdbc.password=pc
#jdbc.schemaPath=classpath:db.sqlite
-jdbc.schemaPath=classpath:db.new-sqlite, db.insert
\ No newline at end of file
+jdbc.schemaPath=classpath:db.new-sqlite, db.insert, db.predefined
\ No newline at end of file