Search in sources :

Example 1 with SyncResult

use of org.talend.components.marketo.runtime.client.rest.response.SyncResult in project components by Talend.

the class MarketoCustomObjectClientTest method testSyncCustomObjects.

@Test
public void testSyncCustomObjects() throws Exception {
    oprops.customObjectSyncAction.setValue(CustomObjectSyncAction.createOrUpdate);
    oprops.customObjectDedupeBy.setValue("marketoGUID");
    // 
    doThrow(new MarketoException("REST", "error")).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    List<IndexedRecord> records = new ArrayList<>();
    IndexedRecord record = new Record(MarketoConstants.getCustomObjectRecordSchema());
    record.put(0, "mkto-123456");
    records.add(record);
    mktoSR = client.syncCustomObjects(oprops, records);
    assertFalse(mktoSR.isSuccess());
    assertFalse(mktoSR.getErrorsString().isEmpty());
    // 
    doReturn(new SyncResult()).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.syncCustomObjects(oprops, records);
    assertFalse(mktoSR.isSuccess());
    // 
    doReturn(getListOperationResult(true, "deleted")).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.syncCustomObjects(oprops, records);
    assertTrue(mktoSR.isSuccess());
    assertTrue(mktoSR.getErrorsString().isEmpty());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) Test(org.junit.Test)

Example 2 with SyncResult

use of org.talend.components.marketo.runtime.client.rest.response.SyncResult in project components by Talend.

the class MarketoBaseRESTClient method getSyncResultFromRequest.

/**
 * Execute POST or GET request and feed the MarketoSyncResult to return
 *
 * @param paramPOSTJson
 * @return
 */
public MarketoSyncResult getSyncResultFromRequest(boolean sendPOST, JsonObject paramPOSTJson) {
    MarketoSyncResult mkto = new MarketoSyncResult();
    try {
        SyncResult rs;
        if (sendPOST) {
            rs = (SyncResult) executePostRequest(SyncResult.class, paramPOSTJson);
        } else {
            rs = (SyncResult) executeGetRequest(SyncResult.class);
        }
        // 
        mkto.setRequestId(REST + "::" + rs.getRequestId());
        mkto.setStreamPosition(rs.getNextPageToken());
        mkto.setSuccess(rs.isSuccess());
        if (mkto.isSuccess()) {
            mkto.setRecordCount(rs.getResult().size());
            mkto.setRemainCount(0);
            mkto.setRecords(rs.getResult());
            if (rs.isMoreResult()) {
                // cannot know how many remain...
                mkto.setRemainCount(mkto.getRecordCount());
                mkto.setStreamPosition(rs.getNextPageToken());
            }
        // 
        } else {
            mkto.setRecordCount(0);
            mkto.setErrors(rs.getErrors());
        }
        LOG.debug("rs = {}.", rs);
    } catch (MarketoException e) {
        mkto.setSuccess(false);
        mkto.setErrors(Collections.singletonList(e.toMarketoError()));
    }
    return mkto;
}
Also used : MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult)

Example 3 with SyncResult

use of org.talend.components.marketo.runtime.client.rest.response.SyncResult in project components by Talend.

the class MarketoLeadClientTest method testSyncLead.

@Test
public void testSyncLead() throws Exception {
    oprops.afterOutputOperation();
    oprops.beforeMappingInput();
    IndexedRecord record = new Record(MarketoConstants.getRESTOutputSchemaForSyncLead());
    record.put(0, 12345);
    record.put(1, "t@t.com");
    // 
    doThrow(new MarketoException("REST", "error")).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.syncLead(oprops, record);
    assertFalse(mktoSR.isSuccess());
    assertFalse(mktoSR.getErrorsString().isEmpty());
    // 
    doReturn(new SyncResult()).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.syncLead(oprops, record);
    assertFalse(mktoSR.isSuccess());
    // 
    SyncResult sr = new SyncResult();
    sr.setSuccess(true);
    List<SyncStatus> ssr = new ArrayList<>();
    SyncStatus ss = new SyncStatus();
    ss.setStatus("created");
    ss.setMarketoGUID("mkto-123456");
    ss.setSeq(0);
    ss.setId(12345);
    ss.setErrorMessage("");
    ssr.add(ss);
    sr.setResult(ssr);
    doReturn(sr).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.syncLead(oprops, record);
    assertTrue(mktoSR.isSuccess());
    assertTrue(mktoSR.getErrorsString().isEmpty());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Record(org.apache.avro.generic.GenericData.Record) ListRecord(org.talend.components.marketo.runtime.client.rest.type.ListRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) LeadChangeRecord(org.talend.components.marketo.runtime.client.rest.type.LeadChangeRecord) LeadActivityRecord(org.talend.components.marketo.runtime.client.rest.type.LeadActivityRecord) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 4 with SyncResult

use of org.talend.components.marketo.runtime.client.rest.response.SyncResult in project components by Talend.

the class MarketoLeadClientTest method testDeleteLeads.

@Test
public void testDeleteLeads() throws Exception {
    IndexedRecord record = new Record(MarketoConstants.getDeleteLeadsSchema());
    record.put(0, 12345);
    // 
    doThrow(new MarketoException("REST", "error")).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.deleteLeads(new Integer[] { 12345 });
    mktoSR = client.deleteLeads(Arrays.asList(record));
    assertFalse(mktoSR.isSuccess());
    assertFalse(mktoSR.getErrorsString().isEmpty());
    // 
    doReturn(new SyncResult()).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.deleteLeads(new Integer[] { 12345 });
    assertFalse(mktoSR.isSuccess());
    // 
    SyncResult sr = new SyncResult();
    sr.setSuccess(true);
    List<SyncStatus> ssr = new ArrayList<>();
    SyncStatus ss = new SyncStatus();
    ss.setStatus("created");
    ss.setMarketoGUID("mkto-123456");
    ss.setSeq(0);
    ss.setId(12345);
    ss.setErrorMessage("");
    ssr.add(ss);
    sr.setResult(ssr);
    doReturn(sr).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.deleteLeads(new Integer[] { 12345 });
    assertTrue(mktoSR.isSuccess());
    assertTrue(mktoSR.getErrorsString().isEmpty());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Record(org.apache.avro.generic.GenericData.Record) ListRecord(org.talend.components.marketo.runtime.client.rest.type.ListRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) LeadChangeRecord(org.talend.components.marketo.runtime.client.rest.type.LeadChangeRecord) LeadActivityRecord(org.talend.components.marketo.runtime.client.rest.type.LeadActivityRecord) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 5 with SyncResult

use of org.talend.components.marketo.runtime.client.rest.response.SyncResult in project components by Talend.

the class MarketoLeadClientTest method getListOperationResult.

public SyncResult getListOperationResult(boolean isSuccess, String status) {
    SyncResult result = new SyncResult();
    List<SyncStatus> records = new ArrayList<>();
    if (isSuccess) {
        result.setSuccess(true);
        SyncStatus ss = new SyncStatus();
        ss.setSeq(0);
        ss.setMarketoGUID("mkto-123456");
        ss.setStatus(status);
        ss.setErrorMessage("");
        records.add(ss);
        result.setResult(records);
    } else {
        result.setSuccess(false);
        result.setErrors(Arrays.asList(new MarketoError("REST", "errorlist")));
    }
    return result;
}
Also used : SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError)

Aggregations

SyncResult (org.talend.components.marketo.runtime.client.rest.response.SyncResult)6 ArrayList (java.util.ArrayList)5 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)5 JsonObject (com.google.gson.JsonObject)4 Record (org.apache.avro.generic.GenericData.Record)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)4 Test (org.junit.Test)4 MarketoSyncResult (org.talend.components.marketo.runtime.client.type.MarketoSyncResult)4 SyncStatus (org.talend.components.marketo.runtime.client.rest.type.SyncStatus)3 LeadActivityRecord (org.talend.components.marketo.runtime.client.rest.type.LeadActivityRecord)2 LeadChangeRecord (org.talend.components.marketo.runtime.client.rest.type.LeadChangeRecord)2 ListRecord (org.talend.components.marketo.runtime.client.rest.type.ListRecord)2 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)1