Search in sources :

Example 1 with VirtualSinkSource

use of com.airhacks.enhydrator.in.VirtualSinkSource 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));
}
Also used : LogSink(com.airhacks.enhydrator.out.LogSink) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Persistence(javax.persistence.Persistence) Test(org.junit.Test) Logger(java.util.logging.Logger) Assert.assertThat(org.junit.Assert.assertThat) JDBCSinkTest(com.airhacks.enhydrator.out.JDBCSinkTest) List(java.util.List) JDBCSource(com.airhacks.enhydrator.in.JDBCSource) Ignore(org.junit.Ignore) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) After(org.junit.After) NamedSink(com.airhacks.enhydrator.out.NamedSink) Row(com.airhacks.enhydrator.in.Row) Before(org.junit.Before) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test) JDBCSinkTest(com.airhacks.enhydrator.out.JDBCSinkTest)

Example 2 with VirtualSinkSource

use of com.airhacks.enhydrator.in.VirtualSinkSource 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();
}
Also used : LogSink(com.airhacks.enhydrator.out.LogSink) Memory(com.airhacks.enhydrator.transform.Memory) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ColumnCopier(com.airhacks.enhydrator.transform.ColumnCopier) Column(com.airhacks.enhydrator.in.Column) Test(org.junit.Test) Assert.assertThat(org.junit.Assert.assertThat) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Datatype(com.airhacks.enhydrator.transform.Datatype) DatatypeNameMapper(com.airhacks.enhydrator.transform.DatatypeNameMapper) Pump(com.airhacks.enhydrator.Pump) Row(com.airhacks.enhydrator.in.Row) Before(org.junit.Before) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) ColumnCopier(com.airhacks.enhydrator.transform.ColumnCopier) DatatypeNameMapper(com.airhacks.enhydrator.transform.DatatypeNameMapper) Before(org.junit.Before)

Example 3 with VirtualSinkSource

use of com.airhacks.enhydrator.in.VirtualSinkSource 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;
}
Also used : Path(java.nio.file.Path) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) Source(com.airhacks.enhydrator.in.Source) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Pump(com.airhacks.enhydrator.Pump) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource)

Example 4 with VirtualSinkSource

use of com.airhacks.enhydrator.in.VirtualSinkSource 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)));
}
Also used : NonRecursiveTree(com.airhacks.enhydrator.functions.NonRecursiveTree) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) Row(com.airhacks.enhydrator.in.Row) 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 5 with VirtualSinkSource

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

the class PumpTest method continueOnError.

@Test
public void continueOnError() {
    List<Row> inputRows = new ArrayList<>();
    inputRows.add(getStringRow());
    inputRows.add(getIntRow());
    VirtualSinkSource in = new VirtualSinkSource("in", inputRows);
    VirtualSinkSource out = new VirtualSinkSource();
    Pump cut = new Pump.Engine().from(in).startWith(t -> {
        t.getColumnByName("a").convertToInteger();
        return t;
    }).to(out).continueOnError().build();
    Memory memory = cut.start();
    assertTrue(memory.areErrorsOccured());
    Set<Row> erroneousRows = memory.getErroneousRows();
    assertNotNull(erroneousRows);
    assertFalse(erroneousRows.isEmpty());
    assertThat(memory.getProcessedRowCount(), is(1l));
}
Also used : Memory(com.airhacks.enhydrator.transform.Memory) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Date(java.util.Date) Assert.assertNotNull(org.junit.Assert.assertNotNull) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) Test(org.junit.Test) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Assert.assertFalse(org.junit.Assert.assertFalse) RowTransformer(com.airhacks.enhydrator.transform.RowTransformer) Map(java.util.Map) Row(com.airhacks.enhydrator.in.Row) Mockito.mock(org.mockito.Mockito.mock) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Memory(com.airhacks.enhydrator.transform.Memory) ArrayList(java.util.ArrayList) Row(com.airhacks.enhydrator.in.Row) 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