Search in sources :

Example 31 with File

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

the class FromFtpPreMoveNoopTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() throws Exception {
            from(getFtpUrl()).process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    // assert the file is pre moved
                    File file = new File(FTP_ROOT_DIR + "/movefile/work/hello.txt");
                    assertTrue("The file should have been moved", file.exists());
                }
            }).to("mock:result");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) File(java.io.File)

Example 32 with File

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

the class FromFtpDeleteFileTest method prepareFtpServer.

private void prepareFtpServer() throws Exception {
    // prepares the FTP Server by creating a file on the server that we want to unit
    // test that we can pool and store as a local file
    Endpoint endpoint = context.getEndpoint(getFtpUrl());
    Exchange exchange = endpoint.createExchange();
    exchange.getIn().setBody("Hello World this file will be deleted");
    exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
    Producer producer = endpoint.createProducer();
    producer.start();
    producer.process(exchange);
    producer.stop();
    // assert file is created
    File file = new File(FTP_ROOT_DIR + "/deletefile/hello.txt");
    assertTrue("The file should exists", file.exists());
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) File(java.io.File)

Example 33 with File

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

the class FromFtpNoopTest method testNoop.

@Test
public void testNoop() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    // we should not be able to poll the file more than once since its noop and idempotent
    mock.expectedMessageCount(1);
    mock.assertIsSatisfied();
    // assert the file is still there
    File file = new File(FTP_ROOT_DIR + "/noop/hello.txt");
    assertTrue("The file should exists", file.exists());
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File) Test(org.junit.Test)

Example 34 with File

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

the class FtpBrowsableEndpointTest method testBrowsableTwoFiles.

@Test
public void testBrowsableTwoFiles() throws Exception {
    template.sendBodyAndHeader(getFtpUrl(), "A", Exchange.FILE_NAME, "a.txt");
    template.sendBodyAndHeader(getFtpUrl(), "B", Exchange.FILE_NAME, "b.txt");
    FtpEndpoint<?> endpoint = context.getEndpoint(getFtpUrl() + "&sortBy=file:name", FtpEndpoint.class);
    assertNotNull(endpoint);
    MemoryIdempotentRepository repo = (MemoryIdempotentRepository) endpoint.getInProgressRepository();
    assertEquals(0, repo.getCacheSize());
    List<Exchange> list = endpoint.getExchanges();
    assertNotNull(list);
    assertEquals(2, list.size());
    assertEquals("a.txt", list.get(0).getIn().getHeader(Exchange.FILE_NAME));
    assertEquals("b.txt", list.get(1).getIn().getHeader(Exchange.FILE_NAME));
    // the in progress repo should not leak
    assertEquals(0, repo.getCacheSize());
    // and the files is still there
    File fileA = new File(FTP_ROOT_DIR + "/browse/a.txt");
    assertTrue("File should exist " + fileA, fileA.exists());
    File fileB = new File(FTP_ROOT_DIR + "/browse/b.txt");
    assertTrue("File should exist " + fileB, fileB.exists());
}
Also used : Exchange(org.apache.camel.Exchange) File(java.io.File) MemoryIdempotentRepository(org.apache.camel.processor.idempotent.MemoryIdempotentRepository) Test(org.junit.Test)

Example 35 with File

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

the class FtpConsumerWithCharsetTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    byte[] iso = payload.getBytes("iso-8859-1");
    byte[] utf = payload.getBytes("utf-8");
    log.debug("iso: {}", new String(iso, Charset.forName("iso-8859-1")));
    log.debug("utf: {}", new String(utf, Charset.forName("utf-8")));
    for (byte b : iso) {
        log.debug("iso byte: {}", b);
    }
    for (byte b : utf) {
        log.debug("utf byte: {}", b);
    }
    prepareFtpServer();
    // Check that the payload exists in upload and is in iso charset.ß
    File file = new File(FTP_ROOT_DIR + "/upload/iso.txt");
    assertTrue("The uploaded file should exists", file.exists());
    // Lets also test byte wise
    InputStream fis = IOHelper.buffered(new FileInputStream(file));
    byte[] buffer = new byte[100];
    int len = fis.read(buffer);
    assertTrue("Should read data: " + len, len != -1);
    byte[] data = new byte[len];
    System.arraycopy(buffer, 0, data, 0, len);
    fis.close();
    // data should be in iso, where the danish ae is -26, oe is -8 aa is -27
    // and copyright is -87
    assertEquals(5, data.length);
    assertEquals(-26, data[0]);
    assertEquals(-8, data[1]);
    assertEquals(-27, data[2]);
    assertEquals(32, data[3]);
    assertEquals(-87, data[4]);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Before(org.junit.Before)

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