use of java.io.File in project camel by apache.
the class FromFtpDoNotDeleteFileIfProcessFailsTest method prepareFtpServer.
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());
}
use of java.io.File in project camel by apache.
the class FromFtpDoNotDeleteFileIfProcessFailsTest method testPollFileAndShouldNotBeDeleted.
@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());
}
use of java.io.File in project camel by apache.
the class FromFtpKeepLastModifiedTest method testDoNotKeepLastModifiedIsDefault.
@Test
public void testDoNotKeepLastModifiedIsDefault() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(getFtpUrl()).delay(3000).to("file://target/keep/out", "mock:result");
}
});
context.start();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
mock.expectedFileExists("target/keep/out/hello.txt");
mock.message(0).header(Exchange.FILE_LAST_MODIFIED).isNotNull();
assertMockEndpointsSatisfied();
long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED, long.class);
long t2 = new File("target/keep/out/hello.txt").lastModified();
assertNotSame("Timestamp should NOT have been kept", t1, t2);
}
use of java.io.File in project camel by apache.
the class FromFileToFtpDeleteTest method testFromFileToFtpDelete.
@Test
public void testFromFileToFtpDelete() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBodyAndHeader("file:target/delete", "Hello World", Exchange.FILE_NAME, "hello.txt");
assertMockEndpointsSatisfied();
assertTrue(notify.matchesMockWaitTime());
// file should be deleted
File file = new File("target/delete/hello.txt");
assertFalse("File should be deleted", file.exists());
// file should exists on ftp server
file = new File(FTP_ROOT_DIR + "/hello.txt");
assertTrue("File should exist on ftp server", file.exists());
}
use of java.io.File in project camel by apache.
the class FromFtpPreMoveDeleteTest method testPreMoveDelete.
@Test
public void testPreMoveDelete() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
mock.expectedBodiesReceived("Hello World this file will be moved");
mock.assertIsSatisfied();
// and file should be deleted
Thread.sleep(1000);
File file = new File(FTP_ROOT_DIR + "/movefile/work/hello.txt");
assertFalse("The file should have been deleted", file.exists());
}
Aggregations