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