use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method removeMemberships_group.
@Test
public void removeMemberships_group() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-7-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-8-");
Group group = groupDao.createGroup();
GroupMembership membership1 = groupDao.addMembershipTwoWay(group, id1, "pilot");
GroupMembership membership2 = groupDao.addMembershipTwoWay(group, id2, "pilot");
Assert.assertNotNull(membership1);
Assert.assertNotNull(membership2);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> memberships = groupDao.getMemberships(group, "pilot");
Assert.assertEquals(2, memberships.size());
// remove
groupDao.removeMemberships(group);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> deletedMemberships = groupDao.getMemberships(group, "pilot");
Assert.assertTrue(deletedMemberships.isEmpty());
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method getMemberships.
@Test
public void getMemberships() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-1-");
Group group = groupDao.createGroup();
GroupMembership membership = groupDao.addMembershipTwoWay(group, id, "author");
dbInstance.commit();
Assert.assertNotNull(membership);
dbInstance.getCurrentEntityManager().detach(group);
dbInstance.commitAndCloseSession();
List<GroupMembership> members = groupDao.getMemberships(group, "author");
Assert.assertNotNull(members);
Assert.assertEquals(1, members.size());
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method createGroupMembership_oneWay_v2.
@Test
public void createGroupMembership_oneWay_v2() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-1-");
Group group = groupDao.createGroup();
groupDao.addMembershipOneWay(group, id, "author");
dbInstance.commitAndCloseSession();
GroupImpl loadedGroup = (GroupImpl) groupDao.loadGroup(group.getKey());
Assert.assertNotNull(loadedGroup);
Set<GroupMembership> members = loadedGroup.getMembers();
Assert.assertNotNull(members);
Assert.assertEquals(1, members.size());
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAO method removeMembership.
public int removeMembership(Group group, Identity identity) {
EntityManager em = dbInstance.getCurrentEntityManager();
List<GroupMembership> memberships = em.createNamedQuery("membershipsByGroupAndIdentity", GroupMembership.class).setParameter("groupKey", group.getKey()).setParameter("identityKey", identity.getKey()).getResultList();
for (GroupMembership membership : memberships) {
em.remove(membership);
}
return memberships.size();
}
use of org.olat.basesecurity.GroupMembership in project openolat by klemens.
the class GroupDAOTest method getMemberships_oneWay.
@Test
public void getMemberships_oneWay() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-1-");
Group group = groupDao.createGroup();
groupDao.addMembershipOneWay(group, id, "author");
dbInstance.commitAndCloseSession();
List<GroupMembership> members = groupDao.getMemberships(group, "author");
Assert.assertNotNull(members);
Assert.assertEquals(1, members.size());
}
Aggregations