Search in sources :

Example 16 with OLATResource

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

the class UserCourseInformationsManagerTest method updateInitialLaunchDates_concurrent.

/**
 * This test is to analyze a red screen
 */
@Test
public void updateInitialLaunchDates_concurrent() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-concurrent-6-" + UUID.randomUUID().toString());
    ICourse course = CoursesWebService.createEmptyCourse(user, "course-concurrent-launch-dates", "course long name", null);
    dbInstance.commitAndCloseSession();
    final int numThreads = 20;
    CountDownLatch latch = new CountDownLatch(numThreads);
    UpdateThread[] threads = new UpdateThread[numThreads];
    for (int i = 0; i < threads.length; i++) {
        OLATResource courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
        threads[i] = new UpdateThread(user, courseResource, userCourseInformationsManager, latch, dbInstance);
    }
    for (int i = 0; i < threads.length; i++) {
        threads[i].start();
    }
    try {
        latch.await(120, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        Assert.fail("Takes too long (more than 120sec)");
    }
    int countErrors = 0;
    for (int i = 0; i < threads.length; i++) {
        countErrors += threads[i].getErrors();
    }
    Assert.assertEquals(0, countErrors);
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) Identity(org.olat.core.id.Identity) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 17 with OLATResource

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

the class UserCourseInformationsManagerTest method getInitialLaunchDates.

@Test
public void getInitialLaunchDates() {
    Identity user1 = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-3-" + UUID.randomUUID().toString());
    Identity user2 = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-4-" + UUID.randomUUID().toString());
    ICourse course = CoursesWebService.createEmptyCourse(user1, "course-launch-dates", "course long name", null);
    dbInstance.commitAndCloseSession();
    OLATResource courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    userCourseInformationsManager.updateUserCourseInformations(courseResource, user1);
    userCourseInformationsManager.updateUserCourseInformations(courseResource, user2);
    dbInstance.commitAndCloseSession();
    List<Identity> users = new ArrayList<Identity>();
    users.add(user1);
    users.add(user2);
    Map<Long, Date> launchDates = userCourseInformationsManager.getInitialLaunchDates(courseResource, users);
    Assert.assertNotNull(launchDates);
    Assert.assertEquals(2, launchDates.size());
    Assert.assertTrue(launchDates.containsKey(user1.getKey()));
    Assert.assertNotNull(launchDates.get(user1.getKey()));
    Assert.assertTrue(launchDates.containsKey(user2.getKey()));
    Assert.assertNotNull(launchDates.get(user2.getKey()));
}
Also used : ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 18 with OLATResource

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

the class UserCourseInformationsManagerTest method getInitialParticiantLaunchDate_businessGroup.

@Test
public void getInitialParticiantLaunchDate_businessGroup() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("init-launch-1-");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("init-launch-2-");
    ICourse course = CoursesWebService.createEmptyCourse(id1, "course-launch-dates", "course long name", null);
    dbInstance.commitAndCloseSession();
    OLATResource courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    userCourseInformationsManager.updateUserCourseInformations(courseResource, id1);
    userCourseInformationsManager.updateUserCourseInformations(courseResource, id2);
    dbInstance.commit();
    // add user to a group
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "initial launch", "tg", null, null, false, false, courseEntry);
    businessGroupRelationDao.addRole(id1, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    Date launchDate = userCourseInformationsManager.getInitialParticipantLaunchDate(courseEntry, group);
    Assert.assertNotNull(launchDate);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 19 with OLATResource

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

the class UserCourseInformationsManagerTest method getInitialLaunchDate_repositoryEntry.

@Test
public void getInitialLaunchDate_repositoryEntry() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-2-" + UUID.randomUUID().toString());
    ICourse course = CoursesWebService.createEmptyCourse(user, "course-launch-dates", "course long name", null);
    dbInstance.commitAndCloseSession();
    OLATResource courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    userCourseInformationsManager.updateUserCourseInformations(courseResource, user);
    dbInstance.commitAndCloseSession();
    Date launchDate = userCourseInformationsManager.getInitialLaunchDate(courseEntry, user);
    Assert.assertNotNull(launchDate);
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 20 with OLATResource

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

the class UserCourseInformationsManagerTest method createUpdateCourseInfos_updateToo_implementationDetails.

/**
 * Check the low level update statement, it's the critical part of the
 * method which update the user course informations.
 */
@Test
public void createUpdateCourseInfos_updateToo_implementationDetails() {
    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();
    int updated1 = ((UserCourseInformationsManagerImpl) userCourseInformationsManager).lowLevelUpdate(courseResource, user);
    dbInstance.commitAndCloseSession();
    Assert.assertEquals(1, updated1);
    int updated2 = ((UserCourseInformationsManagerImpl) userCourseInformationsManager).lowLevelUpdate(courseResource, user);
    dbInstance.commitAndCloseSession();
    Assert.assertEquals(1, updated2);
    UserCourseInformations infos = userCourseInformationsManager.getUserCourseInformations(courseResource, user);
    Assert.assertNotNull(infos);
    Assert.assertNotNull(infos.getIdentity());
    Assert.assertEquals(3, infos.getVisit());
}
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