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);
}
}
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());
}
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());
}
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);
}
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);
}
}
Aggregations