Search in sources :

Example 1 with FileEndpoint

use of org.apache.camel.component.file.FileEndpoint in project camel by apache.

the class SpringFileRouteTest method testMocksAreValid.

@Test
public void testMocksAreValid() throws Exception {
    // lets check that our injected endpoint is valid
    FileEndpoint fileEndpoint = assertIsInstanceOf(FileEndpoint.class, inputFile);
    assertEquals("File", new File("target/test-default-inbox"), fileEndpoint.getFile());
    result.expectedBodiesReceived(expectedBody);
    result.setResultWaitTime(5000);
    template.sendBodyAndHeader(inputFile, expectedBody, Exchange.FILE_NAME, "hello.txt");
    result.assertIsSatisfied();
}
Also used : FileEndpoint(org.apache.camel.component.file.FileEndpoint) File(java.io.File) Test(org.junit.Test)

Example 2 with FileEndpoint

use of org.apache.camel.component.file.FileEndpoint in project camel by apache.

the class FileLanguageExtSingleTest method createExchange.

public Exchange createExchange() {
    // create the file
    String uri = "file://target/filelanguage?fileExist=Override";
    template.sendBodyAndHeader(uri, "Bye World", Exchange.FILE_NAME, "test/bye.def.txt");
    // get the file handle
    file = new File("target/filelanguage/test/bye.def.txt");
    GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null, false);
    FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);
    Exchange answer = endpoint.createExchange(gf);
    endpoint.configureMessage(gf, answer.getIn());
    Calendar cal = Calendar.getInstance();
    cal.set(1974, Calendar.APRIL, 20);
    answer.getIn().setHeader("birthday", cal.getTime());
    cal.set(2008, Calendar.AUGUST, 8);
    answer.getOut().setHeader("special", cal.getTime());
    return answer;
}
Also used : Exchange(org.apache.camel.Exchange) Calendar(java.util.Calendar) FileEndpoint(org.apache.camel.component.file.FileEndpoint) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File)

Example 3 with FileEndpoint

use of org.apache.camel.component.file.FileEndpoint in project camel by apache.

the class FileLanguageTest method createExchange.

public Exchange createExchange() {
    // create the file
    String uri = "file://target/filelanguage?fileExist=Override";
    template.sendBodyAndHeader(uri, "Hello World", Exchange.FILE_NAME, "test/hello.txt");
    // get the file handle
    file = new File("target/filelanguage/test/hello.txt");
    GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null, false);
    FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);
    Exchange answer = endpoint.createExchange(gf);
    endpoint.configureMessage(gf, answer.getIn());
    Calendar cal = Calendar.getInstance();
    cal.set(1974, Calendar.APRIL, 20);
    answer.getIn().setHeader("birthday", cal.getTime());
    cal.set(2008, Calendar.AUGUST, 8);
    answer.getOut().setHeader("special", cal.getTime());
    return answer;
}
Also used : Exchange(org.apache.camel.Exchange) Calendar(java.util.Calendar) FileEndpoint(org.apache.camel.component.file.FileEndpoint) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File)

Example 4 with FileEndpoint

use of org.apache.camel.component.file.FileEndpoint in project camel by apache.

the class FileLanguageTest method testFileNameDoubleExtension.

public void testFileNameDoubleExtension() throws Exception {
    file = new File("target/filelanguage/test/bigfile.tar.gz");
    String uri = "file://target/filelanguage?fileExist=Override";
    GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null, false);
    FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);
    Exchange answer = endpoint.createExchange(gf);
    endpoint.configureMessage(gf, answer.getIn());
    assertEquals("bigfile.tar.gz", file.getName());
    assertExpression(answer, "${file:onlyname}", "bigfile.tar.gz");
    assertExpression(answer, "${file:ext}", "tar.gz");
}
Also used : Exchange(org.apache.camel.Exchange) FileEndpoint(org.apache.camel.component.file.FileEndpoint) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File)

Aggregations

File (java.io.File)4 FileEndpoint (org.apache.camel.component.file.FileEndpoint)4 Exchange (org.apache.camel.Exchange)3 GenericFile (org.apache.camel.component.file.GenericFile)3 Calendar (java.util.Calendar)2 Test (org.junit.Test)1