Search in sources :

Example 16 with SalesforceConnection

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);
}
Also used : Delete(org.teiid.language.Delete) QueryResult(com.sforce.soap.partner.QueryResult) ExecutionContext(org.teiid.translator.ExecutionContext) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) SObject(com.sforce.soap.partner.sobject.SObject) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 17 with SalesforceConnection

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());
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult) ExecutionContext(org.teiid.translator.ExecutionContext) Execution(org.teiid.translator.Execution) Command(org.teiid.language.Command) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection)

Aggregations

ExecutionContext (org.teiid.translator.ExecutionContext)17 SalesforceConnection (org.teiid.translator.salesforce.SalesforceConnection)17 Test (org.junit.Test)16 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)16 SalesForceExecutionFactory (org.teiid.translator.salesforce.SalesForceExecutionFactory)10 SObject (com.sforce.soap.partner.sobject.SObject)7 Command (org.teiid.language.Command)7 TranslationUtility (org.teiid.cdk.api.TranslationUtility)6 QueryResult (com.sforce.soap.partner.QueryResult)5 Select (org.teiid.language.Select)5 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)5 JobInfo (com.sforce.async.JobInfo)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ColumnReference (org.teiid.language.ColumnReference)3 Expression (org.teiid.language.Expression)3 ExpressionValueSource (org.teiid.language.ExpressionValueSource)3 Insert (org.teiid.language.Insert)3 NamedTable (org.teiid.language.NamedTable)3 Table (org.teiid.metadata.Table)3