Search in sources :

Example 1 with Memory

use of com.airhacks.enhydrator.transform.Memory in project enhydrator by AdamBien.

the class PumpTest method getStringRow.

Row getStringRow() {
    Row row = new Row();
    row.useMemory(new Memory());
    row.addColumn(0, "a", "java");
    row.addColumn(1, "b", "tengah");
    return row;
}
Also used : Memory(com.airhacks.enhydrator.transform.Memory) Row(com.airhacks.enhydrator.in.Row)

Example 2 with Memory

use of com.airhacks.enhydrator.transform.Memory 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)

Example 3 with Memory

use of com.airhacks.enhydrator.transform.Memory in project enhydrator by AdamBien.

the class PumpTest method scriptEngineBindings.

@Test
public void scriptEngineBindings() {
    List<Row> inputRows = new ArrayList<>();
    inputRows.add(getStringRow());
    Map<String, Object> bindings = new HashMap<>();
    bindings.put("date", new Date());
    VirtualSinkSource in = new VirtualSinkSource("in", inputRows);
    VirtualSinkSource out = new VirtualSinkSource();
    Pump cut = new Pump.Engine().homeScriptFolder(EXISTING_HOME_FOLDER, bindings).from(in).startWith("date_should_exist").to(out).build();
    Memory memory = cut.start();
    assertNotNull(memory.get("date"));
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) HashMap(java.util.HashMap) Memory(com.airhacks.enhydrator.transform.Memory) ArrayList(java.util.ArrayList) Row(com.airhacks.enhydrator.in.Row) Date(java.util.Date) Test(org.junit.Test)

Example 4 with Memory

use of com.airhacks.enhydrator.transform.Memory in project enhydrator by AdamBien.

the class PumpTest method columnExpressionTransformer.

@Test
public void columnExpressionTransformer() {
    Map<String, Object> bindings = new HashMap<>();
    bindings.put("prefix", "java");
    Row row = new Row();
    row.addColumn(0, "developer", "duke");
    VirtualSinkSource input = new VirtualSinkSource();
    input.addRow(row);
    VirtualSinkSource output = new VirtualSinkSource();
    Pump pump = new Pump.Engine().from(input).homeScriptFolder(EXISTING_HOME_FOLDER, bindings).withColumnExpression("developer", "function execute(column){return prefix + ' ' + column}").to(output).build();
    Memory memory = pump.start();
    assertThat(memory.areErrorsOccured(), is(false));
    Row first = output.getRow(0);
    Object expected = "java duke";
    Object actual = first.getColumnValue("developer");
    assertThat(expected, is(actual.toString()));
}
Also used : VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) HashMap(java.util.HashMap) Memory(com.airhacks.enhydrator.transform.Memory) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 5 with Memory

use of com.airhacks.enhydrator.transform.Memory in project enhydrator by AdamBien.

the class PumpTest method getIntRow.

Row getIntRow() {
    Row row = new Row();
    row.useMemory(new Memory());
    row.addColumn(0, "a", "1");
    row.addColumn(1, "b", "2");
    return row;
}
Also used : Memory(com.airhacks.enhydrator.transform.Memory) Row(com.airhacks.enhydrator.in.Row)

Aggregations

Memory (com.airhacks.enhydrator.transform.Memory)8 Row (com.airhacks.enhydrator.in.Row)7 Test (org.junit.Test)6 VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)5 HashMap (java.util.HashMap)3 Pump (com.airhacks.enhydrator.Pump)2 CSVFileSource (com.airhacks.enhydrator.in.CSVFileSource)2 Source (com.airhacks.enhydrator.in.Source)2 LogSink (com.airhacks.enhydrator.out.LogSink)2 DatatypeNameMapper (com.airhacks.enhydrator.transform.DatatypeNameMapper)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Column (com.airhacks.enhydrator.in.Column)1 ScriptableSource (com.airhacks.enhydrator.in.ScriptableSource)1 RowTransformer (com.airhacks.enhydrator.transform.RowTransformer)1 SkipFirstRow (com.airhacks.enhydrator.transform.SkipFirstRow)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1