use of java.io.File in project camel by apache.
the class FileConsumeDoneFileIssueTest method testFileConsumeDoneFileIssue.
public void testFileConsumeDoneFileIssue() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
template.sendBodyAndHeader("file:target/done", "A", Exchange.FILE_NAME, "foo-a.txt");
template.sendBodyAndHeader("file:target/done", "B", Exchange.FILE_NAME, "foo-b.txt");
template.sendBodyAndHeader("file:target/done", "C", Exchange.FILE_NAME, "foo-c.txt");
template.sendBodyAndHeader("file:target/done", "D", Exchange.FILE_NAME, "foo-d.txt");
template.sendBodyAndHeader("file:target/done", "E", Exchange.FILE_NAME, "foo-e.txt");
template.sendBodyAndHeader("file:target/done", "E", Exchange.FILE_NAME, "foo.done");
assertTrue("Done file should exists", new File("target/done/foo.done").exists());
getMockEndpoint("mock:result").expectedBodiesReceivedInAnyOrder("A", "B", "C", "D", "E");
context.startRoute("foo");
assertMockEndpointsSatisfied();
assertTrue(notify.matchesMockWaitTime());
Thread.sleep(250);
// the done file should be deleted
assertFalse("Done file should be deleted", new File("target/done/foo.done").exists());
}
use of java.io.File in project camel by apache.
the class FileConsumeFilesAndDeleteTest method testConsumeAndDelete.
public void testConsumeAndDelete() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
assertMockEndpointsSatisfied();
oneExchangeDone.matchesMockWaitTime();
// file should not exists
assertFalse("File should been deleted", new File("target/files/report.txt").exists());
}
use of java.io.File in project camel by apache.
the class FileConsumeMultipleDirectoriesTest method testMultiDir.
@SuppressWarnings("unchecked")
public void testMultiDir() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Bye World", "Hello World", "Godday World");
assertMockEndpointsSatisfied();
Exchange exchange = mock.getExchanges().get(0);
GenericFile<File> gf = (GenericFile<File>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
File file = gf.getFile();
assertDirectoryEquals("target/multidir/bye.txt", file.getPath());
assertEquals("bye.txt", file.getName());
exchange = mock.getExchanges().get(1);
gf = (GenericFile<File>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
file = gf.getFile();
assertDirectoryEquals("target/multidir/sub/hello.txt", file.getPath());
assertEquals("hello.txt", file.getName());
exchange = mock.getExchanges().get(2);
gf = (GenericFile<File>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
file = gf.getFile();
assertDirectoryEquals("target/multidir/sub/sub2/godday.txt", file.getPath());
assertEquals("godday.txt", file.getName());
}
use of java.io.File in project camel by apache.
the class FileConsumerFailureHandledTest method assertFiles.
private static void assertFiles(String filename, boolean deleted) throws InterruptedException {
// file should be deleted as delete=true in parameter in the route below
File file = new File("target/messages/input/" + filename);
assertEquals("File " + filename + " should be deleted: " + deleted, deleted, !file.exists());
// and no lock files
String lock = filename + FileComponent.DEFAULT_LOCK_FILE_POSTFIX;
file = new File("target/messages/input/" + lock);
assertFalse("File " + lock + " should be deleted", file.exists());
}
use of java.io.File in project camel by apache.
the class FileConsumerIdempotentRefTest method testIdempotentRef.
public void testIdempotentRef() throws Exception {
// consume the file the first time
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
mock.expectedMessageCount(1);
assertMockEndpointsSatisfied();
oneExchangeDone.matchesMockWaitTime();
// reset mock and set new expectations
mock.reset();
mock.expectedMessageCount(0);
// move file back
File file = new File("target/idempotent/done/report.txt");
File renamed = new File("target/idempotent/report.txt");
file.renameTo(renamed);
// should NOT consume the file again, let a bit time go
Thread.sleep(100);
assertMockEndpointsSatisfied();
assertTrue("MyIdempotentRepository should have been invoked", invoked);
}
Aggregations