use of org.teiid.language.Command in project teiid by teiid.
the class TestSalesForceDirectQueryExecution method testSearch.
@Test
public void testSearch() throws Exception {
String input = "exec native('search;SELECT Account.Id, Account.Type, Account.Name FROM Account')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
QueryResult qr = Mockito.mock(QueryResult.class);
Mockito.stub(qr.isDone()).toReturn(true);
SObject[] results = new SObject[1];
SObject s = new SObject();
s.setType("Account");
s.setId("The ID");
results[0] = s;
s.addField("Type", "The Type");
s.addField("Name", "The Name");
Mockito.stub(qr.getRecords()).toReturn(results);
Mockito.stub(connection.query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false)).toReturn(qr);
DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(connection, Mockito.times(1)).query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false);
assertArrayEquals(new Object[] { "The ID", "The Type", "The Name" }, (Object[]) execution.next().get(0));
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestSalesForceDirectQueryExecution method testDelete.
@Test
public void testDelete() throws Exception {
String input = "exec native('delete;', 'id1','id2')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
ArgumentCaptor<String[]> payloadArgument = ArgumentCaptor.forClass(String[].class);
Mockito.stub(connection.delete(payloadArgument.capture())).toReturn(23);
DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(connection, Mockito.times(1)).delete(payloadArgument.capture());
assertEquals("id1", payloadArgument.getValue()[0]);
assertEquals("id2", payloadArgument.getValue()[1]);
assertArrayEquals(new Object[] { 23 }, (Object[]) execution.next().get(0));
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestYahooTranslation method helpTestTranslation.
public void helpTestTranslation(String sql, String expectedUrl) throws Exception {
Command command = FakeTranslationFactory.getInstance().getYahooTranslationUtility().parseCommand(sql);
String url = YahooExecution.translateIntoUrl((Select) command);
// $NON-NLS-1$
assertEquals("Did not get expected url", expectedUrl, url);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestOracleTranslator method testConcat2.
@Test
public void testConcat2() throws Exception {
// $NON-NLS-1$
String input = "select concat2(stringnum, stringkey) from bqt1.Smalla";
// $NON-NLS-1$
String output = "SELECT (g_0.StringNum || g_0.StringKey) FROM SmallA g_0";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
commandBuilder.getLanguageBridgeFactory().setSupportsConcat2(true);
Command obj = commandBuilder.getCommand(input, true, true);
TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestOracleTranslator method testCursorResult.
@Test
public void testCursorResult() throws Exception {
// $NON-NLS-1$
String input = "call proc('foo')";
// $NON-NLS-1$
String output = "{call proc(?,?)}";
String ddl = "create foreign procedure proc (in x string, out y object options (native_type 'REF CURSOR')) returns table (a string);";
Command command = helpTestVisitor(RealMetadataFactory.fromDDL(ddl, "x", "y"), input, EMPTY_CONTEXT, null, output);
Connection connection = Mockito.mock(Connection.class);
CallableStatement cs = Mockito.mock(CallableStatement.class);
Mockito.stub(cs.getUpdateCount()).toReturn(-1);
ResultSet rs = Mockito.mock(ResultSet.class);
Mockito.stub(cs.getObject(2)).toReturn(rs);
// $NON-NLS-1$
Mockito.stub(connection.prepareCall(output)).toReturn(cs);
OracleExecutionFactory ef = new OracleExecutionFactory();
JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), ef);
procedureExecution.execute();
// TODO we may not want to actually return the resultset, but this ensures full compatibility
assertEquals(Arrays.asList(rs), procedureExecution.getOutputParameterValues());
Mockito.verify(cs, Mockito.times(1)).registerOutParameter(2, OracleExecutionFactory.CURSOR_TYPE);
}
Aggregations