use of org.teiid.translator.ExecutionContext in project teiid by teiid.
the class TestSimpleDBExecution method testDelete.
@Test
public void testDelete() throws Exception {
String query = "delete from item where somedate = {ts '2014-04-04 10:50:45'}";
Mockito.stub(connection.performDelete(Mockito.anyString(), Mockito.anyString())).toReturn(100);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
UpdateExecution exec = translator.createUpdateExecution(cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
Mockito.verify(connection).performDelete("item", "SELECT itemName() FROM item WHERE somedate = '2014-04-04 10:50:45.0'");
}
use of org.teiid.translator.ExecutionContext in project teiid by teiid.
the class TestSimpleDBExecution method testUpdate.
@Test
public void testUpdate() throws Exception {
String query = "UPDATE item set attribute = 'value', somedate = {ts '2014-04-04 10:50:45'} where attribute > 'name'";
Mockito.stub(connection.performUpdate(Mockito.anyString(), Mockito.anyMap(), Mockito.anyString())).toReturn(100);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
UpdateExecution exec = translator.createUpdateExecution(cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
Map<String, Object> attributes = new TreeMap<String, Object>();
attributes.put("attribute", "value");
attributes.put("somedate", "2014-04-04 10:50:45.0");
Mockito.verify(connection).performUpdate("item", attributes, "SELECT itemName() FROM item WHERE attribute > 'name'");
}
use of org.teiid.translator.ExecutionContext in project teiid by teiid.
the class TestSimpleDBExecution method testDirectExecution.
@Test
public void testDirectExecution() throws Exception {
SelectResult result = new SelectResult();
result.setItems(mockResult());
String query = "select * from item where attribute > 'name'";
Mockito.stub(connection.performSelect(Mockito.anyString(), Mockito.anyString())).toReturn(result);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
List<Argument> arguments = new ArrayList<Argument>();
Argument arg = new Argument(Direction.IN, String.class, Mockito.mock(ProcedureParameter.class));
arg.setArgumentValue(LanguageFactory.INSTANCE.createLiteral(query, String.class));
arguments.add(arg);
ResultSetExecution exec = translator.createDirectExecution(arguments, cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
List row = exec.next();
Mockito.verify(connection).performSelect("select * from item where attribute > 'name'", null);
Object[] results = (Object[]) row.get(0);
assertEquals("a1", results[0]);
assertEquals("[a2, a22]", results[1]);
}
use of org.teiid.translator.ExecutionContext in project teiid by teiid.
the class TestSimpleDBExecution method testUpdateArray.
@Test
public void testUpdateArray() throws Exception {
String query = "UPDATE item set strarray = ('1','2')";
Mockito.stub(connection.performUpdate(Mockito.anyString(), Mockito.anyMap(), Mockito.anyString())).toReturn(100);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
UpdateExecution exec = translator.createUpdateExecution(cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
ArgumentCaptor<String> item = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> select = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<HashMap> args = ArgumentCaptor.forClass(HashMap.class);
Mockito.verify(connection, Mockito.times(1)).performUpdate(item.capture(), args.capture(), select.capture());
System.out.println();
assertEquals("1,2,", arrayToStr((String[]) args.getAllValues().get(0).get("strarray")));
assertEquals("item", item.getAllValues().get(0));
assertEquals("SELECT itemName() FROM item", select.getAllValues().get(0));
}
use of org.teiid.translator.ExecutionContext in project teiid by teiid.
the class TestSQLtoSpreadsheetQuery method testInsertExecution.
@Test
public void testInsertExecution() throws Exception {
String sql = "insert into PeopleList(A,B,C) values ('String,String', 'val', 15.5)";
Insert insert = (Insert) getCommand(sql);
GoogleSpreadsheetConnection gsc = Mockito.mock(GoogleSpreadsheetConnection.class);
Mockito.stub(gsc.getSpreadsheetInfo()).toReturn(people);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
SpreadsheetUpdateExecution sue = new SpreadsheetUpdateExecution(insert, gsc, ec, rm);
sue.execute();
LinkedHashMap<String, Object> vals = new LinkedHashMap<String, Object>();
vals.put("A", "String,String");
vals.put("B", "val");
vals.put("C", 15.5);
Mockito.verify(gsc).executeRowInsert("PeopleList", vals);
}
Aggregations