@Test
  public void testHandleFileMessage() throws Exception {
    File file = new File("remote-target-dir", "template.mf.test");
    if (file.exists()) {
      file.delete();
    }
    SessionFactory sessionFactory = new TestSftpSessionFactory();
    FileTransferringMessageHandler handler = new FileTransferringMessageHandler(sessionFactory);
    DefaultFileNameGenerator fGenerator = new DefaultFileNameGenerator();
    fGenerator.setExpression("payload + '.test'");
    handler.setFileNameGenerator(fGenerator);
    handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));

    handler.handleMessage(new GenericMessage<File>(new File("template.mf")));
    assertTrue(new File("remote-target-dir", "template.mf.test").exists());
  }
  @Test
  public void testHandleBytesMessage() throws Exception {
    File file = new File("remote-target-dir", "foo.txt");
    if (file.exists()) {
      file.delete();
    }
    SessionFactory<LsEntry> sessionFactory = new TestSftpSessionFactory();
    FileTransferringMessageHandler<LsEntry> handler =
        new FileTransferringMessageHandler<LsEntry>(sessionFactory);
    DefaultFileNameGenerator fGenerator = new DefaultFileNameGenerator();
    fGenerator.setExpression("'foo.txt'");
    handler.setFileNameGenerator(fGenerator);
    handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));

    handler.handleMessage(new GenericMessage<byte[]>("hello".getBytes()));
    assertTrue(new File("remote-target-dir", "foo.txt").exists());
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Test
  public void testHandleStringMessage() throws Exception {
    File file = new File("remote-target-dir", "foo.txt");
    if (file.exists()) {
      file.delete();
    }
    SessionFactory sessionFactory = new TestSftpSessionFactory();
    FileTransferringMessageHandler handler = new FileTransferringMessageHandler(sessionFactory);
    DefaultFileNameGenerator fGenerator = new DefaultFileNameGenerator();
    fGenerator.setExpression("'foo.txt'");
    handler.setFileNameGenerator(fGenerator);
    handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));

    handler.handleMessage(new GenericMessage("hello"));
    assertTrue(new File("remote-target-dir", "foo.txt").exists());
  }
  @Test
  public void testHandleFileMessage() throws Exception {
    File targetDir = new File("remote-target-dir");
    assertTrue("target directory does not exist: " + targetDir.getName(), targetDir.exists());

    SessionFactory<LsEntry> sessionFactory = new TestSftpSessionFactory();
    FileTransferringMessageHandler<LsEntry> handler =
        new FileTransferringMessageHandler<LsEntry>(sessionFactory);
    handler.setRemoteDirectoryExpression(new LiteralExpression(targetDir.getName()));
    DefaultFileNameGenerator fGenerator = new DefaultFileNameGenerator();
    fGenerator.setExpression("payload + '.test'");
    handler.setFileNameGenerator(fGenerator);

    File srcFile = File.createTempFile("testHandleFileMessage", ".tmp", new File("."));
    srcFile.deleteOnExit();

    File destFile = new File(targetDir, srcFile.getName() + ".test");
    destFile.deleteOnExit();

    handler.handleMessage(new GenericMessage<File>(srcFile));
    assertTrue("destination file was not created", destFile.exists());
  }