use of org.teiid.language.Command in project teiid by teiid.
the class TestJDBCDirectQueryExecution method testPrepareUpdateCount.
@Test
public void testPrepareUpdateCount() throws Exception {
// $NON-NLS-1$
Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call native('update source set e1=? where e2 = ?', 2, 'foo')");
Connection connection = Mockito.mock(Connection.class);
PreparedStatement stmt = Mockito.mock(PreparedStatement.class);
ResultSet rs = Mockito.mock(ResultSet.class);
ResultSetMetaData rsm = Mockito.mock(ResultSetMetaData.class);
Mockito.stub(stmt.getUpdateCount()).toReturn(-1);
Mockito.stub(stmt.getUpdateCount()).toReturn(5);
Mockito.stub(stmt.execute()).toReturn(false);
Mockito.stub(rs.getMetaData()).toReturn(rsm);
Mockito.stub(rsm.getColumnCount()).toReturn(2);
// $NON-NLS-1$
Mockito.stub(connection.prepareStatement("update source set e1=? where e2 = ?")).toReturn(stmt);
DatabaseMetaData dbmd = Mockito.mock(DatabaseMetaData.class);
Mockito.stub(connection.getMetaData()).toReturn(dbmd);
JDBCExecutionFactory ef = new JDBCExecutionFactory();
ef.setSupportsDirectQueryProcedure(true);
ResultSetExecution execution = (ResultSetExecution) ef.createExecution(command, new FakeExecutionContextImpl(), Mockito.mock(RuntimeMetadata.class), connection);
execution.execute();
assertArrayEquals(new Object[] { 5 }, (Object[]) execution.next().get(0));
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestModeShapeSqlTranslator method helpTestVisitor.
public void helpTestVisitor(String input, String expectedOutput) throws TranslatorException {
Command obj = UTIL.parseCommand(input, true, true);
TranslationHelper.helpTestVisitor(expectedOutput, TRANSLATOR, obj);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestNetezzaTranslatorCapabilities method helpTestVisitor.
public void helpTestVisitor(String input, String expectedOutput) throws TranslatorException {
// Convert from sql to objects
Command obj = FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(input);
TranslatedCommand tc = new TranslatedCommand(Mockito.mock(ExecutionContext.class), TRANSLATOR);
tc.translateCommand(obj);
// Check stuff
assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestLDAPDirectQueryExecution method testDelete.
@Test
public void testDelete() throws Exception {
String input = "exec native('delete;uid=doe,ou=people,o=teiid.org')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
LdapContext connection = Mockito.mock(LdapContext.class);
LdapContext ctx = Mockito.mock(LdapContext.class);
Mockito.stub(connection.lookup("")).toReturn(ctx);
LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(ctx, Mockito.times(1)).destroySubcontext("uid=doe,ou=people,o=teiid.org");
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestLDAPDirectQueryExecution method testCreateFail.
@Test(expected = TranslatorException.class)
public void testCreateFail() throws Exception {
String input = "exec native('create;uid=doe,ou=people,o=teiid.org;attributes=one,two,three', 'one')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
LdapContext connection = Mockito.mock(LdapContext.class);
LdapContext ctx = Mockito.mock(LdapContext.class);
Mockito.stub(connection.lookup("")).toReturn(ctx);
LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
}
Aggregations