Search in sources :

Example 6 with Row

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

the class FunctionScriptLoaderTest method bindingsAvailable.

@Test
public void bindingsAvailable() {
    Row input = new Row();
    final String inputValue = "duke";
    input.addColumn(-1, "name", inputValue);
    RowTransformer function = this.cut.getRowTransformer("bindings");
    Row output = function.execute(input);
    assertNotNull(output);
    final Column outputColumn = output.getColumnByName("synthetic");
    assertNotNull(outputColumn);
    assertThat(outputColumn.getValue(), is(inputValue));
}
Also used : Column(com.airhacks.enhydrator.in.Column) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 7 with Row

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

the class IndexMapperTest method testExecuteReIndexColumns.

/**
     * Test of execute method, of class IndexMapper.
     */
@Test
public void testExecuteReIndexColumns() {
    // define the index of columns by the ordered names array list
    indexMapper.orderedNames = new ArrayList<String>() {

        {
            add("name");
            add("age");
            add("weight");
            add("height");
        }
    };
    // do the test
    Row actualRow = indexMapper.execute(row);
    // check the indices
    assertEquals(0, actualRow.getColumnByName("name").getIndex());
    assertEquals(1, actualRow.getColumnByName("age").getIndex());
    assertEquals(2, actualRow.getColumnByName("weight").getIndex());
    assertEquals(3, actualRow.getColumnByName("height").getIndex());
    assertEquals(-1, actualRow.getColumnByName("resetIndexOne").getIndex());
    assertEquals(-1, actualRow.getColumnByName("resetIndexTwo").getIndex());
    Column nameColumn = actualRow.getColumnByIndex(0);
    assertEquals(0, nameColumn.getIndex());
    Column ageColumn = actualRow.getColumnByIndex(1);
    assertEquals(1, ageColumn.getIndex());
    Column weightColumn = actualRow.getColumnByIndex(2);
    assertEquals(2, weightColumn.getIndex());
    Column heightColumn = actualRow.getColumnByIndex(3);
    assertEquals(3, heightColumn.getIndex());
    // index -1 has only one entry - it was overwritten during the reindex of the column by index map
    Column columnByIndex = actualRow.getColumnByIndex(-1);
}
Also used : Column(com.airhacks.enhydrator.in.Column) Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 8 with Row

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

the class MemoryTest method areErrorsOccured.

@Test
public void areErrorsOccured() {
    Memory memory = new Memory();
    Collection<Throwable> processingErrors = memory.getProcessingErrors();
    assertTrue(processingErrors.isEmpty());
    assertFalse(memory.areErrorsOccured());
    final Row row = new Row();
    memory.addProcessingError(row, new Exception("test"));
    assertTrue(memory.areErrorsOccured());
    processingErrors = memory.getProcessingErrors();
    assertThat(processingErrors.size(), is(1));
    Set<Row> erroneousRows = memory.getErroneousRows();
    assertThat(erroneousRows.size(), is(1));
    assertTrue(erroneousRows.contains(row));
}
Also used : Row(com.airhacks.enhydrator.in.Row) Test(org.junit.Test)

Example 9 with Row

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

the class ScriptingEnvironmentProviderTest method emptyRowHasMemory.

@Test
public void emptyRowHasMemory() {
    Row row = new Row();
    Memory expected = new Memory();
    row.useMemory(expected);
    Bindings bindings = ScriptingEnvironmentProvider.create(new ScriptEngineManager(), null, row);
    Object actual = bindings.get("$MEMORY");
    assertNotNull(actual);
    assertThat(actual, is(expected));
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) Row(com.airhacks.enhydrator.in.Row) Bindings(javax.script.Bindings) Test(org.junit.Test)

Example 10 with Row

use of com.airhacks.enhydrator.in.Row 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)

Aggregations

Row (com.airhacks.enhydrator.in.Row)68 Test (org.junit.Test)54 VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)10 Column (com.airhacks.enhydrator.in.Column)8 Memory (com.airhacks.enhydrator.transform.Memory)8 ArrayList (java.util.ArrayList)5 LogSink (com.airhacks.enhydrator.out.LogSink)4 HashMap (java.util.HashMap)4 PipelineTest (com.airhacks.enhydrator.flexpipe.PipelineTest)3 CSVFileSource (com.airhacks.enhydrator.in.CSVFileSource)3 Source (com.airhacks.enhydrator.in.Source)3 SkipFirstRow (com.airhacks.enhydrator.transform.SkipFirstRow)3 List (java.util.List)3 Map (java.util.Map)3 Bindings (javax.script.Bindings)3 Pump (com.airhacks.enhydrator.Pump)2 NamedSink (com.airhacks.enhydrator.out.NamedSink)2 RowTransformer (com.airhacks.enhydrator.transform.RowTransformer)2 Date (java.util.Date)2 Function (java.util.function.Function)2