use of org.teiid.translator.ExecutionContext in project teiid by teiid.
the class TestSolrUpdateExecution method helpUpdate.
private UpdateRequest helpUpdate(String query, QueryResponse... responseDocs) throws TranslatorException {
Command cmd = this.utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
Mockito.stub(context.getCommandContext()).toReturn(Mockito.mock(CommandContext.class));
SolrConnection connection = Mockito.mock(SolrConnection.class);
UpdateResponse response = Mockito.mock(UpdateResponse.class);
ArgumentCaptor<UpdateRequest> argument = ArgumentCaptor.forClass(UpdateRequest.class);
Mockito.when(connection.query(Mockito.any(SolrQuery.class))).thenReturn(responseDocs[0], responseDocs[1]);
Mockito.stub(connection.update(Mockito.any(UpdateRequest.class))).toReturn(response);
UpdateExecution execution = this.translator.createUpdateExecution(cmd, context, this.utility.createRuntimeMetadata(), connection);
execution.execute();
Mockito.verify(connection).update(argument.capture());
return argument.getValue();
}
use of org.teiid.translator.ExecutionContext 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());
}
use of org.teiid.translator.ExecutionContext in project teiid by teiid.
the class TestSalesForceDirectQueryExecution method testWithoutMarker.
@Test(expected = TranslatorException.class)
public void testWithoutMarker() throws Exception {
String input = "exec native('salesforce query')";
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);
DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
}
use of org.teiid.translator.ExecutionContext 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.translator.ExecutionContext 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));
}
Aggregations