Search in sources :

Example 76 with RepositoryEntry

use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.

the class EnrollmentManagerConcurrentTest method setup.

/**
 * @see junit.framework.TestCase#setUp()
 */
@Before
public void setup() throws Exception {
    // Identities
    id1 = JunitTestHelper.createAndPersistIdentityAsUser("id1");
    DBFactory.getInstance().closeSession();
    // create business-group with waiting-list
    String bgWithWaitingListName = "Group with WaitingList";
    String bgWithWaitingListDesc = "some short description for Group with WaitingList";
    Boolean enableWaitinglist = new Boolean(true);
    Boolean enableAutoCloseRanks = new Boolean(true);
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    log.info("testAddToWaitingListAndFireEvent: resource=" + resource);
    bgWithWaitingList = businessGroupService.createBusinessGroup(id1, bgWithWaitingListName, bgWithWaitingListDesc, -1, -1, enableWaitinglist, enableAutoCloseRanks, resource);
    bgWithWaitingList.setMaxParticipants(new Integer(2));
    log.info("TEST bgWithWaitingList=" + bgWithWaitingList);
    log.info("TEST bgWithWaitingList.getMaxParticipants()=" + bgWithWaitingList.getMaxParticipants());
    log.info("TEST bgWithWaitingList.getWaitingListEnabled()=" + bgWithWaitingList.getWaitingListEnabled());
    // create mock objects
    testTranslator = Util.createPackageTranslator(EnrollmentManagerConcurrentTest.class, new Locale("de"));
    // Identities
    wg1 = JunitTestHelper.createAndPersistIdentityAsUser("wg1");
    wg1Roles = securityManager.getRoles(wg1);
    wg2 = JunitTestHelper.createAndPersistIdentityAsUser("wg2");
    wg2Roles = securityManager.getRoles(wg2);
    wg3 = JunitTestHelper.createAndPersistIdentityAsUser("wg3");
    wg3Roles = securityManager.getRoles(wg3);
    DBFactory.getInstance().closeSession();
}
Also used : Locale(java.util.Locale) RepositoryEntry(org.olat.repository.RepositoryEntry) Before(org.junit.Before)

Example 77 with RepositoryEntry

use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.

the class GTAReminderRuleTest method assignTask_individual.

@Test
public void assignTask_individual() {
    // prepare a course with a volatile task
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    RepositoryEntry re = deployGTACourse();
    repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name());
    dbInstance.commit();
    GTACourseNode node = getGTACourseNode(re);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    Calendar cal = Calendar.getInstance();
    cal.add(2, Calendar.MONTH);
    node.getModuleConfiguration().setDateValue(GTACourseNode.GTASK_ASSIGNMENT_DEADLINE, cal.getTime());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("solo.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    // select a task
    AssignmentResponse response = gtaManager.selectTask(participant1, tasks, node, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertEquals(AssignmentResponse.Status.ok, response.getStatus());
    // only remind participant 2
    List<Identity> toRemind = assignTaskRuleSPI.getPeopleToRemind(re, node);
    Assert.assertEquals(1, toRemind.size());
    Assert.assertTrue(toRemind.contains(participant2));
    {
        // check before 30 days
        ReminderRuleImpl rule = getAssignedTaskRules(30, LaunchUnit.day);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 5 weeks
        ReminderRuleImpl rule = getAssignedTaskRules(5, LaunchUnit.week);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 1 month
        ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.month);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before  90 days
        ReminderRuleImpl rule = getAssignedTaskRules(90, LaunchUnit.day);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before  12 weeks
        ReminderRuleImpl rule = getAssignedTaskRules(12, LaunchUnit.week);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before  3 month
        ReminderRuleImpl rule = getAssignedTaskRules(3, LaunchUnit.month);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
    {
        // check before 1 year
        ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.year);
        List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(1, all.size());
        Assert.assertTrue(toRemind.contains(participant2));
    }
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) Calendar(java.util.Calendar) TaskList(org.olat.course.nodes.gta.TaskList) GTACourseNode(org.olat.course.nodes.GTACourseNode) AssignmentResponse(org.olat.course.nodes.gta.AssignmentResponse) ArrayList(java.util.ArrayList) TaskList(org.olat.course.nodes.gta.TaskList) List(java.util.List) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) File(java.io.File) Test(org.junit.Test)

Example 78 with RepositoryEntry

use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.

the class GTAReminderRuleTest method submitTask_relativeLifecycle.

@Test
public void submitTask_relativeLifecycle() {
    // prepare a course with a volatile task
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name());
    dbInstance.commit();
    String label = "Life cycle for relative date";
    String softKey = UUID.randomUUID().toString();
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DATE, -5);
    Date from = cal.getTime();
    cal.add(Calendar.DATE, 20);
    Date to = cal.getTime();
    RepositoryEntryLifecycle lifecycle = reLifeCycleDao.create(label, softKey, true, from, to);
    re.setLifecycle(lifecycle);
    re = dbInstance.getCurrentEntityManager().merge(re);
    dbInstance.commit();
    // create a fake node with a relative submit deadline 15 days after the start of the course
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    node.getModuleConfiguration().setBooleanEntry(GTACourseNode.GTASK_RELATIVE_DATES, true);
    node.getModuleConfiguration().setIntValue(GTACourseNode.GTASK_SUBMIT_DEADLINE_RELATIVE, 15);
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_SUBMIT_DEADLINE_RELATIVE_TO, GTARelativeToDates.courseStart.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commitAndCloseSession();
    // the course has start 5 days before, deadline is 15 days after it
    // conclusion the deadline is 10 days from now
    {
        // check before 5 days
        ReminderRuleImpl rule = getSubmitTaskRules(5, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 1 week
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.week);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(0, all.size());
    }
    {
        // check before 10 days
        ReminderRuleImpl rule = getSubmitTaskRules(10, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
    {
        // check before 2 days
        ReminderRuleImpl rule = getSubmitTaskRules(10, LaunchUnit.week);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
    {
        // check before 30 days
        ReminderRuleImpl rule = getSubmitTaskRules(30, LaunchUnit.day);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
    {
        // check before 1 months
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.month);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
    {
        // check before 5 months
        ReminderRuleImpl rule = getSubmitTaskRules(5, LaunchUnit.month);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
    {
        // check before 1 year
        ReminderRuleImpl rule = getSubmitTaskRules(1, LaunchUnit.year);
        List<Identity> all = submissionTaskRuleSPI.evaluateRule(re, node, rule);
        Assert.assertEquals(2, all.size());
        Assert.assertTrue(all.contains(participant1));
        Assert.assertTrue(all.contains(participant2));
    }
}
Also used : ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Calendar(java.util.Calendar) TaskList(org.olat.course.nodes.gta.TaskList) GTACourseNode(org.olat.course.nodes.GTACourseNode) ArrayList(java.util.ArrayList) TaskList(org.olat.course.nodes.gta.TaskList) List(java.util.List) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 79 with RepositoryEntry

use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.

the class GTAReminderRuleTest method assignTask_businessGroup.

@Test
public void assignTask_businessGroup() {
    // prepare
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2");
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-3");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-4");
    Identity participant3 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-5");
    Identity participant4 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-6");
    BusinessGroup businessGroup1 = businessGroupDao.createAndPersist(coach, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    BusinessGroup businessGroup2 = businessGroupDao.createAndPersist(coach, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(participant1, businessGroup1, GroupRole.participant.name());
    businessGroupRelationDao.addRole(participant2, businessGroup1, GroupRole.participant.name());
    businessGroupRelationDao.addRole(participant3, businessGroup2, GroupRole.participant.name());
    businessGroupRelationDao.addRole(participant4, businessGroup2, GroupRole.participant.name());
    dbInstance.commit();
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    businessGroupRelationDao.addRelationToResource(businessGroup1, re);
    businessGroupRelationDao.addRelationToResource(businessGroup2, re);
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.group.name());
    List<Long> groupKeys = new ArrayList<>(2);
    groupKeys.add(businessGroup1.getKey());
    groupKeys.add(businessGroup2.getKey());
    node.getModuleConfiguration().setList(GTACourseNode.GTASK_GROUPS, groupKeys);
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("bg.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();
    // group 1 select a task
    AssignmentResponse response = gtaManager.selectTask(businessGroup1, tasks, node, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertEquals(AssignmentResponse.Status.ok, response.getStatus());
    // only remind group 2
    List<Identity> toRemind = assignTaskRuleSPI.getPeopleToRemind(re, node);
    Assert.assertEquals(2, toRemind.size());
    Assert.assertTrue(toRemind.contains(participant3));
    Assert.assertTrue(toRemind.contains(participant4));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) TaskList(org.olat.course.nodes.gta.TaskList) ArrayList(java.util.ArrayList) GTACourseNode(org.olat.course.nodes.GTACourseNode) AssignmentResponse(org.olat.course.nodes.gta.AssignmentResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) File(java.io.File) Test(org.junit.Test)

Example 80 with RepositoryEntry

use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.

the class ProjectBrokerManagerTest method setup.

@Before
public void setup() throws Exception {
    try {
        id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("project-id1");
        id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("project-id2");
        if (resourceableId == null) {
            Identity author = JunitTestHelper.createAndPersistIdentityAsUser("project-auth-" + UUID.randomUUID());
            RepositoryEntry repositoryEntry = JunitTestHelper.deployDemoCourse(author);
            resourceableId = repositoryEntry.getOlatResource().getResourceableId();
            log.info("Demo course imported - resourceableId: " + resourceableId);
        }
        DBFactory.getInstance().closeSession();
    } catch (Exception e) {
        log.error("", e);
        fail(e.getMessage());
    }
}
Also used : RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Before(org.junit.Before)

Aggregations

RepositoryEntry (org.olat.repository.RepositoryEntry)2108 Test (org.junit.Test)922 Identity (org.olat.core.id.Identity)888 BusinessGroup (org.olat.group.BusinessGroup)344 ArrayList (java.util.ArrayList)258 File (java.io.File)246 ICourse (org.olat.course.ICourse)246 Date (java.util.Date)234 OLATResource (org.olat.resource.OLATResource)200 URI (java.net.URI)176 HttpResponse (org.apache.http.HttpResponse)172 OLATResourceable (org.olat.core.id.OLATResourceable)132 RepositoryManager (org.olat.repository.RepositoryManager)122 Roles (org.olat.core.id.Roles)104 RepositoryService (org.olat.repository.RepositoryService)104 LectureBlock (org.olat.modules.lecture.LectureBlock)94 Path (javax.ws.rs.Path)90 URL (java.net.URL)84 VFSContainer (org.olat.core.util.vfs.VFSContainer)76 WindowControl (org.olat.core.gui.control.WindowControl)74