Search in sources :

Example 36 with MarketoSource

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

the class MarketoRESTClientTestIT method testGetMultipleLeadsListIdFail.

@Test
public void testGetMultipleLeadsListIdFail() throws Exception {
    iprops.inputOperation.setValue(getMultipleLeads);
    iprops.afterInputOperation();
    iprops.batchSize.setValue(200);
    // 
    iprops.leadSelectorREST.setValue(StaticListSelector);
    iprops.listParam.setValue(STATIC_LIST_ID);
    iprops.listParamListName.setValue("-666");
    MarketoSource source = new MarketoSource();
    source.initialize(null, iprops);
    MarketoClientService client = source.getClientService(null);
    // 
    MarketoRecordResult result = client.getMultipleLeads(iprops, null);
    LOG.debug("{}", result);
    assertFalse(result.isSuccess());
    assertNotNull(result.getErrors());
    assertEquals(0, result.getRecordCount());
    assertEquals(0, result.getRemainCount());
    assertFalse(result.getRecordCount() > 0);
    assertEquals(emptyList(), result.getRecords());
}
Also used : MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 37 with MarketoSource

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

the class MarketoRESTClientTestIT method testRemoveFromList.

@Test
public void testRemoveFromList() 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(20) });
    // 
    // first subscribe lead
    MarketoSyncResult result = client.addToList(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 remove it
    result = client.removeFromList(parms);
    LOG.debug("result = {}.", result);
    changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertEquals("removed", 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 38 with MarketoSource

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

the class MarketoClientCustomObjectsTestIT method testDeleteCustomObjectsByIdField.

@Test
public void testDeleteCustomObjectsByIdField() throws Exception {
    MarketoSyncResult rs = createCustomObjectRecords("");
    assertTrue(rs.isSuccess());
    List<String> mktoIds = new ArrayList<>();
    for (SyncStatus sr : rs.getRecords()) {
        mktoIds.add(sr.getMarketoGUID());
    }
    // 
    oprops.customObjectName.setValue(TEST_CO_NAME_SMARTPHONE);
    Schema s = // 
    SchemaBuilder.record("sn").fields().name(FIELD_CO_MARKETO_GUID).type().stringType().noDefault().endRecord();
    List<IndexedRecord> records = new ArrayList<>();
    IndexedRecord r1;
    for (String m : mktoIds) {
        r1 = new Record(s);
        r1.put(0, m);
        records.add(r1);
    }
    MarketoSource source = new MarketoSource();
    oprops.customObjectDeleteBy.setValue(CustomObjectDeleteBy.idField);
    source.initialize(null, oprops);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    rs = client.deleteCustomObjects(oprops, records);
    assertTrue(rs.isSuccess());
    List<SyncStatus> changes = rs.getRecords();
    assertEquals(TEST_SMARTPHONE_MODELS.length, changes.size());
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getSeq());
        assertEquals(STATUS_DELETED, r.getStatus());
        LOG.debug("r = {}.", r);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 39 with MarketoSource

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

the class MarketoClientCustomObjectsTestIT method testGetCustomObjectsAllRecords.

@Test
public void testGetCustomObjectsAllRecords() throws Exception {
    MarketoSource source = new MarketoSource();
    source.initialize(null, irProps);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    irProps.customObjectName.setValue(TEST_CO_NAME_SMARTPHONE);
    irProps.batchSize.setValue(500);
    irProps.schemaInput.schema.setValue(MarketoConstants.getCustomObjectRecordSchema());
    MarketoRecordResult result = client.getCustomObjects(irProps, null);
    assertFalse(result.isSuccess());
    assertEquals(0, result.getRecordCount());
    assertNotNull(result.getErrors());
    Object err = result.getErrors().get(0);
    assertTrue(err instanceof MarketoError);
    assertEquals("REST", ((MarketoError) err).getApiMode());
    assertEquals("1003", ((MarketoError) err).getCode());
    assertEquals("filterType not specified", ((MarketoError) err).getMessage());
}
Also used : MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) Test(org.junit.Test)

Example 40 with MarketoSource

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

the class MarketoClientCustomObjectsTestIT method testGetCustomObjects.

@Test
public void testGetCustomObjects() throws Exception {
    MarketoSyncResult rs = createCustomObjectRecords("");
    MarketoSource source = new MarketoSource();
    source.initialize(null, irProps);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    irProps.customObjectName.setValue(TEST_CO_NAME_SMARTPHONE);
    irProps.customObjectFilterType.setValue(FIELD_CO_SMARTPHONE_MODEL);
    irProps.customObjectFilterValues.setValue(MarketoRESTClient.csvString(TEST_SMARTPHONE_MODELS));
    irProps.batchSize.setValue(500);
    irProps.schemaInput.schema.setValue(MarketoConstants.getCustomObjectRecordSchema());
    MarketoRecordResult result = client.getCustomObjects(irProps, null);
    assertNotNull(result.getRecords());
    assertEquals(TEST_SMARTPHONE_MODELS.length, result.getRecords().size());
    LOG.debug("result = {}.", result.getRecords().get(0));
    checkCustomObjectRecord(result.getRecords().get(0));
}
Also used : MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) 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