Search in sources :

Example 31 with TSalesforceInputProperties

use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.

the class SalesforceInputReaderTestIT method testClosingAlreadyClosedJob.

@Test
public void testClosingAlreadyClosedJob() {
    try {
        TSalesforceInputProperties properties = createTSalesforceInputProperties(false, true);
        properties.manualQuery.setValue(false);
        SalesforceBulkQueryInputReader reader = (SalesforceBulkQueryInputReader) this.<IndexedRecord>createBoundedReader(properties);
        reader.start();
        reader.close();
        // Job could be closed on Salesforce side and previously we tried to close it again, we shouldn't do that.
        // We can emulate this like calling close the job second time.
        reader.close();
    } catch (Throwable t) {
        Assert.fail("This test shouldn't throw any errors, since we're closing already closed job");
    }
}
Also used : TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) Test(org.junit.Test)

Example 32 with TSalesforceInputProperties

use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.

the class SalesforceInputReaderTestIT method testAggregrateQueryWithDoubleTypeAndBasicQuery.

@Test
public void testAggregrateQueryWithDoubleTypeAndBasicQuery() throws Throwable {
    TSalesforceInputProperties props = createTSalesforceInputProperties(true, false);
    props.manualQuery.setValue(true);
    // alias is necessary and should be the same with schema
    props.query.setValue("SELECT AVG(Amount) VALUE FROM Opportunity");
    props.module.main.schema.setValue(SCHEMA_DOUBLE);
    List<IndexedRecord> outputRows = readRows(props);
    assertEquals(1, outputRows.size());
    IndexedRecord record = outputRows.get(0);
    assertNotNull(record.getSchema());
    Object value = record.get(0);
    Assert.assertTrue(value != null && value instanceof Double);
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) Test(org.junit.Test)

Example 33 with TSalesforceInputProperties

use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.

the class SalesforceInputReaderTestIT method runInputTest.

protected void runInputTest(boolean emptySchema, boolean isBulkQury) throws Throwable {
    TSalesforceInputProperties props = createTSalesforceInputProperties(emptySchema, isBulkQury);
    String random = createNewRandom();
    int count = 10;
    // store rows in SF to retrieve them afterward to test the input.
    List<IndexedRecord> outputRows = makeRows(random, count, true);
    outputRows = writeRows(random, props, outputRows);
    checkRows(random, outputRows, count);
    try {
        List<IndexedRecord> rows = readRows(props);
        checkRows(random, rows, count);
        testBulkQueryNullValue(props, random);
    } finally {
        deleteRows(outputRows, props);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)

Example 34 with TSalesforceInputProperties

use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.

the class SalesforceInputReaderTestIT method testManualQueryDynamic.

public void testManualQueryDynamic(boolean isBulkQuery) throws Throwable {
    TSalesforceInputProperties props = createTSalesforceInputProperties(true, false);
    props.manualQuery.setValue(true);
    props.query.setValue("select Id,IsDeleted,Name,Phone,CreatedDate from Account limit 1");
    if (isBulkQuery) {
        props.queryMode.setValue(TSalesforceInputProperties.QueryMode.Bulk);
    }
    List<IndexedRecord> outputRows = readRows(props);
    assertEquals(1, outputRows.size());
    IndexedRecord record = outputRows.get(0);
    assertNotNull(record.getSchema());
    Schema.Field field = record.getSchema().getField("CreatedDate");
    assertEquals("yyyy-MM-dd'T'HH:mm:ss'.000Z'", field.getObjectProp(SchemaConstants.TALEND_COLUMN_PATTERN));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)

Example 35 with TSalesforceInputProperties

use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.

the class SalesforceInputReaderTestIT method testDynamicFieldsOrder.

/*
     * Test salesforce input manual query with dynamic return fields order same with SOQL fields order
     */
@Test
public void testDynamicFieldsOrder() throws Throwable {
    TSalesforceInputProperties props = createTSalesforceInputProperties(true, false);
    LOGGER.debug(props.module.main.schema.getStringValue());
    props.manualQuery.setValue(true);
    props.query.setValue("Select Name,IsDeleted,Id, Type,ParentId,MasterRecordId ,CreatedDate from Account order by CreatedDate limit 1 ");
    List<IndexedRecord> rows = readRows(props);
    assertEquals("No record returned!", 1, rows.size());
    List<Schema.Field> fields = rows.get(0).getSchema().getFields();
    assertEquals(7, fields.size());
    assertEquals("Name", fields.get(0).name());
    assertEquals("IsDeleted", fields.get(1).name());
    assertEquals("Id", fields.get(2).name());
    assertEquals("Type", fields.get(3).name());
    assertEquals("ParentId", fields.get(4).name());
    assertEquals("MasterRecordId", fields.get(5).name());
    assertEquals("CreatedDate", fields.get(6).name());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) Test(org.junit.Test)

Aggregations

TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)55 Test (org.junit.Test)32 IndexedRecord (org.apache.avro.generic.IndexedRecord)30 Schema (org.apache.avro.Schema)11 ArrayList (java.util.ArrayList)10 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)10 TSalesforceOutputProperties (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties)9 TSalesforceOutputDefinition (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputDefinition)7 Result (org.talend.components.api.component.runtime.Result)6 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)5 IOException (java.io.IOException)4 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)4 Form (org.talend.daikon.properties.presentation.Form)4 PartnerConnection (com.sforce.soap.partner.PartnerConnection)3 LoginFault (com.sforce.soap.partner.fault.LoginFault)3 File (java.io.File)3 List (java.util.List)3 Ignore (org.junit.Ignore)3 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)3 TSalesforceInputDefinition (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputDefinition)3