FtpClient extends AbstractEndpoint implements Producer, ReplyConsumer, InitializingBean, DisposableBean { protected FtpMessage deleteFile(DeleteCommand delete, TestContext context) { String remoteFilePath = context.replaceDynamicContentInString(delete.getTarget().getPath()); try { if (!StringUtils.hasText(remoteFilePath)) { return null; } boolean success = true; if (isDirectory(remoteFilePath)) { if (!ftpClient.changeWorkingDirectory(remoteFilePath)) { throw new CitrusRuntimeException("Failed to change working directory to " + remoteFilePath + ". FTP reply code: " + ftpClient.getReplyString()); } if (delete.isRecursive()) { FTPFile[] ftpFiles = ftpClient.listFiles(); for (FTPFile ftpFile : ftpFiles) { DeleteCommand recursiveDelete = new DeleteCommand(); DeleteCommand.Target target = new DeleteCommand.Target(); target.setPath(remoteFilePath + "/" + ftpFile.getName()); recursiveDelete.setTarget(target); recursiveDelete.setIncludeCurrent(true); deleteFile(recursiveDelete, context); } } if (delete.isIncludeCurrent()) { ftpClient.changeWorkingDirectory("/"); success = ftpClient.removeDirectory(remoteFilePath); } } else { success = ftpClient.deleteFile(remoteFilePath); } if (!success) { throw new CitrusRuntimeException("Failed to delete path " + remoteFilePath + ". FTP reply code: " + ftpClient.getReplyString()); } } catch (IOException e) { throw new CitrusRuntimeException("Failed to delete file from FTP server", e); } if (ftpClient.getReplyCode() != FILE_ACTION_OK) { return FtpMessage.deleteResult(FILE_ACTION_OK, String.format("%s No files to delete.", FILE_ACTION_OK), true); } return FtpMessage.deleteResult(ftpClient.getReplyCode(), ftpClient.getReplyString(), isPositive(ftpClient.getReplyCode())); } FtpClient(); protected  FtpClient(FtpEndpointConfiguration endpointConfiguration); @Override FtpEndpointConfiguration getEndpointConfiguration(); @Override void send(Message message, TestContext context); @Override Message receive(TestContext context); @Override Message receive(String selector, TestContext context); @Override Message receive(TestContext context, long timeout); @Override Message receive(String selector, TestContext context, long timeout); @Override void afterPropertiesSet(); @Override void destroy(); @Override Producer createProducer(); @Override SelectiveConsumer createConsumer(); void setFtpClient(FTPClient ftpClient); FTPClient getFtpClient(); void setCorrelationManager(CorrelationManager<Message> correlationManager);  }
@Test public void testDeleteCurrentDirectory() { assertTrue(fakeFtpServer.getFileSystem().exists(COMPLETELY_DELETE_FOLDER)); DeleteCommand deleteCommand = deleteCommand(COMPLETELY_DELETE_FOLDER); deleteCommand.setIncludeCurrent(true); FtpMessage ftpMessage = ftpClient.deleteFile(deleteCommand, context); verifyMessage(ftpMessage, DeleteCommandResult.class, FILE_ACTION_OK, "250 \"/completely_delete\" removed."); assertFalse(fakeFtpServer.getFileSystem().exists(COMPLETELY_DELETE_FOLDER)); }
@Test public void testDeleteFile() { assertTrue(fakeFtpServer.getFileSystem().exists(SINGLE_FILE)); FtpMessage ftpMessage = ftpClient.deleteFile(deleteCommand(SINGLE_FILE), context); verifyMessage(ftpMessage, DeleteCommandResult.class, FILE_ACTION_OK, "250 \"/single_file\" deleted."); assertFalse(fakeFtpServer.getFileSystem().exists(SINGLE_FILE)); }
@Test(expectedExceptions = {CitrusRuntimeException.class}, expectedExceptionsMessageRegExp = ".*/path/not/valid.*") public void testDeleteInvalidPath() { String invalidPath = "/path/not/valid"; assertFalse(fakeFtpServer.getFileSystem().exists(invalidPath)); ftpClient.deleteFile(deleteCommand(invalidPath), context); }