Search in sources :

Example 31 with GroupMembership

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

Example 32 with GroupMembership

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

Example 33 with GroupMembership

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

Example 34 with GroupMembership

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

Example 35 with GroupMembership

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());
}
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