use of org.talend.components.api.component.runtime.Writer in project components by Talend.
the class SalesforceRuntimeTestUtil method simulateRuntimeCaller.
public void simulateRuntimeCaller(TSalesforceOutputBulkDefinition definition, TSalesforceOutputBulkProperties modelProperties, Schema schema, List<Map<String, String>> rows) throws IOException {
Writer writer = initWriter(definition, modelProperties);
try {
for (Map<String, String> row : rows) {
GenericRecord record = new GenericData.Record(schema);
for (Map.Entry<String, String> entry : row.entrySet()) {
record.put(entry.getKey(), entry.getValue());
}
writer.write(record);
}
} finally {
writer.close();
}
}
use of org.talend.components.api.component.runtime.Writer in project components by Talend.
the class MarketoInputWriterTestIT method testGetMultipleLeadsLeadKeyWithIdRESTTDI39008.
@Test
public void testGetMultipleLeadsLeadKeyWithIdRESTTDI39008() throws Exception {
propsREST.leadKeyTypeREST.setValue(LeadKeyTypeREST.id);
propsREST.leadKeyValues.setValue("id");
sink.initialize(null, propsREST);
Writer tmpWriter = sink.createWriteOperation().createWriter(null);
assertTrue(tmpWriter instanceof MarketoInputWriter);
MarketoInputWriter writer = (MarketoInputWriter) tmpWriter;
Schema s = SchemaBuilder.builder().record("input").fields().name("id").type().intType().noDefault().endRecord();
IndexedRecord input = new GenericData.Record(s);
writer.open("RESTTests");
input.put(0, 4221930);
writer.write(input);
input.put(0, 4221931);
writer.write(input);
writer.close();
assertEquals(2, writer.result.successCount);
}
use of org.talend.components.api.component.runtime.Writer in project components by Talend.
the class SalesforceRuntimeTestUtil method initWriter.
private Writer initWriter(TSalesforceOutputBulkDefinition definition, TSalesforceOutputBulkProperties modelProperties) throws IOException {
// simulate to generate the runtime code
TSalesforceOutputBulkProperties runtimeProperties = (TSalesforceOutputBulkProperties) definition.createRuntimeProperties();
// pass all the value from the ui model
runtimeProperties.schema.schema.setValue(modelProperties.schema.schema.getValue());
runtimeProperties.bulkFilePath.setValue(modelProperties.bulkFilePath.getStringValue());
runtimeProperties.append.setValue(modelProperties.append.getValue());
runtimeProperties.ignoreNull.setValue(modelProperties.ignoreNull.getValue());
Object obj = modelProperties.upsertRelationTable.columnName.getValue();
if (obj != null && obj instanceof List && !((List) obj).isEmpty()) {
runtimeProperties.upsertRelationTable.columnName.setValue(modelProperties.upsertRelationTable.columnName.getValue());
runtimeProperties.upsertRelationTable.lookupFieldExternalIdName.setValue(modelProperties.upsertRelationTable.lookupFieldExternalIdName.getValue());
runtimeProperties.upsertRelationTable.lookupFieldModuleName.setValue(modelProperties.upsertRelationTable.lookupFieldModuleName.getValue());
runtimeProperties.upsertRelationTable.lookupRelationshipFieldName.setValue(modelProperties.upsertRelationTable.lookupRelationshipFieldName.getValue());
runtimeProperties.upsertRelationTable.polymorphic.setValue(modelProperties.upsertRelationTable.polymorphic.getValue());
}
SourceOrSink source_sink = new SalesforceBulkFileSink();
source_sink.initialize(null, runtimeProperties);
ValidationResult result = source_sink.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
Sink sink = (Sink) source_sink;
WriteOperation writeOperation = sink.createWriteOperation();
writeOperation.initialize(null);
Writer writer = writeOperation.createWriter(null);
writer.open("component_instance_id");
return writer;
}
use of org.talend.components.api.component.runtime.Writer in project components by Talend.
the class MarketoInputWriterTestIT method testGetMultipleLeadsLeadKeyWithEmailREST.
@Test
public void testGetMultipleLeadsLeadKeyWithEmailREST() throws Exception {
sink.initialize(null, propsREST);
Writer tmpWriter = sink.createWriteOperation().createWriter(null);
assertTrue(tmpWriter instanceof MarketoInputWriter);
MarketoInputWriter writer = (MarketoInputWriter) tmpWriter;
// create an input IndexedRecord
Schema s = SchemaBuilder.builder().record("input").fields().name("email").type().stringType().noDefault().name("dummy").type().stringType().noDefault().endRecord();
IndexedRecord input = new GenericData.Record(s);
input.put(0, "undx@undx.net");
input.put(1, "dummy value");
//
writer.open("RESTTests");
writer.write(input);
List<IndexedRecord> successes = writer.getSuccessfulWrites();
assertNotNull(successes);
IndexedRecord record = successes.get(0);
assertNotNull(record);
LOG.debug("record = {}.", record);
Schema sout = record.getSchema();
assertEquals("id", sout.getFields().get(0).name());
assertNotNull(record.get(0));
assertEquals("email", sout.getFields().get(1).name());
assertNotNull(record.get(1));
assertEquals("firstName", sout.getFields().get(2).name());
assertEquals("lastName", sout.getFields().get(3).name());
assertEquals("createdAt", sout.getFields().get(4).name());
assertEquals("updatedAt", sout.getFields().get(5).name());
}
use of org.talend.components.api.component.runtime.Writer in project components by Talend.
the class MarketoInputWriterTestIT method testGetMultipleLeadsLeadKeyWithEmailDynamicREST.
@Test
public void testGetMultipleLeadsLeadKeyWithEmailDynamicREST() throws Exception {
sink.initialize(null, propsREST);
Writer tmpWriter = sink.createWriteOperation().createWriter(null);
assertTrue(tmpWriter instanceof MarketoInputWriter);
MarketoInputWriter writer = (MarketoInputWriter) tmpWriter;
// create an input IndexedRecord
Schema s = SchemaBuilder.builder().record("input").fields().name("email").type().stringType().noDefault().name("dummy").type().stringType().noDefault().endRecord();
propsREST.schemaInput.schema.setValue(SchemaBuilder.builder().record("test").prop(SchemaConstants.INCLUDE_ALL_FIELDS, "true").fields().endRecord());
IndexedRecord input = new GenericData.Record(s);
input.put(0, "undx@undx.net");
input.put(1, "dummy value");
//
writer.open("RESTTests");
writer.write(input);
List<IndexedRecord> successes = writer.getSuccessfulWrites();
assertNotNull(successes);
IndexedRecord record = successes.get(0);
assertNotNull(record);
LOG.debug("record = {}.", record);
Schema sout = record.getSchema();
}
Aggregations