Search in sources :

Example 1 with MarketoException

use of org.talend.components.marketo.runtime.client.type.MarketoException 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 MarketoException

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

the class MarketoLeadClientTest method testListOperations.

@Test
public void testListOperations() throws Exception {
    lprops.afterListOperation();
    ListOperationParameters parms = new ListOperationParameters();
    parms.setApiMode(REST.name());
    parms.setListId(666123);
    parms.setLeadIds(new Integer[] { 12345 });
    // 
    doThrow(new MarketoException("REST", "error")).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.addToList(parms);
    assertFalse(mktoSR.isSuccess());
    assertFalse(mktoSR.getErrorsString().isEmpty());
    // 
    doReturn(getListOperationResult(false, "skipped")).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.removeFromList(parms);
    assertFalse(mktoSR.isSuccess());
    assertNotNull(mktoSR.getErrorsString());
    // 
    doReturn(getListOperationResult(true, "removed")).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.removeFromList(parms);
    assertTrue(mktoSR.isSuccess());
    // 
    doReturn(getListOperationResult(true, "memberof")).when(client).executeGetRequest(eq(SyncResult.class));
    mktoSR = client.isMemberOfList(parms);
    assertTrue(mktoSR.isSuccess());
    assertNotNull(mktoSR.getRecords().get(0));
}
Also used : ListOperationParameters(org.talend.components.marketo.runtime.client.type.ListOperationParameters) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) JsonObject(com.google.gson.JsonObject) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 3 with MarketoException

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

the class MarketoLeadClientTest method testGetListIdByName.

@Test
public void testGetListIdByName() throws Exception {
    doReturn(null).when(client).executeGetRequest(StaticListResult.class);
    try {
        client.getListIdByName("test_list");
        fail("Should not be here");
    } catch (MarketoException e) {
    }
    StaticListResult rr = new StaticListResult();
    rr.setSuccess(true);
    ListRecord lr = new ListRecord();
    lr.setId(666);
    rr.setResult(Arrays.asList(lr));
    doReturn(rr).when(client).executeGetRequest(StaticListResult.class);
    assertEquals(Integer.valueOf(666), client.getListIdByName("test_list"));
}
Also used : StaticListResult(org.talend.components.marketo.runtime.client.rest.response.StaticListResult) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) ListRecord(org.talend.components.marketo.runtime.client.rest.type.ListRecord) Test(org.junit.Test)

Example 4 with MarketoException

use of org.talend.components.marketo.runtime.client.type.MarketoException 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 5 with MarketoException

use of org.talend.components.marketo.runtime.client.type.MarketoException 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());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) Test(org.junit.Test)

Aggregations

MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)37 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)12 JsonObject (com.google.gson.JsonObject)11 MarketoRecordResult (org.talend.components.marketo.runtime.client.type.MarketoRecordResult)10 URL (java.net.URL)9 IndexedRecord (org.apache.avro.generic.IndexedRecord)9 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)8 InputStreamReader (java.io.InputStreamReader)7 Schema (org.apache.avro.Schema)7 Field (org.apache.avro.Schema.Field)7 Gson (com.google.gson.Gson)6 SyncResult (org.talend.components.marketo.runtime.client.rest.response.SyncResult)6 Record (org.apache.avro.generic.GenericData.Record)5 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)5 OutputStreamWriter (java.io.OutputStreamWriter)4 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)3 Reader (java.io.Reader)3