@Test
  public void updateFolderPathTest() {
    EntityManagerFactory emf = mock(EntityManagerFactory.class);

    stub(emf.createEntityManager())
        .toReturn(createEntityManager())
        .toReturn(createEntityManager())
        .toReturn(createEntityManager())
        .toReturn(createEntityManager())
        .toReturn(createEntityManager())
        .toReturn(createEntityManager());

    ProjectDAOFactory projectDAOFactory = new ProjectDAOFactory();
    FolderDAOFactory folderDAOFactory = new FolderDAOFactory();
    ResearchFileDAOFactory researchFileDAOFactory = new ResearchFileDAOFactory();
    MetadataAssociationDAOFactory metadataAssociationDAOFactory =
        new MetadataAssociationDAOFactory();
    SubmissionPackageDAOFactory submissionPackageDAOFactory = new SubmissionPackageDAOFactory();
    SchemaDAO schemaDAO = new SchemaDAO(emf.createEntityManager());

    projectService =
        new ProjectService(
            emf,
            projectDAOFactory,
            folderDAOFactory,
            researchFileDAOFactory,
            metadataAssociationDAOFactory,
            submissionPackageDAOFactory);

    ResearchFileDAO researchFileDAO =
        researchFileDAOFactory.createInstance(emf.createEntityManager());

    Folder folder = new Folder(new File("/tmp"));
    ResearchFile file1 = new ResearchFile(new File("/tmp/file1.txt"));
    ResearchFile file2 = new ResearchFile(new File("/tmp/file2.txt"));
    researchFileDAO.createResearchFile(file1);
    researchFileDAO.createResearchFile(file2);

    folder.getFiles().add(file1);
    folder.getFiles().add(file2);

    final Schema schema = new Schema("", "", "", Boolean.TRUE);
    schemaDAO.createSchema(schema);

    Project project =
        projectService.createProject(
            new ProjectFieldsDTO(
                "name",
                "owner",
                "institution",
                "email",
                "desc",
                "collectionType",
                "rightsStatement",
                "accessRights",
                "license",
                "identifier",
                "subject",
                "electronicLocation",
                "physicalLocation",
                "placeOrRegionName",
                "geoCoverage",
                "datesOfCapture",
                "citationInformation",
                "counries",
                "languages",
                null,
                "fundingBody",
                "grantID",
                "relatedParty",
                "relatedGrant",
                "relatedInformation"),
            schema);

    projectService.mapFolderToProject(project, folder);

    File updatedFileObject = new File("/new/location");

    projectService.updateFolderPath(folder.getId(), updatedFileObject);

    Folder folderFromDB =
        folderDAOFactory.createInstance(emf.createEntityManager()).findById(folder.getId());

    assertTrue(folderFromDB.getFolder().getPath().equals(updatedFileObject.getPath()));

    for (ResearchFile file : folderFromDB.getFiles()) {
      assertEquals(
          updatedFileObject.getAbsolutePath() + File.separator + file.getFile().getName(),
          file.getFile().getAbsolutePath());
    }
  }
  @Test
  public void removeFoldersFromprojectTest() {
    EntityManagerFactory emf = mock(EntityManagerFactory.class);

    stub(emf.createEntityManager())
        .toReturn(createEntityManager())
        .toReturn(createEntityManager())
        .toReturn(createEntityManager())
        .toReturn(createEntityManager())
        .toReturn(createEntityManager());

    Folder folder1 = new Folder(new File("/tmp1"));
    Folder folder2 = new Folder(new File("/tmp2"));

    ProjectDAOFactory projectDAOFactory = new ProjectDAOFactory();
    FolderDAOFactory folderDAOFactory = new FolderDAOFactory();
    ResearchFileDAOFactory researchFileDAOFactory = new ResearchFileDAOFactory();
    MetadataAssociationDAOFactory metadataAssociationDAOFactory =
        new MetadataAssociationDAOFactory();
    SubmissionPackageDAOFactory submissionPackageDAOFactory = new SubmissionPackageDAOFactory();
    SchemaDAO schemaDAO = new SchemaDAO(emf.createEntityManager());

    projectService =
        new ProjectService(
            emf,
            projectDAOFactory,
            folderDAOFactory,
            researchFileDAOFactory,
            metadataAssociationDAOFactory,
            submissionPackageDAOFactory);

    final Schema schema = new Schema("", "", "", Boolean.TRUE);
    schemaDAO.createSchema(schema);

    Project project =
        projectService.createProject(
            new ProjectFieldsDTO(
                "name",
                "owner",
                "institution",
                "email",
                "desc",
                "collectionType",
                "rightsStatement",
                "accessRights",
                "license",
                "identifier",
                "subject",
                "electronicLocation",
                "physicalLocation",
                "placeOrRegionName",
                "geoCoverage",
                "datesOfCapture",
                "citationInformation",
                "counries",
                "languages",
                null,
                "fundingBody",
                "grantID",
                "relatedParty",
                "relatedGrant",
                "relatedInformation"),
            schema);

    projectService.mapFolderToProject(project, folder1);
    projectService.mapFolderToProject(project, folder2);

    List<String> deletedFolderList = new ArrayList<String>(0);

    deletedFolderList.add(folder2.getFolder().getAbsolutePath());

    projectService.removeFoldersFromProject(project, deletedFolderList);

    Project newProject =
        projectDAOFactory.createInstance(createEntityManager()).findById(project.getId());

    assertEquals(1, newProject.getFolders().size());
    assertEquals(
        folder1.getFolder().getPath(), newProject.getFolders().get(0).getFolder().getPath());
  }