Search in sources :

Example 26 with MarketoSource

use of org.talend.components.marketo.runtime.MarketoSource in project components by Talend.

the class MarketoRESTClientTestIT method testGetLeadDynamic.

/*
     * 
     * Dynamic fields
     * 
     */
@Test
public void testGetLeadDynamic() throws Exception {
    iprops.inputOperation.setValue(getLead);
    iprops.leadKeyTypeREST.setValue(LeadKeyTypeREST.id);
    iprops.batchSize.setValue(1);
    iprops.afterInputOperation();
    iprops.leadKeyValue.setValue(createdLeads.get(0).toString());
    iprops.schemaInput.schema.setValue(SchemaBuilder.builder().record("test").prop(SchemaConstants.INCLUDE_ALL_FIELDS, "true").fields().endRecord());
    MarketoSource source = new MarketoSource();
    source.initialize(null, iprops);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    Schema design = this.iprops.schemaInput.schema.getValue();
    // preserve mappings to re-apply them after
    Map<String, String> mappings = iprops.mappingInput.getNameMappingsForMarketo();
    Schema runtimeSchema = source.getDynamicSchema("", design);
    List<String> columnNames = new ArrayList<>();
    List<String> mktoNames = new ArrayList<>();
    for (Field f : runtimeSchema.getFields()) {
        columnNames.add(f.name());
        if (mappings.get(f.name()) != null) {
            mktoNames.add(mappings.get(f.name()));
        } else {
            mktoNames.add("");
        }
    }
    iprops.mappingInput.columnName.setValue(columnNames);
    iprops.mappingInput.marketoColumnName.setValue(mktoNames);
    iprops.schemaInput.schema.setValue(runtimeSchema);
    MarketoRecordResult result = client.getLead(iprops, null);
    LOG.debug("result = {}.", result);
    IndexedRecord r = result.getRecords().get(0);
    assertNotNull(r);
    LOG.debug("r = {}.", r);
    assertEquals("Retail-Dev", r.get(runtimeSchema.getField("company").pos()));
    assertEquals(COMMON_LINKEDIN_ID.toString(), r.get(runtimeSchema.getField("linkedInId").pos()));
    assertEquals(COMMON_SFDC_ACCOUNT_ID, r.get(runtimeSchema.getField("sfdcAccountId").pos()));
}
Also used : Field(org.apache.avro.Schema.Field) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 27 with MarketoSource

use of org.talend.components.marketo.runtime.MarketoSource in project components by Talend.

the class MarketoRESTClientTestIT method testGetLead.

/*
     *
     * ************************ getLead ************************
     *
     */
@Test
public void testGetLead() throws Exception {
    iprops.inputOperation.setValue(getLead);
    iprops.leadKeyTypeREST.setValue(email);
    iprops.afterInputOperation();
    // 
    String email = EMAIL_UNDX00;
    iprops.leadKeyValue.setValue(email);
    MarketoSource source = new MarketoSource();
    source.initialize(null, iprops);
    MarketoClientService client = source.getClientService(null);
    assertTrue(((MarketoRESTClient) client).isAvailable());
    // 
    MarketoRecordResult result = client.getLead(iprops, null);
    LOG.debug("{}", result);
    List<IndexedRecord> records = result.getRecords();
    assertNotEquals(emptyList(), records);
    IndexedRecord record = records.get(0);
    assertNotNull(record);
    assertNotNull(record.get(0));
    assertEquals(email, record.get(1));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 28 with MarketoSource

use of org.talend.components.marketo.runtime.MarketoSource in project components by Talend.

the class MarketoRESTClientTestIT method testGetMultipleLeadsLeadKey.

/*
     *
     * ************************ getMultipleLeads ************************
     *
     */
@Test
public void testGetMultipleLeadsLeadKey() throws Exception {
    iprops.inputOperation.setValue(getMultipleLeads);
    iprops.afterInputOperation();
    iprops.batchSize.setValue(100);
    iprops.leadKeyTypeREST.setValue(email);
    iprops.leadKeyValues.setValue("undx00@undx.net,undx10@undx.net,undx20@undx.net,undx30@undx.net");
    MarketoSource source = new MarketoSource();
    source.initialize(null, iprops);
    MarketoClientService client = source.getClientService(null);
    // 
    MarketoRecordResult result = client.getMultipleLeads(iprops, null);
    LOG.debug("{}", result);
    List<IndexedRecord> records = result.getRecords();
    assertTrue(records.size() >= 4);
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 29 with MarketoSource

use of org.talend.components.marketo.runtime.MarketoSource in project components by Talend.

the class MarketoRESTClientTestIT method testBadURIConnectionString.

@Test(expected = IOException.class)
public void testBadURIConnectionString() throws Exception {
    iprops.connection.endpoint.setValue("htps:marketo.comrestv1");
    MarketoSource source = new MarketoSource();
    source.initialize(null, iprops);
    MarketoClientService client = source.getClientService(null);
    fail("Shouldn't be here");
}
Also used : MarketoSource(org.talend.components.marketo.runtime.MarketoSource) Test(org.junit.Test)

Example 30 with MarketoSource

use of org.talend.components.marketo.runtime.MarketoSource in project components by Talend.

the class MarketoRESTClientTestIT method testIsMemberOfList.

@Test
public void testIsMemberOfList() throws Exception {
    MarketoSource source = new MarketoSource();
    source.initialize(null, listProperties);
    MarketoClientService client = source.getClientService(null);
    // 
    ListOperationParameters parms = new ListOperationParameters();
    parms.setApiMode(APIMode.REST.name());
    parms.setListId(UNDX_TEST_LIST_SMALL_ID);
    parms.setLeadIds(new Integer[] { createdLeads.get(0), createdLeads.get(1), createdLeads.get(2) });
    // 
    MarketoSyncResult result = client.isMemberOfList(parms);
    LOG.debug("result = {}.", result);
    List<SyncStatus> changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertEquals("memberof", r.getStatus());
        LOG.debug("r = {}.", r);
    }
}
Also used : ListOperationParameters(org.talend.components.marketo.runtime.client.type.ListOperationParameters) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Aggregations

MarketoSource (org.talend.components.marketo.runtime.MarketoSource)73 Test (org.junit.Test)72 MarketoRecordResult (org.talend.components.marketo.runtime.client.type.MarketoRecordResult)49 IndexedRecord (org.apache.avro.generic.IndexedRecord)37 MarketoSyncResult (org.talend.components.marketo.runtime.client.type.MarketoSyncResult)17 Schema (org.apache.avro.Schema)14 SyncStatus (org.talend.components.marketo.runtime.client.rest.type.SyncStatus)13 ArrayList (java.util.ArrayList)9 ListOperationParameters (org.talend.components.marketo.runtime.client.type.ListOperationParameters)7 Field (org.apache.avro.Schema.Field)5 Record (org.apache.avro.generic.GenericData.Record)4 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)3 LeadRecord (com.marketo.mktows.LeadRecord)2 Path (java.nio.file.Path)2 GenericData (org.apache.avro.generic.GenericData)1