use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class AssessmentModeManagerTest method createAssessmentModeToArea.
@Test
public void createAssessmentModeToArea() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-1");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
BusinessGroup businessGroup = businessGroupService.createBusinessGroup(author, "as_mode_1", "", null, null, null, null, false, false, null);
BGArea area = areaMgr.createAndPersistBGArea("little area", "My little secret area", entry.getOlatResource());
areaMgr.addBGToBGArea(businessGroup, area);
AssessmentMode mode = createMinimalAssessmentmode(entry);
mode = assessmentModeMgr.persist(mode);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(mode);
AssessmentModeToArea modeToArea = assessmentModeMgr.createAssessmentModeToArea(mode, area);
mode.getAreas().add(modeToArea);
AssessmentMode savedMode = assessmentModeMgr.merge(mode, true);
dbInstance.commitAndCloseSession();
AssessmentMode reloadedMode = assessmentModeMgr.getAssessmentModeById(mode.getKey());
Assert.assertEquals(mode, reloadedMode);
Assert.assertEquals(savedMode, reloadedMode);
Assert.assertNotNull(reloadedMode.getAreas());
Assert.assertEquals(1, reloadedMode.getAreas().size());
Assert.assertEquals(modeToArea, reloadedMode.getAreas().iterator().next());
dbInstance.commitAndCloseSession();
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class AssessmentModeManagerTest method deleteAssessmentMode.
@Test
public void deleteAssessmentMode() {
// prepare the setup
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-1");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
BusinessGroup businessGroup = businessGroupService.createBusinessGroup(author, "as_mode_1", "", null, null, null, null, false, false, null);
AssessmentMode mode = createMinimalAssessmentmode(entry);
mode = assessmentModeMgr.persist(mode);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(mode);
AssessmentModeToGroup modeToGroup = assessmentModeMgr.createAssessmentModeToGroup(mode, businessGroup);
mode.getGroups().add(modeToGroup);
AssessmentMode savedMode = assessmentModeMgr.merge(mode, true);
dbInstance.commitAndCloseSession();
BusinessGroup businessGroupForArea = businessGroupService.createBusinessGroup(author, "as_mode_1", "", null, null, null, null, false, false, null);
BGArea area = areaMgr.createAndPersistBGArea("little area", "My little secret area", entry.getOlatResource());
areaMgr.addBGToBGArea(businessGroupForArea, area);
dbInstance.commitAndCloseSession();
AssessmentModeToArea modeToArea = assessmentModeMgr.createAssessmentModeToArea(savedMode, area);
savedMode.getAreas().add(modeToArea);
savedMode = assessmentModeMgr.merge(savedMode, true);
dbInstance.commitAndCloseSession();
// delete
assessmentModeMgr.delete(savedMode);
dbInstance.commit();
// check
AssessmentMode deletedMode = assessmentModeMgr.getAssessmentModeById(mode.getKey());
Assert.assertNull(deletedMode);
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class AssessmentModeManagerTest method getAssessedIdentities_course_areas.
@Test
public void getAssessedIdentities_course_areas() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-20");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-21");
Identity coach1 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-22");
BusinessGroup businessGroup = businessGroupService.createBusinessGroup(null, "as-mode-5", "", null, null, null, null, false, false, entry);
businessGroupRelationDao.addRole(participant1, businessGroup, GroupRoles.participant.name());
businessGroupRelationDao.addRole(coach1, businessGroup, GroupRoles.coach.name());
Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-23");
Identity coach2 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-24");
repositoryEntryRelationDao.addRole(participant2, entry, GroupRoles.participant.name());
repositoryEntryRelationDao.addRole(coach2, entry, GroupRoles.coach.name());
repositoryEntryRelationDao.addRole(author, entry, GroupRoles.owner.name());
AssessmentMode mode = createMinimalAssessmentmode(entry);
mode.setTargetAudience(AssessmentMode.Target.courseAndGroups);
mode.setApplySettingsForCoach(true);
mode = assessmentModeMgr.persist(mode);
BGArea area = areaMgr.createAndPersistBGArea("area for people", "", entry.getOlatResource());
areaMgr.addBGToBGArea(businessGroup, area);
AssessmentModeToArea modeToArea = assessmentModeMgr.createAssessmentModeToArea(mode, area);
mode.getAreas().add(modeToArea);
mode = assessmentModeMgr.merge(mode, true);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(mode);
Set<Long> assessedIdentityKeys = assessmentModeMgr.getAssessedIdentityKeys(mode);
Assert.assertNotNull(assessedIdentityKeys);
Assert.assertEquals(4, assessedIdentityKeys.size());
Assert.assertFalse(assessedIdentityKeys.contains(author.getKey()));
Assert.assertTrue(assessedIdentityKeys.contains(coach1.getKey()));
Assert.assertTrue(assessedIdentityKeys.contains(participant1.getKey()));
Assert.assertTrue(assessedIdentityKeys.contains(coach2.getKey()));
Assert.assertTrue(assessedIdentityKeys.contains(participant2.getKey()));
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class BGAreaManagerTest method addAndFindByGroups.
@Test
public void addAndFindByGroups() {
// 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());
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);
BusinessGroup group4 = businessGroupService.createBusinessGroup(null, "area-4-group", "area-group-desc", 0, -1, false, false, resource);
dbInstance.commitAndCloseSession();
// add the relation
areaManager.addBGToBGArea(group1, area1);
areaManager.addBGToBGArea(group2, area2);
areaManager.addBGToBGArea(group3, area1);
areaManager.addBGToBGArea(group3, area2);
areaManager.addBGToBGArea(group4, area2);
dbInstance.commitAndCloseSession();
// check find group 1
List<BGArea> areasGroup1 = areaManager.findBGAreasOfBusinessGroups(Collections.singletonList(group1));
Assert.assertNotNull(areasGroup1);
Assert.assertEquals(1, areasGroup1.size());
Assert.assertTrue(areasGroup1.contains(area1));
// check find group 2 and 4 -> only area 2
List<BusinessGroup> groups2_4 = new ArrayList<BusinessGroup>();
groups2_4.add(group2);
groups2_4.add(group4);
List<BGArea> areasGroup2_4 = areaManager.findBGAreasOfBusinessGroups(groups2_4);
Assert.assertNotNull(areasGroup2_4);
Assert.assertEquals(1, areasGroup2_4.size());
Assert.assertTrue(areasGroup2_4.contains(area2));
// check find all groups
List<BusinessGroup> allGroups = new ArrayList<BusinessGroup>();
allGroups.add(group1);
allGroups.add(group2);
allGroups.add(group3);
allGroups.add(group4);
List<BGArea> areasAllGroups = areaManager.findBGAreasOfBusinessGroups(allGroups);
Assert.assertNotNull(areasAllGroups);
Assert.assertEquals(2, areasAllGroups.size());
Assert.assertTrue(areasAllGroups.contains(area1));
Assert.assertTrue(areasAllGroups.contains(area2));
// check empty list
List<BGArea> areasEmpty = areaManager.findBGAreasOfBusinessGroups(Collections.<BusinessGroup>emptyList());
Assert.assertNotNull(areasEmpty);
Assert.assertEquals(0, areasEmpty.size());
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class BGAreaManagerTest method testSynchronisationCreateBGArea.
/**
* Do in different threads ant check that no exception happens :
* 1. create BG-Area
* 5. delete
*/
@Test
public void testSynchronisationCreateBGArea() {
// => 400 x 100ms => 40sec => finished in 50sec
final int maxLoop = 75;
final String areaName = "BGArea_1";
final List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1));
final CountDownLatch finfishCount = new CountDownLatch(3);
BGArea bgArea = areaManager.findBGArea(areaName, c1);
assertNull(bgArea);
startThreadCreateDeleteBGArea(areaName, maxLoop, exceptionHolder, 100, 20, finfishCount);
startThreadCreateDeleteBGArea(areaName, maxLoop, exceptionHolder, 30, 40, finfishCount);
startThreadCreateDeleteBGArea(areaName, maxLoop, exceptionHolder, 15, 20, finfishCount);
// sleep until t1 and t2 should have terminated/excepted
try {
finfishCount.await(120, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.error("", e);
}
// if not -> they are in deadlock and the db did not detect it
for (Exception exception : exceptionHolder) {
log.error("exception: ", exception);
}
assertTrue("Exceptions #" + exceptionHolder.size(), exceptionHolder.size() == 0);
assertEquals("Not all threads has finished", 0, finfishCount.getCount());
}
Aggregations