Search in sources :

Example 11 with SalesforceInputProperties

use of org.talend.components.salesforce.dataprep.SalesforceInputProperties in project components by Talend.

the class SalesforceInputTestIT method testLimitOfSalesforceBulQueryReader.

public void testLimitOfSalesforceBulQueryReader() throws Exception {
    SalesforceInputProperties properties = createCommonSalesforceInputPropertiesForModule();
    SalesforceDataprepSource source = new SalesforceDataprepSource();
    source.initialize(null, properties);
    source.validate(null);
    properties.getDatasetProperties().selectColumnIds.setValue(Arrays.asList("IsDeleted", "Id", "Name"));
    try (Reader reader = source.createReader(null)) {
        ((SalesforceBulkQueryReader) reader).setLimit(1);
        reader.start();
        reader.advance();
        IndexedRecord record = (IndexedRecord) reader.getCurrent();
        assertEquals(3, record.getSchema().getFields().size());
        try {
            reader.advance();
            fail();
        } catch (IOException e) {
        // Excepted to happen
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) SalesforceInputProperties(org.talend.components.salesforce.dataprep.SalesforceInputProperties) Reader(org.talend.components.api.component.runtime.Reader) IOException(java.io.IOException)

Example 12 with SalesforceInputProperties

use of org.talend.components.salesforce.dataprep.SalesforceInputProperties in project components by Talend.

the class SalesforceInputTestIT method createCommonSalesforceInputPropertiesForModule.

private SalesforceInputProperties createCommonSalesforceInputPropertiesForModule() {
    SalesforceDatastoreDefinition datastore_def = new SalesforceDatastoreDefinition();
    SalesforceDatastoreProperties datastore_props = new SalesforceDatastoreProperties("datastore");
    CommonTestUtils.setValueForDatastoreProperties(datastore_props);
    SalesforceDatasetProperties dataset = (SalesforceDatasetProperties) datastore_def.createDatasetProperties(datastore_props);
    dataset.moduleName.setValue("Account");
    SalesforceInputDefinition input_def = new SalesforceInputDefinition();
    SalesforceInputProperties input_props = (SalesforceInputProperties) input_def.createRuntimeProperties();
    input_props.setDatasetProperties(dataset);
    List<String> products = input_def.getSupportedProducts();
    assertNotNull(products);
    assertEquals(1, products.size());
    assertEquals(SupportedProduct.DATAPREP, products.get(0));
    return input_props;
}
Also used : SalesforceDatastoreProperties(org.talend.components.salesforce.datastore.SalesforceDatastoreProperties) SalesforceDatastoreDefinition(org.talend.components.salesforce.datastore.SalesforceDatastoreDefinition) SalesforceInputProperties(org.talend.components.salesforce.dataprep.SalesforceInputProperties) SalesforceInputDefinition(org.talend.components.salesforce.dataprep.SalesforceInputDefinition) SalesforceDatasetProperties(org.talend.components.salesforce.dataset.SalesforceDatasetProperties)

Example 13 with SalesforceInputProperties

use of org.talend.components.salesforce.dataprep.SalesforceInputProperties in project components by Talend.

the class SalesforceInputTestIT method testReaderForQuery.

@Test
public void testReaderForQuery() {
    Reader reader = null;
    try {
        SalesforceInputProperties properties = createCommonSalesforceInputPropertiesForQuery();
        SalesforceDataprepSource source = new SalesforceDataprepSource();
        source.initialize(null, properties);
        source.validate(null);
        reader = source.createReader(null);
        reader.start();
        IndexedRecord row = (IndexedRecord) reader.getCurrent();
        String id = (String) row.get(0);
        String name = (String) row.get(1);
        Assert.assertNotNull("id is null", id);
        reader.advance();
        row = (IndexedRecord) reader.getCurrent();
        Assert.assertNotNull("id is null", id);
        reader.close();
    // Map<String, Object> returnMap = reader.getReturnValues();
    // Assert.assertEquals(3, returnMap.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                Assert.fail(e.getMessage());
            }
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Reader(org.talend.components.api.component.runtime.Reader) SalesforceInputProperties(org.talend.components.salesforce.dataprep.SalesforceInputProperties) IOException(java.io.IOException) ComponentException(org.talend.components.api.exception.ComponentException) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with SalesforceInputProperties

use of org.talend.components.salesforce.dataprep.SalesforceInputProperties in project components by Talend.

the class SalesforceInputTestIT method createCommonSalesforceInputPropertiesForQuery.

private SalesforceInputProperties createCommonSalesforceInputPropertiesForQuery() {
    SalesforceDatastoreDefinition datastore_def = new SalesforceDatastoreDefinition();
    SalesforceDatastoreProperties datastore_props = new SalesforceDatastoreProperties("datastore");
    CommonTestUtils.setValueForDatastoreProperties(datastore_props);
    SalesforceDatasetProperties dataset = (SalesforceDatasetProperties) datastore_def.createDatasetProperties(datastore_props);
    dataset.sourceType.setValue(SalesforceDatasetProperties.SourceType.SOQL_QUERY);
    dataset.query.setValue("SELECT Id, Name FROM Account");
    SalesforceInputDefinition input_def = new SalesforceInputDefinition();
    SalesforceInputProperties input_props = (SalesforceInputProperties) input_def.createRuntimeProperties();
    input_props.setDatasetProperties(dataset);
    return input_props;
}
Also used : SalesforceDatastoreProperties(org.talend.components.salesforce.datastore.SalesforceDatastoreProperties) SalesforceDatastoreDefinition(org.talend.components.salesforce.datastore.SalesforceDatastoreDefinition) SalesforceInputProperties(org.talend.components.salesforce.dataprep.SalesforceInputProperties) SalesforceInputDefinition(org.talend.components.salesforce.dataprep.SalesforceInputDefinition) SalesforceDatasetProperties(org.talend.components.salesforce.dataset.SalesforceDatasetProperties)

Example 15 with SalesforceInputProperties

use of org.talend.components.salesforce.dataprep.SalesforceInputProperties in project components by Talend.

the class SalesforceInputTestIT method testTypeForModuleWithPickListType.

@Test
public void testTypeForModuleWithPickListType() throws Exception {
    SalesforceInputProperties properties = createCommonSalesforceInputPropertiesForModule();
    SalesforceDataprepSource source = new SalesforceDataprepSource();
    source.initialize(null, properties);
    source.validate(null);
    properties.getDatasetProperties().selectColumnIds.setValue(Arrays.asList("IsDeleted", "Id", "Name", "Type"));
    try (Reader reader = source.createReader(null)) {
        int count = 3;
        for (boolean available = reader.start(); available; available = reader.advance()) {
            IndexedRecord record = (IndexedRecord) reader.getCurrent();
            assertEquals(4, record.getSchema().getFields().size());
            if ((count--) < 1) {
                break;
            }
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) SalesforceInputProperties(org.talend.components.salesforce.dataprep.SalesforceInputProperties) Reader(org.talend.components.api.component.runtime.Reader) Test(org.junit.Test)

Aggregations

SalesforceInputProperties (org.talend.components.salesforce.dataprep.SalesforceInputProperties)17 Reader (org.talend.components.api.component.runtime.Reader)9 IndexedRecord (org.apache.avro.generic.IndexedRecord)8 Test (org.junit.Test)8 IOException (java.io.IOException)5 SalesforceDatasetProperties (org.talend.components.salesforce.dataset.SalesforceDatasetProperties)4 ComponentException (org.talend.components.api.exception.ComponentException)3 SalesforceDatastoreProperties (org.talend.components.salesforce.datastore.SalesforceDatastoreProperties)3 SalesforceInputDefinition (org.talend.components.salesforce.dataprep.SalesforceInputDefinition)2 SalesforceDatastoreDefinition (org.talend.components.salesforce.datastore.SalesforceDatastoreDefinition)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 Before (org.junit.Before)1 ReaderDataProvider (org.talend.components.api.component.runtime.ReaderDataProvider)1 ComponentProperties (org.talend.components.api.properties.ComponentProperties)1 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)1 SalesforceDefinition.getSandboxedInstance (org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance)1 SalesforceRuntimeSourceOrSink (org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink)1 ValidationResult (org.talend.daikon.properties.ValidationResult)1