use of java.io.File in project camel by apache.
the class FtpPollingConsumerTest method testPollingConsumer.
@Test
public void testPollingConsumer() throws Exception {
template.sendBodyAndHeader(getFtpUrl(), "Hello World", Exchange.FILE_NAME, "hello.txt");
PollingConsumer consumer = context.getEndpoint(getFtpUrl()).createPollingConsumer();
consumer.start();
Exchange exchange = consumer.receive(5000);
assertNotNull(exchange);
assertEquals("Hello World", exchange.getIn().getBody(String.class));
// sleep a bit to ensure polling consumer would be suspended after we have used it
Thread.sleep(1000);
// drop a new file which should not be picked up by the consumer
template.sendBodyAndHeader(getFtpUrl(), "Bye World", Exchange.FILE_NAME, "bye.txt");
// sleep a bit to ensure polling consumer would not have picked up that file
Thread.sleep(1000);
File file = new File(FTP_ROOT_DIR + "/polling/bye.txt");
assertTrue("File should exist " + file, file.exists());
consumer.stop();
}
use of java.io.File in project camel by apache.
the class FromFtpThirdPoolOkTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
// no redeliveries as we want the ftp consumer to try again
// use no delay for fast unit testing
onException(IllegalArgumentException.class).logStackTrace(false).to("mock:error");
from(getFtpUrl()).process(new Processor() {
public void process(Exchange exchange) throws Exception {
counter++;
if (counter < 3) {
// file should exists
File file = new File(FTP_ROOT_DIR + "/thirdpool/hello.txt");
assertTrue("The file should NOT have been deleted", file.exists());
throw new IllegalArgumentException("Forced by unittest");
}
}
}).to("mock:result");
}
};
}
use of java.io.File in project camel by apache.
the class FtpConsumerLocalWorkDirectoryTest method testLocalWorkDirectory.
@Test
public void testLocalWorkDirectory() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
mock.expectedMessageCount(1);
assertMockEndpointsSatisfied();
// give test some time to close file resources
Thread.sleep(6000);
// and the out file should exists
File out = new File("target/out/hello.txt");
assertTrue("file should exists", out.exists());
assertEquals("Hello World", IOConverter.toString(out, null));
// now the lwd file should be deleted
File local = new File("target/lwd/hello.txt");
assertFalse("Local work file should have been deleted", local.exists());
}
use of java.io.File in project camel by apache.
the class FtpConsumerTemplateTest method testConsumerTemplateNotDone.
@Test
public void testConsumerTemplateNotDone() throws Exception {
Exchange exchange = consumer.receive(getFtpUrl(), 5000);
assertNotNull(exchange);
assertEquals("hello.txt", exchange.getIn().getHeader(Exchange.FILE_NAME));
assertEquals("Hello World", exchange.getIn().getBody(String.class));
// forget to call done
Thread.sleep(500);
// try poll the same file again
Exchange exchange2 = consumer.receive(getFtpUrl(), 2000);
assertNull(exchange2);
// now done the original exchange
consumer.doneUoW(exchange);
// now we can poll the file again as we have done the exchange
exchange2 = consumer.receive(getFtpUrl(), 2000);
assertNotNull(exchange2);
assertEquals("hello.txt", exchange2.getIn().getHeader(Exchange.FILE_NAME));
assertEquals("Hello World", exchange2.getIn().getBody(String.class));
consumer.doneUoW(exchange2);
// file should still exists
Thread.sleep(500);
File file = new File(FTP_ROOT_DIR + "/template/hello.txt");
assertTrue("The file should exist: " + file, file.exists());
}
use of java.io.File in project camel by apache.
the class FtpConsumerTemplateTest method testConsumerTemplate.
@Test
public void testConsumerTemplate() throws Exception {
Exchange exchange = consumer.receive(getFtpUrl(), 5000);
assertNotNull(exchange);
assertEquals("hello.txt", exchange.getIn().getHeader(Exchange.FILE_NAME));
assertEquals("Hello World", exchange.getIn().getBody(String.class));
// must done when we are done using the exchange
consumer.doneUoW(exchange);
Thread.sleep(500);
// poll the same file again
exchange = consumer.receive(getFtpUrl(), 5000);
assertNotNull(exchange);
assertEquals("hello.txt", exchange.getIn().getHeader(Exchange.FILE_NAME));
assertEquals("Hello World", exchange.getIn().getBody(String.class));
// must done when we are done using the exchange
consumer.doneUoW(exchange);
// file should still exists
Thread.sleep(500);
File file = new File(FTP_ROOT_DIR + "/template/hello.txt");
assertTrue("The file should exist: " + file, file.exists());
}
Aggregations