use of org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition in project components by Talend.
the class SalesforceBulkFileWriterTestIT method testAppendWhenFileIsEmptyOrNotExist.
@Test
public void testAppendWhenFileIsEmptyOrNotExist() 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());
modelProperties.append.setValue(true);
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);
}
use of org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition in project components by Talend.
the class SalesforceBulkFileWriterTestIT method testUpsertAction.
@Test
public void testUpsertAction() 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());
java.util.List<String> columnNames = new java.util.ArrayList<String>();
columnNames.add("Phone");
modelProperties.upsertRelationTable.columnName.setValue(columnNames);
java.util.List<String> lookupFieldExternalIdNames = new java.util.ArrayList<String>();
lookupFieldExternalIdNames.add("eid");
modelProperties.upsertRelationTable.lookupFieldExternalIdName.setValue(lookupFieldExternalIdNames);
java.util.List<String> lookupRelationshipFieldNames = new java.util.ArrayList<String>();
lookupRelationshipFieldNames.add("lfn");
modelProperties.upsertRelationTable.lookupRelationshipFieldName.setValue(lookupRelationshipFieldNames);
java.util.List<Boolean> polymorphics = new java.util.ArrayList<Boolean>();
polymorphics.add(Boolean.TRUE);
modelProperties.upsertRelationTable.polymorphic.setValue(polymorphics);
java.util.List<String> lookupFieldModuleNames = new java.util.ArrayList<String>();
lookupFieldModuleNames.add("fmn");
modelProperties.upsertRelationTable.lookupFieldModuleName.setValue(lookupFieldModuleNames);
util.simulateRuntimeCaller(definition, modelProperties, util.getTestSchema1(), util.getTestData());
String[] expected1 = { "FirstName,LastName,fmn:lfn.eid", "Wei,Wang,010-11111111", "Jin,Zhao,010-11111112", "Wei,Yuan,#N/A" };
util.compareFileContent(data_file, expected1);
}
use of org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition 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.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition 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.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition in project components by Talend.
the class SalesforceBulkLoadTestIT method testUpdate.
@Test
public void testUpdate() 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>();
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 reject
datarow.put("Id", "not_exist");
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.UPDATE);
try {
IndexedRecordConverter<Object, ? extends IndexedRecord> factory = null;
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);
Assert.assertEquals(id, resultid);
Assert.assertEquals("010-89492686", phone);
} catch (DataRejectException e) {
java.util.Map<String, Object> info = e.getRejectInfo();
Object data = info.get("talend_record");
String err = (String) info.get("error");
factory = initCurrentData(factory, data);
IndexedRecord record = factory.convertToAvro(data);
String resultid = (String) record.get(0);
String firstname = (String) record.get(1);
String lastname = (String) record.get(2);
String phone = (String) record.get(3);
Assert.assertNull(resultid);
Assert.assertEquals("Who", firstname);
Assert.assertEquals("Who", lastname);
Assert.assertEquals("010-89492686", phone);
Assert.assertTrue(err != null);
}
}
} finally {
try {
reader.close();
} finally {
util.deleteTestData(ids);
}
}
}
Aggregations