use of org.talend.components.api.component.runtime.Result in project components by Talend.
the class AzureStorageQueueSinkTest method testCreateWriteOperation.
/**
* Test method for
* {@link org.talend.components.azurestorage.queue.runtime.AzureStorageQueueSink#createWriteOperation()}.
*/
@Test
public final void testCreateWriteOperation() {
AzureStorageQueueSink sink = new AzureStorageQueueSink();
TAzureStorageQueueOutputProperties p = new TAzureStorageQueueOutputProperties("test");
p.connection.setupProperties();
p.setupProperties();
sink.initialize(null, p);
assertNotNull(sink.createWriteOperation());
assertNotNull(sink.createWriteOperation().createWriter(null));
assertEquals(sink, sink.createWriteOperation().getSink());
List<Result> writerResults = new ArrayList<Result>();
Result r = new Result("test");
writerResults.add(r);
AzureStorageQueueWriteOperation wo = (AzureStorageQueueWriteOperation) sink.createWriteOperation();
wo.initialize(null);
assertNotNull(wo.finalize(writerResults, null));
}
use of org.talend.components.api.component.runtime.Result in project components by Talend.
the class AzureStorageTableWriteOperationTest method testASTWO.
@Test
public void testASTWO() throws Exception {
assertEquals(ValidationResult.Result.OK, sink.initialize(container, properties).getStatus());
assertEquals(ValidationResult.Result.OK, sink.validate(container).getStatus());
azureStorageTableWriteOperation = (AzureStorageTableWriteOperation) sink.createWriteOperation();
assertNotNull(azureStorageTableWriteOperation.getSink());
List<Result> writerResults = new ArrayList<Result>();
Result r = new Result("test");
writerResults.add(r);
assertNotNull(azureStorageTableWriteOperation.finalize(writerResults, container));
}
use of org.talend.components.api.component.runtime.Result in project components by Talend.
the class SalesforceWriterTestIT method runOutputInsert.
/**
* @param isDynamic true if the actual rows should contain more columns than the schema specified in the component
* properties.
*/
protected void runOutputInsert(boolean isDynamic) throws Exception {
TSalesforceOutputProperties props = createSalesforceoutputProperties(EXISTING_MODULE_NAME);
setupProps(props.connection, !SalesforceTestBase.ADD_QUOTES);
props.module.moduleName.setValue(EXISTING_MODULE_NAME);
props.module.main.schema.setValue(getMakeRowSchema(isDynamic));
props.outputAction.setValue(TSalesforceOutputProperties.OutputAction.INSERT);
Writer<Result> saleforceWriter = createSalesforceOutputWriter(props);
String random = createNewRandom();
List<IndexedRecord> outputRows = makeRows(random, 10, isDynamic);
List<IndexedRecord> inputRows = null;
Exception firstException = null;
try {
Result writeResult = writeRows(saleforceWriter, outputRows);
Map<String, Object> resultMap = getConsolidatedResults(writeResult, saleforceWriter);
assertEquals(outputRows.size(), resultMap.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
// create a new props for reading the data, the schema may be altered in the original output props
TSalesforceOutputProperties readprops = createSalesforceoutputProperties(EXISTING_MODULE_NAME);
setupProps(readprops.connection, !SalesforceTestBase.ADD_QUOTES);
readprops.module.moduleName.setValue(EXISTING_MODULE_NAME);
// to update the schema.
readprops.module.afterModuleName();
inputRows = readRows(readprops);
List<IndexedRecord> allReadTestRows = filterAllTestRows(random, inputRows);
assertNotEquals(0, allReadTestRows.size());
assertEquals(outputRows.size(), allReadTestRows.size());
} catch (Exception e) {
firstException = e;
} finally {
if (firstException == null) {
if (inputRows == null) {
inputRows = readRows(props);
}
List<IndexedRecord> allReadTestRows = filterAllTestRows(random, inputRows);
deleteRows(allReadTestRows, props);
inputRows = readRows(props);
assertEquals(0, filterAllTestRows(random, inputRows).size());
} else {
throw firstException;
}
}
}
use of org.talend.components.api.component.runtime.Result in project components by Talend.
the class SalesforceWriterTestIT method testNillableBase64Field.
@Test
public void testNillableBase64Field() throws Throwable {
String moduleName = "StaticResource";
ComponentDefinition sfDef = new TSalesforceOutputDefinition();
TSalesforceOutputProperties sfProps = (TSalesforceOutputProperties) sfDef.createRuntimeProperties();
SalesforceTestBase.setupProps(sfProps.connection, false);
sfProps.module.setValue("moduleName", moduleName);
sfProps.module.main.schema.setValue(SCHEMA_STATIC_RESOURCE);
sfProps.ceaseForError.setValue(true);
sfProps.module.schemaListener.afterSchema();
List records = new ArrayList<IndexedRecord>();
String randomName = getRandomString(10);
IndexedRecord record = new GenericData.Record(SCHEMA_STATIC_RESOURCE);
record.put(0, randomName);
record.put(1, "text/plain");
record.put(2, "dGhpcyBpcyBiYXNlNjQgIHRlc3QgZmlsZS4g");
record.put(3, "this is base64 test file.");
records.add(record);
SalesforceSink salesforceSink = new SalesforceSink();
salesforceSink.initialize(adaptor, sfProps);
salesforceSink.validate(adaptor);
Writer<Result> batchWriter = salesforceSink.createWriteOperation().createWriter(adaptor);
writeRows(batchWriter, records);
TSalesforceInputProperties sfInputProps = getSalesforceInputProperties();
sfInputProps.copyValuesFrom(sfProps);
sfInputProps.condition.setValue("Name = '" + randomName + "'");
sfProps.module.setValue("moduleName", moduleName);
sfProps.module.main.schema.setValue(SCHEMA_STATIC_RESOURCE);
List<IndexedRecord> inpuRecords = readRows(sfInputProps);
try {
assertEquals(1, inpuRecords.size());
IndexedRecord r = inpuRecords.get(0);
assertEquals(randomName, r.get(0));
assertEquals("text/plain", r.get(1));
assertEquals("dGhpcyBpcyBiYXNlNjQgIHRlc3QgZmlsZS4g", r.get(2));
assertEquals("this is base64 test file.", r.get(3));
assertNotNull(r.get(4));
} finally {
deleteRows(inpuRecords, sfInputProps);
}
}
use of org.talend.components.api.component.runtime.Result in project components by Talend.
the class SalesforceWriterTestIT method testWriteDynamicWithFeedback.
/**
* Test write dynamic with feedback
*/
@Test
public void testWriteDynamicWithFeedback() throws Exception {
// Component framework objects.
ComponentDefinition sfDef = new TSalesforceOutputDefinition();
TSalesforceOutputProperties sfProps = (TSalesforceOutputProperties) sfDef.createRuntimeProperties();
SalesforceTestBase.setupProps(sfProps.connection, false);
sfProps.module.setValue("moduleName", "Account");
Schema dynamicSchema = //
SchemaBuilder.builder().record("Schema").prop(SchemaConstants.INCLUDE_ALL_FIELDS, //
"true").prop("di.dynamic.column.position", "1").fields().name("Name").type().stringType().noDefault().endRecord();
Schema dynamicRuntimeSchema = //
SchemaBuilder.builder().record("Schema").prop(SchemaConstants.INCLUDE_ALL_FIELDS, //
"true").prop("di.dynamic.column.position", "1").fields().name("Name").type().stringType().noDefault().name("BillingStreet").type().stringType().noDefault().name("BillingCity").type().stringType().noDefault().name("BillingState").type().stringType().noDefault().endRecord();
sfProps.module.main.schema.setValue(dynamicSchema);
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 r1 = new GenericData.Record(dynamicRuntimeSchema);
r1.put(0, "test");
r1.put(1, "deleteme");
r1.put(2, "deleteme");
r1.put(3, "deleteme");
sfWriter.write(r1);
// Check success
assertThat(sfWriter.getSuccessfulWrites(), hasSize(1));
IndexedRecord success = sfWriter.getSuccessfulWrites().get(0);
assertThat(success.getSchema().getFields(), hasSize(4));
// Check the values copied from the incoming record.
for (int i = 0; i < r1.getSchema().getFields().size(); i++) {
assertThat(success.getSchema().getFields().get(i), is(r1.getSchema().getFields().get(i)));
assertThat(success.get(i), is(r1.get(i)));
}
// The success fields.
assertThat(success.getSchema().getFields().get(0).name(), is("Name"));
assertThat(success.getSchema().getFields().get(1).name(), is("BillingStreet"));
assertThat(success.getSchema().getFields().get(2).name(), is("BillingCity"));
assertThat(success.getSchema().getFields().get(3).name(), is("BillingState"));
assertThat(success.get(0), is((Object) "test"));
assertThat(success.get(1), is((Object) "deleteme"));
assertThat(success.get(2), is((Object) "deleteme"));
assertThat(success.get(3), is((Object) "deleteme"));
// Check reject
IndexedRecord r2 = new GenericData.Record(dynamicRuntimeSchema);
r2.put(1, "deleteme");
r2.put(2, "deleteme");
r2.put(3, "deleteme");
sfWriter.write(r2);
assertThat(sfWriter.getRejectedWrites(), hasSize(1));
IndexedRecord rejected = sfWriter.getRejectedWrites().get(0);
assertThat(rejected.getSchema().getFields(), hasSize(7));
// The rejected fields.
assertThat(rejected.getSchema().getFields().get(0).name(), is("Name"));
assertThat(rejected.getSchema().getFields().get(1).name(), is("BillingStreet"));
assertThat(rejected.getSchema().getFields().get(2).name(), is("BillingCity"));
assertThat(rejected.getSchema().getFields().get(3).name(), is("BillingState"));
assertThat(rejected.getSchema().getFields().get(4).name(), is(TSalesforceOutputProperties.FIELD_ERROR_CODE));
assertThat(rejected.getSchema().getFields().get(5).name(), is(TSalesforceOutputProperties.FIELD_ERROR_FIELDS));
assertThat(rejected.getSchema().getFields().get(6).name(), is(TSalesforceOutputProperties.FIELD_ERROR_MESSAGE));
assertNull(rejected.get(0));
assertThat(rejected.get(1), is((Object) "deleteme"));
assertThat(rejected.get(2), is((Object) "deleteme"));
assertThat(rejected.get(3), is((Object) "deleteme"));
assertNotNull(rejected.get(4));
assertNotNull(rejected.get(5));
assertNotNull(rejected.get(6));
// Finish the Writer, WriteOperation and Sink.
Result wr1 = sfWriter.close();
sfWriteOp.finalize(Arrays.asList(wr1), container);
}
Aggregations