@Test public void selectTask_identity() { // prepare Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1"); RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false); GTACourseNode node = new GTACourseNode(); node.getModuleConfiguration() .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name()); TaskList tasks = gtaManager.createIfNotExists(re, node); File taskFile = new File("solo.txt"); Assert.assertNotNull(tasks); dbInstance.commit(); // select AssignmentResponse response = gtaManager.selectTask(participant, tasks, node, taskFile); dbInstance.commitAndCloseSession(); // check Assert.assertNotNull(response); Assert.assertNotNull(response.getTask()); Assert.assertEquals(AssignmentResponse.Status.ok, response.getStatus()); Task task = response.getTask(); Assert.assertNotNull(task.getKey()); Assert.assertNull(task.getBusinessGroup()); Assert.assertNotNull(task.getCreationDate()); Assert.assertNotNull(task.getLastModified()); Assert.assertEquals(tasks, task.getTaskList()); Assert.assertEquals("solo.txt", task.getTaskName()); Assert.assertEquals(participant, task.getIdentity()); }
@Test public void isTaskInProcess() { // prepare Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-11"); RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false); GTACourseNode node = new GTACourseNode(); node.getModuleConfiguration() .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name()); TaskList tasks = gtaManager.createIfNotExists(re, node); File taskFile = new File("solo.txt"); Assert.assertNotNull(tasks); dbInstance.commit(); // select AssignmentResponse response = gtaManager.selectTask(participant, tasks, node, taskFile); dbInstance.commitAndCloseSession(); Assert.assertNotNull(response); Assert.assertNotNull(response.getTask()); // check boolean inProcess = gtaManager.isTaskInProcess(re, node, taskFile.getName()); Assert.assertTrue(inProcess); // check dummy file name which cannot be in process boolean notInProcess = gtaManager.isTaskInProcess(re, node, "qwertz"); Assert.assertFalse(notInProcess); }
@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)); }
@Test public void isTaskAssigned() { // create an individual task Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-6"); RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false); GTACourseNode node = new GTACourseNode(); node.getModuleConfiguration() .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name()); TaskList tasks = gtaManager.createIfNotExists(re, node); dbInstance.commit(); Assert.assertNotNull(tasks); // select File taskFile = new File("bg.txt"); AssignmentResponse response = gtaManager.selectTask(participant, tasks, node, taskFile); Assert.assertNotNull(response); Assert.assertEquals(Status.ok, response.getStatus()); // check is assigned boolean assigned = gtaManager.isTaskAssigned(tasks, taskFile.getName()); Assert.assertTrue(assigned); boolean notAssigned = gtaManager.isTaskAssigned(tasks, "noise.txt"); Assert.assertFalse(notAssigned); }
@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 = JunitTestHelper.createAndPersistRepositoryEntry("", false); repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name()); repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name()); dbInstance.commit(); GTACourseNode node = new GTACourseNode(); 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)); } }