Beispiel #1
0
 private Object readResolve() {
   // filling FileChecksumContainer:
   if (ProjectManager.getInstance().getCurrentProject() != null) {
     FileChecksumContainer container = ProjectManager.getInstance().getFileChecksumContainer();
     for (SoundInfo soundInfo : soundList) {
       container.addChecksum(soundInfo.getChecksum(), soundInfo.getAbsolutePath());
     }
     for (LookData lookData : lookList) {
       container.addChecksum(lookData.getChecksum(), lookData.getAbsolutePath());
     }
   }
   return this;
 }
  public void testContainer() throws IOException, InterruptedException {

    storageHandler.copyImage(currentProjectName, testImage.getAbsolutePath(), null);

    String checksumImage = Utils.md5Checksum(testImage);

    FileChecksumContainer fileChecksumContainer = projectManager.getFileChecksumContainer();
    assertTrue(
        "Checksum isn't in container", fileChecksumContainer.containsChecksum(checksumImage));

    // wait to get a different timestamp on next file
    Thread.sleep(2000);

    File newTestImage =
        storageHandler.copyImage(currentProjectName, testImage.getAbsolutePath(), null);
    File imageDirectory =
        new File(
            Constants.DEFAULT_ROOT
                + "/"
                + currentProjectName
                + "/"
                + Constants.IMAGE_DIRECTORY
                + "/");
    File[] filesImage = imageDirectory.listFiles();

    // nomedia file is also in images folder
    assertEquals("Wrong amount of files in folder", 2, filesImage.length);

    File newTestSound = storageHandler.copySoundFile(testSound.getAbsolutePath());
    String checksumSound = Utils.md5Checksum(testSound);
    assertTrue(
        "Checksum isn't in container", fileChecksumContainer.containsChecksum(checksumSound));
    File soundDirectory =
        new File(
            Constants.DEFAULT_ROOT + "/" + currentProjectName + "/" + Constants.SOUND_DIRECTORY);
    File[] filesSound = soundDirectory.listFiles();

    // nomedia file is also in sounds folder
    assertEquals("Wrong amount of files in folder", 2, filesSound.length);

    fileChecksumContainer.decrementUsage(newTestImage.getAbsolutePath());
    assertTrue("Checksum was deleted", fileChecksumContainer.containsChecksum(checksumImage));
    fileChecksumContainer.decrementUsage(newTestImage.getAbsolutePath());
    assertFalse("Checksum wasn't deleted", fileChecksumContainer.containsChecksum(checksumImage));
    fileChecksumContainer.decrementUsage(newTestSound.getAbsolutePath());
    assertFalse("Checksum wasn't deleted", fileChecksumContainer.containsChecksum(checksumSound));
  }