Search in sources :

Example 6 with BGRights

use of org.olat.group.right.BGRights in project OpenOLAT by OpenOLAT.

the class BGRightManagerTest method findBGRights_wrapped.

@Test
public void findBGRights_wrapped() {
    // create
    RepositoryEntry resource1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry resource2 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry resource3 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "findRights", null, -1, -1, false, false, resource1);
    businessGroupService.addResourceTo(group1, resource2);
    BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "findRights", null, -1, -1, false, false, resource3);
    rightManager.addBGRight("bgr.fr1", group1.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.tutor);
    rightManager.addBGRight("bgr.fr2", group1.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.participant);
    rightManager.addBGRight("bgr.fr3", group2.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.tutor);
    rightManager.addBGRight("bgr.fr4", group2.getBaseGroup(), resource2.getOlatResource(), BGRightsRole.tutor);
    rightManager.addBGRight("bgr.fr5", group2.getBaseGroup(), resource3.getOlatResource(), BGRightsRole.participant);
    dbInstance.commitAndCloseSession();
    // check
    List<BGRights> rights1_1 = rightManager.findBGRights(Collections.singletonList(group1.getBaseGroup()), resource1.getOlatResource());
    Assert.assertNotNull(rights1_1);
    Assert.assertEquals(2, rights1_1.size());
    List<BGRights> rights2_2 = rightManager.findBGRights(Collections.singletonList(group2.getBaseGroup()), resource2.getOlatResource());
    Assert.assertNotNull(rights2_2);
    Assert.assertEquals(1, rights2_2.size());
    List<BGRights> rights2_3 = rightManager.findBGRights(Collections.singletonList(group2.getBaseGroup()), resource3.getOlatResource());
    Assert.assertNotNull(rights2_3);
    Assert.assertEquals(1, rights2_3.size());
    List<Group> groups = new ArrayList<>();
    groups.add(group1.getBaseGroup());
    groups.add(group2.getBaseGroup());
    List<BGRights> rightsAll_1 = rightManager.findBGRights(groups, resource1.getOlatResource());
    Assert.assertNotNull(rightsAll_1);
    Assert.assertEquals(3, rightsAll_1.size());
}
Also used : BGRights(org.olat.group.right.BGRights) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)6 Group (org.olat.basesecurity.Group)6 BusinessGroup (org.olat.group.BusinessGroup)6 BGRights (org.olat.group.right.BGRights)6 HashMap (java.util.HashMap)4 Test (org.junit.Test)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2