Search in sources :

Example 1 with MarketoRecordResult

use of org.talend.components.marketo.runtime.client.type.MarketoRecordResult in project components by Talend.

the class MarketoRuntimeTestBase method getLeadRecordResult.

public static MarketoRecordResult getLeadRecordResult(boolean withRemainCount) {
    MarketoRecordResult mkto = new MarketoRecordResult();
    mkto.setSuccess(true);
    IndexedRecord record1 = new GenericData.Record(MarketoConstants.getRESTSchemaForGetLeadOrGetMultipleLeads());
    IndexedRecord record2 = new GenericData.Record(MarketoConstants.getRESTSchemaForGetLeadOrGetMultipleLeads());
    // id
    record1.put(0, 12345);
    // email
    record1.put(1, "eg@test.com");
    record1.put(2, "Evanence");
    record1.put(3, "valerian");
    record1.put(4, new Date());
    record1.put(5, new Date());
    // id
    record2.put(0, 12346);
    // email
    record2.put(1, "eg2@test.com");
    record2.put(2, "Evanence2");
    record2.put(3, "valerian2");
    record2.put(4, new Date());
    record2.put(5, new Date());
    if (withRemainCount) {
        mkto.setRemainCount(2);
        mkto.setStreamPosition("streamposition");
    } else {
        mkto.setRemainCount(0);
    }
    mkto.setRecordCount(2);
    mkto.setRecords(Arrays.asList(record1, record2));
    return mkto;
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) Date(java.util.Date) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult)

Example 2 with MarketoRecordResult

use of org.talend.components.marketo.runtime.client.type.MarketoRecordResult in project components by Talend.

the class MarketoSourceOrSinkTest method getDescribeCO.

public MarketoRecordResult getDescribeCO() {
    MarketoRecordResult mkto = new MarketoRecordResult();
    mkto.setSuccess(true);
    IndexedRecord record = new Record(MarketoConstants.getCustomObjectDescribeSchema());
    record.put(0, "car_c");
    record.put(1, "car_c");
    // dedupe
    record.put(6, "[\"model\"]");
    record.put(8, "[{\"displayName\":\"CreatedAt\",\"dataType\":\"datetime\",\"name\":\"createdAt\"," + // fields
    "\"updateable\":false},{\"displayName\":\"MarketoGUID\",\"dataType\":\"string\",\"length\":36,\"name\":\"marketoGUID\",\"updateable\":false}]");
    mkto.setRecords(Arrays.asList(record));
    return mkto;
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult)

Example 3 with MarketoRecordResult

use of org.talend.components.marketo.runtime.client.type.MarketoRecordResult in project components by Talend.

the class MarketoCustomObjectClientTest method testGetCustomObjects.

@Test
public void testGetCustomObjects() throws Exception {
    iprops.customObjectAction.setValue(CustomObjectAction.get);
    doThrow(new MarketoException("REST", "error")).when(client).executeGetRequest(any(Schema.class));
    mktoRR = client.getCustomObjects(iprops, null);
    assertFalse(mktoRR.isSuccess());
    assertFalse(mktoRR.getErrorsString().isEmpty());
    // 
    doReturn(new MarketoRecordResult()).when(client).executeGetRequest(any(Schema.class));
    mktoRR = client.getCustomObjects(iprops, null);
    assertFalse(mktoRR.isSuccess());
    assertTrue(mktoRR.getErrorsString().isEmpty());
    // 
    MarketoRecordResult mrr = new MarketoRecordResult();
    mrr.setSuccess(true);
    mrr.setRemainCount(0);
    mrr.setRecordCount(1);
    List<IndexedRecord> records = new ArrayList<>();
    IndexedRecord record = new Record(MarketoConstants.getCustomObjectRecordSchema());
    record.put(0, "mkto-123456");
    record.put(1, 0);
    record.put(2, new Date());
    record.put(3, new Date());
    records.add(record);
    mrr.setRecords(records);
    doReturn(mrr).when(client).executeGetRequest(any(Schema.class));
    mktoRR = client.getCustomObjects(iprops, null);
    assertTrue(mktoRR.isSuccess());
    assertTrue(mktoRR.getErrorsString().isEmpty());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) Date(java.util.Date) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 4 with MarketoRecordResult

use of org.talend.components.marketo.runtime.client.type.MarketoRecordResult in project components by Talend.

the class MarketoCustomObjectClientTest method testDescribeCustomObject.

@Test
public void testDescribeCustomObject() throws Exception {
    iprops.customObjectAction.setValue(CustomObjectAction.describe);
    // 
    doThrow(new MarketoException("REST", "error")).when(client).executeGetRequest(any(Schema.class));
    mktoRR = client.describeCustomObject(iprops);
    assertFalse(mktoRR.isSuccess());
    assertFalse(mktoRR.getErrorsString().isEmpty());
    // 
    doReturn(new MarketoRecordResult()).when(client).executeGetRequest(any(Schema.class));
    mktoRR = client.describeCustomObject(iprops);
    assertFalse(mktoRR.isSuccess());
    assertTrue(mktoRR.getErrorsString().isEmpty());
    // 
    doReturn(getCustomObjectResult()).when(client).executeGetRequest(any(Schema.class));
    mktoRR = client.describeCustomObject(iprops);
    assertTrue(mktoRR.isSuccess());
    assertTrue(mktoRR.getErrorsString().isEmpty());
}
Also used : MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) Schema(org.apache.avro.Schema) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 5 with MarketoRecordResult

use of org.talend.components.marketo.runtime.client.type.MarketoRecordResult in project components by Talend.

the class MarketoCustomObjectClientTest method testListCustomObjects.

@Test
public void testListCustomObjects() throws Exception {
    iprops.customObjectAction.setValue(CustomObjectAction.list);
    doThrow(new MarketoException("REST", "error")).when(client).executeGetRequest(any(Schema.class));
    mktoRR = client.listCustomObjects(iprops);
    assertFalse(mktoRR.isSuccess());
    assertFalse(mktoRR.getErrorsString().isEmpty());
    // 
    doReturn(new MarketoRecordResult()).when(client).executeGetRequest(any(Schema.class));
    mktoRR = client.listCustomObjects(iprops);
    assertFalse(mktoRR.isSuccess());
    assertTrue(mktoRR.getErrorsString().isEmpty());
    // 
    doReturn(getCustomObjectResult()).when(client).executeGetRequest(any(Schema.class));
    mktoRR = client.listCustomObjects(iprops);
    assertTrue(mktoRR.isSuccess());
    assertTrue(mktoRR.getErrorsString().isEmpty());
}
Also used : MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) Schema(org.apache.avro.Schema) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Aggregations

MarketoRecordResult (org.talend.components.marketo.runtime.client.type.MarketoRecordResult)83 Test (org.junit.Test)61 MarketoSource (org.talend.components.marketo.runtime.MarketoSource)49 IndexedRecord (org.apache.avro.generic.IndexedRecord)47 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)16 Schema (org.apache.avro.Schema)15 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)14 ArrayList (java.util.ArrayList)7 TMarketoBulkExecProperties (org.talend.components.marketo.tmarketobulkexec.TMarketoBulkExecProperties)6 IOException (java.io.IOException)5 Date (java.util.Date)5 Gson (com.google.gson.Gson)4 JsonObject (com.google.gson.JsonObject)4 ArrayOfString (com.marketo.mktows.ArrayOfString)4 MalformedURLException (java.net.MalformedURLException)4 InvalidKeyException (java.security.InvalidKeyException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 ParseException (java.text.ParseException)4 List (java.util.List)4 JAXBException (javax.xml.bind.JAXBException)4