Search in sources :

Example 1 with TSalesforceBulkExecProperties

use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties 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 2 with TSalesforceBulkExecProperties

use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties 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)

Example 3 with TSalesforceBulkExecProperties

use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties in project components by Talend.

the class SalesforceBulkExecReader method getSchema.

@Override
protected Schema getSchema() throws IOException {
    if (querySchema == null) {
        TSalesforceBulkExecProperties sprops = (TSalesforceBulkExecProperties) properties;
        // TODO check the assert : the output schema have values even when no output connector
        querySchema = sprops.schemaFlow.schema.getValue();
    }
    return querySchema;
}
Also used : TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties)

Example 4 with TSalesforceBulkExecProperties

use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties 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 5 with TSalesforceBulkExecProperties

use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties in project components by Talend.

the class TSalesforceOutputBulkExecPropertiesTest method testGetOutputComponentProperties.

@Test
public void testGetOutputComponentProperties() {
    properties.init();
    TSalesforceBulkExecProperties outputProperties = (TSalesforceBulkExecProperties) properties.getOutputComponentProperties();
    assertEquals(properties.schemaFlow, outputProperties.schemaFlow);
    assertEquals(properties.schemaReject, outputProperties.schemaReject);
    assertEquals(properties.upsertRelationTable.columnName.getPossibleValues(), outputProperties.upsertRelationTable.columnName.getPossibleValues());
    assertNotNull(outputProperties.getForm(Form.MAIN));
    assertNotNull(outputProperties.getForm(Form.ADVANCED));
}
Also used : TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties) Test(org.junit.Test)

Aggregations

TSalesforceBulkExecProperties (org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties)12 Test (org.junit.Test)6 IndexedRecord (org.apache.avro.generic.IndexedRecord)5 TSalesforceBulkExecDefinition (org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecDefinition)5 TSalesforceOutputBulkProperties (org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Reader (org.talend.components.api.component.runtime.Reader)4 DataRejectException (org.talend.components.api.exception.DataRejectException)4 TSalesforceOutputBulkDefinition (org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition)4 AsyncApiException (com.sforce.async.AsyncApiException)2 ConnectionException (com.sforce.ws.ConnectionException)2 IOException (java.io.IOException)2 ComponentException (org.talend.components.api.exception.ComponentException)1 TSalesforceGetDeletedProperties (org.talend.components.salesforce.tsalesforcegetdeleted.TSalesforceGetDeletedProperties)1 TSalesforceGetServerTimestampProperties (org.talend.components.salesforce.tsalesforcegetservertimestamp.TSalesforceGetServerTimestampProperties)1 TSalesforceGetUpdatedProperties (org.talend.components.salesforce.tsalesforcegetupdated.TSalesforceGetUpdatedProperties)1 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)1 TSalesforceOutputBulkExecProperties (org.talend.components.salesforce.tsalesforceoutputbulkexec.TSalesforceOutputBulkExecProperties)1