use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.
the class SalesforceProxyTestIT method testProxyWithBulkQuery.
@Test
public void testProxyWithBulkQuery() {
TSalesforceInputDefinition definition = (TSalesforceInputDefinition) getComponentService().getComponentDefinition(TSalesforceInputDefinition.COMPONENT_NAME);
TSalesforceInputProperties properties = (TSalesforceInputProperties) definition.createRuntimeProperties();
properties.connection.bulkConnection.setValue(true);
properties.queryMode.setValue(QueryMode.Bulk);
SalesforceRuntimeTestUtil util = new SalesforceRuntimeTestUtil();
properties.module.moduleName.setValue(util.getTestModuleName());
properties.module.main.schema.setValue(util.getTestSchema1());
properties.connection.userPassword.userId.setValue(userId);
properties.connection.userPassword.password.setValue(password);
properties.connection.userPassword.securityKey.setValue(securityKey);
Source source = new SalesforceSource();
source.initialize(null, properties);
org.talend.daikon.properties.ValidationResult vr = source.validate(null);
Assert.assertEquals(ValidationResult.Result.OK, vr.getStatus());
Reader reader = source.createReader(null);
try {
reader.start();
do {
reader.getCurrent();
} while (reader.advance());
reader.close();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.
the class SalesforceSessionReuseTestIT method testInputReuseSession.
/*
* If the logic changes for this test please specify appropriate timeout.
* The average execution time for this test 3.2-4.7 sec.
*/
@Test(timeout = 40_000)
public void testInputReuseSession() throws Throwable {
File sessionFolder = new File(tempFolder.getRoot().getPath() + "/tsalesforceinput/");
assertEquals(0, sessionFolder.getTotalSpace());
LOGGER.debug("session folder: " + sessionFolder.getAbsolutePath());
// $NON-NLS-1$
TSalesforceInputProperties props = (TSalesforceInputProperties) new TSalesforceInputProperties("foo").init();
props.module.moduleName.setValue(EXISTING_MODULE_NAME);
props.module.main.schema.setValue(getMakeRowSchema(false));
props.connection = setupProps(null, !ADD_QUOTES);
// setup session function
props.connection.reuseSession.setValue(true);
props.connection.sessionDirectory.setValue(sessionFolder.getAbsolutePath());
// Init session
assertEquals(ValidationResult.Result.OK, testConnection(props).getStatus());
assertNotEquals(0, sessionFolder.getTotalSpace());
// Invalid session, test whether it can be renew the session
invalidSession(props.connection, null);
List<IndexedRecord> records = readRows(props);
assertNotNull(records);
LOGGER.debug("current records number in module " + EXISTING_MODULE_NAME + ": " + records.size());
assertNotEquals(0, records.size());
// Set wrong pwd to test reuse session from session folder
props.connection.userPassword.password.setValue(WRONG_PWD);
try {
testConnection(props);
records = readRows(props);
assertNotNull(records);
LOGGER.debug("current records number in module " + EXISTING_MODULE_NAME + ": " + records.size());
assertNotEquals(0, records.size());
// Test reuse session fails with wrong pwd
invalidSession(props.connection, null);
// This means that the session is disabled by current test
} catch (IOException e) {
Throwable caused = e.getCause();
// Maybe get exception when same account run in parallel
// The session maybe disabled by other test
assertThat(caused, instanceOf(LoginFault.class));
assertEquals(ExceptionCode.INVALID_LOGIN, ((LoginFault) caused).getExceptionCode());
LOGGER.debug("session is disabled by other test!");
}
try {
readRows(props);
} catch (IOException e) {
Throwable caused = e.getCause();
// Should login fails with wrong pwd
assertThat(caused, instanceOf(LoginFault.class));
assertEquals(ExceptionCode.INVALID_LOGIN, ((LoginFault) caused).getExceptionCode());
LOGGER.debug("expect login fails: " + e.getMessage());
}
// Disable reuse session function
props.connection.reuseSession.setValue(false);
LOGGER.debug("expect login fails:");
assertEquals(ValidationResult.Result.ERROR, testConnection(props).getStatus());
}
use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.
the class SalesforceSourceOrSinkTestIT method testInitialize.
@Test
public void testInitialize() {
SalesforceSourceOrSink salesforceSourceOrSink = new SalesforceSourceOrSink();
TSalesforceInputProperties properties = new TSalesforceInputProperties(null);
salesforceSourceOrSink.initialize(null, properties);
assertEquals(properties.connection, salesforceSourceOrSink.getConnectionProperties());
}
use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.
the class SalesforceSourceOrSinkTestIT method testSalesForcePasswordExpired.
@Test(expected = ConnectionException.class)
public void testSalesForcePasswordExpired() throws ConnectionException {
SalesforceSourceOrSink salesforceSourceOrSink = new SalesforceSourceOrSink();
TSalesforceInputProperties properties = (TSalesforceInputProperties) new TSalesforceInputProperties(null).init();
salesforceSourceOrSink.initialize(null, properties);
ConnectorConfig config = new ConnectorConfig();
config.setUsername(StringUtils.strip(USER_ID_EXPIRED, "\""));
String password = StringUtils.strip(PASSWORD_EXPIRED, "\"");
String securityKey = StringUtils.strip(SECURITY_KEY_EXPIRED, "\"");
if (StringUtils.isNotEmpty(securityKey)) {
password = password + securityKey;
}
config.setPassword(password);
PartnerConnection connection = null;
try {
connection = salesforceSourceOrSink.doConnection(config, true);
} catch (LoginFault ex) {
Assert.fail("Must be an exception related to expired password, not the Login Fault.");
} finally {
if (null != connection) {
connection.logout();
}
}
}
use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.
the class SalesforceSource method createReader.
@Override
public BoundedReader createReader(RuntimeContainer adaptor) {
if (properties instanceof TSalesforceInputProperties) {
TSalesforceInputProperties sfInProperties = (TSalesforceInputProperties) properties;
boolean isBulk = TSalesforceInputProperties.QueryMode.Bulk.equals(sfInProperties.queryMode.getValue());
sfInProperties.connection.bulkConnection.setValue(isBulk);
if (isBulk) {
return new SalesforceBulkQueryInputReader(adaptor, this, sfInProperties);
} else {
return new SalesforceInputReader(adaptor, this, sfInProperties);
}
} else if (properties instanceof TSalesforceGetServerTimestampProperties) {
return new SalesforceServerTimeStampReader(adaptor, this, (TSalesforceGetServerTimestampProperties) properties);
} else if (properties instanceof TSalesforceGetDeletedProperties) {
return new SalesforceGetDeletedReader(adaptor, this, (TSalesforceGetDeletedProperties) properties);
} else if (properties instanceof TSalesforceGetUpdatedProperties) {
return new SalesforceGetUpdatedReader(adaptor, this, (TSalesforceGetUpdatedProperties) properties);
} else if (properties instanceof TSalesforceBulkExecProperties) {
((TSalesforceBulkExecProperties) properties).connection.bulkConnection.setValue(true);
return new SalesforceBulkExecReader(adaptor, this, (TSalesforceBulkExecProperties) properties);
}
return null;
}
Aggregations