Beispiel #1
0
  @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);
  }
Beispiel #2
0
  @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());
  }
Beispiel #3
0
  @Test
  public void createIfNotExists() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    Assert.assertNotNull(node.getIdent());

    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commit();

    // reload and check
    TaskList reloadedTasks = gtaManager.getTaskList(re, node);
    Assert.assertNotNull(reloadedTasks);
    Assert.assertEquals(tasks, reloadedTasks);
    Assert.assertTrue(reloadedTasks instanceof TaskListImpl);
    TaskListImpl tasksImpl = (TaskListImpl) reloadedTasks;
    Assert.assertNotNull(tasksImpl.getCreationDate());
    Assert.assertNotNull(tasksImpl.getLastModified());
    Assert.assertEquals(re, tasksImpl.getEntry());
    Assert.assertEquals(node.getIdent(), tasksImpl.getCourseNodeIdent());
    dbInstance.commit();

    // check that a second call doesn't create a new task list
    TaskList secondTasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(secondTasks);
    dbInstance.commit();
    Assert.assertEquals(tasks, secondTasks);
  }
Beispiel #4
0
  @Test
  public void updateTaskName() {
    // create an individual task
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-7");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-8");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList taskList = gtaManager.createIfNotExists(re, node);
    dbInstance.commit();
    Assert.assertNotNull(taskList);

    // select
    gtaManager.selectTask(id1, taskList, node, new File("work_1.txt"));
    gtaManager.selectTask(id2, taskList, node, new File("work_2.txt"));
    dbInstance.commit();

    // change a name
    int rowUpdated = gtaManager.updateTaskName(taskList, "work_1.txt", "changed_work.txt");
    dbInstance.commitAndCloseSession();
    Assert.assertEquals(1, rowUpdated);

    // check
    Task assignedTaskToId1 = gtaManager.getTask(id1, taskList);
    Assert.assertNotNull(assignedTaskToId1);
    Assert.assertEquals("changed_work.txt", assignedTaskToId1.getTaskName());

    List<Task> assignedTaskToId2 = gtaManager.getTasks(id2, re, node);
    Assert.assertNotNull(assignedTaskToId2);
    Assert.assertEquals(1, assignedTaskToId2.size());
    Assert.assertEquals("work_2.txt", assignedTaskToId2.get(0).getTaskName());
  }
Beispiel #5
0
  /**
   * Create 2 pseudo nodes in a course, and delete the task of the first node and check that the
   * task of second are always there.
   */
  @Test
  public void deleteTaskList_parano() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-9");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-10");
    BusinessGroup businessGroup =
        businessGroupDao.createAndPersist(
            coach, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(participant, businessGroup, GroupRole.participant.name());
    dbInstance.commit();
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);

    // node 1
    GTACourseNode node1 = new GTACourseNode();
    node1.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.group.name());
    TaskList tasks1 = gtaManager.createIfNotExists(re, node1);
    File taskFile = new File("bg.txt");
    Assert.assertNotNull(tasks1);
    dbInstance.commit();

    // node 2
    GTACourseNode node2 = new GTACourseNode();
    node2.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.group.name());
    TaskList tasks2 = gtaManager.createIfNotExists(re, node2);
    Assert.assertNotNull(tasks2);
    dbInstance.commit();

    // select node 1
    AssignmentResponse response1 = gtaManager.selectTask(businessGroup, tasks1, node1, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response1);

    // select node 2
    AssignmentResponse response2 = gtaManager.selectTask(businessGroup, tasks2, node2, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response2);

    // check that there is tasks
    List<Task> assignedTasks1 = gtaManager.getTasks(participant, re, node1);
    Assert.assertNotNull(assignedTasks1);
    Assert.assertEquals(1, assignedTasks1.size());

    List<Task> assignedTasks2 = gtaManager.getTasks(participant, re, node2);
    Assert.assertNotNull(assignedTasks2);
    Assert.assertEquals(1, assignedTasks2.size());

    // delete
    int numOfDeletedObjects = gtaManager.deleteTaskList(re, node1);
    Assert.assertEquals(2, numOfDeletedObjects);
    dbInstance.commitAndCloseSession();

    // check that there isn't any tasks in node 1
    List<Task> deletedAssignedTasks = gtaManager.getTasks(participant, re, node1);
    Assert.assertNotNull(deletedAssignedTasks);
    Assert.assertEquals(0, deletedAssignedTasks.size());

    // but always in node 2
    List<Task> notDeletedAssignedTasks2 = gtaManager.getTasks(participant, re, node2);
    Assert.assertNotNull(notDeletedAssignedTasks2);
    Assert.assertEquals(1, notDeletedAssignedTasks2.size());
  }
Beispiel #6
0
  @Test
  public void getTasks() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-3");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-4");
    BusinessGroup businessGroup =
        businessGroupDao.createAndPersist(
            coach, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(participant, businessGroup, GroupRole.participant.name());
    dbInstance.commit();
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.group.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("bg.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();

    // select
    AssignmentResponse response = gtaManager.selectTask(businessGroup, tasks, node, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response);

    List<Task> assignedTasks = gtaManager.getTasks(participant, re, node);
    Assert.assertNotNull(assignedTasks);
    Assert.assertEquals(1, assignedTasks.size());
  }
  @Test
  public void testRemoveCoach_withBusinessGroups() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    // create a group with members
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
    Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");

    repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());

    BusinessGroup businessGroup =
        businessGroupDao.createAndPersist(
            coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(businessGroup, re);

    // create a publisher
    SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    Assert.assertNotNull(publisher);
    dbInstance.commitAndCloseSession();

    // subscribe
    notificationManager.subscribe(owner, context, publisherData);
    notificationManager.subscribe(member, context, publisherData);
    notificationManager.subscribe(coach, context, publisherData);
    dbInstance.commitAndCloseSession();

    // remove member and coach as coach of the repo entry
    List<Identity> removeIdentities = new ArrayList<>(2);
    removeIdentities.add(member);
    removeIdentities.add(coach);
    repositoryManager.removeTutors(owner, removeIdentities, re);

    // wait for the remove of subscription
    waitForCondition(
        new CheckUnsubscription(member, context, dbInstance, notificationManager), 5000);
    sleep(1000);

    // check that subscription of id1 was deleted but not the ones of id2 and coach
    boolean subscribedMember = notificationManager.isSubscribed(member, context);
    Assert.assertFalse(subscribedMember);
    boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
    Assert.assertTrue(subscribedCoach);
    boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
    Assert.assertTrue(subscribedOwner);
  }
Beispiel #8
0
  @Test
  public void isTasksInProcess_no() {
    // prepare
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commit();

    // check
    boolean inProcess = gtaManager.isTasksInProcess(re, node);
    Assert.assertFalse(inProcess);
  }
  @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 testRemoveParticipant() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    // create a group with members
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
    Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");

    repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(member, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());

    // create a publisher
    SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    Assert.assertNotNull(publisher);
    dbInstance.commitAndCloseSession();

    // subscribe
    notificationManager.subscribe(owner, context, publisherData);
    notificationManager.subscribe(member, context, publisherData);
    notificationManager.subscribe(participant, context, publisherData);
    dbInstance.commitAndCloseSession();

    // remove member and participant as participant of the repo entry
    List<Identity> removeIdentities = new ArrayList<>(2);
    removeIdentities.add(member);
    removeIdentities.add(participant);
    MailPackage mailing = new MailPackage(false);
    repositoryManager.removeParticipants(owner, removeIdentities, re, mailing, false);

    // wait for the remove of subscription
    waitForCondition(
        new CheckUnsubscription(participant, context, dbInstance, notificationManager), 5000);
    sleep(1000);

    // check that subscription of id1 was deleted but not the ones of id2 and coach
    boolean subscribedPart = notificationManager.isSubscribed(participant, context);
    Assert.assertFalse(subscribedPart);
    boolean subscribedMember = notificationManager.isSubscribed(member, context);
    Assert.assertTrue(subscribedMember);
    boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
    Assert.assertTrue(subscribedOwner);
  }
Beispiel #11
0
  @Test
  public void deleteAllTaskLists() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-9");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-10");
    dbInstance.commit();
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());

    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    File taskFile = new File("bg.txt");
    Assert.assertNotNull(tasks);
    dbInstance.commit();

    // select
    AssignmentResponse response = gtaManager.selectTask(participant, tasks, node, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response);

    // check that there is tasks
    List<Task> assignedTasks = gtaManager.getTasks(participant, re, node);
    Assert.assertNotNull(assignedTasks);
    Assert.assertEquals(1, assignedTasks.size());

    // delete
    int numOfDeletedObjects = gtaManager.deleteAllTaskLists(re);
    Assert.assertEquals(2, numOfDeletedObjects);
    dbInstance.commitAndCloseSession();

    // check that there isn't any tasks
    List<Task> deletedAssignedTasks = gtaManager.getTasks(participant, re, node);
    Assert.assertNotNull(deletedAssignedTasks);
    Assert.assertEquals(0, deletedAssignedTasks.size());
  }
Beispiel #12
0
  @Test
  public void getAssignedTasks() {
    // create an individual task
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-7");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-8");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    GTACourseNode node = new GTACourseNode();
    node.getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList taskList = gtaManager.createIfNotExists(re, node);
    dbInstance.commit();
    Assert.assertNotNull(taskList);

    // select
    gtaManager.selectTask(id1, taskList, node, new File("work_1.txt"));
    gtaManager.selectTask(id2, taskList, node, new File("work_2.txt"));

    // get assigned tasks
    List<String> assigned = gtaManager.getAssignedTasks(taskList);
    Assert.assertNotNull(assigned);
    Assert.assertEquals(2, assigned.size());
    Assert.assertTrue(assigned.contains("work_1.txt"));
    Assert.assertTrue(assigned.contains("work_2.txt"));
  }
Beispiel #13
0
  @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);
  }
Beispiel #14
0
  /**
   * Create 2 pseudo courses in a course, and delete the task of the first course and check that the
   * task of second are always there.
   */
  @Test
  public void deleteAllTaskLists_parano() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-20");
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-21");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-22");

    RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    repositoryEntryRelationDao.addRole(coach, re1, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(participant1, re1, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant2, re1, GroupRoles.participant.name());

    // course 1
    GTACourseNode node1 = new GTACourseNode();
    node1
        .getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList tasks1 = gtaManager.createIfNotExists(re1, node1);
    File taskFile = new File("bg.txt");
    Assert.assertNotNull(tasks1);
    dbInstance.commit();

    RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    repositoryEntryRelationDao.addRole(coach, re2, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(participant1, re2, GroupRoles.participant.name());

    // participant 2 course 2
    GTACourseNode node2 = new GTACourseNode();
    node2
        .getModuleConfiguration()
        .setStringValue(GTACourseNode.GTASK_TYPE, GTAType.individual.name());
    TaskList tasks2 = gtaManager.createIfNotExists(re2, node2);
    Assert.assertNotNull(tasks2);
    dbInstance.commit();

    // participant 1 and 2 select course 1
    AssignmentResponse response1_1 = gtaManager.selectTask(participant1, tasks1, node1, taskFile);
    AssignmentResponse response1_2 = gtaManager.selectTask(participant2, tasks1, node1, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response1_1);
    Assert.assertNotNull(response1_2);

    // participant 2 select node 2
    AssignmentResponse response2_2 = gtaManager.selectTask(participant2, tasks2, node2, taskFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(response2_2);

    // check that there is tasks
    List<Task> assignedTasks1_1 = gtaManager.getTasks(participant1, re1, node1);
    Assert.assertNotNull(assignedTasks1_1);
    Assert.assertEquals(1, assignedTasks1_1.size());

    List<Task> assignedTasks1_2 = gtaManager.getTasks(participant2, re1, node1);
    Assert.assertNotNull(assignedTasks1_2);
    Assert.assertEquals(1, assignedTasks1_2.size());

    List<Task> assignedTasks2_2 = gtaManager.getTasks(participant2, re2, node2);
    Assert.assertNotNull(assignedTasks2_2);
    Assert.assertEquals(1, assignedTasks2_2.size());

    // delete
    int numOfDeletedObjects = gtaManager.deleteAllTaskLists(re1);
    Assert.assertEquals(3, numOfDeletedObjects);
    dbInstance.commitAndCloseSession();

    // check that there isn't any tasks in node 1
    List<Task> deletedAssignedTasks1_1 = gtaManager.getTasks(participant1, re1, node1);
    Assert.assertNotNull(deletedAssignedTasks1_1);
    Assert.assertEquals(0, deletedAssignedTasks1_1.size());

    List<Task> deletedAssignedTasks1_2 = gtaManager.getTasks(participant2, re1, node1);
    Assert.assertNotNull(deletedAssignedTasks1_2);
    Assert.assertEquals(0, deletedAssignedTasks1_2.size());

    // but always in node 2
    List<Task> notDeletedAssignedTasks2_2 = gtaManager.getTasks(participant2, re2, node2);
    Assert.assertNotNull(notDeletedAssignedTasks2_2);
    Assert.assertEquals(1, notDeletedAssignedTasks2_2.size());
  }
  @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));
    }
  }
  @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));
    }
  }
  @Test
  public void assignTask_relativeToDateEnrollment() {
    // 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);
    addEnrollmentDate(re, participant1, GroupRoles.participant, -12, Calendar.DATE);
    addEnrollmentDate(re, participant2, GroupRoles.participant, -5, Calendar.DATE);
    dbInstance.commit();

    // create a fake node
    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_ASSIGNMENT_DEADLINE_RELATIVE, 15);
    node.getModuleConfiguration()
        .setStringValue(
            GTACourseNode.GTASK_ASSIGNMENT_DEADLINE_RELATIVE_TO,
            GTARelativeToDates.enrollment.name());

    // need the task list
    TaskList tasks = gtaManager.createIfNotExists(re, node);
    Assert.assertNotNull(tasks);
    dbInstance.commit();

    // participant 1 has still 3 days to choose a task
    // participant 2 has still 10 days to choose a task

    { // check before 1 day
      ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.day);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(0, all.size());
    }

    { // check before 5 days
      ReminderRuleImpl rule = getAssignedTaskRules(5, LaunchUnit.day);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(1, all.size());
      Assert.assertTrue(all.contains(participant1));
    }

    { // check before 1 week
      ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.week);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(1, all.size());
      Assert.assertTrue(all.contains(participant1));
    }

    { // check before 1 month
      ReminderRuleImpl rule = getAssignedTaskRules(1, LaunchUnit.month);
      List<Identity> all = assignTaskRuleSPI.evaluateRule(re, node, rule);

      Assert.assertEquals(2, all.size());
      Assert.assertTrue(all.contains(participant1));
      Assert.assertTrue(all.contains(participant2));
    }
  }