Search in sources :

Example 16 with TSalesforceInputProperties

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

the class SalesforceInputReaderTestIT method testQueryWithTypes.

@Test
public void testQueryWithTypes() throws Throwable {
    Schema test_schema_long = // 
    SchemaBuilder.builder().record("Schema").fields().name("Id").type().stringType().noDefault().name("NumberOfEmployees").type().longType().noDefault().name("AnnualRevenue").type(AvroUtils._float()).noDefault().endRecord();
    Schema test_schema_short = // 
    SchemaBuilder.builder().record("Schema").fields().name("Id").type().stringType().noDefault().name("NumberOfEmployees").type(AvroUtils._short()).noDefault().name("AnnualRevenue").type(AvroUtils._float()).noDefault().endRecord();
    Schema test_schema_byte = // 
    SchemaBuilder.builder().record("Schema").fields().name("Id").type().stringType().noDefault().name("NumberOfEmployees").type(AvroUtils._byte()).noDefault().name("AnnualRevenue").type(AvroUtils._float()).noDefault().endRecord();
    try {
        TSalesforceInputProperties sfInputProps = createTSalesforceInputProperties(false, false);
        sfInputProps.condition.setValue("NumberOfEmployees != null  limit 1");
        // 1.Test long and float type
        sfInputProps.module.main.schema.setValue(test_schema_long);
        List<IndexedRecord> inpuRecords = readRows(sfInputProps);
        IndexedRecord record = null;
        if (inpuRecords.size() < 1) {
            LOGGER.warn("Salesforce default records have been changed!");
        } else {
            record = inpuRecords.get(0);
            Object longValue = record.get(1);
            Object floatValue = record.get(2);
            if (longValue != null) {
                assertThat(longValue, instanceOf(Long.class));
            }
            if (floatValue != null) {
                assertThat(floatValue, instanceOf(Float.class));
            }
        }
        // 2.Test short type
        sfInputProps.condition.setValue("NumberOfEmployees = null  limit 1");
        sfInputProps.module.main.schema.setValue(test_schema_short);
        inpuRecords = readRows(sfInputProps);
        if (inpuRecords.size() == 1) {
            record = inpuRecords.get(0);
            assertNull(record.get(1));
        }
        // 3.Test byte type
        sfInputProps.module.main.schema.setValue(test_schema_byte);
        inpuRecords = readRows(sfInputProps);
        if (inpuRecords.size() == 1) {
            record = inpuRecords.get(0);
            assertNull(record.get(1));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Unexpected error: " + e.getMessage());
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with TSalesforceInputProperties

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

the class SalesforceInputReaderTestIT method testColumnNameCaseSensitive.

/**
 * Test query mode fields of schema is not case sensitive
 */
@Test
public void testColumnNameCaseSensitive() throws Throwable {
    TSalesforceInputProperties props = createTSalesforceInputProperties(false, false);
    Schema schema = // 
    SchemaBuilder.builder().record("Schema").fields().name("ID").type().stringType().noDefault().name("type").type().stringType().noDefault().name("NAME").type().stringType().noDefault().endRecord();
    props.module.main.schema.setValue(schema);
    props.condition.setValue("Id != null and name != null and type!=null Limit 1");
    props.validateGuessSchema();
    List<IndexedRecord> rows = readRows(props);
    if (rows.size() > 0) {
        assertEquals(1, rows.size());
        IndexedRecord row = rows.get(0);
        Schema runtimeSchema = row.getSchema();
        assertEquals(3, runtimeSchema.getFields().size());
        assertNotNull(row.get(schema.getField("ID").pos()));
        assertNotNull(row.get(schema.getField("type").pos()));
        assertNotEquals("Account", row.get(schema.getField("type").pos()));
        assertNotNull(row.get(schema.getField("NAME").pos()));
    } else {
        LOGGER.warn("Query result is empty!");
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) Test(org.junit.Test)

Example 18 with TSalesforceInputProperties

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

the class SalesforceInputReaderTestIT method testBulkApiWithPkChunking.

@Ignore("Our Salesforce credentials were used too many time in ITs they may create huge amount of data and this test can execute too long")
@Test
public void testBulkApiWithPkChunking() throws Throwable {
    TSalesforceInputProperties properties = createTSalesforceInputProperties(false, true);
    properties.manualQuery.setValue(false);
    // Some records can't be erased by deleteAllAccountTestRows(),
    // they have relations to other tables, we need to extract them(count) from main test.
    List<IndexedRecord> readRows = readRows(properties);
    int defaultRecordsInSalesforce = readRows.size();
    properties.pkChunking.setValue(true);
    // This all test were run to many times and created/deleted huge amount of data,
    // to avoid Error: TotalRequests Limit exceeded lets get data with chunk size 100_000(default on Salesforce)
    properties.chunkSize.setValue(TSalesforceInputProperties.DEFAULT_CHUNK_SIZE);
    int count = 1500;
    String random = createNewRandom();
    List<IndexedRecord> outputRows = makeRows(random, count, true);
    outputRows = writeRows(random, properties, outputRows);
    try {
        readRows = readRows(properties);
        LOGGER.info("Read rows count - {}", readRows.size());
        Assert.assertEquals((readRows.size() - defaultRecordsInSalesforce), outputRows.size());
    } finally {
        deleteRows(outputRows, properties);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with TSalesforceInputProperties

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

the class SalesforceInputReaderTestIT method testComplexSOQLQuery.

/*
     * Test nested query of SOQL. Checking if data was placed correctly by guessed schema method.
     */
@Test
public void testComplexSOQLQuery() throws Throwable {
    TSalesforceInputProperties props = createTSalesforceInputProperties(false, false);
    props.manualQuery.setValue(true);
    // Manual query with foreign key
    // Need to specify where clause to be sure that this record exists and has parent-to-child relation.
    props.query.setValue("Select Id, Name,(Select Contact.Id,Contact.Name from Account.Contacts) from Account WHERE Name = 'United Oil & Gas, UK' Limit 1");
    props.validateGuessSchema();
    List<IndexedRecord> rows = readRows(props);
    if (rows.size() > 0) {
        for (IndexedRecord row : rows) {
            Schema schema = row.getSchema();
            assertNotNull(schema.getField("Id"));
            assertNotNull(schema.getField("Name"));
            assertNotNull(schema.getField("Account_Contacts_records_Contact_Id"));
            assertNotNull(schema.getField("Account_Contacts_records_Contact_Name"));
            assertNotNull(row.get(schema.getField("Id").pos()));
            assertNotNull(row.get(schema.getField("Name").pos()));
            assertNotNull(row.get(schema.getField("Account_Contacts_records_Contact_Id").pos()));
            assertNotNull(row.get(schema.getField("Account_Contacts_records_Contact_Name").pos()));
        }
    } else {
        LOGGER.warn("Query result is empty!");
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) Test(org.junit.Test)

Example 20 with TSalesforceInputProperties

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

the class SalesforceInputReaderTestIT method testAggregateQueryColumnNameCaseSensitive.

/**
 * Test aggregate query field not case sensitive
 */
@Test
public void testAggregateQueryColumnNameCaseSensitive() throws Throwable {
    TSalesforceInputProperties props = createTSalesforceInputProperties(true, false);
    props.manualQuery.setValue(true);
    props.query.setValue("SELECT MIN(CreatedDate) value FROM Contact GROUP BY FirstName, LastName LIMIT 1");
    props.module.main.schema.setValue(SCHEMA_DATE);
    List<IndexedRecord> outputRows = readRows(props);
    if (outputRows.isEmpty()) {
        return;
    }
    IndexedRecord record = outputRows.get(0);
    assertNotNull(record.getSchema());
    Object value = record.get(0);
    Assert.assertTrue(value != null && value instanceof Long);
}
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