Search in sources :

Example 36 with File

use of java.io.File in project camel by apache.

the class FtpConsumerLocalWorkDirectoryAsAbsolutePathTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() throws Exception {
            from(getFtpUrl()).process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    File body = exchange.getIn().getBody(File.class);
                    assertNotNull(body);
                    assertTrue("Should be absolute path", body.isAbsolute());
                    assertTrue("Local work file should exists", body.exists());
                    assertEquals(FileUtil.normalizePath(base + "/hello.txt"), body.getPath());
                }
            }).to("mock:result", "file://target/out");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) File(java.io.File)

Example 37 with File

use of java.io.File in project camel by apache.

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

Example 38 with File

use of java.io.File in project camel by apache.

the class FtpConsumerLocalWorkDirectoryDirectTest method testLocalWorkDirectory.

@Test
public void testLocalWorkDirectory() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
    assertTrue("Should process one file", notify.matchesMockWaitTime());
    // 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 : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) File(java.io.File) Test(org.junit.Test)

Example 39 with File

use of java.io.File in project camel by apache.

the class FtpConsumerLocalWorkDirectoryTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() throws Exception {
            from(getFtpUrl()).process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    File body = exchange.getIn().getBody(File.class);
                    assertNotNull(body);
                    assertTrue("Local work file should exists", body.exists());
                    assertEquals(FileUtil.normalizePath("target/lwd/hello.txt"), body.getPath());
                }
            }).to("mock:result", "file://target/out");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) File(java.io.File)

Example 40 with File

use of java.io.File in project camel by apache.

the class FtpLoginNoRetryTest method testBadLogin.

@Test
public void testBadLogin() throws Exception {
    try {
        uploadFile("dummy", "cantremeber");
        fail("Should have thrown a GenericFileOperationFailedException");
    } catch (GenericFileOperationFailedException e) {
        // expected
        assertEquals(530, e.getCode());
    }
    // assert file NOT created
    File file = new File(FTP_ROOT_DIR + "login/report.txt");
    assertFalse("The file should NOT exists", file.exists());
}
Also used : GenericFileOperationFailedException(org.apache.camel.component.file.GenericFileOperationFailedException) 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