Search in sources :

Example 36 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class FileToFtpTempFileNameTest method testFileToFtp.

@Test
public void testFileToFtp() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
    template.sendBodyAndHeader("file:target/in", "Hello World", Exchange.FILE_NAME, "sub/hello.txt");
    assertTrue(notify.matchesMockWaitTime());
    File file = new File(FTP_ROOT_DIR + "/out/sub/hello.txt");
    assertTrue("File should exists " + file, file.exists());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) File(java.io.File) Test(org.junit.Test)

Example 37 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class FromFileToFtpDeleteTest method testFromFileToFtpDelete.

@Test
public void testFromFileToFtpDelete() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBodyAndHeader("file:target/delete", "Hello World", Exchange.FILE_NAME, "hello.txt");
    assertMockEndpointsSatisfied();
    assertTrue(notify.matchesMockWaitTime());
    // file should be deleted
    File file = new File("target/delete/hello.txt");
    assertFalse("File should be deleted", file.exists());
    // file should exists on ftp server
    file = new File(FTP_ROOT_DIR + "/hello.txt");
    assertTrue("File should exist on ftp server", file.exists());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File) Test(org.junit.Test)

Example 38 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class FtpConsumerIdempotentMemoryRefTest method testIdempotent.

@Test
public void testIdempotent() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
    getMockEndpoint("mock:result").expectedMessageCount(5);
    sendFile(getFtpUrl(), "Hello A", "a.txt");
    sendFile(getFtpUrl(), "Hello B", "b.txt");
    sendFile(getFtpUrl(), "Hello C", "c.txt");
    sendFile(getFtpUrl(), "Hello D", "d.txt");
    sendFile(getFtpUrl(), "Hello E", "e.txt");
    assertMockEndpointsSatisfied();
    assertTrue(notify.matchesMockWaitTime());
    assertEquals(5, repo.getCache().size());
    assertTrue(repo.contains("a.txt"));
    assertTrue(repo.contains("b.txt"));
    assertTrue(repo.contains("c.txt"));
    assertTrue(repo.contains("d.txt"));
    assertTrue(repo.contains("e.txt"));
    resetMocks();
    notify = new NotifyBuilder(context).whenDone(2).create();
    getMockEndpoint("mock:result").expectedMessageCount(2);
    // duplicate
    sendFile(getFtpUrl(), "Hello A", "a.txt");
    sendFile(getFtpUrl(), "Hello B", "b.txt");
    // new files
    sendFile(getFtpUrl(), "Hello F", "f.txt");
    sendFile(getFtpUrl(), "Hello G", "g.txt");
    assertMockEndpointsSatisfied();
    assertTrue(notify.matchesMockWaitTime());
    assertEquals(5, repo.getCache().size());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Example 39 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder 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 40 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder 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)

Aggregations

NotifyBuilder (org.apache.camel.builder.NotifyBuilder)109 Test (org.junit.Test)72 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)30 File (java.io.File)24 Exchange (org.apache.camel.Exchange)10 RouteBuilder (org.apache.camel.builder.RouteBuilder)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashSet (java.util.HashSet)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 Processor (org.apache.camel.Processor)4 StopWatch (org.apache.camel.util.StopWatch)4 ConnectException (java.net.ConnectException)3 ExecutorService (java.util.concurrent.ExecutorService)3 Ignore (org.junit.Ignore)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Future (java.util.concurrent.Future)2 ZipFile (java.util.zip.ZipFile)2