Search in sources :

Example 11 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class BGAreaManagerTest method startThreadCreateDeleteBGArea.

/**
 * thread 1 : try to create - sleep - delete sleep
 *
 * @param areaName
 * @param maxLoop
 * @param exceptionHolder
 * @param sleepAfterCreate
 * @param sleepAfterDelete
 */
private void startThreadCreateDeleteBGArea(final String areaName, final int maxLoop, final List<Exception> exceptionHolder, final int sleepAfterCreate, final int sleepAfterDelete, final CountDownLatch finishedCount) {
    new Thread(new Runnable() {

        public void run() {
            try {
                for (int i = 0; i < maxLoop; i++) {
                    try {
                        BGArea bgArea = areaManager.createAndPersistBGArea(areaName, "description:" + areaName, c1);
                        if (bgArea != null) {
                            DBFactory.getInstance().closeSession();
                            // created a new bg area
                            sleep(sleepAfterCreate);
                            areaManager.deleteBGArea(bgArea);
                        }
                    } catch (Exception e) {
                        exceptionHolder.add(e);
                    } finally {
                        try {
                            DBFactory.getInstance().closeSession();
                        } catch (Exception e) {
                        // ignore
                        }
                        ;
                    }
                    sleep(sleepAfterDelete);
                }
            } catch (Exception e) {
                exceptionHolder.add(e);
            } finally {
                finishedCount.countDown();
            }
        }
    }).start();
}
Also used : BGArea(org.olat.group.area.BGArea)

Example 12 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class BGAreaManagerTest method updateBGArea.

@Test
public void updateBGArea() {
    OLATResource resource = JunitTestHelper.createRandomResource();
    String areaName = UUID.randomUUID().toString();
    BGArea area = areaManager.createAndPersistBGArea("upd-1-" + areaName, "description:" + areaName, resource);
    dbInstance.commitAndCloseSession();
    // update the area
    area.setName("Hello world");
    area.setDescription("The world is big");
    BGArea updatedArea = areaManager.updateBGArea(area);
    // check output
    Assert.assertNotNull(updatedArea);
    Assert.assertEquals("Hello world", updatedArea.getName());
    Assert.assertEquals("The world is big", updatedArea.getDescription());
    dbInstance.commitAndCloseSession();
    BGArea reloadedArea = areaManager.loadArea(area.getKey());
    Assert.assertNotNull(reloadedArea);
    Assert.assertEquals("Hello world", reloadedArea.getName());
    Assert.assertEquals("The world is big", reloadedArea.getDescription());
}
Also used : BGArea(org.olat.group.area.BGArea) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 13 with BGArea

use of org.olat.group.area.BGArea 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 14 with BGArea

use of org.olat.group.area.BGArea 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 15 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class BusinessGroupImportExportTest method importLearningGroupsAndAreasWithResource.

@Test
public void importLearningGroupsAndAreasWithResource() throws URISyntaxException {
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    URL input = BusinessGroupImportExportTest.class.getResource("learninggroupexport_3.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());
    // check if all three areas are imported
    List<BGArea> areas = areaManager.findBGAreasInContext(resource.getOlatResource());
    Assert.assertNotNull(areas);
    Assert.assertEquals(3, areas.size());
    // check first area
    BGArea area1 = areaManager.findBGArea("Area 1", resource.getOlatResource());
    Assert.assertNotNull(area1);
    Assert.assertEquals("Area 1", area1.getName());
    Assert.assertEquals("<p>Area 1 description</p>", area1.getDescription());
    // check relation to groups
    List<BusinessGroup> groupArea1 = areaManager.findBusinessGroupsOfArea(area1);
    Assert.assertNotNull(groupArea1);
    Assert.assertEquals(2, groupArea1.size());
    Assert.assertTrue(groupArea1.get(0).getName().equals("Export group 1") || groupArea1.get(1).getName().equals("Export group 1"));
    Assert.assertTrue(groupArea1.get(0).getName().equals("Export group 2") || groupArea1.get(1).getName().equals("Export group 2"));
    // check empty area
    BGArea area3 = areaManager.findBGArea("Area 3", resource.getOlatResource());
    Assert.assertNotNull(area1);
    Assert.assertEquals("Area 3", area3.getName());
    // check relation to groups
    List<BusinessGroup> groupArea3 = areaManager.findBusinessGroupsOfArea(area3);
    Assert.assertNotNull(groupArea3);
    Assert.assertEquals(0, groupArea3.size());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BGArea(org.olat.group.area.BGArea) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

BGArea (org.olat.group.area.BGArea)124 BusinessGroup (org.olat.group.BusinessGroup)70 Test (org.junit.Test)68 RepositoryEntry (org.olat.repository.RepositoryEntry)52 ArrayList (java.util.ArrayList)22 Identity (org.olat.core.id.Identity)22 BGAreaReference (org.olat.group.model.BGAreaReference)18 AssessmentModeToArea (org.olat.course.assessment.AssessmentModeToArea)16 CourseEnvironmentMapper (org.olat.course.export.CourseEnvironmentMapper)16 HashSet (java.util.HashSet)14 AssessmentMode (org.olat.course.assessment.AssessmentMode)12 BusinessGroupReference (org.olat.group.model.BusinessGroupReference)12 OLATResource (org.olat.resource.OLATResource)12 AssessmentModeToGroup (org.olat.course.assessment.AssessmentModeToGroup)10 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 CollaborationTools (org.olat.collaboration.CollaborationTools)6 BusinessGroupShort (org.olat.group.BusinessGroupShort)6 File (java.io.File)4 IOException (java.io.IOException)4 Field (java.lang.reflect.Field)4