Search in sources :

Example 11 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class EnrollmentManagerConcurrentTest method testEnroll.

// Test for WaitingList
// /////////////////////
/**
 * Enroll 3 identities (group with max-size=2 and waiting-list).
 * Cancel enrollment. Check size after each step.
 */
@Test
public void testEnroll() throws Exception {
    log.info("testEnroll: start...");
    ENCourseNode enNode = new ENCourseNode();
    OLATResource resource = resourceManager.createOLATResourceInstance(CourseModule.class);
    RepositoryEntry addedEntry = repositoryService.create("Ayanami", "-", "Enrollment test course 1", "A JUnit course", resource);
    CourseEnvironment cenv = CourseFactory.createCourse(addedEntry, "Test", "Test", "learningObjectives").getCourseEnvironment();
    // 1. enroll wg1 user
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(wg1);
    UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    CoursePropertyManager coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    log.info("enrollmentManager=" + enrollmentManager);
    log.info("bgWithWaitingList=" + bgWithWaitingList);
    assertTrue("bgWithWaitingList is null", bgWithWaitingList != null);
    log.info("userCourseEnv=" + userCourseEnv);
    log.info("userCourseEnv.getCourseEnvironment()=" + userCourseEnv.getCourseEnvironment());
    enrollmentManager.doEnroll(wg1, wg1Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
    new ArrayList<Long>(), /*enrollableAreaNames*/
    userCourseEnv.getCourseEnvironment().getCourseGroupManager());
    assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    int participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 1);
    // 2. enroll wg2 user
    ienv = new IdentityEnvironment();
    ienv.setIdentity(wg2);
    userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    enrollmentManager.doEnroll(wg2, wg2Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
    new ArrayList<Long>(), /*enrollableAreaNames*/
    userCourseEnv.getCourseEnvironment().getCourseGroupManager());
    assertTrue("Enrollment failed, user='wg2'", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
    assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 2);
    // 3. enroll wg3 user => list is full => waiting-list
    ienv = new IdentityEnvironment();
    ienv.setIdentity(wg3);
    userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    enrollmentManager.doEnroll(wg3, wg3Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
    new ArrayList<Long>(), /*enrollableAreaNames*/
    userCourseEnv.getCourseEnvironment().getCourseGroupManager());
    assertFalse("Wrong enrollment, user='wg3' is in PartipiciantGroup, must be on waiting-list", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
    assertFalse("Wrong enrollment, user='wg3' is in PartipiciantGroup, must be on waiting-list", businessGroupService.hasRoles(wg3, bgWithWaitingList, GroupRoles.participant.name()));
    assertTrue("Wrong enrollment, user='wg3' must be on waiting-list", businessGroupService.hasRoles(wg3, bgWithWaitingList, GroupRoles.waiting.name()));
    assertTrue("Enrollment failed, user='wg2'", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
    assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 2);
    int waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
    assertTrue("Wrong number of waiting-list, must be 1, is " + waitingListCounter, waitingListCounter == 1);
    // cancel enrollment for wg2 => transfer wg3 from waiting-list to participants
    ienv = new IdentityEnvironment();
    ienv.setIdentity(wg2);
    userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    enrollmentManager.doCancelEnrollment(wg2, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator);
    assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
    assertTrue("Enrollment failed, user='wg3'", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
    assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants, must be 2, is " + participantsCounter, participantsCounter == 2);
    waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
    assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
    // cancel enrollment for wg1
    ienv = new IdentityEnvironment();
    ienv.setIdentity(wg1);
    userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    enrollmentManager.doCancelEnrollment(wg1, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator);
    assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
    assertFalse("Cancel enrollment failed, user='wg1' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    assertTrue("Enrollment failed, user='wg3'", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
    participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants, must be 1, is " + participantsCounter, participantsCounter == 1);
    waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
    assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
    // cancel enrollment for wg3
    ienv = new IdentityEnvironment();
    ienv.setIdentity(wg3);
    userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
    coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
    enrollmentManager.doCancelEnrollment(wg3, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
    testTranslator);
    assertFalse("Cancel enrollment failed, user='wg3' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
    assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
    assertFalse("Cancel enrollment failed, user='wg1' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
    participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
    assertTrue("Wrong number of participants, must be 0, is " + participantsCounter, participantsCounter == 0);
    waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
    assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
    log.info("testEnroll: done...");
}
Also used : ENCourseNode(org.olat.course.nodes.ENCourseNode) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) Test(org.junit.Test)

Example 12 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class BGAreaManagerTest method testLoadByKeys.

@Test
public void testLoadByKeys() {
    // create a resource with areas
    OLATResource resource = JunitTestHelper.createRandomResource();
    String areaName = UUID.randomUUID().toString();
    BGArea area1 = areaManager.createAndPersistBGArea("load-1-" + areaName, "description:" + areaName, resource);
    BGArea area2 = areaManager.createAndPersistBGArea("load-2-" + areaName, "description:" + areaName, resource);
    dbInstance.commitAndCloseSession();
    // check if it's robust agains empty argument
    List<BGArea> emptyList = areaManager.loadAreas(Collections.<Long>emptyList());
    Assert.assertNotNull(emptyList);
    Assert.assertTrue(emptyList.isEmpty());
    // check by loading 1 area
    List<BGArea> single = areaManager.loadAreas(Collections.singletonList(area2.getKey()));
    Assert.assertNotNull(single);
    Assert.assertEquals(1, single.size());
    Assert.assertEquals(area2, single.get(0));
    // check by loading 2 areas
    List<Long> areaKeys = new ArrayList<Long>();
    areaKeys.add(area1.getKey());
    areaKeys.add(area2.getKey());
    List<BGArea> areaList = areaManager.loadAreas(areaKeys);
    Assert.assertNotNull(areaList);
    Assert.assertEquals(2, areaList.size());
    Assert.assertTrue(areaList.contains(area1));
    Assert.assertTrue(areaList.contains(area2));
}
Also used : BGArea(org.olat.group.area.BGArea) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 13 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class BGAreaManagerTest method findBGArea.

@Test
public void findBGArea() {
    // create a resource with areas
    OLATResource resource = JunitTestHelper.createRandomResource();
    String areaName = UUID.randomUUID().toString();
    BGArea area1 = areaManager.createAndPersistBGArea("find-1-" + areaName, "description:" + areaName, resource);
    BGArea area2 = areaManager.createAndPersistBGArea("find-2-" + areaName, "description:" + areaName, resource);
    dbInstance.commitAndCloseSession();
    BGArea fArea1 = areaManager.findBGArea("find-1-" + areaName, resource);
    Assert.assertNotNull(fArea1);
    Assert.assertEquals(area1, fArea1);
    BGArea fArea2 = areaManager.findBGArea("find-2-" + areaName, resource);
    Assert.assertNotNull(fArea2);
    Assert.assertEquals(area2, fArea2);
}
Also used : BGArea(org.olat.group.area.BGArea) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 14 with OLATResource

use of org.olat.resource.OLATResource 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 15 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class UserCourseInformationsManagerTest method createUpdateCourseInfos_create.

@Test
public void createUpdateCourseInfos_create() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-1-" + UUID.randomUUID().toString());
    ICourse course = CoursesWebService.createEmptyCourse(user, "course-launch-dates", "course long name", null);
    dbInstance.commitAndCloseSession();
    OLATResource courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    userCourseInformationsManager.updateUserCourseInformations(courseResource, user);
    dbInstance.commitAndCloseSession();
    UserCourseInformations infos = userCourseInformationsManager.getUserCourseInformations(courseResource, user);
    Assert.assertNotNull(infos);
    Assert.assertNotNull(infos.getIdentity());
    Assert.assertNotNull(infos.getResource());
    Assert.assertNotNull(infos.getInitialLaunch());
    Assert.assertNotNull(infos.getRecentLaunch());
    Assert.assertEquals(1, infos.getVisit());
    Assert.assertEquals(infos.getIdentity(), user);
    Assert.assertEquals(course.getResourceableId(), infos.getResource().getResourceableId());
    Assert.assertEquals(course.getResourceableTypeName(), infos.getResource().getResourceableTypeName());
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) Identity(org.olat.core.id.Identity) UserCourseInformations(org.olat.course.assessment.UserCourseInformations) Test(org.junit.Test)

Aggregations

OLATResource (org.olat.resource.OLATResource)706 Test (org.junit.Test)304 RepositoryEntry (org.olat.repository.RepositoryEntry)198 Identity (org.olat.core.id.Identity)170 File (java.io.File)80 Date (java.util.Date)72 Feed (org.olat.modules.webFeed.Feed)72 ArrayList (java.util.ArrayList)64 ICourse (org.olat.course.ICourse)64 RepositoryService (org.olat.repository.RepositoryService)62 OLATResourceable (org.olat.core.id.OLATResourceable)60 BusinessGroup (org.olat.group.BusinessGroup)58 Item (org.olat.modules.webFeed.Item)44 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)38 OLATResourceManager (org.olat.resource.OLATResourceManager)34 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)34 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)30 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)30 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)28 Group (org.olat.basesecurity.Group)26