Search in sources :

Example 11 with VirtualSinkSource

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

the class CSVImportTest method nullHandling.

@Test
public void nullHandling() {
    VirtualSinkSource vss = getSource("./src/test/files/nullcolumns.csv");
    int numberOfRows = vss.getNumberOfRows();
    assertThat(numberOfRows, is(3));
    Iterable<Row> query = vss.query();
    Iterator<Row> iterator = query.iterator();
    //skipping header
    iterator.next();
    Row first = iterator.next();
    assertNull(first.getColumnValue("1"));
    assertNull(first.getColumnValue("2"));
    assertNull(first.getColumnValue("3"));
    assertNull(first.getColumnValue("4"));
    Row second = iterator.next();
    String emptyString = " ";
    assertThat(second.getColumnValue("1"), is(emptyString));
    assertThat(second.getColumnValue("2"), is(emptyString));
    assertThat(second.getColumnValue("3"), is(emptyString));
    assertNull(second.getColumnValue("4"));
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 12 with VirtualSinkSource

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

the class CSVImportTest method copy.

/**
     * 1997;Ford;E350;2,34
     */
@Test
public void copy() {
    VirtualSinkSource vss = getSource("./src/test/files/cars.csv");
    int numberOfRows = vss.getNumberOfRows();
    assertTrue(numberOfRows > 0);
    Iterable<Row> query = vss.query();
    boolean foundFord = false;
    for (Row list : query) {
        assertThat(list.getNumberOfColumns(), is(4));
        if ("Ford".equals(list.getColumnValue("Make"))) {
            foundFord = true;
        }
    }
    assertTrue(foundFord);
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 13 with VirtualSinkSource

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

the class JSONImportTest method readFromJSON.

@Test
public void readFromJSON() throws FileNotFoundException {
    VirtualSinkSource vss = getSource("./src/test/files/languages.json");
    int numberOfRows = vss.getNumberOfRows();
    assertThat(numberOfRows, is(1));
    Iterable<Row> query = vss.query();
    Iterator<Row> iterator = query.iterator();
    Row first = iterator.next();
    assertThat(first.getColumnValue("java"), is("1"));
    assertThat(first.getColumnValue("c"), is("2"));
    assertThat(first.getColumnValue("cobol"), is("3"));
    assertThat(first.getColumnValue("esoteric"), is("4"));
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 14 with VirtualSinkSource

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

the class ReadJDKVersionsTest method readFromCSV.

@Test
public void readFromCSV() {
    Source input = new CSVFileSource("./src/test/files/jdk-dates.csv", ";", "UTF-8", true);
    VirtualSinkSource output = new VirtualSinkSource();
    Pump pump = new Pump.Engine().from(input).startWith(new SkipFirstRow()).startWith(new DatatypeNameMapper().addMapping("Year", Datatype.INTEGER)).filter("$ROW.getColumnValue('Year') > 2000").to(new LogSink()).to(output).build();
    Memory memory = pump.start();
    Assert.assertFalse(memory.areErrorsOccured());
    List<Row> rows = output.getRows();
    assertFalse(rows.isEmpty());
    Row first = rows.get(1);
    Object year = first.getColumnValue("Year");
    System.out.println("The year is: " + year);
}
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) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) Row(com.airhacks.enhydrator.in.Row) DatatypeNameMapper(com.airhacks.enhydrator.transform.DatatypeNameMapper) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Pump(com.airhacks.enhydrator.Pump) Test(org.junit.Test)

Example 15 with VirtualSinkSource

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

the class CSVImportTest method getSource.

VirtualSinkSource getSource(final String fileName) {
    Source source = new CSVFileSource(fileName, ";", "UTF-8", true);
    VirtualSinkSource vss = new VirtualSinkSource();
    Pump pump = new Pump.Engine().from(source).to(vss).to(new LogSink()).build();
    pump.start();
    return vss;
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Source(com.airhacks.enhydrator.in.Source) Pump(com.airhacks.enhydrator.Pump)

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