Search in sources :

Example 21 with GroupMembership

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());
}
Also used : Group(org.olat.basesecurity.Group) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 22 with GroupMembership

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);
}
Also used : Group(org.olat.basesecurity.Group) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 23 with GroupMembership

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());
}
Also used : Group(org.olat.basesecurity.Group) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 24 with GroupMembership

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));
}
Also used : Group(org.olat.basesecurity.Group) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 25 with GroupMembership

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);
}
Also used : Group(org.olat.basesecurity.Group) GroupMembership(org.olat.basesecurity.GroupMembership) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

GroupMembership (org.olat.basesecurity.GroupMembership)40 Identity (org.olat.core.id.Identity)30 Test (org.junit.Test)26 Group (org.olat.basesecurity.Group)26 GroupImpl (org.olat.basesecurity.model.GroupImpl)8 Date (java.util.Date)6 EntityManager (javax.persistence.EntityManager)6 GroupMembershipImpl (org.olat.basesecurity.model.GroupMembershipImpl)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 GroupMemberView (org.olat.admin.securitygroup.gui.GroupMemberView)2 IdentitiesOfGroupTableDataModel (org.olat.admin.securitygroup.gui.IdentitiesOfGroupTableDataModel)2 SecurityGroupMembershipImpl (org.olat.basesecurity.SecurityGroupMembershipImpl)2 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)2