Search in sources :

Example 51 with ExecutionContext

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'");
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) UpdateExecution(org.teiid.translator.UpdateExecution) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 52 with ExecutionContext

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'");
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) UpdateExecution(org.teiid.translator.UpdateExecution) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 53 with ExecutionContext

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]);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Argument(org.teiid.language.Argument) ArrayList(java.util.ArrayList) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SelectResult(com.amazonaws.services.simpledb.model.SelectResult) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 54 with ExecutionContext

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));
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) HashMap(java.util.HashMap) UpdateExecution(org.teiid.translator.UpdateExecution) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 55 with ExecutionContext

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);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Insert(org.teiid.language.Insert) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) GoogleSpreadsheetConnection(org.teiid.translator.google.api.GoogleSpreadsheetConnection) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

ExecutionContext (org.teiid.translator.ExecutionContext)65 Test (org.junit.Test)50 Command (org.teiid.language.Command)49 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)48 TranslationUtility (org.teiid.cdk.api.TranslationUtility)32 ResultSetExecution (org.teiid.translator.ResultSetExecution)23 List (java.util.List)17 UpdateExecution (org.teiid.translator.UpdateExecution)14 TranslatorException (org.teiid.translator.TranslatorException)11 ArrayList (java.util.ArrayList)10 QueryExpression (org.teiid.language.QueryExpression)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 LdapContext (javax.naming.ldap.LdapContext)9 ExecutionFactory (org.teiid.translator.ExecutionFactory)9 SalesforceConnection (org.teiid.translator.salesforce.SalesforceConnection)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 HashMap (java.util.HashMap)6 DataSource (javax.activation.DataSource)6 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)6 WSConnection (org.teiid.translator.WSConnection)6