Search in sources :

Example 21 with File

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

Example 22 with File

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

Example 23 with File

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

Example 24 with File

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

Example 25 with File

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