use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties in project components by Talend.
the class SalesforceBulkLoadTestIT method testInsert.
@Test
public void testInsert() throws Throwable {
String data_file = tempFolder.newFile("data.txt").getAbsolutePath();
// outputbulk part
TSalesforceOutputBulkDefinition definition = (TSalesforceOutputBulkDefinition) getComponentService().getComponentDefinition(TSalesforceOutputBulkDefinition.COMPONENT_NAME);
TSalesforceOutputBulkProperties modelProperties = util.simulateUserBasicAction(definition, data_file, util.getTestSchema1());
util.simulateRuntimeCaller(definition, modelProperties, util.getTestSchema1(), util.getTestData());
// bulkexec part
TSalesforceBulkExecDefinition defin = (TSalesforceBulkExecDefinition) getComponentService().getComponentDefinition(TSalesforceBulkExecDefinition.COMPONENT_NAME);
TSalesforceBulkExecProperties modelProps = (TSalesforceBulkExecProperties) defin.createRuntimeProperties();
Reader reader = util.initReader(defin, data_file, modelProps, util.getTestSchema1(), util.getTestSchema2());
modelProps.outputAction.setValue(TSalesforceBulkExecProperties.OutputAction.INSERT);
List<String> ids = new ArrayList<String>();
List<String> sids = new ArrayList<String>();
try {
IndexedRecordConverter<Object, ? extends IndexedRecord> factory = null;
final List<Map<String, String>> result = new ArrayList<Map<String, String>>();
for (boolean available = reader.start(); available; available = reader.advance()) {
try {
Object data = reader.getCurrent();
factory = initCurrentData(factory, data);
IndexedRecord record = factory.convertToAvro(data);
String id = (String) record.get(0);
ids.add(id);
String firstname = (String) record.get(1);
String lasttname = (String) record.get(2);
String phone = (String) record.get(3);
String salesforce_id = (String) record.get(4);
sids.add(salesforce_id);
Map<String, String> row = new HashMap<String, String>();
row.put("FirstName", firstname);
row.put("LastName", lasttname);
row.put("Phone", phone);
result.add(row);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
Assert.assertEquals(ids, sids);
Assert.assertEquals(util.getTestData(), result);
} finally {
try {
reader.close();
} finally {
util.deleteTestData(ids);
}
}
}
use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties in project components by Talend.
the class SalesforceBulkLoadTestIT method testDelete.
@Test
public void testDelete() throws Throwable {
List<String> ids = util.createTestData();
final List<Map<String, String>> testData = new ArrayList<Map<String, String>>();
for (String id : ids) {
Map<String, String> row = new HashMap<String, String>();
row.put("Id", id);
testData.add(row);
}
String data_file = tempFolder.newFile("data.txt").getAbsolutePath();
// outputbulk part
TSalesforceOutputBulkDefinition definition = (TSalesforceOutputBulkDefinition) getComponentService().getComponentDefinition(TSalesforceOutputBulkDefinition.COMPONENT_NAME);
TSalesforceOutputBulkProperties modelProperties = util.simulateUserBasicAction(definition, data_file, util.getTestSchema3());
util.simulateRuntimeCaller(definition, modelProperties, util.getTestSchema3(), testData);
// bulkexec part
TSalesforceBulkExecDefinition defin = (TSalesforceBulkExecDefinition) getComponentService().getComponentDefinition(TSalesforceBulkExecDefinition.COMPONENT_NAME);
TSalesforceBulkExecProperties modelProps = (TSalesforceBulkExecProperties) defin.createRuntimeProperties();
Reader reader = util.initReader(defin, data_file, modelProps, util.getTestSchema1(), util.getTestSchema3());
modelProps.outputAction.setValue(TSalesforceBulkExecProperties.OutputAction.DELETE);
try {
IndexedRecordConverter<Object, ? extends IndexedRecord> factory = null;
List<String> resultIds = new ArrayList<String>();
for (boolean available = reader.start(); available; available = reader.advance()) {
try {
Object data = reader.getCurrent();
factory = initCurrentData(factory, data);
IndexedRecord record = factory.convertToAvro(data);
String id = (String) record.get(0);
resultIds.add(id);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
Assert.assertEquals(ids, resultIds);
} finally {
try {
reader.close();
} finally {
// do nothing
}
}
}
use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties in project components by Talend.
the class SalesforceBulkExecReader method getSchema.
@Override
protected Schema getSchema() throws IOException {
if (querySchema == null) {
TSalesforceBulkExecProperties sprops = (TSalesforceBulkExecProperties) properties;
// TODO check the assert : the output schema have values even when no output connector
querySchema = sprops.schemaFlow.schema.getValue();
}
return querySchema;
}
use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties in project components by Talend.
the class SalesforceBulkExecReaderTestIT method testOutputBulkExec.
/**
* This test for tSalesforceOutputBulk and tSalesforceBulkExec The runtime of tSalesforceOutputBulkExec should be
* work like this.
*/
private void testOutputBulkExec(int count) throws Throwable {
String random = createNewRandom();
List<IndexedRecord> rows = makeRows(random, count, false);
TSalesforceOutputBulkExecProperties outputBulkExecProperties = createAccountSalesforceOutputBulkExecProperties();
// Prepare the bulk file
TSalesforceOutputBulkProperties outputBulkProperties = (TSalesforceOutputBulkProperties) outputBulkExecProperties.getInputComponentProperties();
generateBulkFile(outputBulkProperties, rows);
// Test append
outputBulkProperties.append.setValue(true);
generateBulkFile(outputBulkProperties, rows);
// Execute the bulk action
TSalesforceBulkExecProperties bulkExecProperties = (TSalesforceBulkExecProperties) outputBulkExecProperties.getOutputComponentProperties();
try {
executeBulkInsert(bulkExecProperties, random, count * 2);
} finally {
// Delete the generated bulk file
delete(outputBulkProperties);
List<IndexedRecord> inputRows = readRows(bulkExecProperties);
List<IndexedRecord> allReadTestRows = filterAllTestRows(random, inputRows);
deleteRows(allReadTestRows, bulkExecProperties);
inputRows = readRows(bulkExecProperties);
assertEquals(0, filterAllTestRows(random, inputRows).size());
}
}
use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties in project components by Talend.
the class TSalesforceOutputBulkExecPropertiesTest method testGetOutputComponentProperties.
@Test
public void testGetOutputComponentProperties() {
properties.init();
TSalesforceBulkExecProperties outputProperties = (TSalesforceBulkExecProperties) properties.getOutputComponentProperties();
assertEquals(properties.schemaFlow, outputProperties.schemaFlow);
assertEquals(properties.schemaReject, outputProperties.schemaReject);
assertEquals(properties.upsertRelationTable.columnName.getPossibleValues(), outputProperties.upsertRelationTable.columnName.getPossibleValues());
assertNotNull(outputProperties.getForm(Form.MAIN));
assertNotNull(outputProperties.getForm(Form.ADVANCED));
}
Aggregations