Created
September 18, 2018 08:18
-
-
Save przodownikR1/8fbac8f046ce79a0791104dfa87f85ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FromFtpDoNotDeleteFileIfProcessFailsTest extends FtpServerTestSupport { | |
private String getFtpUrl() { | |
return "ftp://admin@localhost:" + getPort() + "/deletefile/?password=admin&delete=true"; | |
} | |
@Override | |
@Before | |
public void setUp() throws Exception { | |
super.setUp(); | |
prepareFtpServer(); | |
} | |
@Test | |
public void testPollFileAndShouldNotBeDeleted() throws Exception { | |
MockEndpoint mock = getMockEndpoint("mock:error"); | |
mock.expectedMessageCount(1); | |
mock.expectedBodiesReceived("Hello World this file will NOT be deleted"); | |
mock.assertIsSatisfied(); | |
// give time to NOT delete file | |
Thread.sleep(200); | |
// assert the file is deleted | |
File file = new File(FTP_ROOT_DIR + "/deletefile/hello.txt"); | |
assertTrue("The file should NOT have been deleted", file.exists()); | |
} | |
private void prepareFtpServer() throws Exception { | |
// prepares the FTP Server by creating a file on the server that we want to unit | |
// test that we can pool and store as a local file | |
Endpoint endpoint = context.getEndpoint(getFtpUrl()); | |
Exchange exchange = endpoint.createExchange(); | |
exchange.getIn().setBody("Hello World this file will NOT be deleted"); | |
exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt"); | |
Producer producer = endpoint.createProducer(); | |
producer.start(); | |
producer.process(exchange); | |
producer.stop(); | |
// assert file is created | |
File file = new File(FTP_ROOT_DIR + "/deletefile/hello.txt"); | |
assertTrue("The file should exists", file.exists()); | |
} | |
protected RouteBuilder createRouteBuilder() throws Exception { | |
return new RouteBuilder() { | |
public void configure() throws Exception { | |
// use no delay for fast unit testing | |
onException(IllegalArgumentException.class) | |
.maximumRedeliveries(2).redeliveryDelay(0) | |
.to("mock:error"); | |
from(getFtpUrl()).process(new Processor() { | |
public void process(Exchange exchange) throws Exception { | |
throw new IllegalArgumentException("Forced by unittest"); | |
} | |
}); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment