public void testPollingConsumer() throws Exception {
deleteDirectory("target/enrich");
template.sendBodyAndHeader("file:target/enrich", "Hello World", Exchange.FILE_NAME, "hello.txt");
PollingConsumer consumer = context.getEndpoint("file:target/enrich").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("file:target/enrich", "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("target/enrich/bye.txt").getAbsoluteFile();
assertTrue("File should exist " + file, file.exists());
// and no exchange on consumer as
exchange = consumer.receiveNoWait();
assertNull(exchange);
consumer.stop();
}