Search in sources :

Example 76 with File

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

the class FileConsumerMoveExpressionTest method testRenameToComplexWithId.

public void testRenameToComplexWithId() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("file://target/filelanguage/?exclude=.*bak" + "&move=backup-${id}-${file:name.noext}.bak").convertBodyTo(String.class).to("mock:result");
        }
    });
    context.start();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Bye World");
    template.sendBodyAndHeader("file://target/filelanguage/", "Bye World", Exchange.FILE_NAME, "report2.txt");
    assertMockEndpointsSatisfied();
    oneExchangeDone.matchesMockWaitTime();
    String id = mock.getExchanges().get(0).getIn().getMessageId();
    File file = new File("target/filelanguage/backup-" + id + "-report2.bak");
    assertTrue("File should have been renamed", file.exists());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File)

Example 77 with File

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

the class FileConsumerMoveExpressionTest method testRenameToId.

public void testRenameToId() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("file://target/filelanguage/?exclude=.*bak" + "&move=${id}.bak").convertBodyTo(String.class).to("mock:result");
        }
    });
    context.start();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    template.sendBodyAndHeader("file://target/filelanguage/", "Hello World", Exchange.FILE_NAME, "report.txt");
    assertMockEndpointsSatisfied();
    oneExchangeDone.matchesMockWaitTime();
    String id = mock.getExchanges().get(0).getIn().getMessageId();
    File file = new File("target/filelanguage/" + id + ".bak");
    assertTrue("File should have been renamed", file.exists());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File)

Example 78 with File

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

the class FileConsumerAbsolutePathWithAbsoluteMoveTest method setUp.

@Override
protected void setUp() throws Exception {
    deleteDirectory("target/reports");
    // use current dir as base as absolute path
    base = new File("").getAbsolutePath() + "/target/reports";
    super.setUp();
}
Also used : File(java.io.File)

Example 79 with File

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

the class FileConsumerAbsolutePathWithRelativeMoveTest method setUp.

@Override
protected void setUp() throws Exception {
    deleteDirectory("target/reports");
    deleteDirectory("target/done");
    // use current dir as base as absolute path
    base = new File("").getAbsolutePath() + "/target/reports";
    super.setUp();
}
Also used : File(java.io.File)

Example 80 with File

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

the class FileConsumerAutoCreateDirectoryTest method testDoNotCreateDirectory.

public void testDoNotCreateDirectory() throws Exception {
    deleteDirectory("target/file/foo");
    Endpoint endpoint = context.getEndpoint("file://target/file/foo?autoCreate=false");
    Consumer consumer = endpoint.createConsumer(new Processor() {

        public void process(Exchange exchange) throws Exception {
        // noop
        }
    });
    consumer.start();
    consumer.stop();
    // the directory should NOT exists
    File dir = new File("target/file/foo");
    assertFalse("Directory should NOT be created", dir.exists());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Endpoint(org.apache.camel.Endpoint) Consumer(org.apache.camel.Consumer) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException)

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