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());
}
}
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!");
}
}
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);
}
}
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!");
}
}
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);
}
Aggregations