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());
}
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));
}
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"));
}
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()));
}
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());
}
Aggregations