Esempio n. 1
0
 private void getFileContent(FileRecord file)
     throws DigitalLibraryException, IOException, NotFoundException, AccessDeniedException {
   HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin();
   try {
     InputStream f = dl.getFileContents(RO_URI, file.path);
     assertNotNull(f);
     f.close();
     assertEquals(file.mimeType, dl.getFileInfo(RO_URI, file.path).getMimeType());
   } finally {
     HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
   }
 }
Esempio n. 2
0
 /** @throws java.lang.Exception */
 @After
 public void tearDown() throws Exception {
   HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin();
   dl = new FilesystemDL(BASE);
   dl.deleteResearchObject(RO_URI);
   dl = new FilesystemDL(BASE);
   dl.deleteUser(USER.getLogin());
   HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
   try {
     Files.delete(Paths.get(BASE));
   } catch (DirectoryNotEmptyException | NoSuchFileException e) {
     // was not empty
   }
 }
Esempio n. 3
0
 private void deleteFile(String path) throws DigitalLibraryException, NotFoundException {
   HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin();
   try {
     dl.deleteFile(RO_URI, path);
   } finally {
     HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
   }
 }
Esempio n. 4
0
 private void checkFileExists(String path) throws DigitalLibraryException, NotFoundException {
   HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin();
   try {
     Assert.assertTrue(dl.fileExists(RO_URI, path));
   } finally {
     HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
   }
 }
Esempio n. 5
0
  /** @throws java.lang.Exception */
  @Before
  public void setUp() throws Exception {
    HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin();
    dl = new FilesystemDL(BASE);
    dl.createOrUpdateUser(USER.getLogin(), USER_PASSWORD, USER.getName());
    dl = new FilesystemDL(BASE);
    dl.createResearchObject(
        RO_URI,
        new ByteArrayInputStream(MAIN_FILE_CONTENT.getBytes()),
        MAIN_FILE_PATH,
        MAIN_FILE_MIME_TYPE);

    files[0] = new FileRecord("singleFiles/file1.txt", "file1.txt", "text/plain");
    files[1] = new FileRecord("singleFiles/file2.txt", "dir/file2.txt", "text/plain");
    files[2] = new FileRecord("singleFiles/file3.jpg", "testdir/file3.jpg", "image/jpg");
    Files.createDirectories(Paths.get(BASE));
    HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
  }
Esempio n. 6
0
 private void getZippedVersion() throws DigitalLibraryException, NotFoundException {
   HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin();
   try {
     InputStream zip1 = dl.getZippedResearchObject(RO_URI);
     assertNotNull(zip1);
   } finally {
     HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
   }
 }
Esempio n. 7
0
 private void createOrUpdateDirectory(String path)
     throws DigitalLibraryException, IOException, NotFoundException, AccessDeniedException {
   HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin();
   try {
     ResourceMetadata r1 =
         dl.createOrUpdateFile(RO_URI, path, new ByteArrayInputStream(new byte[0]), "text/plain");
     assertNotNull(r1);
   } finally {
     HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
   }
 }
Esempio n. 8
0
 private void getZippedFolder(String path)
     throws DigitalLibraryException, IOException, NotFoundException {
   HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin();
   try {
     InputStream zip = dl.getZippedFolder(RO_URI, path);
     assertNotNull(zip);
     zip.close();
   } finally {
     HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
   }
 }
Esempio n. 9
0
 private void checkNoFile(String path) throws DigitalLibraryException, IOException {
   HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin();
   try {
     dl.getFileContents(RO_URI, path).close();
     fail("Deleted file doesn't throw IdNotFoundException");
   } catch (NotFoundException e) {
     // good
   } finally {
     HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
   }
 }
Esempio n. 10
0
 private void createOrUpdateFile(FileRecord file)
     throws DigitalLibraryException, IOException, NotFoundException, AccessDeniedException {
   HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin();
   try {
     InputStream f = file.open();
     ResourceMetadata r1 = dl.createOrUpdateFile(RO_URI, file.path, f, file.mimeType);
     f.close();
     assertNotNull(r1);
   } finally {
     HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
   }
 }
Esempio n. 11
0
 private void checkCantCreateOrUpdateFile(FileRecord file)
     throws DigitalLibraryException, IOException, NotFoundException {
   HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin();
   InputStream f = file.open();
   try {
     dl.createOrUpdateFile(RO_URI, file.path, f, file.mimeType);
     fail("Should throw an exception when creating file");
   } catch (Exception e) {
     // good
   } finally {
     f.close();
     HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
   }
 }