use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
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());
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method createGroupMembership.
@Test
public void createGroupMembership() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-1-");
Group group = groupDao.createGroup();
GroupMembership membership = groupDao.addMembershipTwoWay(group, id, "author");
dbInstance.commit();
Assert.assertNotNull(membership);
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method getMembers.
@Test
public void getMembers() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-3-");
Group group = groupDao.createGroup();
GroupMembership membership = groupDao.addMembershipTwoWay(group, id, "author");
dbInstance.commit();
Assert.assertNotNull(membership);
dbInstance.commitAndCloseSession();
List<Identity> members = groupDao.getMembers(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 removeMemberships_identity.
@Test
public void removeMemberships_identity() {
//
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-9-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-10-");
Group group1 = groupDao.createGroup();
GroupMembership membership1 = groupDao.addMembershipTwoWay(group1, id1, "pilot");
GroupMembership membership2 = groupDao.addMembershipTwoWay(group1, id2, "pilot");
Assert.assertNotNull(membership1);
Assert.assertNotNull(membership2);
dbInstance.commitAndCloseSession();
Group group2 = groupDao.createGroup();
GroupMembership membership3 = groupDao.addMembershipTwoWay(group2, id1, "passanger");
GroupMembership membership4 = groupDao.addMembershipTwoWay(group2, id2, "passanger");
Assert.assertNotNull(membership3);
Assert.assertNotNull(membership4);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> memberships = groupDao.getMemberships(group1, "pilot");
Assert.assertEquals(2, memberships.size());
// remove
groupDao.removeMemberships(id1);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> deletedMemberships1 = groupDao.getMemberships(group1, "pilot");
Assert.assertEquals(1, deletedMemberships1.size());
Assert.assertEquals(membership2, deletedMemberships1.get(0));
List<GroupMembership> deletedMemberships2 = groupDao.getMemberships(group2, "passanger");
Assert.assertEquals(1, deletedMemberships2.size());
Assert.assertEquals(membership4, deletedMemberships2.get(0));
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method removeMembership_byRole.
@Test
public void removeMembership_byRole() {
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");
GroupMembership membership2alt = groupDao.addMembershipTwoWay(group, id2, "commander");
Assert.assertNotNull(membership1);
Assert.assertNotNull(membership2);
Assert.assertNotNull(membership2alt);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> memberships = groupDao.getMemberships(group, "pilot");
Assert.assertEquals(2, memberships.size());
List<GroupMembership> membershipsAlt = groupDao.getMemberships(group, "commander");
Assert.assertEquals(1, membershipsAlt.size());
// remove
groupDao.removeMembership(group, id2, "pilot");
dbInstance.commitAndCloseSession();
// check pilots
List<GroupMembership> stayingMemberships = groupDao.getMemberships(group, "pilot");
Assert.assertEquals(1, stayingMemberships.size());
Identity stayingMember = stayingMemberships.get(0).getIdentity();
Assert.assertNotNull(stayingMember);
Assert.assertEquals(id1, stayingMember);
// check commanders
List<GroupMembership> stayingMembershipsAlt = groupDao.getMemberships(group, "commander");
Assert.assertEquals(1, stayingMembershipsAlt.size());
Identity stayingMemberAlt = stayingMembershipsAlt.get(0).getIdentity();
Assert.assertNotNull(stayingMemberAlt);
Assert.assertEquals(id2, stayingMemberAlt);
}
Aggregations