Search in sources :

Example 31 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class BGAreaManagerTest method addAndDeleteRelations.

@Test
public void addAndDeleteRelations() {
    // create a resource, an area, a group
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    String areaName = UUID.randomUUID().toString();
    BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource.getOlatResource());
    BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource.getOlatResource());
    // create 2 groups
    BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource);
    BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource);
    BusinessGroup group3 = businessGroupService.createBusinessGroup(null, "area-3-group", "area-group-desc", 0, -1, false, false, resource);
    dbInstance.commitAndCloseSession();
    // add the relations
    areaManager.addBGToBGArea(group1, area1);
    areaManager.addBGToBGArea(group2, area1);
    areaManager.addBGToBGArea(group2, area2);
    areaManager.addBGToBGArea(group3, area1);
    dbInstance.commitAndCloseSession();
    // check with find groups
    List<BGArea> areaGroup2 = areaManager.findBGAreasOfBusinessGroup(group2);
    Assert.assertNotNull(areaGroup2);
    Assert.assertEquals(2, areaGroup2.size());
    Assert.assertTrue(areaGroup2.contains(area1));
    Assert.assertTrue(areaGroup2.contains(area2));
    // remove relation to group2
    areaManager.deleteBGtoAreaRelations(group2);
    dbInstance.commitAndCloseSession();
    // check find groups
    List<BGArea> areaGroup2After = areaManager.findBGAreasOfBusinessGroup(group2);
    Assert.assertNotNull(areaGroup2After);
    Assert.assertEquals(0, areaGroup2After.size());
}
Also used : BGArea(org.olat.group.area.BGArea) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 32 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class BGAreaManagerTest method isIdentityInBGArea.

@Test
public void isIdentityInBGArea() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("attendee-1-" + UUID.randomUUID().toString());
    // create a resource, an area, a group
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    String areaName = UUID.randomUUID().toString();
    BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource.getOlatResource());
    BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource.getOlatResource());
    BGArea area3 = areaManager.createAndPersistBGArea("area-3-" + areaName, "description:" + areaName, resource.getOlatResource());
    // create 2 groups
    BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource);
    BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource);
    BusinessGroup group3 = businessGroupService.createBusinessGroup(null, "area-3-group", "area-group-desc", 0, -1, false, false, resource);
    dbInstance.commitAndCloseSession();
    // add the relations
    areaManager.addBGToBGArea(group1, area1);
    areaManager.addBGToBGArea(group2, area1);
    areaManager.addBGToBGArea(group2, area2);
    areaManager.addBGToBGArea(group3, area3);
    dbInstance.commitAndCloseSession();
    // add attendee
    businessGroupRelationDao.addRole(id1, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id1, group2, GroupRoles.coach.name());
    dbInstance.commitAndCloseSession();
    // check in area 1
    boolean testArea1 = areaManager.isIdentityInBGArea(id1, "area-1-" + areaName, null, resource.getOlatResource());
    Assert.assertTrue(testArea1);
    // check in area 1
    boolean testArea2 = areaManager.isIdentityInBGArea(id1, "area-2-" + areaName, null, resource.getOlatResource());
    Assert.assertTrue(testArea2);
    // check in area 1
    boolean testArea3 = areaManager.isIdentityInBGArea(id1, "area-3-" + areaName, null, resource.getOlatResource());
    Assert.assertFalse(testArea3);
    // check with keys
    // check in area 1
    boolean testArea4 = areaManager.isIdentityInBGArea(id1, null, area1.getKey(), resource.getOlatResource());
    Assert.assertTrue(testArea4);
    // check in area 1
    boolean testArea5 = areaManager.isIdentityInBGArea(id1, null, area2.getKey(), resource.getOlatResource());
    Assert.assertTrue(testArea5);
    // check in area 1
    boolean testArea6 = areaManager.isIdentityInBGArea(id1, null, area3.getKey(), resource.getOlatResource());
    Assert.assertFalse(testArea6);
}
Also used : BGArea(org.olat.group.area.BGArea) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 33 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class BGAreaManagerTest method findGroupsByAreas.

@Test
public void findGroupsByAreas() {
    // create a resource, 3 area and 2 group
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    String areaName = UUID.randomUUID().toString();
    BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource.getOlatResource());
    BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource.getOlatResource());
    BGArea area3 = areaManager.createAndPersistBGArea("area-3-" + areaName, "description:" + areaName, resource.getOlatResource());
    // create 2 groups
    BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource);
    BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource);
    dbInstance.commitAndCloseSession();
    // add the relations
    areaManager.addBGToBGArea(group1, area1);
    areaManager.addBGToBGArea(group1, area2);
    areaManager.addBGToBGArea(group1, area3);
    areaManager.addBGToBGArea(group2, area1);
    dbInstance.commitAndCloseSession();
    // check with empty list
    List<BusinessGroup> groupEmpty = areaManager.findBusinessGroupsOfAreas(Collections.<BGArea>emptyList());
    Assert.assertNotNull(groupEmpty);
    Assert.assertEquals(0, groupEmpty.size());
    // check find area 3 -> only group 1
    List<BusinessGroup> groupArea3 = areaManager.findBusinessGroupsOfAreas(Collections.singletonList(area3));
    Assert.assertNotNull(groupArea3);
    Assert.assertEquals(1, groupArea3.size());
    Assert.assertTrue(groupArea3.contains(group1));
    // check find area 1,2 and 3 -> only group 1 and 2
    List<BGArea> allAreas = new ArrayList<BGArea>();
    allAreas.add(area1);
    allAreas.add(area2);
    allAreas.add(area3);
    List<BusinessGroup> groupAllAreas = areaManager.findBusinessGroupsOfAreas(allAreas);
    Assert.assertNotNull(groupAllAreas);
    Assert.assertEquals(2, groupAllAreas.size());
    Assert.assertTrue(groupAllAreas.contains(group1));
    Assert.assertTrue(groupAllAreas.contains(group2));
}
Also used : BGArea(org.olat.group.area.BGArea) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 34 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class BusinessGroupConcurrentTest method concurrentSetLastUsageFor_multipleUser.

@Test
public void concurrentSetLastUsageFor_multipleUser() {
    BusinessGroup group = businessGroupDao.createAndPersist(null, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    dbInstance.commit();
    int numOfThreads = 25;
    final CountDownLatch doneSignal = new CountDownLatch(numOfThreads);
    SetLastUsageThread[] threads = new SetLastUsageThread[numOfThreads];
    for (int i = numOfThreads; i-- > 0; ) {
        Identity id = JunitTestHelper.createAndPersistIdentityAsUser("group-concurent-" + i + "-" + UUID.randomUUID().toString());
        businessGroupRelationDao.addRole(id, group, GroupRoles.participant.name());
        threads[i] = new SetLastUsageThread(group.getKey(), id, doneSignal);
    }
    dbInstance.commitAndCloseSession();
    ;
    for (int i = numOfThreads; i-- > 0; ) {
        threads[i].start();
    }
    try {
        boolean interrupt = doneSignal.await(240, TimeUnit.SECONDS);
        assertTrue("Test takes too long (more than 10s)", interrupt);
    } catch (InterruptedException e) {
        fail("" + e.getMessage());
    }
    int errorCount = 0;
    for (int i = numOfThreads; i-- > 0; ) {
        errorCount += threads[i].getErrorCount();
    }
    Assert.assertEquals(0, errorCount);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) CountDownLatch(java.util.concurrent.CountDownLatch) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 35 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class BusinessGroupImportExportTest method importLearningGroupsWithResource.

@Test
public void importLearningGroupsWithResource() throws URISyntaxException {
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    URL input = BusinessGroupImportExportTest.class.getResource("learninggroupexport_2.xml");
    File importXml = new File(input.toURI());
    businessGroupService.importGroups(resource, importXml);
    dbInstance.commitAndCloseSession();
    // check if all three groups are imported
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, resource, 0, -1);
    Assert.assertNotNull(groups);
    Assert.assertEquals(3, groups.size());
    // get first group (members true, true, false) (no collaboration tools)
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    params.setExactName("Export group 1");
    List<BusinessGroup> group1List = businessGroupService.findBusinessGroups(params, resource, 0, -1);
    Assert.assertNotNull(group1List);
    Assert.assertEquals(1, group1List.size());
    // check settings of the first group
    BusinessGroup group1 = group1List.get(0);
    Assert.assertEquals("Export group 1", group1.getName());
    Assert.assertEquals("<p>Export group 1</p>", group1.getDescription());
    Assert.assertFalse(group1.getAutoCloseRanksEnabled().booleanValue());
    Assert.assertFalse(group1.getWaitingListEnabled().booleanValue());
    // check display members settings
    Assert.assertTrue(group1.isOwnersVisibleIntern());
    Assert.assertTrue(group1.isParticipantsVisibleIntern());
    Assert.assertFalse(group1.isWaitingListVisibleIntern());
    // check collaboration tools
    CollaborationTools toolGroup1 = CollaborationToolsFactory.getInstance().getCollaborationToolsIfExists(group1);
    Assert.assertNotNull(toolGroup1);
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_CALENDAR));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_CHAT));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_CONTACT));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_FOLDER));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_FORUM));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_NEWS));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_PORTFOLIO));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_WIKI));
    // get third group (members true, true, true) (all collaboration tools)
    params.setExactName("Export group 3");
    List<BusinessGroup> group3List = businessGroupService.findBusinessGroups(params, resource, 0, -1);
    Assert.assertNotNull(group3List);
    Assert.assertEquals(1, group3List.size());
    // check settings of the first group
    BusinessGroup group3 = group3List.get(0);
    Assert.assertEquals("Export group 3", group3.getName());
    Assert.assertEquals("<p>Export group 2</p>", group3.getDescription());
    Assert.assertFalse(group3.getAutoCloseRanksEnabled().booleanValue());
    Assert.assertTrue(group3.getWaitingListEnabled().booleanValue());
    Assert.assertEquals(new Integer(25), group3.getMaxParticipants());
    // check display members settings
    Assert.assertTrue(group3.isOwnersVisibleIntern());
    Assert.assertTrue(group3.isParticipantsVisibleIntern());
    Assert.assertTrue(group3.isWaitingListVisibleIntern());
    // check collaboration tools
    CollaborationTools toolGroup3 = CollaborationToolsFactory.getInstance().getCollaborationToolsIfExists(group3);
    Assert.assertNotNull(toolGroup3);
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_CALENDAR));
    // Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_CHAT)); chat is not enabled during unit tests
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_CONTACT));
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_FOLDER));
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_FORUM));
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_NEWS));
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_PORTFOLIO));
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_WIKI));
    Assert.assertEquals("<p>Hello Mitglied</p>", toolGroup3.lookupNews());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) URL(java.net.URL) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Test(org.junit.Test)

Aggregations

BusinessGroup (org.olat.group.BusinessGroup)1034 Test (org.junit.Test)536 Identity (org.olat.core.id.Identity)536 RepositoryEntry (org.olat.repository.RepositoryEntry)324 ArrayList (java.util.ArrayList)224 BusinessGroupService (org.olat.group.BusinessGroupService)116 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)84 BGArea (org.olat.group.area.BGArea)70 CollaborationTools (org.olat.collaboration.CollaborationTools)58 OLATResource (org.olat.resource.OLATResource)56 Date (java.util.Date)54 HashSet (java.util.HashSet)50 File (java.io.File)46 Path (javax.ws.rs.Path)42 Group (org.olat.basesecurity.Group)42 HashMap (java.util.HashMap)38 Roles (org.olat.core.id.Roles)38 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)38 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)38 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)38