use of org.olat.basesecurity.GroupMembership in project openolat by klemens.
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 klemens.
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 klemens.
the class GroupDAOTest method createGroupMembership_v2.
@Test
public void createGroupMembership_v2() {
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();
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 klemens.
the class GroupDAOTest method hasRole.
@Test
public void hasRole() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-2-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-2b-");
Group group = groupDao.createGroup();
GroupMembership membership = groupDao.addMembershipTwoWay(group, id, "author");
dbInstance.commit();
Assert.assertNotNull(membership);
dbInstance.commitAndCloseSession();
boolean hasRole = groupDao.hasRole(group, id, "author");
Assert.assertTrue(hasRole);
// negative tests
boolean hasNotRole = groupDao.hasRole(group, id, "pilot");
Assert.assertFalse(hasNotRole);
boolean id2_hasNotRole = groupDao.hasRole(group, id2, "author");
Assert.assertFalse(id2_hasNotRole);
}
use of org.olat.basesecurity.GroupMembership in project openolat by klemens.
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());
}
Aggregations