Search in sources :

Example 41 with File

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();
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) File(java.io.File) Test(org.junit.Test)

Example 42 with File

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");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) File(java.io.File)

Example 43 with File

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());
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File) Test(org.junit.Test)

Example 44 with File

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());
}
Also used : Exchange(org.apache.camel.Exchange) File(java.io.File) Test(org.junit.Test)

Example 45 with File

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());
}
Also used : Exchange(org.apache.camel.Exchange) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)45560 IOException (java.io.IOException)9550 Test (org.junit.Test)9009 FileOutputStream (java.io.FileOutputStream)3388 ArrayList (java.util.ArrayList)3273 FileInputStream (java.io.FileInputStream)2915 InputStream (java.io.InputStream)1783 FileNotFoundException (java.io.FileNotFoundException)1743 URL (java.net.URL)1649 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1478 Test (org.testng.annotations.Test)1411 HashMap (java.util.HashMap)1404 RandomAccessFile (java.io.RandomAccessFile)1154 FileWriter (java.io.FileWriter)1081 Properties (java.util.Properties)1019 ZipFile (java.util.zip.ZipFile)959 JarFile (java.util.jar.JarFile)866 List (java.util.List)850 BufferedReader (java.io.BufferedReader)840 OutputStream (java.io.OutputStream)811