use of org.talend.components.marketo.runtime.client.rest.response.LeadResult in project components by Talend.
the class MarketoLeadClientTest method getLeadResult.
public LeadResult getLeadResult() {
LeadResult lr = new LeadResult();
lr.setSuccess(true);
List<Map<String, String>> kv = new ArrayList<>();
Map<String, String> lv = new HashMap<>();
lv.put("id", "12345");
lv.put("firstName", "testFN");
lv.put("lastName", "testLN");
lv.put("attrName", "attrValue");
kv.add(lv);
lr.setResult(kv);
return lr;
}
use of org.talend.components.marketo.runtime.client.rest.response.LeadResult in project components by Talend.
the class MarketoLeadClientTest method testGetLead.
@Test
public void testGetLead() throws Exception {
iprops.inputOperation.setValue(InputOperation.getLead);
iprops.leadKeyTypeREST.setValue(LeadKeyTypeREST.id);
iprops.leadKeyValue.setValue("12345");
iprops.afterInputOperation();
Field attr = new Field("attrName", AvroUtils._string(), "", null);
iprops.schemaInput.schema.setValue(MarketoUtils.newSchema(iprops.schemaInput.schema.getValue(), "test", Collections.singletonList(attr)));
iprops.beforeMappingInput();
//
doThrow(new MarketoException("REST", "error")).when(client).executeFakeGetRequestForLead(anyString());
mktoRR = client.getLead(iprops, null);
assertFalse(mktoRR.isSuccess());
assertFalse(mktoRR.getErrorsString().isEmpty());
//
doReturn(new LeadResult()).when(client).executeFakeGetRequestForLead(anyString());
mktoRR = client.getLead(iprops, null);
assertFalse(mktoRR.isSuccess());
//
doReturn(getLeadResult()).when(client).executeFakeGetRequestForLead(anyString());
mktoRR = client.getLead(iprops, null);
assertTrue(mktoRR.isSuccess());
List<IndexedRecord> records = mktoRR.getRecords();
assertNotNull(records);
IndexedRecord record = records.get(0);
assertNotNull(record);
Schema refSchema = iprops.schemaInput.schema.getValue();
assertEquals(refSchema, record.getSchema());
assertEquals(12345, record.get(refSchema.getField("id").pos()));
assertEquals("testFN", record.get(refSchema.getField("firstName").pos()));
assertEquals("testLN", record.get(refSchema.getField("lastName").pos()));
assertEquals("attrValue", record.get(refSchema.getField("attrName").pos()));
}
use of org.talend.components.marketo.runtime.client.rest.response.LeadResult in project components by Talend.
the class MarketoBaseRESTClient method getPageToken.
public String getPageToken(String sinceDatetime) throws MarketoException {
current_uri = //
new StringBuilder(basicPath).append(//
API_PATH_PAGINGTOKEN).append(//
fmtParams(FIELD_ACCESS_TOKEN, accessToken, true)).append(fmtParams(FIELD_SINCE_DATETIME, sinceDatetime));
LeadResult getResponse = (LeadResult) executeGetRequest(LeadResult.class);
if (getResponse != null) {
return getResponse.getNextPageToken();
}
return null;
}
use of org.talend.components.marketo.runtime.client.rest.response.LeadResult in project components by Talend.
the class MarketoLeadClient method getRecordResultForLead.
public MarketoRecordResult getRecordResultForLead(InputOperation operation, String requestParams, int limit, Schema schema, Map<String, String> mappings) {
MarketoRecordResult mkto = new MarketoRecordResult();
try {
PaginateResult result = null;
switch(operation) {
case getLead:
case getMultipleLeads:
result = executeFakeGetRequestForLead(requestParams);
break;
case getLeadActivity:
result = (LeadActivitiesResult) executeGetRequest(LeadActivitiesResult.class);
break;
case getLeadChanges:
result = (LeadChangesResult) executeGetRequest(LeadChangesResult.class);
break;
default:
throw new IllegalArgumentException("Invalid operation for getRecordResultForLead: " + operation);
}
mkto.setSuccess(result.isSuccess());
if (mkto.isSuccess()) {
mkto.setRecordCount(result.getResult().isEmpty() ? 0 : result.getResult().size());
mkto.setRemainCount((result.getNextPageToken() != null) ? limit : 0);
mkto.setStreamPosition(result.getNextPageToken());
if (mkto.getRecordCount() > 0) {
switch(operation) {
case getLead:
case getMultipleLeads:
mkto.setRecords(convertLeadRecords(((LeadResult) result).getResult(), schema, mappings));
break;
case getLeadActivity:
mkto.setRecords(convertLeadActivityRecords(((LeadActivitiesResult) result).getResult(), schema, mappings));
break;
case getLeadChanges:
mkto.setRecords(convertLeadChangesRecords(((LeadChangesResult) result).getResult(), schema, mappings));
break;
default:
throw new IllegalArgumentException("Invalid operation for getRecordResultForLead: " + operation);
}
}
} else {
mkto.setErrors(result.getErrors());
}
} catch (MarketoException e) {
LOG.error("Error {}.", e.toString());
mkto.setSuccess(false);
mkto.setErrors(Collections.singletonList(e.toMarketoError()));
}
return mkto;
}
use of org.talend.components.marketo.runtime.client.rest.response.LeadResult in project components by Talend.
the class MarketoLeadClientTest method testGetMultipleLeads.
@Test
public void testGetMultipleLeads() throws Exception {
iprops.inputOperation.setValue(InputOperation.getMultipleLeads);
iprops.leadKeyTypeREST.setValue(LeadKeyTypeREST.id);
iprops.leadKeyValues.setValue("12345");
iprops.afterInputOperation();
//
doThrow(new MarketoException("REST", "error")).when(client).executeFakeGetRequestForLead(anyString());
mktoRR = client.getMultipleLeads(iprops, null);
assertFalse(mktoRR.isSuccess());
assertFalse(mktoRR.getErrorsString().isEmpty());
//
doReturn(new LeadResult()).when(client).executeFakeGetRequestForLead(anyString());
mktoRR = client.getMultipleLeads(iprops, null);
assertFalse(mktoRR.isSuccess());
//
doReturn(getLeadResult()).when(client).executeFakeGetRequestForLead(anyString());
mktoRR = client.getMultipleLeads(iprops, null);
assertTrue(mktoRR.isSuccess());
//
iprops.leadSelectorREST.setValue(LeadSelector.StaticListSelector);
iprops.listParam.setValue(ListParam.STATIC_LIST_ID);
iprops.listParamListId.setValue(666123);
mktoRR = client.getMultipleLeads(iprops, null);
assertTrue(mktoRR.isSuccess());
}
Aggregations