Search in sources :

Example 1 with RuntimeContainer

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

the class SalesforceSourceOrSinkTestIT method prepareAndGetConnectionHolder.

private void prepareAndGetConnectionHolder(boolean isBulk) throws Exception {
    final SalesforceConnectionProperties connectionProperties = setupProps(null, false);
    connectionProperties.bulkConnection.setValue(isBulk);
    RuntimeContainer container = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return connectionProperties.getName();
        }
    };
    SalesforceSourceOrSink sourceOrSink = new SalesforceSourceOrSink();
    sourceOrSink.initialize(container, connectionProperties);
    // Creating and saving PartnerConnection + BulkConnection(holder) inside container.
    sourceOrSink.validate(container);
    PartnerConnection partnerConnection = (PartnerConnection) container.getComponentData(connectionProperties.getName(), SalesforceSourceOrSink.KEY_CONNECTION);
    TSalesforceInputProperties inputProperties = new TSalesforceInputProperties("input");
    inputProperties.connection.referencedComponent.componentInstanceId.setValue(connectionProperties.getName());
    sourceOrSink.initialize(container, inputProperties);
    ConnectionHolder actualHolder = sourceOrSink.connect(container);
    Assert.assertEquals(partnerConnection, actualHolder.connection);
    if (isBulk) {
        Assert.assertNotNull(actualHolder.bulkConnection);
    } else {
        // Check if bulk connection was not chosen but created.
        Assert.assertNull(actualHolder.bulkConnection);
    }
}
Also used : SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) PartnerConnection(com.sforce.soap.partner.PartnerConnection) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) ConnectionHolder(org.talend.components.salesforce.runtime.common.ConnectionHolder)

Example 2 with RuntimeContainer

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

the class SalesforceSessionReuseTestIT method testUseExistingConnection.

@Ignore("Need to solve test failed randomly")
@Test(timeout = 30_000)
public void testUseExistingConnection() throws Throwable {
    File sessionFolder = new File(tempFolder.getRoot().getPath() + "/tsalesforceconnection_1/");
    assertEquals(0, sessionFolder.getTotalSpace());
    LOGGER.debug("session folder: " + sessionFolder.getAbsolutePath());
    SalesforceConnectionProperties connProps = (SalesforceConnectionProperties) getComponentService().getComponentProperties(TSalesforceConnectionDefinition.COMPONENT_NAME);
    setupProps(connProps, !ADD_QUOTES);
    // setup session function
    connProps.reuseSession.setValue(true);
    connProps.sessionDirectory.setValue(sessionFolder.getAbsolutePath());
    final String currentComponentName = TSalesforceConnectionDefinition.COMPONENT_NAME + "_1";
    final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();
    RuntimeContainer connContainer = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return currentComponentName;
        }

        @Override
        public Object getComponentData(String componentId, String key) {
            return globalMap.get(componentId + "_" + key);
        }

        @Override
        public void setComponentData(String componentId, String key, Object data) {
            globalMap.put(componentId + "_" + key, data);
        }

        @Override
        public Object getGlobalData(String key) {
            return globalMap.get(key);
        }
    };
    // 1. salesforce connection would save the session to a session file
    SalesforceSourceOrSink salesforceSourceOrSink = new SalesforceSourceOrSink();
    salesforceSourceOrSink.initialize(connContainer, connProps);
    assertEquals(ValidationResult.Result.OK, salesforceSourceOrSink.validate(connContainer).getStatus());
    // 2. set a wrong pwd to connection properties
    connProps.userPassword.password.setValue(WRONG_PWD);
    // Input component get connection from the tSalesforceConnection
    TSalesforceInputProperties inProps = (TSalesforceInputProperties) getComponentService().getComponentProperties(TSalesforceInputDefinition.COMPONENT_NAME);
    inProps.connection.referencedComponent.componentInstanceId.setValue(currentComponentName);
    inProps.connection.referencedComponent.setReference(connProps);
    checkAndAfter(inProps.connection.referencedComponent.getReference().getForm(Form.REFERENCE), "referencedComponent", inProps.connection);
    ComponentTestUtils.checkSerialize(inProps, errorCollector);
    assertEquals(2, inProps.getForms().size());
    Form f = inProps.module.getForm(Form.REFERENCE);
    assertTrue(f.getWidget("moduleName").isCallBeforeActivate());
    ComponentProperties moduleProps = (ComponentProperties) f.getProperties();
    try {
        // 3. input components would be get connection from connection session file
        moduleProps = (ComponentProperties) PropertiesTestUtils.checkAndBeforeActivate(getComponentService(), f, "moduleName", moduleProps);
        Object connection = connContainer.getComponentData(currentComponentName, SalesforceSourceOrSink.KEY_CONNECTION);
        assertNotNull(connection);
        ((PartnerConnection) connection).getConfig().setPassword(WRONG_PWD);
        // Check whether the session disable by other test.
        ((PartnerConnection) connection).getUserInfo();
        Property<?> prop = (Property<?>) f.getWidget("moduleName").getContent();
        assertTrue(prop.getPossibleValues().size() > 100);
        LOGGER.debug(moduleProps.getValidationResult().toString());
        assertEquals(ValidationResult.Result.OK, moduleProps.getValidationResult().getStatus());
        invalidSession(connProps, null);
        // This means that the session is disabled by current test
        // 4. invalid the session, then the session should be renew based on reference connection information(wrong pwd)
        // connect would be fail
        moduleProps = (ComponentProperties) PropertiesTestUtils.checkAndBeforeActivate(getComponentService(), f, "moduleName", moduleProps);
        assertEquals(ValidationResult.Result.ERROR, moduleProps.getValidationResult().getStatus());
        LOGGER.debug(moduleProps.getValidationResult().toString());
    } catch (ConnectionException e) {
        // Maybe get exception when same account run in parallel
        // The session maybe disabled by other test
        assertThat(e, instanceOf(LoginFault.class));
        assertEquals(ExceptionCode.INVALID_LOGIN, ((LoginFault) e).getExceptionCode());
        LOGGER.debug("session is disabled by other test!");
    }
    // 5.set correct pwd back
    setupProps(connProps, !ADD_QUOTES);
    moduleProps = (ComponentProperties) PropertiesTestUtils.checkAndBeforeActivate(getComponentService(), f, "moduleName", moduleProps);
    assertEquals(ValidationResult.Result.OK, moduleProps.getValidationResult().getStatus());
    LOGGER.debug(moduleProps.getValidationResult().toString());
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) Form(org.talend.daikon.properties.presentation.Form) PartnerConnection(com.sforce.soap.partner.PartnerConnection) LoginFault(com.sforce.soap.partner.fault.LoginFault) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) File(java.io.File) Property(org.talend.daikon.properties.property.Property) ConnectionException(com.sforce.ws.ConnectionException) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with RuntimeContainer

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

the class SalesforceComponentTestIT method testUseExistingConnection.

@Test
public void testUseExistingConnection() throws Throwable {
    SalesforceConnectionProperties connProps = (SalesforceConnectionProperties) getComponentService().getComponentProperties(TSalesforceConnectionDefinition.COMPONENT_NAME);
    setupProps(connProps, !ADD_QUOTES);
    final String currentComponentName = TSalesforceConnectionDefinition.COMPONENT_NAME + "_1";
    RuntimeContainer connContainer = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return currentComponentName;
        }
    };
    SalesforceSourceOrSink salesforceSourceOrSink = new SalesforceSourceOrSink();
    salesforceSourceOrSink.initialize(connContainer, connProps);
    assertEquals(ValidationResult.Result.OK, salesforceSourceOrSink.validate(connContainer).getStatus());
    // Input component get connection from the tSalesforceConnection
    ComponentDefinition inputDefinition = getComponentService().getComponentDefinition(TSalesforceInputDefinition.COMPONENT_NAME);
    TSalesforceInputProperties inProps = (TSalesforceInputProperties) getComponentService().getComponentProperties(TSalesforceInputDefinition.COMPONENT_NAME);
    inProps.connection.referencedComponent.componentInstanceId.setValue(currentComponentName);
    SalesforceSourceOrSink salesforceInputSourceOrSink = new SalesforceSourceOrSink();
    salesforceInputSourceOrSink.initialize(connContainer, inProps);
    assertEquals(ValidationResult.Result.OK, salesforceInputSourceOrSink.validate(connContainer).getStatus());
}
Also used : SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) SalesforceSourceOrSink(org.talend.components.salesforce.runtime.SalesforceSourceOrSink) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Test(org.junit.Test)

Example 4 with RuntimeContainer

use of org.talend.components.api.container.RuntimeContainer 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 5 with RuntimeContainer

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

the class NetSuiteSearchInputReaderIT method testInput.

@Test
public void testInput() throws Exception {
    RuntimeContainer container = mock(RuntimeContainer.class);
    NetSuiteInputProperties properties = new NetSuiteInputProperties("test");
    properties.init();
    properties.connection.endpoint.setValue(webServiceTestFixture.getEndpointUrl());
    properties.connection.email.setValue(webServiceTestFixture.getCredentials().getEmail());
    properties.connection.password.setValue(webServiceTestFixture.getCredentials().getPassword());
    properties.connection.account.setValue(webServiceTestFixture.getCredentials().getAccount());
    properties.connection.role.setValue(Integer.valueOf(webServiceTestFixture.getCredentials().getRoleId()));
    properties.connection.applicationId.setValue(webServiceTestFixture.getCredentials().getApplicationId());
    properties.module.moduleName.setValue("Account");
    NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
    NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    properties.module.main.schema.setValue(schema);
    properties.module.afterModuleName();
    properties.module.searchQuery.field.setValue(Arrays.asList("Type"));
    properties.module.searchQuery.operator.setValue(Arrays.asList("List.anyOf"));
    properties.module.searchQuery.value1.setValue(Arrays.<Object>asList("Bank"));
    properties.module.searchQuery.value2.setValue(Arrays.<Object>asList((String) null));
    NetSuiteSource source = new NetSuiteSourceImpl();
    source.initialize(container, properties);
    NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(container);
    boolean started = reader.start();
    assertTrue(started);
    IndexedRecord record = reader.getCurrent();
    assertNotNull(record);
    List<Schema.Field> fields = record.getSchema().getFields();
    for (int i = 0; i < fields.size(); i++) {
        Schema.Field typeField = getFieldByName(fields, "AcctType");
        Object value = record.get(typeField.pos());
        assertNotNull(value);
        assertEquals(AccountType.BANK.value(), value);
    }
}
Also used : NetSuiteInputProperties(org.talend.components.netsuite.input.NetSuiteInputProperties) NetSuiteSourceImpl(org.talend.components.netsuite.v2014_2.NetSuiteSourceImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteSearchInputReader(org.talend.components.netsuite.input.NetSuiteSearchInputReader) Schema(org.apache.avro.Schema) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteSource(org.talend.components.netsuite.NetSuiteSource) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2014_2.NetSuiteRuntimeImpl) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Aggregations

RuntimeContainer (org.talend.components.api.container.RuntimeContainer)36 Test (org.junit.Test)34 DatabaseClient (com.marklogic.client.DatabaseClient)14 Schema (org.apache.avro.Schema)10 IndexedRecord (org.apache.avro.generic.IndexedRecord)10 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)9 MarkLogicOutputProperties (org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties)7 List (java.util.List)6 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)6 ValidationResult (org.talend.daikon.properties.ValidationResult)6 NetSuiteRuntimeImpl (org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl)5 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)4 CustomFieldList (com.netsuite.webservices.v2016_2.platform.core.CustomFieldList)4 CustomRecordRef (com.netsuite.webservices.v2016_2.platform.core.CustomRecordRef)4 RecordRefList (com.netsuite.webservices.v2016_2.platform.core.RecordRefList)4 GetListRequest (com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)4 ArrayList (java.util.ArrayList)4 Result (org.talend.components.api.component.runtime.Result)4 NetSuiteSink (org.talend.components.netsuite.NetSuiteSink)4 NetSuiteClientService (org.talend.components.netsuite.client.NetSuiteClientService)4