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());
}
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;
}
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());
}
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());
}
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;
}
Aggregations