use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoOutputWriterTest method testWriteSyncLead.
@Test
public void testWriteSyncLead() throws Exception {
props.outputOperation.setValue(OutputOperation.syncLead);
props.dieOnError.setValue(false);
props.batchSize.setValue(1);
props.updateSchemaRelated();
when(sink.getProperties()).thenReturn(props);
doReturn(getFailedSyncResult(false)).when(client).syncLead(any(TMarketoOutputProperties.class), any(IndexedRecord.class));
doReturn(getFailedSyncResult(false)).when(client).syncMultipleLeads(any(TMarketoOutputProperties.class), any(List.class));
IndexedRecord record = new Record(MarketoConstants.getRESTOutputSchemaForSyncLead());
record.put(0, 12345);
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
doReturn(getSuccessSyncResult("created")).when(client).syncLead(any(TMarketoOutputProperties.class), any(IndexedRecord.class));
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
//
//
props.outputOperation.setValue(OutputOperation.syncMultipleLeads);
props.batchSize.setValue(2);
when(sink.getProperties()).thenReturn(props);
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
doReturn(getSuccessSyncResult("created")).when(client).syncMultipleLeads(any(TMarketoOutputProperties.class), any(List.class));
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
//
props.schemaInput.schema.setValue(getLeadDynamicSchema());
props.updateOutputSchemas();
when(sink.getProperties()).thenReturn(props);
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
//
props.connection.apiMode.setValue(APIMode.SOAP);
props.updateSchemaRelated();
when(sink.getProperties()).thenReturn(props);
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
}
use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoOutputWriterTest method testWriteCustomObject.
@Test
public void testWriteCustomObject() throws Exception {
props.outputOperation.setValue(OutputOperation.deleteCustomObjects);
props.updateSchemaRelated();
when(sink.getProperties()).thenReturn(props);
doReturn(getSuccessSyncResult("deleted")).when(client).deleteCustomObjects(any(TMarketoOutputProperties.class), any(List.class));
IndexedRecord record = new Record(MarketoConstants.getRESTOutputSchemaForSyncLead());
record.put(0, 12345);
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
//
props.outputOperation.setValue(OutputOperation.syncCustomObjects);
when(sink.getProperties()).thenReturn(props);
doReturn(getSuccessSyncResult("updated")).when(client).syncCustomObjects(any(TMarketoOutputProperties.class), any(List.class));
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
}
use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoOutputWriterTest method testRetryOperationFailNonRecoverableErrror.
@Test
public void testRetryOperationFailNonRecoverableErrror() throws Exception {
IndexedRecord record = new Record(MarketoConstants.getRESTOutputSchemaForSyncMultipleLeads());
record.put(0, 12345);
doReturn(false).when(client).isErrorRecoverable(any(List.class));
doReturn(getFailedSyncResult("REST", "902", "Invalid operation")).when(client).syncMultipleLeads(any(TMarketoOutputProperties.class), any(List.class));
props.dieOnError.setValue(false);
props.outputOperation.setValue(OutputOperation.syncMultipleLeads);
props.updateSchemaRelated();
when(sink.getProperties()).thenReturn(props);
writer.open("test");
writer.write(record);
MarketoResult result = (MarketoResult) writer.close();
assertEquals(1, result.apiCalls);
assertEquals(Collections.emptyList(), writer.getSuccessfulWrites());
List<IndexedRecord> rejects = writer.getRejectedWrites();
IndexedRecord reject = rejects.get(0);
assertNotNull(reject);
assertEquals("failed", reject.get(4));
assertTrue(String.valueOf(reject.get(5)).contains("902"));
}
use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoOutputWriterTest method testWriteDeleteLeads.
@Test
public void testWriteDeleteLeads() throws Exception {
writer.open("test");
writer.write(null);
// deleteLeads
doReturn(getFailedSyncResult(true)).when(client).deleteLeads(any(ArrayList.class));
IndexedRecord record = new Record(MarketoConstants.getDeleteLeadsSchema());
record.put(0, 12345);
try {
writer.write(record);
fail("Should not be here");
} catch (Exception e) {
}
props.dieOnError.setValue(false);
when(sink.getProperties()).thenReturn(props);
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
}
use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoSOAPClient method convertLeadChangeRecords.
private List<IndexedRecord> convertLeadChangeRecords(List<LeadChangeRecord> value, Schema schema, Map<String, String> mappings) {
List<IndexedRecord> results = new ArrayList<>();
for (LeadChangeRecord input : value) {
IndexedRecord record = new Record(schema);
for (Field f : schema.getFields()) {
// find matching marketo column name
String col = mappings.get(f.name());
if (col == null) {
LOG.warn("[convertLeadChangeRecords] Couldn't find mapping for column {}.", f.name());
continue;
}
switch(col) {
case FIELD_ID:
record.put(f.pos(), input.getId().getValue());
break;
case FIELD_MARKETO_GUID:
record.put(f.pos(), input.getMarketoGUID());
break;
case FIELD_ACTIVITY_DATE_TIME:
record.put(f.pos(), input.getActivityDateTime() != null ? input.getActivityDateTime().toGregorianCalendar().getTimeInMillis() : null);
break;
case FIELD_ACTIVITY_TYPE:
record.put(f.pos(), input.getActivityType());
break;
case FIELD_MKTG_ASSET_NAME:
record.put(f.pos(), input.getMktgAssetName() != null ? input.getMktgAssetName().getValue() : null);
break;
case FIELD_MKT_PERSON_ID:
record.put(f.pos(), input.getMktPersonId());
break;
case FIELD_CAMPAIGN:
record.put(f.pos(), input.getCampaign());
break;
default:
if (!input.getActivityAttributes().isNil()) {
for (Attribute attr : input.getActivityAttributes().getValue().getAttributes()) {
if (attr.getAttrName().equals(col)) {
record.put(f.pos(), attr.getAttrValue());
}
}
}
}
}
results.add(record);
}
return results;
}
Aggregations