Search in sources :

Example 6 with TSalesforceOutputBulkProperties

use of org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties 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());
    }
}
Also used : TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) TSalesforceOutputBulkExecProperties(org.talend.components.salesforce.tsalesforceoutputbulkexec.TSalesforceOutputBulkExecProperties) TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties)

Example 7 with TSalesforceOutputBulkProperties

use of org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties in project components by Talend.

the class TSalesforceOutputBulkExecPropertiesTest method testGetInputComponentProperties.

@Test
public void testGetInputComponentProperties() {
    properties.init();
    TSalesforceOutputBulkProperties inputProperties = (TSalesforceOutputBulkProperties) properties.getInputComponentProperties();
    assertEquals(properties.module.main.schema, inputProperties.schema.schema);
    assertEquals(properties.module.main.schema.getValueEvaluator(), inputProperties.schema.schema.getValueEvaluator());
    assertEquals(properties.bulkFilePath, inputProperties.bulkFilePath);
    assertEquals(properties.bulkFilePath.getValueEvaluator(), inputProperties.bulkFilePath.getValueEvaluator());
    assertEquals(properties.upsertRelationTable, inputProperties.upsertRelationTable);
    assertEquals(properties.upsertRelationTable.columnName.getPossibleValues(), inputProperties.upsertRelationTable.columnName.getPossibleValues());
    assertNotNull(inputProperties.getForm(Form.MAIN));
    assertNotNull(inputProperties.getForm(Form.ADVANCED));
}
Also used : TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) Test(org.junit.Test)

Example 8 with TSalesforceOutputBulkProperties

use of org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties in project components by Talend.

the class SalesforceRuntimeTestUtil method simulateUserBasicAction.

public TSalesforceOutputBulkProperties simulateUserBasicAction(TSalesforceOutputBulkDefinition definition, String data_file, Schema schema) {
    // simulate some ui action
    // user create component
    // setup
    TSalesforceOutputBulkProperties modelProperties = (TSalesforceOutputBulkProperties) definition.createProperties();
    // the
    // properties,
    // trigger
    // the
    // setup
    // layout
    // and
    // refresh
    // layout
    // user set the schema and file path
    modelProperties.schema.schema.setValue(schema);
    modelProperties.bulkFilePath.setValue(data_file);
    // user switch the ui and trigger it
    modelProperties.beforeUpsertRelationTable();
    return modelProperties;
}
Also used : TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties)

Example 9 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) SalesforceBulkFileSink(org.talend.components.salesforce.runtime.SalesforceBulkFileSink) WriteOperation(org.talend.components.api.component.runtime.WriteOperation) SObject(com.sforce.soap.partner.sobject.SObject) ArrayList(java.util.ArrayList) List(java.util.List) SalesforceBulkFileSink(org.talend.components.salesforce.runtime.SalesforceBulkFileSink) ValidationResult(org.talend.daikon.properties.ValidationResult) Writer(org.talend.components.api.component.runtime.Writer)

Example 10 with TSalesforceOutputBulkProperties

use of org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties in project components by Talend.

the class SalesforceBulkFileWriterTest method setup.

@Before
public void setup() {
    TSalesforceOutputBulkProperties salesforceBulkProperties = new TSalesforceOutputBulkProperties("foo");
    salesforceBulkProperties.outputAction.setValue(OutputAction.INSERT);
    writer = new SalesforceBulkFileWriter(Mockito.mock(SalesforceBulkFileWriteOperation.class), salesforceBulkProperties, null);
}
Also used : TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) Before(org.junit.Before)

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