Search in sources :

Example 16 with VirtualSinkSource

use of com.airhacks.enhydrator.in.VirtualSinkSource in project enhydrator by AdamBien.

the class FromJsonToCSVTest method filterAndCastFromCSVFileToLog.

@Test
public void filterAndCastFromCSVFileToLog() {
    Source source = new CSVFileSource(INPUT + "/languages.csv", ";", "utf-8", true);
    VirtualSinkSource sink = new VirtualSinkSource();
    Pump pump = new Pump.Engine().from(source).filter("$ROW.getColumnValue('language') === 'java'").startWith(new DatatypeNameMapper().addMapping("rank", Datatype.INTEGER)).to(sink).to(new LogSink()).build();
    Memory memory = pump.start();
    assertFalse(memory.areErrorsOccured());
    assertThat(memory.getProcessedRowCount(), is(5l));
    //expecting only "java" language
    assertThat(sink.getNumberOfRows(), is(1));
    String languageValue = (String) sink.getRow(0).getColumnValue("language");
    assertThat(languageValue, is("java"));
    //expecting "java" having rank 1 as Integer
    Object rankValue = sink.getRow(0).getColumnValue("rank");
    assertTrue(rankValue instanceof Integer);
    assertThat((Integer) rankValue, is(1));
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) Memory(com.airhacks.enhydrator.transform.Memory) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) DatatypeNameMapper(com.airhacks.enhydrator.transform.DatatypeNameMapper) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Pump(com.airhacks.enhydrator.Pump) Test(org.junit.Test)

Aggregations

VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)16 Test (org.junit.Test)12 Row (com.airhacks.enhydrator.in.Row)11 LogSink (com.airhacks.enhydrator.out.LogSink)9 Source (com.airhacks.enhydrator.in.Source)7 Pump (com.airhacks.enhydrator.Pump)6 CSVFileSource (com.airhacks.enhydrator.in.CSVFileSource)6 Memory (com.airhacks.enhydrator.transform.Memory)6 ScriptableSource (com.airhacks.enhydrator.in.ScriptableSource)4 JDBCSource (com.airhacks.enhydrator.in.JDBCSource)3 NamedSink (com.airhacks.enhydrator.out.NamedSink)3 DatatypeNameMapper (com.airhacks.enhydrator.transform.DatatypeNameMapper)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CoreMatchers.is (org.hamcrest.CoreMatchers.is)3 Assert.assertThat (org.junit.Assert.assertThat)3 DatatypeIndexMapper (com.airhacks.enhydrator.transform.DatatypeIndexMapper)2 DestinationMapper (com.airhacks.enhydrator.transform.DestinationMapper)2 NashornRowTransformer (com.airhacks.enhydrator.transform.NashornRowTransformer)2 SkipFirstRow (com.airhacks.enhydrator.transform.SkipFirstRow)2