Search in sources :

Example 1 with DescribeFieldsResult

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

the class MarketoLeadClientTest method testGetAllLeadFields.

@Test
public void testGetAllLeadFields() throws Exception {
    doThrow(new MarketoException("REST", "error")).when(client).executeGetRequest(DescribeFieldsResult.class);
    List<Field> result = client.getAllLeadFields();
    assertTrue(result.isEmpty());
    // 
    doReturn(new DescribeFieldsResult()).when(client).executeGetRequest(DescribeFieldsResult.class);
    result = client.getAllLeadFields();
    assertTrue(result.isEmpty());
    // 
    DescribeFieldsResult dfr = new DescribeFieldsResult();
    dfr.setSuccess(true);
    List<FieldDescription> fields = new ArrayList<>();
    FieldDescription fd = new FieldDescription();
    fd.setName("test");
    fd.setDataType("string");
    fd.setDisplayName("test");
    fd.setId(124566);
    fd.setLength(10);
    fd.setUpdateable(true);
    fields.add(fd);
    dfr.setResult(fields);
    doReturn(dfr).when(client).executeGetRequest(DescribeFieldsResult.class);
    result = client.getAllLeadFields();
    assertFalse(result.isEmpty());
}
Also used : Field(org.apache.avro.Schema.Field) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) ArrayList(java.util.ArrayList) DescribeFieldsResult(org.talend.components.marketo.runtime.client.rest.response.DescribeFieldsResult) FieldDescription(org.talend.components.marketo.runtime.client.rest.type.FieldDescription) Test(org.junit.Test)

Example 2 with DescribeFieldsResult

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

the class MarketoLeadClient method getAllLeadFields.

/*
     *
     * management func
     *
     */
public List<Schema.Field> getAllLeadFields() {
    current_uri = // 
    new StringBuilder(basicPath).append(// 
    "/v1/leads").append(// 
    API_PATH_URI_DESCRIBE).append(fmtParams(FIELD_ACCESS_TOKEN, accessToken, true));
    List<Schema.Field> fields = new ArrayList<>();
    try {
        LOG.debug("describeLead {}.", current_uri);
        DescribeFieldsResult rs = (DescribeFieldsResult) executeGetRequest(DescribeFieldsResult.class);
        if (!rs.isSuccess()) {
            return fields;
        }
        // 
        for (FieldDescription d : rs.getResult()) {
            fields.add(d.toAvroField());
        }
    } catch (MarketoException e) {
        LOG.error("describeLeadFields error: {}.", e.toString());
    }
    return fields;
}
Also used : Field(org.apache.avro.Schema.Field) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) ArrayList(java.util.ArrayList) DescribeFieldsResult(org.talend.components.marketo.runtime.client.rest.response.DescribeFieldsResult) FieldDescription(org.talend.components.marketo.runtime.client.rest.type.FieldDescription)

Aggregations

ArrayList (java.util.ArrayList)2 Field (org.apache.avro.Schema.Field)2 DescribeFieldsResult (org.talend.components.marketo.runtime.client.rest.response.DescribeFieldsResult)2 FieldDescription (org.talend.components.marketo.runtime.client.rest.type.FieldDescription)2 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)2 Test (org.junit.Test)1