@Test
  public void isTemplateInUse() {
    // create the template owned by ident1
    final PortfolioStructureMap template =
        epStructureManager.createPortfolioMapTemplate(
            ident1, "Template in user", "Template in use");
    dbInstance.saveObject(template);
    dbInstance.commitAndCloseSession();
    // add a page to it
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(template, "Page title", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // check: the template is not in use
    assertFalse(epFrontendManager.isTemplateInUse(template, null, null, null));

    // use the template: assign the template to ident2
    final PortfolioStructureMap map =
        epFrontendManager.assignStructuredMapToUser(ident2, template, null, null, null, null);
    assertNotNull(map);
    dbInstance.commitAndCloseSession();

    // check: the template is in use
    assertTrue(epFrontendManager.isTemplateInUse(template, null, null, null));
  }
  @Test
  public void allUserPolicies() {
    // create a map
    final PortfolioStructureMap map =
        epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Policies", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // check visiblity (is owner)
    assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
    // check visibility (no policy)
    assertFalse(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
    // check not visible (no policy)
    assertFalse(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));

    // add all user policy
    final EPMapPolicy userPolicy = new EPMapPolicy();
    userPolicy.setType(Type.allusers);
    epFrontendManager.updateMapPolicies(map, Collections.singletonList(userPolicy));
    dbInstance.commitAndCloseSession();

    // one policy
    final List<EPMapPolicy> policies1 = epFrontendManager.getMapPolicies(map);
    assertEquals(1, policies1.size());

    // check visiblity (is owner)
    assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
    // check visibility (is user)
    assertTrue(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
    // check not visible (is user)
    assertTrue(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));
  }
Exemplo n.º 3
0
  /** testGetAllResourceTypeNames */
  @Test
  public void testGetAllResourceTypeNames() {
    // create resource, identity and group
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-3-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            identity, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    // create a property
    Property p =
        pm.createPropertyInstance(
            identity,
            group,
            ores,
            "catall",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    Assert.assertNotNull(p.getResourceTypeName());
    List<String> resTypeNames = pm.getAllResourceTypeNames();
    assertTrue(resTypeNames.contains(ores.getResourceableTypeName()));
  }
Exemplo n.º 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 removePolicyWithInvitation() {
    // create a map
    final PortfolioStructureMap map =
        epFrontendManager.createAndPersistPortfolioDefaultMap(
            ident1, "Remove policies", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // save a list of policies
    final List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
    // invitation
    final Invitation invitation = securityManager.createAndPersistInvitation();
    invitation.setFirstName("John");
    invitation.setLastName("Doe");
    invitation.setMail("*****@*****.**");
    final EPMapPolicy invitationPolicy = new EPMapPolicy();
    invitationPolicy.setType(Type.invitation);
    invitationPolicy.setInvitation(invitation);
    policies.add(invitationPolicy);
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();

    // remove the policy
    policies.clear();
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();

    // check if the policies and the invitation are deleted
    final List<EPMapPolicy> deletedPolicies = epFrontendManager.getMapPolicies(map);
    assertNotNull(deletedPolicies);
    assertTrue(deletedPolicies.isEmpty());
  }
Exemplo n.º 6
0
  @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());
  }
Exemplo n.º 7
0
  /** testUserInsertFindDelete */
  @Test
  public void testUserInsertFindDelete() {
    // create identity and property
    Identity id =
        JunitTestHelper.createAndPersistIdentityAsUser("user-prop-" + UUID.randomUUID().toString());
    Property p =
        pm.createUserPropertyInstance(
            id,
            "catuser",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    p = pm.findUserProperty(id, "catuser", "TestProperty");
    assertNotNull(p);
    assertEquals(p.getStringValue(), "stringValue");
    assertEquals(p.getFloatValue(), new Float(1.1));
    assertEquals(p.getTextValue(), "textValue");

    pm.deleteProperty(p);
    p = pm.findUserProperty(id, "catuser", "TestProperty");
    assertNull(p);
    dbInstance.commitAndCloseSession();
  }
  /** Same workflow as the repository. This workflow is pretty critical. */
  @Test
  public void isStructuredMapOwner() {
    final OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();

    // create a repository entry
    final RepositoryEntry addedEntry =
        repositoryManager.createRepositoryEntryInstance(ident1.getName());

    addedEntry.setCanDownload(false);
    addedEntry.setCanLaunch(true);
    addedEntry.setDisplayname("test repo");
    addedEntry.setResourcename("-");
    addedEntry.setAccess(RepositoryEntry.ACC_OWNERS);

    // Set the resource on the repository entry and save the entry.
    final OLATResource ores = resourceManager.findOrPersistResourceable(resource);
    addedEntry.setOlatResource(ores);

    // create security group
    final SecurityGroup newGroup = securityManager.createAndPersistSecurityGroup();
    securityManager.createAndPersistPolicy(newGroup, Constants.PERMISSION_ACCESS, newGroup);
    securityManager.createAndPersistPolicy(
        newGroup, Constants.PERMISSION_HASROLE, EPStructureManager.ORES_MAPOWNER);
    securityManager.addIdentityToSecurityGroup(ident1, newGroup);
    addedEntry.setOwnerGroup(newGroup);

    repositoryManager.saveRepositoryEntry(addedEntry);
    dbInstance.commitAndCloseSession();

    // create the template owned by ident1
    final PortfolioStructureMap template =
        epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(template, "Page title", "Page description");
    assertNotNull(page1);

    dbInstance.commitAndCloseSession();

    // assign the template to ident2
    final PortfolioStructureMap map =
        epFrontendManager.assignStructuredMapToUser(ident2, template, null, null, null, null);
    assertNotNull(map);
    dbInstance.commitAndCloseSession();

    // check if ident2 is owner of the map
    assertTrue(epFrontendManager.isMapOwner(ident2, map.getOlatResource()));
    // check if ident1 is not the owner of the map
    assertFalse(epFrontendManager.isMapOwner(ident1, map.getOlatResource()));
    // check if ident1 is owner of the template
    assertTrue(epFrontendManager.isMapOwner(ident1, template.getOlatResource()));
  }
  @Test
  public void mergeTwoUserPolicies() {
    // create a map
    final PortfolioStructureMap map =
        epFrontendManager.createAndPersistPortfolioDefaultMap(
            ident1, "Remove policies", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // save a list of policies
    final List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
    // first user policy
    final EPMapPolicy userPolicy1 = new EPMapPolicy();
    userPolicy1.setType(Type.user);
    userPolicy1.getIdentities().add(ident2);
    userPolicy1.getIdentities().add(ident3);
    policies.add(userPolicy1);
    // second user policy
    final EPMapPolicy userPolicy2 = new EPMapPolicy();
    userPolicy2.setType(Type.user);
    userPolicy2.getIdentities().add(ident1);
    policies.add(userPolicy2);
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();

    // check if the policies are correctly merged
    final List<EPMapPolicy> mergedPolicies = epFrontendManager.getMapPolicies(map);
    assertNotNull(mergedPolicies);
    assertEquals(1, mergedPolicies.size());

    final EPMapPolicy mergedPolicy = mergedPolicies.get(0);
    final List<Identity> identities = mergedPolicy.getIdentities();
    assertEquals(3, identities.size());

    int count1, count2, count3;
    count1 = count2 = count3 = 0;
    for (final Identity identity : identities) {
      if (identity.equalsByPersistableKey(ident1)) {
        count1++;
      } else if (identity.equalsByPersistableKey(ident2)) {
        count2++;
      } else if (identity.equalsByPersistableKey(ident3)) {
        count3++;
      }
    }
    assertEquals(1, count1);
    assertEquals(1, count2);
    assertEquals(1, count3);
  }
  @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);
  }
Exemplo n.º 11
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());
  }
Exemplo n.º 12
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);
  }
Exemplo n.º 13
0
  @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());
  }
Exemplo n.º 14
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());
  }
Exemplo n.º 15
0
  @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);
  }
Exemplo n.º 16
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());
  }
  @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);
  }
  @Test
  public void testCopyMap() {
    // create two artefacts
    final AbstractArtefact artefact1 = epFrontendManager.createAndPersistArtefact(ident1, "text");
    assertNotNull(artefact1);

    final AbstractArtefact artefact2 = epFrontendManager.createAndPersistArtefact(ident1, "bc");
    assertNotNull(artefact2);

    dbInstance.commitAndCloseSession();

    // create a map with a page and the page has two artefacts
    final PortfolioStructureMap originalMap =
        epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Title", "Description");
    final PortfolioStructure newPage =
        epFrontendManager.createAndPersistPortfolioPage(
            originalMap, "Page title", "Page description");
    final boolean successfullLink1 =
        epFrontendManager.addArtefactToStructure(ident1, artefact1, newPage);
    assertTrue(successfullLink1);

    final boolean successfullLink2 =
        epFrontendManager.addArtefactToStructure(ident1, artefact2, newPage);
    assertTrue(successfullLink2);

    dbInstance.commitAndCloseSession();

    // 1 test: copy the map one shoot
    final PortfolioStructureMap copyMap =
        epFrontendManager.createAndPersistPortfolioDefaultMap(
            ident1, "Title copy", "Description copy");
    epFrontendManager.copyStructureRecursively(originalMap, copyMap, true);
    assertNotNull(copyMap.getKey());

    dbInstance.commitAndCloseSession();

    // 2 test: copy the map two shoota
    final PortfolioStructureMap copyMap2 =
        epFrontendManager.createAndPersistPortfolioDefaultMap(
            ident1, "Title copy 2", "Description copy 2");
    dbInstance.commitAndCloseSession();
    assertNotNull(copyMap2.getKey());

    epFrontendManager.copyStructureRecursively(originalMap, copyMap2, true);
    dbInstance.commitAndCloseSession();
  }
  @Test
  public void testTaggingOfArtefacts() {
    final AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
    dbInstance.commitAndCloseSession();
    assertNotNull(artefact);

    epFrontendManager.setArtefactTag(ident1, artefact, "Hello");
    epFrontendManager.setArtefactTag(ident2, artefact, "Hello");
    epFrontendManager.setArtefactTag(ident2, artefact, "Tchao");
    dbInstance.commitAndCloseSession();

    final List<String> tags = (List<String>) epFrontendManager.getArtefactTags(artefact);
    assertNotNull(tags);
    assertEquals(2, tags.size());
    assertTrue(tags.get(0).equals("Hello") || tags.get(1).equals("Hello"));
    assertTrue(tags.get(0).equals("Tchao") || tags.get(1).equals("Tchao"));
  }
Exemplo n.º 20
0
  @Test
  public void testDelete_deletable() {
    String licenseKey = "gpl-" + UUID.randomUUID().toString();
    QLicense license = qpoolLicenseDao.create(licenseKey, null, true);
    dbInstance.commitAndCloseSession();

    // delete it
    boolean deleted = qpoolLicenseDao.delete(license);
    dbInstance.commitAndCloseSession();
    Assert.assertTrue(deleted);

    // check that the type is really, really deleted
    QLicense reloadedLicense = qpoolLicenseDao.loadById(license.getKey());
    Assert.assertNull(reloadedLicense);
    List<QLicense> licenses = qpoolLicenseDao.getLicenses();
    Assert.assertFalse(licenses.contains(license));
  }
  @Test
  public void allMapPolicies() {
    // create a map
    final PortfolioStructureMap map =
        epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Policies", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // save a list of policies
    final List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();

    // user policy
    final EPMapPolicy userPolicy = new EPMapPolicy();
    userPolicy.setType(Type.user);
    userPolicy.getIdentities().add(ident2);
    userPolicy.getIdentities().add(ident3);
    policies.add(userPolicy);

    // invitation
    final Invitation invitation = securityManager.createAndPersistInvitation();
    invitation.setFirstName("John");
    invitation.setLastName("Doe");
    invitation.setMail("*****@*****.**");
    final EPMapPolicy invitationPolicy = new EPMapPolicy();
    invitationPolicy.setType(Type.invitation);
    invitationPolicy.setInvitation(invitation);
    policies.add(invitationPolicy);

    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();

    // check visiblity (is owner)
    assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
    // check visibility (is in policy)
    assertTrue(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
    // check visible (is in policy)
    assertTrue(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));

    // retrieved policies
    final List<EPMapPolicy> savedPolicies = epFrontendManager.getMapPolicies(map);
    assertTrue(!savedPolicies.isEmpty());
  }
Exemplo n.º 22
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());
  }
Exemplo n.º 23
0
  @Test
  public void testFindProperties() {
    // create identities, group and resource
    OLATResource res = JunitTestHelper.createRandomResource();
    Identity id1 =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-8-" + UUID.randomUUID().toString());
    Identity id2 =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-9-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            id1, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    String category = "cat3";
    String propertyName = "TestProperty3";
    String textValue = "textValue3";
    Property p =
        pm.createPropertyInstance(
            id1,
            group,
            res,
            category,
            propertyName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            textValue);
    pm.saveProperty(p);
    p =
        pm.createPropertyInstance(
            id2,
            group,
            res,
            category,
            propertyName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            textValue);
    pm.saveProperty(p);
    List<Property> propertyList =
        pm.findProperties(
            id1,
            group,
            res.getResourceableTypeName(),
            res.getResourceableId(),
            category,
            propertyName);
    assertEquals(1, propertyList.size());
    assertEquals(propertyName, propertyList.get(0).getName());
    assertEquals(textValue, propertyList.get(0).getTextValue());
    int deletedCount1 = pm.deleteProperties(id1, group, res, category, propertyName);
    Assert.assertEquals(1, deletedCount1);
    int deletedCount2 = pm.deleteProperties(id2, group, res, category, propertyName);
    Assert.assertEquals(1, deletedCount2);
  }
Exemplo n.º 24
0
  @Test
  public void testFindWithResourceIdList() {
    // create resource, identity
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-2-" + UUID.randomUUID().toString());
    dbInstance.commitAndCloseSession();
    // create the property
    Property p =
        pm.createPropertyInstance(
            identity,
            null,
            ores,
            "catidlist",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    // check with empty list
    List<Property> emptyProps =
        pm.findProperties(
            ores.getResourceableTypeName(),
            Collections.<Long>emptyList(),
            "catidlist",
            "TestProperty");
    assertNotNull(emptyProps);
    Assert.assertTrue(emptyProps.isEmpty());

    // check with a real value and a dummy
    List<Long> resIds = new ArrayList<Long>();
    resIds.add(ores.getResourceableId());
    resIds.add(2456l); // dummy
    List<Property> props =
        pm.findProperties(ores.getResourceableTypeName(), resIds, "catidlist", "TestProperty");
    assertNotNull(props);
    Assert.assertEquals(1, props.size());
    Assert.assertEquals(p, props.get(0));
  }
Exemplo n.º 25
0
  @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());
  }
Exemplo n.º 26
0
  /** testListProperties */
  @Test
  public void testListProperties() {
    // create resource, identity and group
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-4-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            identity, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    Property p =
        pm.createPropertyInstance(
            identity,
            group,
            ores,
            "cat",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);

    List<Property> entries =
        PropertyManager.getInstance()
            .listProperties(
                identity,
                group,
                ores.getResourceableTypeName(),
                ores.getResourceableId(),
                "cat",
                "TestProperty");
    Assert.assertNotNull(entries);
    Assert.assertEquals(1, entries.size());

    Property prop = entries.get(0);
    assertEquals(ores.getResourceableTypeName(), prop.getResourceTypeName());
    assertEquals(ores.getResourceableId(), prop.getResourceTypeId());

    int numOfEntries =
        PropertyManager.getInstance()
            .countProperties(
                identity,
                group,
                ores.getResourceableTypeName(),
                ores.getResourceableId(),
                "cat",
                "TestProperty",
                null,
                null);
    Assert.assertEquals(entries.size(), numOfEntries);
  }
  @Test
  public void closedArtefacts() {
    // create two artefacts
    final AbstractArtefact artefact1 = epFrontendManager.createAndPersistArtefact(ident1, "text");
    assertNotNull(artefact1);

    final AbstractArtefact artefact2 = epFrontendManager.createAndPersistArtefact(ident1, "bc");
    assertNotNull(artefact2);

    dbInstance.commitAndCloseSession();

    // create a map with a page and the page has two artefacts
    final PortfolioStructureMap originalMap =
        epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Title", "Description");
    final PortfolioStructure newPage =
        epFrontendManager.createAndPersistPortfolioPage(
            originalMap, "Page title", "Page description");

    final boolean successfullLink1 =
        epFrontendManager.addArtefactToStructure(ident1, artefact1, newPage);
    assertTrue(successfullLink1);
    final boolean successfullLink2 =
        epFrontendManager.addArtefactToStructure(ident1, artefact2, newPage);
    assertTrue(successfullLink2);

    dbInstance.commitAndCloseSession();

    // check if the artefact is in a closed map
    assertFalse(epFrontendManager.isArtefactClosed(artefact1));
    assertFalse(epFrontendManager.isArtefactClosed(artefact2));

    // closed the map artificially
    ((EPDefaultMap) originalMap).setStatus(StructureStatusEnum.CLOSED);
    dbInstance.updateObject(originalMap);
    dbInstance.commitAndCloseSession();

    // check if the artefact is in a closed map
    assertTrue(epFrontendManager.isArtefactClosed(artefact1));
    assertTrue(epFrontendManager.isArtefactClosed(artefact2));
  }
Exemplo n.º 28
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());
  }
  @Test
  public void isArtefactsInStructure() {

    // create two artefacts
    final AbstractArtefact artefact1 = epFrontendManager.createAndPersistArtefact(ident1, "text");
    assertNotNull(artefact1);

    final AbstractArtefact artefact2 = epFrontendManager.createAndPersistArtefact(ident1, "bc");
    assertNotNull(artefact2);

    dbInstance.commitAndCloseSession();

    // create a map with a page and the page has two artefacts
    final PortfolioStructureMap originalMap =
        epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Title", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(
            originalMap, "Page title", "Page description");
    final PortfolioStructure page2 =
        epFrontendManager.createAndPersistPortfolioPage(
            originalMap, "Page title", "Page description");

    final boolean successfullLink1 =
        epFrontendManager.addArtefactToStructure(ident1, artefact1, page1);
    assertTrue(successfullLink1);
    final boolean successfullLink2 =
        epFrontendManager.addArtefactToStructure(ident1, artefact2, page2);
    assertTrue(successfullLink2);

    dbInstance.commitAndCloseSession();

    assertTrue(epFrontendManager.isArtefactInStructure(artefact1, page1));
    assertFalse(epFrontendManager.isArtefactInStructure(artefact1, page2));
    assertFalse(epFrontendManager.isArtefactInStructure(artefact2, page1));
    assertTrue(epFrontendManager.isArtefactInStructure(artefact2, page2));
  }
Exemplo n.º 30
0
  /** testGenericInsertFindDelete */
  @Test
  public void testGenericInsertFindDelete() {
    // create resource, identity and group
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-1-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            identity, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    Property p =
        pm.createPropertyInstance(
            identity,
            group,
            ores,
            "catgeneric",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    p = pm.findProperty(identity, group, ores, "catgeneric", "TestProperty");
    assertNotNull(p);
    assertEquals(p.getStringValue(), "stringValue");
    assertEquals(p.getFloatValue(), new Float(1.1));
    assertEquals(p.getLongValue(), new Long(123456));
    assertEquals(p.getTextValue(), "textValue");

    pm.deleteProperty(p);
    p = pm.findProperty(identity, group, ores, "catgeneric", "TestProperty");
    assertNull(p);
  }