Search in sources :

Example 1 with SalesforceInputProperties

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

the class SalesforceDataprepSource method initialize.

@Override
public ValidationResult initialize(RuntimeContainer container, ComponentProperties properties) {
    this.properties = (SalesforceInputProperties) properties;
    dataset = this.properties.getDatasetProperties();
    datastore = dataset.getDatastoreProperties();
    String config_file = System.getProperty(CONFIG_FILE_lOCATION_KEY);
    try (InputStream is = config_file != null ? (new FileInputStream(config_file)) : null) {
        if (is == null) {
            LOG.warn("not found the property file, will use the default value for endpoint and timeout");
            return ValidationResult.OK;
        }
        Properties props = new Properties();
        props.load(is);
        String endpoint = props.getProperty("endpoint");
        if (endpoint != null && !endpoint.isEmpty()) {
            this.endpoint = endpoint;
        }
        String timeout = props.getProperty("timeout");
        if (timeout != null && !timeout.isEmpty()) {
            this.timeout = Integer.parseInt(timeout);
        }
    } catch (IOException e) {
        LOG.warn("not found the property file, will use the default value for endpoint and timeout", e);
    }
    return ValidationResult.OK;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) SalesforceInputProperties(org.talend.components.salesforce.dataprep.SalesforceInputProperties) SalesforceDatastoreProperties(org.talend.components.salesforce.datastore.SalesforceDatastoreProperties) Properties(java.util.Properties) SalesforceDatasetProperties(org.talend.components.salesforce.dataset.SalesforceDatasetProperties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) FileInputStream(java.io.FileInputStream)

Example 2 with SalesforceInputProperties

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

the class SalesforceInputTestIT method testTypeForModule.

@Test
public void testTypeForModule() throws Exception {
    SalesforceInputProperties properties = createCommonSalesforceInputPropertiesForModule();
    SalesforceDataprepSource source = new SalesforceDataprepSource();
    source.initialize(null, properties);
    source.validate(null);
    properties.getDatasetProperties().selectColumnIds.setValue(Arrays.asList("IsDeleted", "Id"));
    try (Reader reader = source.createReader(null)) {
        int count = 3;
        for (boolean available = reader.start(); available; available = reader.advance()) {
            IndexedRecord record = (IndexedRecord) reader.getCurrent();
            assertEquals(String.class, record.get(0).getClass());
            assertEquals(String.class, record.get(1).getClass());
            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)

Example 3 with SalesforceInputProperties

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

the class SalesforceInputTestIT method testTypeForModuleWithBadQuery.

@Test(expected = RuntimeException.class)
public void testTypeForModuleWithBadQuery() throws Exception {
    SalesforceInputProperties properties = createCommonSalesforceInputPropertiesForModule();
    SalesforceDataprepSource source = new SalesforceDataprepSource();
    source.initialize(null, properties);
    source.validate(null);
    properties.getDatasetProperties().selectColumnIds.setValue(Arrays.asList("Toto"));
    try (Reader reader = source.createReader(null)) {
        reader.start();
    }
}
Also used : SalesforceInputProperties(org.talend.components.salesforce.dataprep.SalesforceInputProperties) Reader(org.talend.components.api.component.runtime.Reader) Test(org.junit.Test)

Example 4 with SalesforceInputProperties

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

the class SalesforceInputTestIT method testTypeForModuleWithoutSpecifiedFields.

@Test
public void testTypeForModuleWithoutSpecifiedFields() 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)) {
        int count = 3;
        for (boolean available = reader.start(); available; available = reader.advance()) {
            IndexedRecord record = (IndexedRecord) reader.getCurrent();
            assertEquals(3, 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)

Example 5 with SalesforceInputProperties

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

the class SalesforceInputTestIT method testTypeForModuleWithCompoundType.

@Test(expected = ComponentException.class)
public void testTypeForModuleWithCompoundType() 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", "BillingAddress", "ShippingAddress"));
    try (Reader reader = source.createReader(null)) {
        reader.start();
    }
}
Also used : 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