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