Search in sources :

Example 86 with File

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

the class FileConsumeDoneFileIssueTest method testFileConsumeDoneFileIssue.

public void testFileConsumeDoneFileIssue() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
    template.sendBodyAndHeader("file:target/done", "A", Exchange.FILE_NAME, "foo-a.txt");
    template.sendBodyAndHeader("file:target/done", "B", Exchange.FILE_NAME, "foo-b.txt");
    template.sendBodyAndHeader("file:target/done", "C", Exchange.FILE_NAME, "foo-c.txt");
    template.sendBodyAndHeader("file:target/done", "D", Exchange.FILE_NAME, "foo-d.txt");
    template.sendBodyAndHeader("file:target/done", "E", Exchange.FILE_NAME, "foo-e.txt");
    template.sendBodyAndHeader("file:target/done", "E", Exchange.FILE_NAME, "foo.done");
    assertTrue("Done file should exists", new File("target/done/foo.done").exists());
    getMockEndpoint("mock:result").expectedBodiesReceivedInAnyOrder("A", "B", "C", "D", "E");
    context.startRoute("foo");
    assertMockEndpointsSatisfied();
    assertTrue(notify.matchesMockWaitTime());
    Thread.sleep(250);
    // the done file should be deleted
    assertFalse("Done file should be deleted", new File("target/done/foo.done").exists());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) File(java.io.File)

Example 87 with File

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

the class FileConsumeFilesAndDeleteTest 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)

Example 88 with File

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

the class FileConsumeMultipleDirectoriesTest method testMultiDir.

@SuppressWarnings("unchecked")
public void testMultiDir() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Bye World", "Hello World", "Godday World");
    assertMockEndpointsSatisfied();
    Exchange exchange = mock.getExchanges().get(0);
    GenericFile<File> gf = (GenericFile<File>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
    File file = gf.getFile();
    assertDirectoryEquals("target/multidir/bye.txt", file.getPath());
    assertEquals("bye.txt", file.getName());
    exchange = mock.getExchanges().get(1);
    gf = (GenericFile<File>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
    file = gf.getFile();
    assertDirectoryEquals("target/multidir/sub/hello.txt", file.getPath());
    assertEquals("hello.txt", file.getName());
    exchange = mock.getExchanges().get(2);
    gf = (GenericFile<File>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
    file = gf.getFile();
    assertDirectoryEquals("target/multidir/sub/sub2/godday.txt", file.getPath());
    assertEquals("godday.txt", file.getName());
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File)

Example 89 with File

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

the class FileConsumerFailureHandledTest method assertFiles.

private static void assertFiles(String filename, boolean deleted) throws InterruptedException {
    // file should be deleted as delete=true in parameter in the route below
    File file = new File("target/messages/input/" + filename);
    assertEquals("File " + filename + " should be deleted: " + deleted, deleted, !file.exists());
    // and no lock files
    String lock = filename + FileComponent.DEFAULT_LOCK_FILE_POSTFIX;
    file = new File("target/messages/input/" + lock);
    assertFalse("File " + lock + " should be deleted", file.exists());
}
Also used : File(java.io.File)

Example 90 with File

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

the class FileConsumerIdempotentRefTest method testIdempotentRef.

public void testIdempotentRef() throws Exception {
    // consume the file the first time
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    mock.expectedMessageCount(1);
    assertMockEndpointsSatisfied();
    oneExchangeDone.matchesMockWaitTime();
    // reset mock and set new expectations
    mock.reset();
    mock.expectedMessageCount(0);
    // move file back
    File file = new File("target/idempotent/done/report.txt");
    File renamed = new File("target/idempotent/report.txt");
    file.renameTo(renamed);
    // should NOT consume the file again, let a bit time go
    Thread.sleep(100);
    assertMockEndpointsSatisfied();
    assertTrue("MyIdempotentRepository should have been invoked", invoked);
}
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