use of org.teiid.translator.salesforce.SalesforceConnection in project teiid by teiid.
the class TestUpdates method testIds.
@Test
public void testIds() throws Exception {
Delete delete = (Delete) translationUtility.parseCommand("delete from contacts");
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
SalesForceExecutionFactory config = new SalesForceExecutionFactory();
DeleteExecutionImpl updateExecution = new DeleteExecutionImpl(config, delete, connection, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class));
ArgumentCaptor<String> queryArgument = ArgumentCaptor.forClass(String.class);
QueryResult qr = new QueryResult();
SObject so = new SObject();
so.setType("Contact");
so.addField("Id", "x");
qr.setRecords(new SObject[] { so });
qr.setSize(1);
qr.setDone(true);
Mockito.stub(connection.query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean())).toReturn(qr);
Mockito.stub(connection.delete(new String[] { "x" })).toReturn(1);
while (true) {
try {
updateExecution.execute();
org.junit.Assert.assertArrayEquals(new int[] { 1 }, updateExecution.getUpdateCounts());
break;
} catch (DataNotAvailableException e) {
continue;
}
}
Mockito.verify(connection, Mockito.times(1)).query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean());
String query = queryArgument.getValue();
assertEquals("SELECT Id FROM Contact ", query);
}
use of org.teiid.translator.salesforce.SalesforceConnection in project teiid by teiid.
the class TestVisitors method helpTest.
private void helpTest(String sql, String expected) throws Exception {
Command command = translationUtility.parseCommand(sql);
SalesForceExecutionFactory factory = new SalesForceExecutionFactory();
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
ArgumentCaptor<String> queryArgument = ArgumentCaptor.forClass(String.class);
QueryResult qr = Mockito.mock(QueryResult.class);
Mockito.stub(connection.query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean())).toReturn(qr);
Execution execution = factory.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(connection, Mockito.times(1)).query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean());
assertEquals(expected, queryArgument.getValue().trim());
}
Aggregations