use of org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties in project components by Talend.
the class SalesforceRuntimeTestUtil method initWriter.
private Writer<?> initWriter(TSalesforceOutputBulkDefinition definition, TSalesforceOutputBulkProperties modelProperties) throws IOException {
// simulate to generate the runtime code
TSalesforceOutputBulkProperties runtimeProperties = (TSalesforceOutputBulkProperties) definition.createRuntimeProperties();
// pass all the value from the ui model
runtimeProperties.schema.schema.setValue(modelProperties.schema.schema.getValue());
runtimeProperties.bulkFilePath.setValue(modelProperties.bulkFilePath.getStringValue());
runtimeProperties.append.setValue(modelProperties.append.getValue());
runtimeProperties.ignoreNull.setValue(modelProperties.ignoreNull.getValue());
Object obj = modelProperties.upsertRelationTable.columnName.getValue();
if (obj != null && obj instanceof List && !((List<?>) obj).isEmpty()) {
runtimeProperties.upsertRelationTable.columnName.setValue(modelProperties.upsertRelationTable.columnName.getValue());
runtimeProperties.upsertRelationTable.lookupFieldExternalIdName.setValue(modelProperties.upsertRelationTable.lookupFieldExternalIdName.getValue());
runtimeProperties.upsertRelationTable.lookupFieldModuleName.setValue(modelProperties.upsertRelationTable.lookupFieldModuleName.getValue());
runtimeProperties.upsertRelationTable.lookupRelationshipFieldName.setValue(modelProperties.upsertRelationTable.lookupRelationshipFieldName.getValue());
runtimeProperties.upsertRelationTable.polymorphic.setValue(modelProperties.upsertRelationTable.polymorphic.getValue());
}
SourceOrSink source_sink = new SalesforceBulkFileSink();
source_sink.initialize(null, runtimeProperties);
ValidationResult result = source_sink.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
Sink sink = (Sink) source_sink;
WriteOperation<?> writeOperation = sink.createWriteOperation();
writeOperation.initialize(null);
Writer<?> writer = writeOperation.createWriter(null);
writer.open("component_instance_id");
return writer;
}
use of org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties 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.TSalesforceOutputBulkProperties 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.TSalesforceOutputBulkProperties 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.TSalesforceOutputBulkProperties 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
}
}
}
Aggregations