use of org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties 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);
}
}
use of org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties in project components by Talend.
the class SalesforceWriterTestIT method testSinkAllWithStringValue.
/*
* With current API like date/datetime/int/.... string value can't be write to server side So we need convert the field
* value type.
*/
@Test
public void testSinkAllWithStringValue() throws Exception {
// Component framework objects.
ComponentDefinition sfDef = new TSalesforceOutputDefinition();
TSalesforceOutputProperties sfProps = (TSalesforceOutputProperties) sfDef.createRuntimeProperties();
SalesforceTestBase.setupProps(sfProps.connection, false);
sfProps.module.setValue("moduleName", "Event");
sfProps.module.main.schema.setValue(SCHEMA_INSERT_EVENT);
sfProps.ceaseForError.setValue(true);
// Automatically generate the out schemas.
sfProps.module.schemaListener.afterSchema();
DefaultComponentRuntimeContainerImpl container = new DefaultComponentRuntimeContainerImpl();
List<IndexedRecord> records = new ArrayList<>();
String random = createNewRandom();
IndexedRecord r1 = new GenericData.Record(SCHEMA_INSERT_EVENT);
r1.put(0, "2011-02-02T02:02:02");
r1.put(1, "2011-02-02T22:02:02.000Z");
r1.put(2, "2011-02-02");
r1.put(3, "1200");
r1.put(4, "true");
r1.put(5, random);
// Rejected and successful writes are reset on the next record.
IndexedRecord r2 = new GenericData.Record(SCHEMA_INSERT_EVENT);
r2.put(0, "2016-02-02T02:02:02.000Z");
r2.put(1, "2016-02-02T12:02:02");
r2.put(2, "2016-02-02");
r2.put(3, "600");
r2.put(4, "0");
r2.put(5, random);
records.add(r1);
records.add(r2);
SalesforceSink salesforceSink = new SalesforceSink();
salesforceSink.initialize(adaptor, sfProps);
salesforceSink.validate(adaptor);
Writer<Result> batchWriter = salesforceSink.createWriteOperation().createWriter(adaptor);
writeRows(batchWriter, records);
assertEquals(2, ((SalesforceWriter) batchWriter).getSuccessfulWrites().size());
TSalesforceInputProperties sfInputProps = getSalesforceInputProperties();
sfInputProps.copyValuesFrom(sfProps);
sfInputProps.condition.setValue("Subject = '" + random + "' ORDER BY DurationInMinutes ASC");
sfInputProps.module.main.schema.setValue(SCHEMA_INPUT_AND_DELETE_EVENT);
List<IndexedRecord> inpuRecords = readRows(sfInputProps);
try {
assertEquals(2, inpuRecords.size());
IndexedRecord inputRecords_1 = inpuRecords.get(0);
IndexedRecord inputRecords_2 = inpuRecords.get(1);
assertEquals(random, inputRecords_1.get(6));
assertEquals(random, inputRecords_2.get(6));
// we use containsInAnyOrder because we are not garanteed to have the same order every run.
assertThat(Arrays.asList("2011-02-02T02:02:02.000Z", "2016-02-02T02:02:02.000Z"), containsInAnyOrder(inputRecords_1.get(1), inputRecords_2.get(1)));
assertThat(Arrays.asList("2011-02-02T22:02:02.000Z", "2016-02-02T12:02:02.000Z"), containsInAnyOrder(inputRecords_1.get(2), inputRecords_2.get(2)));
assertThat(Arrays.asList("2011-02-02", "2016-02-02"), containsInAnyOrder(inputRecords_1.get(3), inputRecords_2.get(3)));
assertThat(Arrays.asList("1200", "600"), containsInAnyOrder(inputRecords_1.get(4), inputRecords_2.get(4)));
assertThat(Arrays.asList("true", "false"), containsInAnyOrder(inputRecords_1.get(5), inputRecords_2.get(5)));
} finally {
deleteRows(inpuRecords, sfInputProps);
}
}
use of org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties in project components by Talend.
the class SalesforceWriterTestIT method testWriterOpenCloseWithEmptyData.
@Test
public void testWriterOpenCloseWithEmptyData() throws Throwable {
TSalesforceOutputProperties props = createSalesforceoutputProperties(EXISTING_MODULE_NAME);
Map<String, Object> resultMap;
// this is mainly to check that open and close do not throw any exceptions.
// insert
props.outputAction.setValue(TSalesforceOutputProperties.OutputAction.INSERT);
props.afterOutputAction();
Writer<Result> saleforceWriter = createSalesforceOutputWriter(props);
Result writeResult = writeRows(saleforceWriter, Collections.EMPTY_LIST);
resultMap = getConsolidatedResults(writeResult, saleforceWriter);
assertEquals(0, resultMap.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
// deleted
props.outputAction.setValue(TSalesforceOutputProperties.OutputAction.DELETE);
props.afterOutputAction();
saleforceWriter = createSalesforceOutputWriter(props);
writeResult = writeRows(saleforceWriter, Collections.EMPTY_LIST);
resultMap = getConsolidatedResults(writeResult, saleforceWriter);
assertEquals(0, resultMap.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
// update
props.outputAction.setValue(TSalesforceOutputProperties.OutputAction.UPDATE);
props.afterOutputAction();
saleforceWriter = createSalesforceOutputWriter(props);
writeResult = writeRows(saleforceWriter, Collections.EMPTY_LIST);
resultMap = getConsolidatedResults(writeResult, saleforceWriter);
assertEquals(0, resultMap.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
// upsert
props.outputAction.setValue(TSalesforceOutputProperties.OutputAction.UPSERT);
props.afterOutputAction();
saleforceWriter = createSalesforceOutputWriter(props);
writeResult = writeRows(saleforceWriter, Collections.EMPTY_LIST);
resultMap = getConsolidatedResults(writeResult, saleforceWriter);
assertEquals(0, resultMap.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
}
use of org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties in project components by Talend.
the class SalesforceTestBase method deleteAllAccountTestRows.
public static void deleteAllAccountTestRows(String condition) throws Exception {
TSalesforceInputProperties properties = (TSalesforceInputProperties) new TSalesforceInputProperties("foo").init();
properties.condition.setValue("Name = '" + condition + "'");
BoundedReader<?> salesforceInputReader = new SalesforceTestBase().createSalesforceInputReaderFromModule(EXISTING_MODULE_NAME, properties);
// getting all rows
List<IndexedRecord> rows = new ArrayList<>();
try {
salesforceInputReader.start();
rows.add((IndexedRecord) salesforceInputReader.getCurrent());
while (salesforceInputReader.advance()) {
rows.add((IndexedRecord) salesforceInputReader.getCurrent());
}
} finally {
salesforceInputReader.close();
}
// filtering rows
TSalesforceOutputProperties salesforceoutputProperties = createSalesforceoutputProperties(EXISTING_MODULE_NAME);
setupProps(salesforceoutputProperties.connection, !ADD_QUOTES);
new SalesforceTestBase().deleteRows(rows, salesforceoutputProperties);
}
use of org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties in project components by Talend.
the class SalesforceTestBase method createSalesforceoutputProperties.
private static TSalesforceOutputProperties createSalesforceoutputProperties(String moduleName) throws Exception {
TSalesforceOutputProperties props = (TSalesforceOutputProperties) new TSalesforceOutputProperties("foo").init();
setupProps(props.connection, !ADD_QUOTES);
props.module.moduleName.setValue(moduleName);
// to setup schema.
props.module.afterModuleName();
return props;
}
Aggregations