use of org.teiid.translator.salesforce.SalesforceConnection in project teiid by teiid.
the class TestProcedureExecution method testProcedureName.
@Test
public void testProcedureName() throws Exception {
// $NON-NLS-1$
Call command = (Call) translationUtility.parseCommand("exec getupdated('foo', {d '1970-01-01'}, {d '1990-01-01'})");
SalesforceConnection sfc = Mockito.mock(SalesforceConnection.class);
UpdatedResult ur = new UpdatedResult();
ur.setIDs(Arrays.asList("1", "2"));
Mockito.stub(sfc.getUpdated(Mockito.eq("foo"), (Calendar) Mockito.anyObject(), (Calendar) Mockito.anyObject())).toReturn(ur);
ProcedureExecutionParentImpl pepi = new ProcedureExecutionParentImpl(command, sfc, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class));
pepi.execute();
assertNotNull(pepi.next());
assertNotNull(pepi.next());
assertNull(pepi.next());
pepi.close();
}
use of org.teiid.translator.salesforce.SalesforceConnection in project teiid by teiid.
the class TestQueryExecutionImpl method testJoin.
@Test
public void testJoin() throws Exception {
// $NON-NLS-1$
Select command = (Select) translationUtility.parseCommand("select Account.Name, Contact.Id from Account inner join Contact on Account.Id = Contact.AccountId");
SalesforceConnection sfc = Mockito.mock(SalesforceConnection.class);
QueryResult qr = new QueryResult();
SObject so = new SObject();
so.setType("Account");
so.addField("Name", "account name");
SObject so1 = new SObject();
so1.setType("Contact");
so1.addField("Id", "contact id");
so.addField("Contacts", so1);
qr.setRecords(new SObject[] { so });
qr.setDone(true);
Mockito.stub(sfc.query("SELECT Account.Name, Contact.Id FROM Contact WHERE Contact.AccountId != NULL", 0, false)).toReturn(qr);
QueryExecutionImpl qei = new QueryExecutionImpl(command, sfc, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class), new SalesForceExecutionFactory());
qei.execute();
assertEquals(Arrays.asList("account name", "contact id"), qei.next());
assertNull(qei.next());
}
use of org.teiid.translator.salesforce.SalesforceConnection in project teiid by teiid.
the class TestQueryExecutionImpl method testBatching.
@Test
public void testBatching() throws Exception {
// $NON-NLS-1$
Select command = (Select) translationUtility.parseCommand("select Name from Account");
SalesforceConnection sfc = Mockito.mock(SalesforceConnection.class);
QueryResult qr = new QueryResult();
SObject so = new SObject();
so.setType("Account");
so.addField("Name", null);
qr.setRecords(new SObject[] { so });
qr.setDone(false);
QueryResult finalQr = new QueryResult();
finalQr.setRecords(new SObject[] { so });
finalQr.setDone(true);
Mockito.stub(sfc.query("SELECT Account.Name FROM Account", 0, false)).toReturn(qr);
Mockito.stub(sfc.queryMore(null, 0)).toReturn(finalQr);
QueryExecutionImpl qei = new QueryExecutionImpl(command, sfc, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class), new SalesForceExecutionFactory());
qei.execute();
assertNotNull(qei.next());
assertNotNull(qei.next());
assertNull(qei.next());
}
use of org.teiid.translator.salesforce.SalesforceConnection in project teiid by teiid.
the class TestQueryExecutionImpl method testRetrieve.
@Test
public void testRetrieve() throws Exception {
// $NON-NLS-1$
Select command = (Select) translationUtility.parseCommand("select Name from Account where id = 'abc'");
SalesforceConnection sfc = Mockito.mock(SalesforceConnection.class);
Mockito.stub(sfc.retrieve("Account.Name", "Account", Arrays.asList("abc"))).toReturn(new SObject[] { null });
QueryExecutionImpl qei = new QueryExecutionImpl(command, sfc, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class), new SalesForceExecutionFactory());
qei.execute();
assertNull(qei.next());
}
use of org.teiid.translator.salesforce.SalesforceConnection in project teiid by teiid.
the class TestQueryExecutionImpl method testBulkFlow.
@Test
public void testBulkFlow() throws Exception {
// $NON-NLS-1$
Select command = (Select) translationUtility.parseCommand("select Name from Account");
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
JobInfo jobInfo = Mockito.mock(JobInfo.class);
Mockito.when(connection.createBulkJob(Mockito.anyString(), Mockito.eq(OperationEnum.query), Mockito.eq(true))).thenReturn(jobInfo);
final BatchResultInfo info = new BatchResultInfo("x");
Mockito.when(connection.getBatchQueryResults(Mockito.anyString(), Mockito.eq(info))).thenAnswer(new Answer<BulkBatchResult>() {
boolean first = true;
@Override
public BulkBatchResult answer(InvocationOnMock invocation) throws Throwable {
if (first) {
first = false;
throw new DataNotAvailableException();
}
if (info.getAndIncrementResultNum() == 0) {
final Iterator<List<String>> i = Arrays.asList(Arrays.asList("Name"), Arrays.asList("X")).iterator();
return new BulkBatchResult() {
@Override
public List<String> nextRecord() throws IOException {
if (!i.hasNext()) {
return null;
}
return i.next();
}
@Override
public void close() {
}
};
}
return null;
}
});
Mockito.when(connection.addBatch("SELECT Account.Name FROM Account", jobInfo)).thenReturn(info);
ExecutionContext mock = Mockito.mock(ExecutionContext.class);
Mockito.stub(mock.getSourceHints()).toReturn(Arrays.asList("bulk"));
QueryExecutionImpl execution = new QueryExecutionImpl(command, connection, Mockito.mock(RuntimeMetadata.class), mock, new SalesForceExecutionFactory());
execution.execute();
try {
execution.next();
fail();
} catch (DataNotAvailableException e) {
}
List<?> row = execution.next();
assertEquals(Arrays.asList("X"), row);
assertNull(execution.next());
}
Aggregations