use of org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition in project components by Talend.
the class SalesforceBulkLoadTestIT method testUpsert.
@Test
public void testUpsert() throws Throwable {
List<String> ids = util.createTestData();
String id = ids.get(0);
final List<Map<String, String>> testData = new ArrayList<Map<String, String>>();
Map<String, String> datarow = new HashMap<String, String>();
// should update
datarow.put("Id", id);
datarow.put("FirstName", "Wei");
datarow.put("LastName", "Wang");
// update the field
datarow.put("Phone", "010-89492686");
testData.add(datarow);
datarow = new HashMap<String, String>();
// should insert
datarow.put("Id", null);
datarow.put("FirstName", "Who");
datarow.put("LastName", "Who");
datarow.put("Phone", "010-89492686");
testData.add(datarow);
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.getTestSchema4());
util.simulateRuntimeCaller(definition, modelProperties, util.getTestSchema4(), 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.getTestSchema4(), util.getTestSchema4());
modelProps.outputAction.setValue(TSalesforceBulkExecProperties.OutputAction.UPSERT);
modelProps.upsertKeyColumn.setValue("Id");
try {
IndexedRecordConverter<Object, ? extends IndexedRecord> factory = null;
int index = -1;
for (boolean available = reader.start(); available; available = reader.advance()) {
try {
Object data = reader.getCurrent();
factory = initCurrentData(factory, data);
IndexedRecord record = factory.convertToAvro(data);
String resultid = (String) record.get(0);
String phone = (String) record.get(3);
index++;
if (index == 0) {
Assert.assertEquals(id, resultid);
Assert.assertEquals("010-89492686", phone);
} else if (index == 1) {
Assert.assertTrue(resultid != null);
Assert.assertEquals("010-89492686", phone);
}
} catch (DataRejectException e) {
Assert.fail(e.getMessage());
}
}
} finally {
try {
reader.close();
} finally {
util.deleteTestData(ids);
}
}
}
use of org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition in project components by Talend.
the class SalesforceBulkFileWriterTestIT method testBasic.
@Test
public void testBasic() throws Exception {
TSalesforceOutputBulkDefinition definition = (TSalesforceOutputBulkDefinition) getComponentService().getComponentDefinition(TSalesforceOutputBulkDefinition.COMPONENT_NAME);
String data_file = tempFolder.newFile("data.txt").getAbsolutePath();
TSalesforceOutputBulkProperties modelProperties = util.simulateUserBasicAction(definition, data_file, util.getTestSchema1());
String[] expected = { "FirstName", "LastName", "Phone" };
List<String> actual = (List<String>) modelProperties.upsertRelationTable.columnName.getPossibleValues();
Assert.assertArrayEquals(expected, actual.toArray());
util.simulateRuntimeCaller(definition, modelProperties, util.getTestSchema1(), util.getTestData());
String[] expected1 = { "FirstName,LastName,Phone", "Wei,Wang,010-11111111", "Jin,Zhao,010-11111112", "Wei,Yuan,#N/A" };
util.compareFileContent(data_file, expected1);
// test ignore null
modelProperties.ignoreNull.setValue(true);
util.simulateRuntimeCaller(definition, modelProperties, util.getTestSchema1(), util.getTestData());
String[] expected2 = { "FirstName,LastName,Phone", "Wei,Wang,010-11111111", "Jin,Zhao,010-11111112", "Wei,Yuan," };
util.compareFileContent(data_file, expected2);
// test append
modelProperties.append.setValue(true);
util.simulateRuntimeCaller(definition, modelProperties, util.getTestSchema1(), util.getTestData());
String[] expected3 = { "FirstName,LastName,Phone", "Wei,Wang,010-11111111", "Jin,Zhao,010-11111112", "Wei,Yuan,", "Wei,Wang,010-11111111", "Jin,Zhao,010-11111112", "Wei,Yuan," };
util.compareFileContent(data_file, expected3);
}
Aggregations