Search in sources :

Example 1 with TSalesforceOutputBulkProperties

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;
}
Also used : TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) Sink(org.talend.components.api.component.runtime.Sink) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) SObject(com.sforce.soap.partner.sobject.SObject) ArrayList(java.util.ArrayList) List(java.util.List) ValidationResult(org.talend.daikon.properties.ValidationResult)

Example 2 with TSalesforceOutputBulkProperties

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);
}
Also used : TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) TSalesforceOutputBulkDefinition(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition) Test(org.junit.Test)

Example 3 with TSalesforceOutputBulkProperties

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);
}
Also used : TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) TSalesforceOutputBulkDefinition(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition) Test(org.junit.Test)

Example 4 with TSalesforceOutputBulkProperties

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);
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) HashMap(java.util.HashMap) TSalesforceBulkExecDefinition(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecDefinition) ArrayList(java.util.ArrayList) Reader(org.talend.components.api.component.runtime.Reader) DataRejectException(org.talend.components.api.exception.DataRejectException) TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties) TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) TSalesforceOutputBulkDefinition(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with TSalesforceOutputBulkProperties

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
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TSalesforceBulkExecDefinition(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecDefinition) Reader(org.talend.components.api.component.runtime.Reader) DataRejectException(org.talend.components.api.exception.DataRejectException) TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties) TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) TSalesforceOutputBulkDefinition(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

TSalesforceOutputBulkProperties (org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties)15 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 TSalesforceOutputBulkDefinition (org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition)7 IndexedRecord (org.apache.avro.generic.IndexedRecord)5 TSalesforceBulkExecProperties (org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Reader (org.talend.components.api.component.runtime.Reader)4 DataRejectException (org.talend.components.api.exception.DataRejectException)4 TSalesforceBulkExecDefinition (org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecDefinition)4 SObject (com.sforce.soap.partner.sobject.SObject)2 Sink (org.talend.components.api.component.runtime.Sink)2 SourceOrSink (org.talend.components.api.component.runtime.SourceOrSink)2 ValidationResult (org.talend.daikon.properties.ValidationResult)2 Schema (org.apache.avro.Schema)1 Field (org.apache.avro.Schema.Field)1 Before (org.junit.Before)1 WriteOperation (org.talend.components.api.component.runtime.WriteOperation)1