use of com.airhacks.enhydrator.Pump in project enhydrator by AdamBien.
the class FromJsonToCSVTest method fromJSONToCSV.
@Test
public void fromJSONToCSV() throws FileNotFoundException {
Source source = new ScriptableSource(INPUT + "languages.json", INPUT + "converter.js", "UTF-8");
final CSVFileSink csvFileSink = new CSVFileSink("*", getFileName(), ";", true, false);
Pump pump = new Pump.Engine().from(source).to(new LogSink()).to(csvFileSink).build();
pump.start();
}
use of com.airhacks.enhydrator.Pump in project enhydrator by AdamBien.
the class JSONImportTest method getSource.
VirtualSinkSource getSource(final String fileName) throws FileNotFoundException {
final Path pathToContent = Paths.get(fileName);
Reader script = new FileReader("./src/test/files/converter.js");
Source source = new ScriptableSource(pathToContent, script, "UTF-8");
VirtualSinkSource vss = new VirtualSinkSource();
Pump pump = new Pump.Engine().from(source).to(vss).to(new LogSink()).build();
pump.start();
return vss;
}
use of com.airhacks.enhydrator.Pump in project enhydrator by AdamBien.
the class ParentTest method copy.
/**
* Name;Size;Folder
*/
@Test
public void copy() {
Source source = new CSVFileSource("./src/test/files/files.csv", ";", "UTF-8", true);
VirtualSinkSource vss = new VirtualSinkSource();
Pump pump = new Pump.Engine().from(source).startWith(new SkipFirstRow()).startWith(new NonRecursiveTree("Name", "Folder")).to(vss).to(new LogSink()).build();
pump.start();
System.out.println(vss.getRows());
int numberOfRows = vss.getNumberOfRows();
assertThat(numberOfRows, is(2));
Row parentWithChildren = vss.getRow(0);
assertNotNull(parentWithChildren);
assertThat(parentWithChildren.getNumberOfColumns(), is(3));
List<Row> children = parentWithChildren.getChildren();
assertThat(children.size(), is(2));
children.forEach(e -> assertThat(e.getNumberOfColumns(), is(2)));
}
use of com.airhacks.enhydrator.Pump 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.Pump 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