Search in sources :

Example 1 with SalesforceConnection

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();
}
Also used : Call(org.teiid.language.Call) ExecutionContext(org.teiid.translator.ExecutionContext) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 2 with SalesforceConnection

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

Example 3 with SalesforceConnection

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

Example 4 with SalesforceConnection

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());
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) Select(org.teiid.language.Select) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 5 with SalesforceConnection

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());
}
Also used : SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) BatchResultInfo(org.teiid.translator.salesforce.SalesforceConnection.BatchResultInfo) IOException(java.io.IOException) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ExecutionContext(org.teiid.translator.ExecutionContext) JobInfo(com.sforce.async.JobInfo) BulkBatchResult(org.teiid.translator.salesforce.SalesforceConnection.BulkBatchResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Select(org.teiid.language.Select) Iterator(java.util.Iterator) List(java.util.List) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) Test(org.junit.Test)

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