Search in sources :

Example 11 with DefaultComponentRuntimeContainerImpl

use of org.talend.components.api.container.DefaultComponentRuntimeContainerImpl in project components by Talend.

the class JDBCSchemaTestIT method testGetSchema.

@Test
public void testGetSchema() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.main.schema.setValue(DBTestUtils.createTestSchema3(true, tablename));
    properties.tableSelection.tablename.setValue(tablename);
    properties.sql.setValue(DBTestUtils.getSQL(tablename));
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    RuntimeContainer container = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return "tJDBCInput1";
        }
    };
    java.net.URL mappings_url = this.getClass().getResource("/mappings");
    mappings_url = DBTestUtils.correctURL(mappings_url);
    container.setComponentData(container.getCurrentComponentId(), ComponentConstants.MAPPING_URL_SUBFIX, mappings_url);
    Schema schema = source.getEndpointSchema(container, tablename);
    assertEquals(tablename, schema.getName().toUpperCase());
    List<Field> columns = schema.getFields();
    testMetadata(columns);
}
Also used : Field(org.apache.avro.Schema.Field) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) Schema(org.apache.avro.Schema) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) JDBCSource(org.talend.components.jdbc.runtime.JDBCSource) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 12 with DefaultComponentRuntimeContainerImpl

use of org.talend.components.api.container.DefaultComponentRuntimeContainerImpl in project components by Talend.

the class JDBCTypeMappingTestIT method testGetSchema.

@Test
public void testGetSchema() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.main.schema.setValue(DBTestUtils.createTestSchema3(true, tablename));
    properties.tableSelection.tablename.setValue(tablename);
    properties.sql.setValue(DBTestUtils.getSQL(tablename));
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    RuntimeContainer container = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return "tJDBCInput1";
        }
    };
    java.net.URL mappings_url = this.getClass().getResource("/mappings");
    mappings_url = DBTestUtils.correctURL(mappings_url);
    container.setComponentData(container.getCurrentComponentId(), ComponentConstants.MAPPING_URL_SUBFIX, mappings_url);
    Schema schema = source.getEndpointSchema(container, tablename);
    assertEquals(tablename, schema.getName().toUpperCase());
    List<Field> columns = schema.getFields();
    testMetadata(columns);
}
Also used : Field(org.apache.avro.Schema.Field) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) Schema(org.apache.avro.Schema) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) JDBCSource(org.talend.components.jdbc.runtime.JDBCSource) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 13 with DefaultComponentRuntimeContainerImpl

use of org.talend.components.api.container.DefaultComponentRuntimeContainerImpl in project components by Talend.

the class AbstractNetSuiteComponentMockTestFixture method setUp.

@Override
public void setUp() throws Exception {
    if (reinstall) {
        webServiceMockTestFixture.reinstall();
    }
    final PortT port = webServiceMockTestFixture.getPortMock();
    mockLoginResponse(port);
    runtimeContainer = spy(new DefaultComponentRuntimeContainerImpl());
    connectionProperties = new NetSuiteConnectionProperties("test");
    connectionProperties.init();
    connectionProperties.endpoint.setValue(webServiceMockTestFixture.getEndpointAddress().toString());
    connectionProperties.apiVersion.setValue(webServiceMockTestFixture.getClientFactory().getApiVersion().getMajorAsString("."));
    connectionProperties.email.setValue("test@test.com");
    connectionProperties.password.setValue("123");
    connectionProperties.role.setValue(3);
    connectionProperties.account.setValue("test");
    connectionProperties.applicationId.setValue("00000000-0000-0000-0000-000000000000");
    connectionProperties.customizationEnabled.setValue(true);
}
Also used : DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) NetSuiteConnectionProperties(org.talend.components.netsuite.connection.NetSuiteConnectionProperties)

Example 14 with DefaultComponentRuntimeContainerImpl

use of org.talend.components.api.container.DefaultComponentRuntimeContainerImpl in project components by Talend.

the class SalesforceWriterTestIT method testSinkWorkflow_insertRejected.

/**
 * Basic test that shows how the {@link SalesforceSink} is meant to be used to write data.
 */
@Test
public void testSinkWorkflow_insertRejected() throws Exception {
    // Component framework objects.
    ComponentDefinition sfDef = new TSalesforceOutputDefinition();
    TSalesforceOutputProperties sfProps = (TSalesforceOutputProperties) sfDef.createRuntimeProperties();
    SalesforceTestBase.setupProps(sfProps.connection, false);
    sfProps.module.setValue("moduleName", "Account");
    sfProps.module.main.schema.setValue(SCHEMA_INSERT_ACCOUNT);
    sfProps.extendInsert.setValue(false);
    sfProps.ceaseForError.setValue(false);
    // Automatically generate the out schemas.
    sfProps.module.schemaListener.afterSchema();
    DefaultComponentRuntimeContainerImpl container = new DefaultComponentRuntimeContainerImpl();
    // Initialize the Sink, WriteOperation and Writer
    SalesforceSink sfSink = new SalesforceSink();
    sfSink.initialize(container, sfProps);
    sfSink.validate(container);
    SalesforceWriteOperation sfWriteOp = sfSink.createWriteOperation();
    sfWriteOp.initialize(container);
    SalesforceWriter sfWriter = sfSink.createWriteOperation().createWriter(container);
    sfWriter.open("uid1");
    // Write one record, which should fail for missing name.
    IndexedRecord r = new GenericData.Record(SCHEMA_INSERT_ACCOUNT);
    r.put(0, "");
    r.put(1, "deleteme");
    r.put(2, "deleteme");
    r.put(3, "deleteme");
    sfWriter.write(r);
    assertThat(sfWriter.getSuccessfulWrites(), empty());
    assertThat(sfWriter.getRejectedWrites(), hasSize(1));
    // Check the rejected record.
    IndexedRecord rejected = sfWriter.getRejectedWrites().get(0);
    assertThat(rejected.getSchema().getFields(), hasSize(7));
    // Check the values copied from the incoming record.
    for (int i = 0; i < r.getSchema().getFields().size(); i++) {
        assertThat(rejected.getSchema().getFields().get(i), is(r.getSchema().getFields().get(i)));
        assertThat(rejected.get(i), is(r.get(i)));
    }
    // The enriched fields.
    assertThat(rejected.getSchema().getFields().get(4).name(), is("errorCode"));
    assertThat(rejected.getSchema().getFields().get(5).name(), is("errorFields"));
    assertThat(rejected.getSchema().getFields().get(6).name(), is("errorMessage"));
    assertThat(rejected.get(4), is((Object) "REQUIRED_FIELD_MISSING"));
    assertThat(rejected.get(5), is((Object) "Name"));
    // removed the check on value cause it is i18n
    assertThat(rejected.get(6), instanceOf(String.class));
    // Finish the Writer, WriteOperation and Sink.
    Result wr1 = sfWriter.close();
    sfWriteOp.finalize(Arrays.asList(wr1), container);
}
Also used : TSalesforceOutputProperties(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) Result(org.talend.components.api.component.runtime.Result) TSalesforceOutputDefinition(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputDefinition) IndexedRecord(org.apache.avro.generic.IndexedRecord) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Test(org.junit.Test)

Example 15 with DefaultComponentRuntimeContainerImpl

use of org.talend.components.api.container.DefaultComponentRuntimeContainerImpl in project components by Talend.

the class SalesforceWriterTestIT method cleanupAllRecords.

@AfterClass
public static void cleanupAllRecords() throws NoSuchElementException, IOException {
    List<IndexedRecord> recordsToClean = new ArrayList<>();
    String prefixToDelete = UNIQUE_NAME + "_" + UNIQUE_ID;
    // Get the list of records that match the prefix to delete.
    {
        TSalesforceInputProperties sfProps = getSalesforceInputProperties();
        SalesforceTestBase.setupProps(sfProps.connection, false);
        sfProps.module.setValue("moduleName", "Account");
        sfProps.module.main.schema.setValue(SCHEMA_UPDATE_ACCOUNT);
        DefaultComponentRuntimeContainerImpl container = new DefaultComponentRuntimeContainerImpl();
        // Initialize the Source and Reader
        SalesforceSource sfSource = new SalesforceSource();
        sfSource.initialize(container, sfProps);
        sfSource.validate(container);
        int nameIndex = -1;
        @SuppressWarnings("unchecked") Reader<IndexedRecord> sfReader = sfSource.createReader(container);
        if (sfReader.start()) {
            do {
                IndexedRecord r = sfReader.getCurrent();
                if (nameIndex == -1) {
                    nameIndex = r.getSchema().getField("Name").pos();
                }
                if (String.valueOf(r.get(nameIndex)).startsWith(prefixToDelete)) {
                    recordsToClean.add(r);
                }
            } while (sfReader.advance());
        }
    }
    // Delete those records.
    {
        ComponentDefinition sfDef = new TSalesforceOutputDefinition();
        TSalesforceOutputProperties sfProps = (TSalesforceOutputProperties) sfDef.createRuntimeProperties();
        SalesforceTestBase.setupProps(sfProps.connection, false);
        sfProps.outputAction.setValue(OutputAction.DELETE);
        sfProps.module.setValue("moduleName", "Account");
        sfProps.module.main.schema.setValue(SCHEMA_UPDATE_ACCOUNT);
        DefaultComponentRuntimeContainerImpl container = new DefaultComponentRuntimeContainerImpl();
        // Initialize the Sink, WriteOperation and Writer
        SalesforceSink sfSink = new SalesforceSink();
        sfSink.initialize(container, sfProps);
        sfSink.validate(container);
        SalesforceWriteOperation sfWriteOp = sfSink.createWriteOperation();
        sfWriteOp.initialize(container);
        Writer<Result> sfWriter = sfSink.createWriteOperation().createWriter(container);
        sfWriter.open("uid1");
        // Write one record.
        for (IndexedRecord r : recordsToClean) {
            sfWriter.write(r);
        }
        // Finish the Writer, WriteOperation and Sink.
        Result wr1 = sfWriter.close();
        sfWriteOp.finalize(Arrays.asList(wr1), container);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) TSalesforceOutputProperties(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) ArrayList(java.util.ArrayList) Reader(org.talend.components.api.component.runtime.Reader) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) Result(org.talend.components.api.component.runtime.Result) TSalesforceOutputDefinition(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputDefinition) Writer(org.talend.components.api.component.runtime.Writer) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) AfterClass(org.junit.AfterClass)

Aggregations

DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)20 Test (org.junit.Test)14 IndexedRecord (org.apache.avro.generic.IndexedRecord)9 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)9 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)8 Result (org.talend.components.api.component.runtime.Result)8 TSalesforceOutputDefinition (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputDefinition)7 TSalesforceOutputProperties (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties)7 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)5 Schema (org.apache.avro.Schema)4 File (java.io.File)3 Field (org.apache.avro.Schema.Field)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 JDBCSource (org.talend.components.jdbc.runtime.JDBCSource)3 TJDBCInputDefinition (org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition)3 TJDBCInputProperties (org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties)3 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)3 SnowflakeConnectionProperties (org.talend.components.snowflake.SnowflakeConnectionProperties)3 SnowflakeSourceOrSink (org.talend.components.snowflake.runtime.SnowflakeSourceOrSink)3 PartnerConnection (com.sforce.soap.partner.PartnerConnection)2