Search in sources :

Example 1 with LeadResult

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;
}
Also used : HashMap(java.util.HashMap) LeadResult(org.talend.components.marketo.runtime.client.rest.response.LeadResult) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with LeadResult

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()));
}
Also used : Field(org.apache.avro.Schema.Field) IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) Schema(org.apache.avro.Schema) LeadResult(org.talend.components.marketo.runtime.client.rest.response.LeadResult) Test(org.junit.Test)

Example 3 with LeadResult

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;
}
Also used : LeadResult(org.talend.components.marketo.runtime.client.rest.response.LeadResult)

Example 4 with LeadResult

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;
}
Also used : LeadActivitiesResult(org.talend.components.marketo.runtime.client.rest.response.LeadActivitiesResult) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) LeadResult(org.talend.components.marketo.runtime.client.rest.response.LeadResult) PaginateResult(org.talend.components.marketo.runtime.client.rest.response.PaginateResult) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) LeadChangesResult(org.talend.components.marketo.runtime.client.rest.response.LeadChangesResult)

Example 5 with LeadResult

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());
}
Also used : MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) LeadResult(org.talend.components.marketo.runtime.client.rest.response.LeadResult) Test(org.junit.Test)

Aggregations

LeadResult (org.talend.components.marketo.runtime.client.rest.response.LeadResult)5 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Schema (org.apache.avro.Schema)1 Field (org.apache.avro.Schema.Field)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 Matchers.anyString (org.mockito.Matchers.anyString)1 LeadActivitiesResult (org.talend.components.marketo.runtime.client.rest.response.LeadActivitiesResult)1 LeadChangesResult (org.talend.components.marketo.runtime.client.rest.response.LeadChangesResult)1 PaginateResult (org.talend.components.marketo.runtime.client.rest.response.PaginateResult)1 MarketoRecordResult (org.talend.components.marketo.runtime.client.type.MarketoRecordResult)1