use of com.airhacks.enhydrator.out.LogSink 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.out.LogSink in project enhydrator by AdamBien.
the class CopyTableIT method readTable.
@Test
public void readTable() {
final String firstName = "arabica";
final String secondName = "niceone";
CoffeeTestFixture.insertCoffee(firstName, 2, "hawai", Roast.LIGHT, "nice", "whole");
CoffeeTestFixture.insertCoffee(secondName, 3, "russia", Roast.MEDIUM, "awful", "java beans");
VirtualSinkSource vss = new VirtualSinkSource();
Pump pump = new Pump.Engine().flowListener(l -> Logger.getLogger("plainCopy").info(l)).from(this.source).to(new LogSink("*")).to(vss).sqlQuery("select * from Coffee").build();
pump.start();
int numberOfRows = vss.getNumberOfRows();
assertThat(numberOfRows, is(2));
System.out.println(vss.toString());
Row first = vss.getRow(0);
Object name = first.getColumnValue("NAME");
assertThat(firstName, is(name));
Row last = vss.getRow(1);
name = last.getColumnValue("NAME");
assertThat(secondName, is(name));
}
use of com.airhacks.enhydrator.out.LogSink in project enhydrator by AdamBien.
the class ConvertToIntAndCopyTest method init.
@Before
public void init() {
this.input = new VirtualSinkSource();
this.output = new VirtualSinkSource();
//map column answer to Integer
final DatatypeNameMapper datatypeMapper = new DatatypeNameMapper();
datatypeMapper.addMapping("answer", Datatype.INTEGER);
//Copy column question to answer and origin
ColumnCopier columnCopier = new ColumnCopier();
columnCopier.addMapping("question", "answer", "origin");
this.pump = new Pump.Engine().startWith(columnCopier).startWith(datatypeMapper).with("answer", (c) -> {
Integer columnValue = (Integer) c;
return columnValue * 2;
}).from(input).to(output).to(new LogSink()).build();
}
use of com.airhacks.enhydrator.out.LogSink 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.out.LogSink 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)));
}
Aggregations