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"));
}
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);
}
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"));
}
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);
}
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;
}
Aggregations