Search in sources :

Example 81 with File

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

the class FileConfigureTest method assertFileEndpoint.

private void assertFileEndpoint(String endpointUri, String expectedPath, boolean absolute) throws IOException {
    FileEndpoint endpoint = resolveMandatoryEndpoint(endpointUri, FileEndpoint.class);
    assertNotNull("Could not find endpoint: " + endpointUri, endpoint);
    if (!absolute) {
        File file = endpoint.getFile();
        String path = file.getPath();
        assertDirectoryEquals("For uri: " + endpointUri + " the file is not equal", expectedPath, path);
        file = new File(expectedPath + (expectedPath.endsWith(File.separator) ? "" : File.separator) + EXPECT_FILE);
        GenericFile<File> consumedFile = FileConsumer.asGenericFile(endpoint.getFile().getPath(), file, null, false);
        assertEquals(EXPECT_FILE, consumedFile.getRelativeFilePath());
    }
}
Also used : File(java.io.File)

Example 82 with File

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

the class FileConsumeAlterFileNameHeaderIssueTest method testConsumeAndDeleteRemoveAllHeaders.

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

        @Override
        public void configure() throws Exception {
            from("file://target/files?delete=true").removeHeaders("*").to("mock:result");
        }
    });
    context.start();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    template.sendBodyAndHeader("file://target/files", "Hello World", Exchange.FILE_NAME, "hello.txt");
    assertMockEndpointsSatisfied();
    oneExchangeDone.matchesMockWaitTime();
    assertFalse("Headers should have been removed", mock.getExchanges().get(0).getIn().hasHeaders());
    // the original file should have been deleted, as the file consumer should be resilient against
    // end users deleting headers
    assertFalse("File should been deleted", new File("target/files/hello.txt").exists());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File)

Example 83 with File

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

the class FileConsumeAlterFileNameHeaderIssueTest method testConsumeAndMoveChangeFileHeader.

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

        @Override
        public void configure() throws Exception {
            from("file://target/files").setHeader(Exchange.FILE_NAME, constant("bye.txt")).to("mock:result");
        }
    });
    context.start();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    mock.expectedHeaderReceived(Exchange.FILE_NAME, "bye.txt");
    template.sendBodyAndHeader("file://target/files", "Hello World", Exchange.FILE_NAME, "hello.txt");
    assertMockEndpointsSatisfied();
    oneExchangeDone.matchesMockWaitTime();
    // the original file should have been moved, as the file consumer should be resilient against
    // end users changing headers
    assertTrue("File should been moved", new File("target/files/.camel/hello.txt").exists());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File)

Example 84 with File

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

the class FileConsumeAlterFileNameHeaderIssueTest method testConsumeAndDeleteChangeFileHeader.

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

        @Override
        public void configure() throws Exception {
            from("file://target/files?delete=true").setHeader(Exchange.FILE_NAME, constant("bye.txt")).to("mock:result");
        }
    });
    context.start();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    mock.expectedHeaderReceived(Exchange.FILE_NAME, "bye.txt");
    template.sendBodyAndHeader("file://target/files", "Hello World", Exchange.FILE_NAME, "hello.txt");
    assertMockEndpointsSatisfied();
    oneExchangeDone.matchesMockWaitTime();
    // the original file should have been deleted, as the file consumer should be resilient against
    // end users changing headers
    assertFalse("File should been deleted", new File("target/files/hello.txt").exists());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File)

Example 85 with File

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

the class FileConsumeCharsetTest method testConsumeAndDelete.

public void testConsumeAndDelete() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World 你好");
    assertMockEndpointsSatisfied();
    oneExchangeDone.matchesMockWaitTime();
    // file should not exists
    assertFalse("File should been deleted", new File("target/files/report.txt").exists());
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File)

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