Search in sources :

Example 16 with File

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

the class FlatpackFixedLengthWithHeaderAndTrailerDataFormatTest method testUnmarshal.

@Test
public void testUnmarshal() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:unmarshal");
    // by default we get on big message
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(DataSetList.class);
    mock.message(0).header("MyFirstHeader").isEqualTo("1");
    mock.message(0).header("MySecondHeader").isEqualTo("2");
    String data = IOConverter.toString(new File("src/test/data/headerandtrailer/PEOPLE-HeaderAndTrailer.txt"), null);
    template.sendBody("direct:unmarshal", data);
    assertMockEndpointsSatisfied();
    DataSetList list = mock.getExchanges().get(0).getIn().getBody(DataSetList.class);
    assertEquals(6, list.size());
    // assert header
    Map<?, ?> header = list.get(0);
    assertEquals("HBT", header.get("INDICATOR"));
    assertEquals("20080817", header.get("DATE"));
    // assert data
    Map<?, ?> row = list.get(1);
    assertEquals("JOHN", row.get("FIRSTNAME"));
    // assert trailer
    Map<?, ?> trailer = list.get(5);
    assertEquals("FBT", trailer.get("INDICATOR"));
    assertEquals("SUCCESS", trailer.get("STATUS"));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File) Test(org.junit.Test)

Example 17 with File

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

the class FlinkProducerTest method shouldExecuteVoidCallback.

@Test
public void shouldExecuteVoidCallback() throws IOException {
    final File output = File.createTempFile("camel", "flink");
    output.delete();
    template.sendBodyAndHeader(flinkDataSetUri, null, FlinkConstants.FLINK_DATASET_CALLBACK_HEADER, new VoidDataSetCallback() {

        @Override
        public void doOnDataSet(DataSet ds, Object... payloads) {
            ds.writeAsText(output.getAbsolutePath());
        }
    });
    Truth.assertThat(output.length()).isAtLeast(0L);
}
Also used : DataSet(org.apache.flink.api.java.DataSet) File(java.io.File) Test(org.junit.Test)

Example 18 with File

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

the class FlinkProducerTest method shouldExecuteAnnotatedVoidCallback.

@Test
public void shouldExecuteAnnotatedVoidCallback() throws IOException {
    final File output = File.createTempFile("camel", "flink");
    output.delete();
    DataSetCallback dataSetCallback = new AnnotatedDataSetCallback(new Object() {

        @org.apache.camel.component.flink.annotations.DataSetCallback
        void countLines(DataSet<String> textFile) {
            textFile.writeAsText(output.getAbsolutePath());
        }
    });
    template.sendBodyAndHeader(flinkDataSetUri, null, FlinkConstants.FLINK_DATASET_CALLBACK_HEADER, dataSetCallback);
    Truth.assertThat(output.length()).isAtLeast(0L);
}
Also used : AnnotatedDataSetCallback(org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback) AnnotatedDataSetCallback(org.apache.camel.component.flink.annotations.AnnotatedDataSetCallback) File(java.io.File) Test(org.junit.Test)

Example 19 with File

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

the class FlinkProducerTest method shouldExecuteVoidDataStreamCallback.

@Test
public void shouldExecuteVoidDataStreamCallback() throws IOException {
    final File output = File.createTempFile("camel", "flink");
    output.delete();
    template.sendBodyAndHeader(flinkDataStreamUri, null, FlinkConstants.FLINK_DATASTREAM_CALLBACK_HEADER, new VoidDataStreamCallback() {

        @Override
        public void doOnDataStream(DataStream ds, Object... payloads) throws Exception {
            ds.writeAsText(output.getAbsolutePath());
        }
    });
    Truth.assertThat(output.length()).isAtLeast(0L);
}
Also used : DataStream(org.apache.flink.streaming.api.datastream.DataStream) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 20 with File

use of java.io.File 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)

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