Search in sources :

Example 1 with Writer

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();
    }
}
Also used : GenericRecord(org.apache.avro.generic.GenericRecord) GenericRecord(org.apache.avro.generic.GenericRecord) HashMap(java.util.HashMap) Map(java.util.Map) Writer(org.talend.components.api.component.runtime.Writer)

Example 2 with Writer

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);
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) IndexedRecord(org.apache.avro.generic.IndexedRecord) Writer(org.talend.components.api.component.runtime.Writer) Test(org.junit.Test)

Example 3 with Writer

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;
}
Also used : TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) Sink(org.talend.components.api.component.runtime.Sink) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) SalesforceBulkFileSink(org.talend.components.salesforce.runtime.SalesforceBulkFileSink) WriteOperation(org.talend.components.api.component.runtime.WriteOperation) SObject(com.sforce.soap.partner.sobject.SObject) ArrayList(java.util.ArrayList) List(java.util.List) SalesforceBulkFileSink(org.talend.components.salesforce.runtime.SalesforceBulkFileSink) ValidationResult(org.talend.daikon.properties.ValidationResult) Writer(org.talend.components.api.component.runtime.Writer)

Example 4 with 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());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) IndexedRecord(org.apache.avro.generic.IndexedRecord) Writer(org.talend.components.api.component.runtime.Writer) Test(org.junit.Test)

Example 5 with Writer

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();
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) IndexedRecord(org.apache.avro.generic.IndexedRecord) Writer(org.talend.components.api.component.runtime.Writer) Test(org.junit.Test)

Aggregations

Writer (org.talend.components.api.component.runtime.Writer)8 IndexedRecord (org.apache.avro.generic.IndexedRecord)6 Schema (org.apache.avro.Schema)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 SObject (com.sforce.soap.partner.sobject.SObject)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 AfterClass (org.junit.AfterClass)1 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)1 Reader (org.talend.components.api.component.runtime.Reader)1 Result (org.talend.components.api.component.runtime.Result)1 Sink (org.talend.components.api.component.runtime.Sink)1 SourceOrSink (org.talend.components.api.component.runtime.SourceOrSink)1 WriteOperation (org.talend.components.api.component.runtime.WriteOperation)1 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)1 SalesforceBulkFileSink (org.talend.components.salesforce.runtime.SalesforceBulkFileSink)1 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)1