Search in sources :

Example 1 with SimpleDBInsertVisitor

use of org.teiid.translator.simpledb.SimpleDBInsertVisitor in project teiid by teiid.

the class TestSimpleDBExecution method testInsert.

@Test
public void testInsert() throws Exception {
    String query = "insert into item (\"itemName()\", attribute, somedate, strarray) values ('one', 'value', {ts '2014-04-04 10:50:45'}, ('1', '2'))";
    Command cmd = utility.parseCommand(query);
    ExecutionContext context = Mockito.mock(ExecutionContext.class);
    UpdateExecution exec = translator.createUpdateExecution(cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
    exec.execute();
    SimpleDBInsertVisitor visitor = new SimpleDBInsertVisitor();
    visitor.visitNode(cmd);
    ArgumentCaptor<Iterator> argument = ArgumentCaptor.forClass(Iterator.class);
    ArgumentCaptor<String> itemName = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<ArrayList> columns = ArgumentCaptor.forClass(ArrayList.class);
    Mockito.verify(connection).performInsert(itemName.capture(), columns.capture(), argument.capture());
    assertEquals("item", itemName.getValue());
    List<?> values = (List<?>) argument.getValue().next();
    assertEquals("value", values.get(1));
    assertEquals("2014-04-04 10:50:45.0", values.get(2).toString());
    assertEquals("1,2,", arrayToStr((String[]) values.get(3)));
}
Also used : ArrayList(java.util.ArrayList) UpdateExecution(org.teiid.translator.UpdateExecution) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SimpleDBInsertVisitor(org.teiid.translator.simpledb.SimpleDBInsertVisitor) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Test (org.junit.Test)1 Command (org.teiid.language.Command)1 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)1 ExecutionContext (org.teiid.translator.ExecutionContext)1 UpdateExecution (org.teiid.translator.UpdateExecution)1 SimpleDBInsertVisitor (org.teiid.translator.simpledb.SimpleDBInsertVisitor)1