@Test
  public void binderAndSectionAndPageAccessRights_byIdentity() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-5");
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-6");
    String title = "My published binder";
    String summary = "My live";
    Binder binder = portfolioService.createNewBinder(title, summary, null, owner);
    dbInstance.commit();
    portfolioService.appendNewSection("Section", "Coached section", null, null, binder);
    dbInstance.commit();
    List<Section> sections = portfolioService.getSections(binder);
    Section section = sections.get(0);
    portfolioService.appendNewPage(owner, "Reviewed page", "", null, null, section);
    portfolioService.addAccessRights(section, identity, PortfolioRoles.coach);

    dbInstance.commit();
    List<Page> pages = portfolioService.getPages(section);
    Page page = pages.get(0);
    portfolioService.addAccessRights(page, identity, PortfolioRoles.reviewer);

    // load right
    List<AccessRights> rights = portfolioService.getAccessRights(binder, identity);
    Assert.assertNotNull(rights);
    Assert.assertEquals(2, rights.size());
  }
示例#2
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());
  }
示例#3
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());
  }
示例#4
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());
  }
  @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);
  }
示例#6
0
  @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 deleteBinder() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("del-binder-");
    Binder binder = portfolioService.createNewBinder("Binder to delete", "Deletion", "", owner);
    SectionRef sectionRef1 =
        portfolioService.appendNewSection("1. section ", "Section 1", null, null, binder);
    dbInstance.commit();
    SectionRef sectionRef2 =
        portfolioService.appendNewSection("2. section ", "Section 2", null, null, binder);
    dbInstance.commit();
    portfolioService.updateBinderUserInformations(binder, owner);
    dbInstance.commit();

    Section reloadedSection1 = portfolioService.getSection(sectionRef1);
    Page page1 =
        portfolioService.appendNewPage(
            owner, "New page", "A brand new page.", null, null, reloadedSection1);
    Section reloadedSection2 = portfolioService.getSection(sectionRef2);
    Page page2 =
        portfolioService.appendNewPage(
            owner, "New page", "A brand new page.", null, null, reloadedSection2);
    Assert.assertNotNull(page1);
    Assert.assertNotNull(page2);
    dbInstance.commitAndCloseSession();

    // delete
    boolean deleted = portfolioService.deleteBinder(binder);
    dbInstance.commit();
    Assert.assertTrue(deleted);
  }
  @Test
  public void searchOwnedBinders() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("binder-owner-");
    Binder binder =
        portfolioService.createNewBinder("Binder 2", "Binder with one section.", null, owner);
    dbInstance.commitAndCloseSession();
    portfolioService.appendNewSection("First section", "My first section.", null, null, binder);
    dbInstance.commitAndCloseSession();
    portfolioService.appendNewSection("Second section", "My second section.", null, null, binder);
    dbInstance.commitAndCloseSession();

    List<Section> sections = portfolioService.getSections(binder);
    for (int i = 0; i < 2; i++) {
      Section section = sections.get(1);
      portfolioService.appendNewPage(owner, "Page-1-" + i, "", null, null, section);
      portfolioService.appendNewPage(owner, "Page-2-" + i, "", null, null, section);
    }

    List<BinderStatistics> rows = portfolioService.searchOwnedBinders(owner);
    Assert.assertNotNull(rows);
    Assert.assertEquals(1, rows.size());

    BinderStatistics myBinder = rows.get(0);
    Assert.assertEquals(2, myBinder.getNumOfSections());
    Assert.assertEquals(4, myBinder.getNumOfPages());
  }
示例#9
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());
  }
示例#10
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);
  }
  @Test
  public void createAndLoadRepositoryEntry() {
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("auth-1");

    String displayName = "Service test 2";
    String resourceName = "ServiceTest";
    String description = "Test the brand new service";
    RepositoryEntry re =
        repositoryService.create(
            initialAuthor, null, resourceName, displayName, description, null, 0);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(re);

    RepositoryEntry loadedEntry = repositoryService.loadByKey(re.getKey());
    Assert.assertNotNull(loadedEntry);
    Assert.assertNotNull(re.getCreationDate());
    Assert.assertNotNull(re.getLastModified());
    Assert.assertNotNull(re.getOlatResource());
    Assert.assertNotNull(loadedEntry.getGroups());
    Assert.assertEquals(1, loadedEntry.getGroups().size());
    // saved?
    Assert.assertEquals(displayName, re.getDisplayname());
    Assert.assertEquals(resourceName, re.getResourcename());
    Assert.assertEquals(description, re.getDescription());
    // default value
    Assert.assertFalse(re.getCanCopy());
    Assert.assertFalse(re.getCanDownload());
    Assert.assertFalse(re.getCanReference());
    Assert.assertEquals(0, re.getAccess());
  }
示例#12
0
  @Test
  public void isTemplateInUse() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-9");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();

    // assign a template
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    Binder template = portfolioService.assignBinder(id, templateBinder, templateEntry, null, null);
    dbInstance.commit();
    Assert.assertNotNull(template);

    boolean inUse = portfolioService.isTemplateInUse(templateBinder, templateEntry, null);
    Assert.assertTrue(inUse);
  }
  @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);
  }
示例#14
0
  @Test
  public void binderAndSectionAndPageAccessRights() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-3");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-4");
    Identity reviewer = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-5");
    String title = "My published binder";
    String summary = "My live";
    Binder binder = portfolioService.createNewBinder(title, summary, null, owner);
    dbInstance.commit();
    portfolioService.appendNewSection("Section", "Coached section", null, null, binder);
    dbInstance.commit();
    List<Section> sections = portfolioService.getSections(binder);
    Section section = sections.get(0);
    portfolioService.appendNewPage(owner, "Reviewed page", "", null, null, section);
    portfolioService.addAccessRights(section, coach, PortfolioRoles.coach);

    dbInstance.commit();
    List<Page> pages = portfolioService.getPages(section);
    Page page = pages.get(0);
    portfolioService.addAccessRights(page, reviewer, PortfolioRoles.reviewer);

    // load right
    List<AccessRights> rights = portfolioService.getAccessRights(binder);
    Assert.assertNotNull(rights);
    Assert.assertEquals(4, rights.size());

    boolean foundOwner = false;
    boolean foundCoach = false;
    boolean foundReviewer = false;

    for (AccessRights right : rights) {
      if (PortfolioRoles.owner.equals(right.getRole()) && owner.equals(right.getIdentity())) {
        foundOwner = true;
      } else if (PortfolioRoles.coach.equals(right.getRole())
          && coach.equals(right.getIdentity())) {
        foundCoach = true;
      } else if (PortfolioRoles.reviewer.equals(right.getRole())
          && reviewer.equals(right.getIdentity())) {
        foundReviewer = true;
      }
    }

    Assert.assertTrue(foundOwner);
    Assert.assertTrue(foundCoach);
    Assert.assertTrue(foundReviewer);
  }
示例#15
0
  @Test
  public void assignTemplate() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-7");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-8");

    // create a template
    String title = "Template binder";
    String summary = "Binder used as a template";
    Binder template = portfolioService.createNewBinder(title, summary, null, owner);
    dbInstance.commit();
    for (int i = 0; i < 4; i++) {
      portfolioService.appendNewSection("Section " + i, "Section " + i, null, null, template);
      dbInstance.commit();
    }
    dbInstance.commitAndCloseSession();
    List<Section> templateSections = portfolioService.getSections(template);
    Assert.assertNotNull(templateSections);
    Assert.assertEquals(4, templateSections.size());

    // user copy the template
    Binder binder = portfolioService.assignBinder(id, template, null, null, new Date());
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(binder);
    Assert.assertNotNull(binder.getKey());
    Assert.assertNotNull(binder.getCopyDate());
    Assert.assertNotNull(template.getTitle(), binder.getTitle());

    List<Section> reloadedSections = portfolioService.getSections(binder);
    Assert.assertNotNull(reloadedSections);
    Assert.assertEquals(4, reloadedSections.size());
    Assert.assertEquals(templateSections.get(0).getTitle(), reloadedSections.get(0).getTitle());
    Assert.assertEquals("Section 1", reloadedSections.get(1).getTitle());
    Assert.assertEquals(templateSections.get(2).getTitle(), reloadedSections.get(2).getTitle());
    Assert.assertEquals("Section 3", reloadedSections.get(3).getTitle());

    Assert.assertEquals(
        templateSections.get(0), ((SectionImpl) reloadedSections.get(0)).getTemplateReference());
    Assert.assertEquals(
        templateSections.get(1), ((SectionImpl) reloadedSections.get(1)).getTemplateReference());
    Assert.assertEquals(
        templateSections.get(2), ((SectionImpl) reloadedSections.get(2)).getTemplateReference());
    Assert.assertEquals(
        templateSections.get(3), ((SectionImpl) reloadedSections.get(3)).getTemplateReference());
  }
示例#16
0
  @Test
  public void syncBinder() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-11");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();

    // make 2 sections
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    // add 2 sections
    for (int i = 0; i < 2; i++) {
      portfolioService.appendNewSection("Section " + i, "Section " + i, null, null, templateBinder);
      dbInstance.commit();
    }

    List<Section> templateSections = portfolioService.getSections(templateBinder);
    Assert.assertNotNull(templateSections);
    Assert.assertEquals(3, templateSections.size());

    // user get a the binder from the template
    Binder binder =
        portfolioService.assignBinder(id, templateBinder, templateEntry, "ac-234", new Date());
    dbInstance.commit();
    Assert.assertNotNull(binder);
    boolean inUse = portfolioService.isTemplateInUse(templateBinder, templateEntry, "ac-234");
    Assert.assertTrue(inUse);

    // update the template with 2 more sections
    for (int i = 2; i < 4; i++) {
      portfolioService.appendNewSection("Section " + i, "Section " + i, null, null, templateBinder);
      dbInstance.commit();
    }

    SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
    Assert.assertNotNull(synchedBinder);
    dbInstance.commit();
    Assert.assertTrue(synchedBinder.isChanged());
    Assert.assertEquals(binder, synchedBinder.getBinder());
    List<Section> synchedSections = portfolioService.getSections(synchedBinder.getBinder());
    Assert.assertEquals(5, synchedSections.size());
  }
  @Test
  public void deleteCoursePermanently() {
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("auth-del-1");
    RepositoryEntry re = JunitTestHelper.deployDemoCourse(initialAuthor);
    dbInstance.commitAndCloseSession();

    Roles roles = new Roles(false, false, false, true, false, false, false);
    ErrorList errors =
        repositoryService.deletePermanently(re, initialAuthor, roles, Locale.ENGLISH);
    Assert.assertNotNull(errors);
    Assert.assertFalse(errors.hasErrors());
  }
示例#18
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());
  }
示例#19
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"));
  }
示例#20
0
  @Test
  public void binderAccessRights() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-2");
    String title = "My private binder";
    String summary = "My live";
    Binder binder = portfolioService.createNewBinder(title, summary, null, owner);
    dbInstance.commitAndCloseSession();

    // load right
    List<AccessRights> rights = portfolioService.getAccessRights(binder);
    Assert.assertNotNull(rights);
    Assert.assertEquals(1, rights.size());
    AccessRights ownerRight = rights.get(0);
    Assert.assertEquals(binder.getKey(), ownerRight.getBinderKey());
    Assert.assertEquals(owner, ownerRight.getIdentity());
    Assert.assertEquals(PortfolioRoles.owner, ownerRight.getRole());
  }
  @Test
  public void createRepositoryEntry() {
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("auth-1");

    String displayName = "ServiceTest";
    String resourceName = "ServiceTest";
    String description = "Test the brand new service";
    RepositoryEntry re =
        repositoryService.create(
            initialAuthor, null, resourceName, displayName, description, null, 0);
    dbInstance.commit();

    Assert.assertNotNull(re);
    Assert.assertNotNull(re.getCreationDate());
    Assert.assertNotNull(re.getLastModified());
    Assert.assertNotNull(re.getOlatResource());
  }
示例#22
0
  @Test
  public void createNewOwnedPorfolio() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-1");
    String title = "My portfolio";
    String summary = "My live";

    Binder binder = portfolioService.createNewBinder(title, summary, null, id);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(binder);
    Assert.assertNotNull(binder.getKey());
    Assert.assertNotNull(binder.getCreationDate());
    Assert.assertNotNull(binder.getLastModified());
    Assert.assertEquals(title, binder.getTitle());
    Assert.assertEquals(summary, binder.getSummary());

    List<Binder> ownedBinders = portfolioService.getOwnedBinders(id);
    Assert.assertNotNull(ownedBinders);
    Assert.assertEquals(1, ownedBinders.size());
    Binder ownedBinder = ownedBinders.get(0);
    Assert.assertNotNull(ownedBinder);
    Assert.assertEquals(binder, ownedBinder);
  }
示例#23
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);
  }
示例#24
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());
  }
示例#25
0
  @Test
  public void syncBinder_moveInNewSection() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-11");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();

    // make 2 sections
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    SectionRef sectionRef0 = portfolioService.getSections(templateBinder).get(0);
    // add 2 sections
    SectionRef sectionRef1 =
        portfolioService.appendNewSection("1 section ", "Section 1", null, null, templateBinder);
    SectionRef sectionRef2 =
        portfolioService.appendNewSection("2 section ", "Section 2", null, null, templateBinder);
    dbInstance.commit();

    // make 4 assignments
    Section templateSection0 = portfolioService.getSection(sectionRef0);
    Section templateSection1 = portfolioService.getSection(sectionRef1);
    Section templateSection2 = portfolioService.getSection(sectionRef2);
    Assignment assignment1_1 =
        portfolioService.addAssignment(
            "1.1 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection1,
            false,
            false,
            false,
            null);
    Assignment assignment1_2 =
        portfolioService.addAssignment(
            "1.2 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection1,
            false,
            false,
            false,
            null);
    Assignment assignment2_1 =
        portfolioService.addAssignment(
            "2.1 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection2,
            false,
            false,
            false,
            null);
    Assignment assignment2_2 =
        portfolioService.addAssignment(
            "2.2 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection2,
            false,
            false,
            false,
            null);
    dbInstance.commit();
    List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
    Assert.assertEquals(4, templateAssignments.size());

    // a user take the binder and synched it a first time
    Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, "72", null);
    dbInstance.commit();
    SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(synchedBinder);
    Assert.assertEquals(binder, synchedBinder.getBinder());

    // start all assignments
    List<Assignment> assignments = portfolioService.getAssignments(binder, null);
    Assert.assertEquals(4, assignments.size());
    for (Assignment assignment : assignments) {
      portfolioService.startAssignment(assignment, id);
      dbInstance.commit();
    }
    dbInstance.commit();

    // check that the student has it's 4 pages
    List<Page> pages = portfolioService.getPages(binder, null);
    Assert.assertEquals(4, pages.size());

    // author create a new section and move an assignment
    SectionRef sectionRef3 =
        portfolioService.appendNewSection("3 section ", "Section 3", null, null, templateBinder);
    dbInstance.commit();

    Section templateSection3 = portfolioService.getSection(sectionRef3);
    Assignment assignment3_1 =
        portfolioService.addAssignment(
            "3.1 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection3,
            false,
            false,
            false,
            null);
    dbInstance.commit();

    // the author move an assigment
    portfolioService.moveAssignment(templateSection1, assignment1_1, templateSection2);
    dbInstance.commit();
    portfolioService.moveAssignment(templateSection2, assignment2_1, templateSection3);
    dbInstance.commitAndCloseSession();

    // check the move
    List<Assignment> templateAssignmentsSection1 =
        portfolioService.getAssignments(templateSection1, null);
    Assert.assertTrue(templateAssignmentsSection1.contains(assignment1_2));
    List<Assignment> templateAssignmentsSection2 =
        portfolioService.getAssignments(templateSection2, null);
    Assert.assertTrue(templateAssignmentsSection2.contains(assignment2_2));
    Assert.assertTrue(templateAssignmentsSection2.contains(assignment1_1));
    List<Assignment> templateAssignmentsSection3 =
        portfolioService.getAssignments(templateSection3, null);
    Assert.assertTrue(templateAssignmentsSection3.contains(assignment2_1));
    Assert.assertTrue(templateAssignmentsSection3.contains(assignment3_1));

    // synched and check the sections order
    SynchedBinder synchedBinder2 = portfolioService.loadAndSyncBinder(binder);
    Binder freshBinder = synchedBinder2.getBinder();
    List<Section> sections = portfolioService.getSections(freshBinder);
    Assert.assertEquals(4, sections.size());
    Section section0 = sections.get(0);
    Section section1 = sections.get(1);
    Section section2 = sections.get(2);
    Section section3 = sections.get(3);
    Assert.assertEquals(templateSection0, section0.getTemplateReference());
    Assert.assertEquals(templateSection1, section1.getTemplateReference());
    Assert.assertEquals(templateSection2, section2.getTemplateReference());
    Assert.assertEquals(templateSection3, section3.getTemplateReference());

    // load pages from section 1
    List<Page> pagesSection1 = portfolioService.getPages(section1);
    Assert.assertEquals(1, pagesSection1.size());
    Page page1_2 = pagesSection1.get(0);
    Assert.assertTrue(page1_2.getTitle().equals("1.2 Assignment"));

    // and pages from section 2
    List<Page> pagesSection2 = portfolioService.getPages(section2);
    Assert.assertEquals(2, pagesSection2.size());
    Page page2_2 = pagesSection2.get(0);
    Page page1_1 = pagesSection2.get(1);
    Assert.assertTrue(
        page2_2.getTitle().equals("1.1 Assignment") || page2_2.getTitle().equals("2.2 Assignment"));
    Assert.assertTrue(
        page1_1.getTitle().equals("1.1 Assignment") || page1_1.getTitle().equals("2.2 Assignment"));

    // and pages from section 3
    List<Page> pagesSection3 = portfolioService.getPages(section3);
    Assert.assertEquals(1, pagesSection3.size());
    Page page2_1 = pagesSection3.get(0);
    Assert.assertTrue(page2_1.getTitle().equals("2.1 Assignment"));

    List<Assignment> assignmentsSection3 = section3.getAssignments();
    Assert.assertEquals(2, assignmentsSection3.size());

    Assignment templateSynchedSection3a = assignmentsSection3.get(0).getTemplateReference();
    Assignment templateSynchedSection3b = assignmentsSection3.get(1).getTemplateReference();
    Assert.assertTrue(
        assignment3_1.equals(templateSynchedSection3a)
            || assignment3_1.equals(templateSynchedSection3b));
    Assert.assertTrue(
        assignment2_1.equals(templateSynchedSection3a)
            || assignment2_1.equals(templateSynchedSection3b));
  }
示例#26
0
  @Test
  public void removeAssignment_usedOne() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-11");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();

    // make 2 sections
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    SectionRef sectionRef = portfolioService.getSections(templateBinder).get(0);
    dbInstance.commit();

    // make 4 assignments
    Section templateSection = portfolioService.getSection(sectionRef);
    Assignment assignment_1 =
        portfolioService.addAssignment(
            "1 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection,
            false,
            false,
            false,
            null);
    Assignment assignment_2 =
        portfolioService.addAssignment(
            "2 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection,
            false,
            false,
            false,
            null);
    Assignment assignment_3 =
        portfolioService.addAssignment(
            "3 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection,
            false,
            false,
            false,
            null);
    Assignment assignment_4 =
        portfolioService.addAssignment(
            "4 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection,
            false,
            false,
            false,
            null);
    dbInstance.commit();
    List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
    Assert.assertEquals(4, templateAssignments.size());
    Assert.assertTrue(templateAssignments.contains(assignment_1));
    Assert.assertTrue(templateAssignments.contains(assignment_2));
    Assert.assertTrue(templateAssignments.contains(assignment_3));
    Assert.assertTrue(templateAssignments.contains(assignment_4));

    // synched and check the sections order
    Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, null, null);
    SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
    binder = synchedBinder.getBinder();
    dbInstance.commitAndCloseSession();

    List<Assignment> assignments = portfolioService.getAssignments(binder, null);
    portfolioService.startAssignment(assignments.get(0), id);
    portfolioService.startAssignment(assignments.get(1), id);
    portfolioService.startAssignment(assignments.get(2), id);
    portfolioService.startAssignment(assignments.get(3), id);
    dbInstance.commit();

    List<Section> sections = portfolioService.getSections(binder);
    List<Page> pages = portfolioService.getPages(sections.get(0));
    Assert.assertEquals(4, pages.size());

    // delete an assignment
    boolean ok = portfolioService.deleteAssignment(assignment_3);
    Assert.assertTrue(ok);
    dbInstance.commitAndCloseSession();

    // sync the binder
    SynchedBinder reSynchedBinder = portfolioService.loadAndSyncBinder(binder);
    binder = reSynchedBinder.getBinder();
    dbInstance.commitAndCloseSession();

    // deleting an assignment doesn't delete the pages
    List<Page> allPages = portfolioService.getPages(sections.get(0));
    Assert.assertEquals(4, allPages.size());

    // sync twice
    SynchedBinder reReSynchedBinder = portfolioService.loadAndSyncBinder(binder);
    binder = reReSynchedBinder.getBinder();
    dbInstance.commitAndCloseSession();
  }
示例#27
0
  @Test
  public void syncBinder_moveInNewSection_moreComplexCase() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-11");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();

    // make 2 sections
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    SectionRef sectionRef0 = portfolioService.getSections(templateBinder).get(0);
    // add 2 sections
    SectionRef sectionRef1 =
        portfolioService.appendNewSection("1 section ", "Section 1", null, null, templateBinder);
    SectionRef sectionRef2 =
        portfolioService.appendNewSection("2 section ", "Section 2", null, null, templateBinder);
    dbInstance.commit();

    // make 4 assignments
    Section templateSection0 = portfolioService.getSection(sectionRef0);
    Section templateSection1 = portfolioService.getSection(sectionRef1);
    Section templateSection2 = portfolioService.getSection(sectionRef2);
    Assignment assignment0_1 =
        portfolioService.addAssignment(
            "0.1 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection0,
            false,
            false,
            false,
            null);
    Assignment assignment1_1 =
        portfolioService.addAssignment(
            "1.1 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection1,
            false,
            false,
            false,
            null);
    Assignment assignment1_2 =
        portfolioService.addAssignment(
            "1.2 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection1,
            false,
            false,
            false,
            null);
    Assignment assignment2_1 =
        portfolioService.addAssignment(
            "2.1 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection2,
            false,
            false,
            false,
            null);
    Assignment assignment2_2 =
        portfolioService.addAssignment(
            "2.2 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection2,
            false,
            false,
            false,
            null);
    dbInstance.commit();
    List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
    Assert.assertEquals(5, templateAssignments.size());

    // a user take the binder and synched it a first time
    Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, "74", null);
    dbInstance.commit();
    SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(synchedBinder);
    Assert.assertEquals(binder, synchedBinder.getBinder());

    // start all assignments
    List<Assignment> assignments = portfolioService.getAssignments(binder, null);
    Assert.assertEquals(5, assignments.size());
    for (Assignment assignment : assignments) {
      portfolioService.startAssignment(assignment, id);
      dbInstance.commit();
    }
    dbInstance.commit();

    // check that the student has it's 4 pages
    List<Page> pages = portfolioService.getPages(binder, null);
    Assert.assertEquals(5, pages.size());

    // author create 2 new sections, move the 4 to the top
    SectionRef sectionRef3 =
        portfolioService.appendNewSection("3 section ", "Section 3", null, null, templateBinder);
    SectionRef sectionRef4 =
        portfolioService.appendNewSection("4 section ", "Section 4", null, null, templateBinder);
    dbInstance.commit();

    Section templateSection3 = portfolioService.getSection(sectionRef3);
    Section templateSection4 = portfolioService.getSection(sectionRef4);

    templateBinder = portfolioService.moveUpSection(templateBinder, templateSection4);
    dbInstance.commit();
    templateBinder = portfolioService.moveUpSection(templateBinder, templateSection4);
    dbInstance.commit();
    templateBinder = portfolioService.moveUpSection(templateBinder, templateSection4);
    dbInstance.commit();
    templateBinder = portfolioService.moveUpSection(templateBinder, templateSection4);
    dbInstance.commit();

    // add new assignment
    Assignment assignment3_1 =
        portfolioService.addAssignment(
            "3.1 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection3,
            false,
            false,
            false,
            null);
    Assignment assignment4_1 =
        portfolioService.addAssignment(
            "4.1 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection4,
            false,
            false,
            false,
            null);
    dbInstance.commit();

    // the author move some assignments
    portfolioService.moveAssignment(templateSection1, assignment1_1, templateSection3);
    dbInstance.commit();
    portfolioService.moveAssignment(templateSection1, assignment1_2, templateSection2);
    dbInstance.commit();
    portfolioService.moveAssignment(templateSection2, assignment2_1, templateSection3);
    dbInstance.commit();
    portfolioService.moveAssignment(templateSection2, assignment2_2, templateSection4);
    dbInstance.commitAndCloseSession();

    // update the data of some assignments
    assignment2_1 = assignmentDao.loadAssignmentByKey(assignment2_1.getKey());
    assignment4_1 = assignmentDao.loadAssignmentByKey(assignment4_1.getKey());
    assignment2_1 =
        portfolioService.updateAssignment(
            assignment2_1,
            "2.1 Assignment",
            "Assignment 2 description",
            "",
            AssignmentType.essay,
            false,
            false,
            false,
            null);
    assignment4_1 =
        portfolioService.updateAssignment(
            assignment4_1,
            "4.1 Assignment",
            "Assignment 4 description",
            "",
            AssignmentType.document,
            false,
            false,
            false,
            null);
    dbInstance.commit();

    // check the move
    List<Assignment> templateAssignmentsSection0 =
        portfolioService.getAssignments(templateSection0, null);
    Assert.assertTrue(templateAssignmentsSection0.contains(assignment0_1));

    List<Assignment> templateAssignmentsSection1 =
        portfolioService.getAssignments(templateSection1, null);
    Assert.assertTrue(templateAssignmentsSection1.isEmpty());
    List<Assignment> templateAssignmentsSection2 =
        portfolioService.getAssignments(templateSection2, null);
    Assert.assertEquals(1, templateAssignmentsSection2.size());
    Assert.assertTrue(templateAssignmentsSection2.contains(assignment1_2));
    List<Assignment> templateAssignmentsSection3 =
        portfolioService.getAssignments(templateSection3, null);
    Assert.assertEquals(3, templateAssignmentsSection3.size());
    Assert.assertTrue(templateAssignmentsSection3.contains(assignment1_1));
    Assert.assertTrue(templateAssignmentsSection3.contains(assignment2_1));
    Assert.assertTrue(templateAssignmentsSection3.contains(assignment3_1));
    List<Assignment> templateAssignmentsSection4 =
        portfolioService.getAssignments(templateSection4, null);
    Assert.assertEquals(2, templateAssignmentsSection4.size());
    Assert.assertTrue(templateAssignmentsSection4.contains(assignment2_2));
    Assert.assertTrue(templateAssignmentsSection4.contains(assignment4_1));

    // synched and check the sections order
    SynchedBinder synchedBinder2 = portfolioService.loadAndSyncBinder(binder);
    Binder freshBinder = synchedBinder2.getBinder();
    dbInstance.commitAndCloseSession();

    List<Section> sections = portfolioService.getSections(freshBinder);
    Assert.assertEquals(5, sections.size());
    Section section4 = sections.get(0);
    Section section0 = sections.get(1);
    Section section1 = sections.get(2);
    Section section2 = sections.get(3);
    Section section3 = sections.get(4);
    Assert.assertEquals(templateSection0, section0.getTemplateReference());
    Assert.assertEquals(templateSection1, section1.getTemplateReference());
    Assert.assertEquals(templateSection2, section2.getTemplateReference());
    Assert.assertEquals(templateSection3, section3.getTemplateReference());
    Assert.assertEquals(templateSection4, section4.getTemplateReference());

    // load pages from section 0
    List<Page> pagesSection0 = portfolioService.getPages(section0);
    Assert.assertEquals(1, pagesSection0.size());
    Page page0_1 = pagesSection0.get(0);
    Assert.assertTrue(page0_1.getTitle().equals("0.1 Assignment"));
    // load pages from section 1
    List<Page> pagesSection1 = portfolioService.getPages(section1);
    Assert.assertTrue(pagesSection1.isEmpty());
    // and pages from section 2
    List<Page> pagesSection2 = portfolioService.getPages(section2);
    Assert.assertEquals(1, pagesSection2.size());
    Page page1_2 = pagesSection2.get(0);
    Assert.assertTrue(page1_2.getTitle().equals("1.2 Assignment"));
    // and pages from section 3
    List<Page> pagesSection3 = portfolioService.getPages(section3);
    Assert.assertEquals(2, pagesSection3.size());
    Page page1_1 = pagesSection3.get(0);
    Page page2_1 = pagesSection3.get(1);
    Assert.assertTrue(
        page1_1.getTitle().equals("1.1 Assignment") || page1_1.getTitle().equals("2.1 Assignment"));
    Assert.assertTrue(
        page2_1.getTitle().equals("1.1 Assignment") || page2_1.getTitle().equals("2.1 Assignment"));
    // and pages from section 4
    List<Page> pagesSection4 = portfolioService.getPages(section4);
    Assert.assertEquals(1, pagesSection4.size());
    Page page2_2 = pagesSection4.get(0);
    Assert.assertTrue(page2_2.getTitle().equals("2.2 Assignment"));

    // check the assignments
    // section 0
    List<Assignment> assignmentsSection0 = section0.getAssignments();
    Assert.assertEquals(1, assignmentsSection0.size());
    Assignment templateSynchedSection0a = assignmentsSection0.get(0).getTemplateReference();
    Assert.assertTrue(assignment0_1.equals(templateSynchedSection0a));
    // section 1
    List<Assignment> assignmentsSection1 = section1.getAssignments();
    Assert.assertTrue(assignmentsSection1.isEmpty());
    // section 2
    List<Assignment> assignmentsSection2 = section2.getAssignments();
    Assert.assertEquals(1, assignmentsSection2.size());
    Assignment templateSynchedSection2a = assignmentsSection2.get(0).getTemplateReference();
    Assert.assertTrue(assignment1_2.equals(templateSynchedSection2a));
    // section 3
    List<Assignment> assignmentsSection3 = section3.getAssignments();
    Assert.assertEquals(3, assignmentsSection3.size());
    Assignment templateSynchedSection3a = assignmentsSection3.get(0).getTemplateReference();
    Assignment templateSynchedSection3b = assignmentsSection3.get(1).getTemplateReference();
    Assignment templateSynchedSection3c = assignmentsSection3.get(2).getTemplateReference();
    Assert.assertTrue(
        assignment3_1.equals(templateSynchedSection3a)
            || assignment3_1.equals(templateSynchedSection3b)
            || assignment3_1.equals(templateSynchedSection3c));
    Assert.assertTrue(
        assignment2_1.equals(templateSynchedSection3a)
            || assignment2_1.equals(templateSynchedSection3b)
            || assignment2_1.equals(templateSynchedSection3c));
    Assert.assertTrue(
        assignment1_1.equals(templateSynchedSection3a)
            || assignment1_1.equals(templateSynchedSection3b)
            || assignment1_1.equals(templateSynchedSection3c));
    // section 4
    List<Assignment> assignmentsSection4 = section4.getAssignments();
    Assert.assertEquals(2, assignmentsSection4.size());
    Assignment templateSynchedSection4a = assignmentsSection4.get(0).getTemplateReference();
    Assignment templateSynchedSection4b = assignmentsSection4.get(1).getTemplateReference();
    Assert.assertTrue(
        assignment2_2.equals(templateSynchedSection4a)
            || assignment2_2.equals(templateSynchedSection4b));
    Assert.assertTrue(
        assignment4_1.equals(templateSynchedSection4a)
            || assignment4_1.equals(templateSynchedSection4b));

    // check update of assignments
    Assert.assertEquals("Assignment 2 description", assignment2_1.getSummary());
    Assert.assertEquals("Assignment 4 description", assignment4_1.getSummary());
  }
示例#28
0
  @Test
  public void removeAssignment() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-10");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();

    // make the binder and the section
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    SectionRef sectionRef = portfolioService.getSections(templateBinder).get(0);
    dbInstance.commit();

    // make 4 assignments
    Section templateSection = portfolioService.getSection(sectionRef);
    Assignment assignment_1 =
        portfolioService.addAssignment(
            "1 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection,
            false,
            false,
            false,
            null);
    Assignment assignment_2 =
        portfolioService.addAssignment(
            "2 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection,
            false,
            false,
            false,
            null);
    Assignment assignment_3 =
        portfolioService.addAssignment(
            "3 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection,
            false,
            false,
            false,
            null);
    Assignment assignment_4 =
        portfolioService.addAssignment(
            "3 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection,
            false,
            false,
            false,
            null);
    dbInstance.commitAndCloseSession();

    boolean ok = portfolioService.deleteAssignment(assignment_3);
    Assert.assertTrue(ok);
    dbInstance.commitAndCloseSession();

    List<Assignment> assignments = portfolioService.getSection(sectionRef).getAssignments();
    Assert.assertNotNull(assignments);
    Assert.assertEquals(3, assignments.size());
    Assert.assertTrue(assignments.contains(assignment_1));
    Assert.assertTrue(assignments.contains(assignment_2));
    Assert.assertFalse(assignments.contains(assignment_3));
    Assert.assertTrue(assignments.contains(assignment_4));
  }
示例#29
0
  @Test
  public void deleteSynchedBinder() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-12");
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-13");
    RepositoryEntry templateEntry = createTemplate(owner, "Template", "TE");
    dbInstance.commitAndCloseSession();

    // get section
    Binder templateBinder = portfolioService.getBinderByResource(templateEntry.getOlatResource());
    SectionRef sectionRef = portfolioService.getSections(templateBinder).get(0);
    dbInstance.commit();

    // make 2 assignments
    Section templateSection = portfolioService.getSection(sectionRef);
    Assignment assignment_1 =
        portfolioService.addAssignment(
            "1 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection,
            false,
            false,
            false,
            null);
    Assignment assignment_2 =
        portfolioService.addAssignment(
            "2 Assignment",
            "",
            "",
            AssignmentType.essay,
            templateSection,
            false,
            false,
            false,
            null);
    dbInstance.commit();
    List<Assignment> templateAssignments = portfolioService.getAssignments(templateBinder, null);
    Assert.assertEquals(2, templateAssignments.size());

    // synched and check the sections order
    Binder binder = portfolioService.assignBinder(id, templateBinder, templateEntry, null, null);
    SynchedBinder synchedBinder = portfolioService.loadAndSyncBinder(binder);
    binder = synchedBinder.getBinder();
    dbInstance.commitAndCloseSession();

    List<Assignment> assignments = portfolioService.getAssignments(binder, null);
    Assignment startedAssignment_1 = portfolioService.startAssignment(assignments.get(0), id);
    Assignment startedAssignment_2 = portfolioService.startAssignment(assignments.get(1), id);
    Long startedPageKey_1 = startedAssignment_1.getPage().getKey();
    Long startedPageKey_2 = startedAssignment_2.getPage().getKey();
    dbInstance.commitAndCloseSession();

    // add some comments
    OLATResourceable startedPageOres_1 =
        OresHelper.createOLATResourceableInstance(Page.class, startedPageKey_1);
    userCommentsDao.createComment(id, startedPageOres_1, null, "Hello");

    // delete
    boolean deleted = portfolioService.deleteBinder(binder);
    dbInstance.commit();
    Assert.assertTrue(deleted);

    // check that the template is save
    Assignment reloadAssignment_1 = assignmentDao.loadAssignmentByKey(assignment_1.getKey());
    Assert.assertNotNull(reloadAssignment_1);
    Assignment reloadAssignment_2 = assignmentDao.loadAssignmentByKey(assignment_2.getKey());
    Assert.assertNotNull(reloadAssignment_2);

    // check that the binder is really deleted
    Binder reloadedBinder = binderDao.loadByKey(binder.getKey());
    Assert.assertNull(reloadedBinder);

    Assignment reloadStartedAssignment_1 =
        assignmentDao.loadAssignmentByKey(startedAssignment_1.getKey());
    Assert.assertNull(reloadStartedAssignment_1);
    Assignment reloadStartedAssignment_2 =
        assignmentDao.loadAssignmentByKey(startedAssignment_2.getKey());
    Assert.assertNull(reloadStartedAssignment_2);

    Page reloadedStartedPage_1 = pageDao.loadByKey(startedPageKey_1);
    Assert.assertNull(reloadedStartedPage_1);
    Page reloadedStartedPage_2 = pageDao.loadByKey(startedPageKey_2);
    Assert.assertNull(reloadedStartedPage_2);
  }
  @Test
  public void deleteCourseSoftly() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
    Identity coachGroup = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("auth-del-1");
    RepositoryEntry re = JunitTestHelper.deployDemoCourse(initialAuthor);
    dbInstance.commitAndCloseSession();

    // add business group
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            coachGroup, "Relation 1", "tg", null, null, false, false, re);
    businessGroupService.addResourceTo(group, re);
    dbInstance.commit();

    // catalog
    List<CatalogEntry> rootEntries = catalogManager.getRootCatalogEntries();
    CatalogEntry catEntry = catalogManager.createCatalogEntry();
    catEntry.setName("Soft");
    catEntry.setRepositoryEntry(re);
    catEntry.setParent(rootEntries.get(0));
    catEntry.setOwnerGroup(securityManager.createAndPersistSecurityGroup());
    catalogManager.saveCatalogEntry(catEntry);
    dbInstance.commit();

    // check the catalog
    List<CatalogEntry> catEntries = catalogManager.getCatalogCategoriesFor(re);
    Assert.assertNotNull(catEntries);
    Assert.assertEquals(1, catEntries.size());

    // add owner, coach...
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());
    dbInstance.commit();

    // kill it softly like A. Keys
    repositoryService.deleteSoftly(re, initialAuthor, false);
    dbInstance.commit();

    // check that the members are removed
    List<Identity> coachAndParticipants =
        repositoryEntryRelationDao.getMembers(
            re,
            RepositoryEntryRelationType.both,
            GroupRoles.coach.name(),
            GroupRoles.participant.name());
    Assert.assertNotNull(coachAndParticipants);
    Assert.assertEquals(0, coachAndParticipants.size());

    // check the relations between course and business groups
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, re, 0, -1);
    Assert.assertNotNull(groups);
    Assert.assertEquals(0, groups.size());

    // check the catalog
    List<CatalogEntry> removedCatEntries = catalogManager.getCatalogCategoriesFor(re);
    Assert.assertNotNull(removedCatEntries);
    Assert.assertEquals(0, removedCatEntries.size());

    RepositoryEntry reloadEntry = repositoryService.loadByKey(re.getKey());
    Assert.assertNotNull(reloadEntry);
    Assert.assertEquals(0, reloadEntry.getAccess());
    Assert.assertNotNull(reloadEntry.getDeletionDate());
    Assert.assertEquals(initialAuthor, reloadEntry.getDeletedBy());
  }