Ejemplo n.º 1
0
  /**
   * If the source file exists, it should be moved to the dest path. The destination path should be
   * created and the file must exist in the destination path, as a file.
   *
   * @throws Throwable
   */
  @Test
  public void testProcessWithReadCompleteAsTrue() throws Throwable {
    ActionEvent actionEvent = new ActionEvent();
    String tempDir = System.getProperty("java.io.tmpdir");
    File sourceFilePath = new File(tempDir + "tempsrc");
    sourceFilePath.mkdirs();
    File destPath = new File(tempDir + "tempdest");
    File sourceFile = File.createTempFile("temp-file-name-" + 0, ".tmp", sourceFilePath);

    actionEvent.getHeaders().put(ActionEventHeaderConstants.READ_COMPLETE, "true");
    actionEvent
        .getHeaders()
        .put(ActionEventHeaderConstants.SOURCE_FILE_PATH, sourceFile.getAbsolutePath());
    // actionEvent.getHeaders().put(ActionEventHeaderConstants.SOURCE_FILE_LOCATION,
    // sourceFilePath.getAbsolutePath());
    FileArchiveHandler fileArchiveHandler = new FileArchiveHandler();
    ReflectionTestUtils.setField(fileArchiveHandler, "archivePath", destPath.getAbsolutePath());
    Assert.assertTrue(sourceFile.exists());
    Status status = invoke(actionEvent, fileArchiveHandler);
    Assert.assertEquals(status, Status.READY);
    Assert.assertFalse(new File(sourceFile.getAbsolutePath()).exists());
    Assert.assertTrue(new File(destPath.getAbsolutePath() + sourceFile.getAbsolutePath()).exists());
    Assert.assertFalse(
        new File(destPath.getAbsolutePath() + sourceFile.getAbsolutePath()).isDirectory());
    FileUtils.deleteDirectory(sourceFilePath);
    FileUtils.deleteDirectory(destPath);
  }
Ejemplo n.º 2
0
 @Test
 public void testProcessWithReadCompleteAsFalse() throws Throwable {
   ActionEvent actionEvent = new ActionEvent();
   actionEvent.getHeaders().put(ActionEventHeaderConstants.READ_COMPLETE, "false");
   Status status = invoke(actionEvent);
   Assert.assertEquals(status, Status.READY);
 }
Ejemplo n.º 3
0
  /**
   * If the source file doesn't exist, archive operation should fail with IOException. Status should
   * be returned as READY. Make sure that the destination path exists and exists as a directory.
   *
   * @throws Throwable
   */
  @Test
  public void testProcessWithSourceFileDoesntExist() throws Throwable {
    ActionEvent actionEvent = new ActionEvent();
    String tempDir = System.getProperty("java.io.tmpdir");
    File destPath = new File(tempDir + "tempdest");
    File sourceFile = new File(tempDir + "/tempsrc/tempfile.txt");

    actionEvent.getHeaders().put(ActionEventHeaderConstants.READ_COMPLETE, "true");
    actionEvent
        .getHeaders()
        .put(ActionEventHeaderConstants.SOURCE_FILE_PATH, sourceFile.getAbsolutePath());
    FileArchiveHandler fileArchiveHandler = new FileArchiveHandler();
    ReflectionTestUtils.setField(fileArchiveHandler, "archivePath", destPath.getAbsolutePath());
    Assert.assertFalse(sourceFile.exists());
    Status status = invoke(actionEvent, fileArchiveHandler);
    Assert.assertEquals(status, Status.READY);
    Assert.assertFalse(new File(sourceFile.getAbsolutePath()).exists());

    Assert.assertTrue(new File(destPath.getAbsolutePath() + sourceFile.getAbsolutePath()).exists());
    Assert.assertTrue(
        new File(destPath.getAbsolutePath() + sourceFile.getAbsolutePath()).isDirectory());
    FileUtils.deleteDirectory(destPath);
  }