Search in sources :

Example 6 with DefaultComponentRuntimeContainerImpl

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

the class SalesforceWriterTestIT method testSinkWorkflow_insertAndRetrieveId.

/**
 * Test for a Sink that has an output flow containing the salesforce id.
 */
@Test
public void testSinkWorkflow_insertAndRetrieveId() 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.extendInsert.setValue(false);
    sfProps.ceaseForError.setValue(false);
    sfProps.retrieveInsertId.setValue(true);
    sfProps.module.main.schema.setValue(SCHEMA_INSERT_ACCOUNT);
    // 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.
    IndexedRecord r = new GenericData.Record(SCHEMA_INSERT_ACCOUNT);
    r.put(0, UNIQUE_NAME + "_" + UNIQUE_ID);
    r.put(1, "deleteme");
    r.put(2, "deleteme");
    r.put(3, "deleteme");
    sfWriter.write(r);
    assertThat(sfWriter.getRejectedWrites(), empty());
    assertThat(sfWriter.getSuccessfulWrites(), hasSize(1));
    // Check the successful record (main output)
    IndexedRecord main = sfWriter.getSuccessfulWrites().get(0);
    assertThat(main.getSchema().getFields(), hasSize(5));
    // Check the values copied from the incoming record.
    for (int i = 0; i < r.getSchema().getFields().size(); i++) {
        assertThat(main.getSchema().getFields().get(i), is(r.getSchema().getFields().get(i)));
        assertThat(main.get(i), is(r.get(i)));
    }
    // The enriched fields.
    assertThat(main.getSchema().getFields().get(4).name(), is("salesforce_id"));
    assertThat(main.get(4), not(nullValue()));
    // 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) TSalesforceOutputDefinition(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputDefinition) IndexedRecord(org.apache.avro.generic.IndexedRecord) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Result(org.talend.components.api.component.runtime.Result) Test(org.junit.Test)

Example 7 with DefaultComponentRuntimeContainerImpl

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

the class SalesforceWriterTestIT method testUpdateError.

// This is for reject and caseForError not real test for update
protected void testUpdateError(boolean ceaseForError) throws Exception {
    // Generate log file path
    String logFilePath = tempFolder.getRoot().getAbsolutePath() + "/salesforce_error_" + (ceaseForError ? 0 : 1) + ".log";
    File file = new File(logFilePath);
    assertFalse(file.exists());
    // 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_UPDATE_ACCOUNT);
    sfProps.outputAction.setValue(OutputAction.UPDATE);
    sfProps.extendInsert.setValue(false);
    sfProps.ceaseForError.setValue(ceaseForError);
    // Setup log file path
    LOGGER.debug("Error log path: " + logFilePath);
    sfProps.logFileName.setValue(logFilePath);
    // 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);
    try {
        SalesforceWriter sfWriter = sfSink.createWriteOperation().createWriter(container);
        sfWriter.open("uid1");
        // Write one record, which should fail for the bad ID
        IndexedRecord r = new GenericData.Record(SCHEMA_UPDATE_ACCOUNT);
        r.put(0, "bad id");
        r.put(1, UNIQUE_NAME + "_" + UNIQUE_ID);
        r.put(2, "deleteme");
        r.put(3, "deleteme");
        r.put(4, "deleteme");
        if (!ceaseForError) {
            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(8));
            // 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(0), is(r.get(0)));
            }
            // The enriched fields.
            assertThat(rejected.getSchema().getFields().get(5).name(), is("errorCode"));
            assertThat(rejected.getSchema().getFields().get(6).name(), is("errorFields"));
            assertThat(rejected.getSchema().getFields().get(7).name(), is("errorMessage"));
            assertThat(rejected.get(5), is((Object) "MALFORMED_ID"));
            assertThat(rejected.get(6), is((Object) "Id"));
            // removed the check on value cause it is i18n
            assertThat(rejected.get(7), instanceOf(String.class));
            // Finish the Writer, WriteOperation and Sink.
            Result wr1 = sfWriter.close();
            sfWriteOp.finalize(Arrays.asList(wr1), container);
        } else {
            try {
                sfWriter.write(r);
                sfWriter.close();
                fail("It should get error when insert data!");
            } catch (IOException e) {
                // assertThat(e.getMessage(), is((Object) "Account ID: id value of incorrect type: bad id\n"));
                throw e;
            }
        }
    } finally {
        assertTrue(file.exists());
        assertNotEquals(0, file.length());
    }
}
Also used : TSalesforceOutputProperties(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) IOException(java.io.IOException) Result(org.talend.components.api.component.runtime.Result) TSalesforceOutputDefinition(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputDefinition) IndexedRecord(org.apache.avro.generic.IndexedRecord) File(java.io.File) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Example 8 with DefaultComponentRuntimeContainerImpl

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

the class JDBCInputTestIT method testGetSchema.

@Test
public void testGetSchema() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.main.schema.setValue(DBTestUtils.createTestSchema(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";
        }
    };
    // the getResource method will convert "@" to "%40" when work with maven together, not sure the bug appear where, bug make
    // sure it come from the env, not the function code, so only convert here
    // in the product env, the mappings_url is passed from the platform
    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();
    DBTestUtils.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 9 with DefaultComponentRuntimeContainerImpl

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

the class JiraWriteOperationTest method setupMocks.

@Before
public void setupMocks() {
    sink = mock(JiraSink.class);
    container = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return "tJIRAOutput";
        }
    };
}
Also used : DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) Before(org.junit.Before)

Example 10 with DefaultComponentRuntimeContainerImpl

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

the class GoogleDriveTestBaseRuntime method setUp.

@Before
public void setUp() throws Exception {
    container = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return TEST_CONTAINER;
        }
    };
    // 
    DATA_STORE_DIR = new File(getClass().getClassLoader().getResource("./").toURI().getPath());
    HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
    // 
    drive = mock(Drive.class, RETURNS_DEEP_STUBS);
    sourceOrSink = spy(GoogleDriveSourceOrSink.class);
    source = spy(GoogleDriveSource.class);
    sink = spy(GoogleDriveSink.class);
    doReturn(drive).when(sourceOrSink).getDriveService();
    doReturn(drive).when(source).getDriveService();
    doReturn(drive).when(sink).getDriveService();
    // 
    emptyFileList = new FileList();
    emptyFileList.setFiles(new ArrayList<com.google.api.services.drive.model.File>());
}
Also used : DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) FileList(com.google.api.services.drive.model.FileList) Drive(com.google.api.services.drive.Drive) File(java.io.File) Before(org.junit.Before)

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