Search in sources :

Example 61 with MarketoSource

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

the class MarketoRESTClientTestIT method testGetLeadSchema.

@Test
public void testGetLeadSchema() throws Exception {
    iprops.inputOperation.setValue(getLead);
    iprops.leadKeyTypeREST.setValue(email);
    iprops.afterInputOperation();
    String email = EMAIL_LEAD_MANY_INFOS;
    iprops.leadKeyValue.setValue(email);
    MarketoSource source = new MarketoSource();
    source.initialize(null, iprops);
    MarketoClientService client = source.getClientService(null);
    // 
    MarketoRecordResult result = client.getLead(iprops, null);
    LOG.debug("{}", result);
    List<IndexedRecord> records = result.getRecords();
    assertNotEquals(emptyList(), records);
    IndexedRecord record = records.get(0);
    assertNotNull(record);
    Schema s = record.getSchema();
    assertEquals(s, MarketoConstants.getRESTSchemaForGetLeadOrGetMultipleLeads());
    LOG.debug("record = {}.", record);
    assertEquals("int", s.getField("id").schema().getTypes().get(0).getName());
    assertEquals("string", s.getField("email").schema().getTypes().get(0).getName());
    assertEquals(email, record.get(1));
    assertEquals("string", s.getField("email").schema().getTypes().get(0).getName());
    assertEquals("string", s.getField("firstName").schema().getTypes().get(0).getName());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 62 with MarketoSource

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

the class MarketoRESTClientTestIT method testGetLeadActivity.

/*
     *
     * ************************ getLeadActivity ************************
     *
     */
@Test
public void testGetLeadActivity() throws Exception {
    iprops.inputOperation.setValue(getLeadActivity);
    iprops.afterInputOperation();
    iprops.batchSize.setValue(50);
    iprops.sinceDateTime.setValue(DATE_OLDEST_CREATE);
    iprops.beforeMappingInput();
    // 
    MarketoSource source = new MarketoSource();
    source.initialize(null, iprops);
    MarketoClientService client = source.getClientService(null);
    // 
    MarketoRecordResult result = client.getLeadActivity(iprops, null);
    LOG.debug("{}", result);
    assertTrue(result.isSuccess());
    assertTrue(result.getRecordCount() > 0);
}
Also used : MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 63 with MarketoSource

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

the class MarketoRESTClientTestIT method testGetMultipleLeadsListName.

@Test
public void testGetMultipleLeadsListName() throws Exception {
    iprops.inputOperation.setValue(getMultipleLeads);
    iprops.afterInputOperation();
    // we have at least 5 members with createDatasets.
    iprops.batchSize.setValue(4);
    iprops.leadSelectorREST.setValue(StaticListSelector);
    iprops.listParam.setValue(STATIC_LIST_NAME);
    iprops.listParamListName.setValue(UNDX_TEST_LIST_SMALL);
    MarketoSource source = new MarketoSource();
    source.initialize(null, iprops);
    MarketoClientService client = source.getClientService(null);
    // 
    MarketoRecordResult result = client.getMultipleLeads(iprops, null);
    LOG.debug("{}", result);
    assertTrue(result.isSuccess());
    assertTrue(result.getRecordCount() > 3);
    assertTrue(result.getRemainCount() > 0);
    assertNotNull(result.getStreamPosition());
}
Also used : MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 64 with MarketoSource

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

the class MarketoRESTClientTestIT method testAddToList.

/*
     * 
     * 
     * ListOperations
     *
     */
@Test
public void testAddToList() 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(10) });
    // 
    // first make sure to remove lead
    MarketoSyncResult result = client.removeFromList(parms);
    LOG.debug("result = {}.", result);
    List<SyncStatus> changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        LOG.debug("r = {}.", r);
    }
    // then add it
    result = client.addToList(parms);
    LOG.debug("result = {}.", result);
    changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertEquals("added", 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)

Example 65 with MarketoSource

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

the class MarketoRESTClientTestIT method testIsAccessTokenExpired.

@Test
public void testIsAccessTokenExpired() throws Exception {
    MarketoSource source = new MarketoSource();
    source.initialize(null, iprops);
    MarketoClientService client = source.getClientService(null);
    assertFalse(((MarketoRESTClient) client).isAccessTokenExpired(null));
    MarketoError err = new MarketoError("REST", "200", "dfddf");
    assertFalse(((MarketoRESTClient) client).isAccessTokenExpired(Arrays.asList(err)));
    err.setCode("602");
    assertTrue(((MarketoRESTClient) client).isAccessTokenExpired(Arrays.asList(err)));
}
Also used : MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) 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