Search in sources :

Example 31 with MarketoException

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

the class MarketoLeadClientTest method testGetLeadChanges.

@Test
public void testGetLeadChanges() throws Exception {
    iprops.inputOperation.setValue(InputOperation.getLeadChanges);
    iprops.sinceDateTime.setValue("2017-01-30 10:00:00 +0100");
    iprops.afterInputOperation();
    List<Field> moreFields = new ArrayList<>();
    moreFields.add(new Field("attrName", AvroUtils._string(), "", null));
    moreFields.add(new Field("campaignId", AvroUtils._int(), "", null));
    iprops.schemaInput.schema.setValue(MarketoUtils.newSchema(iprops.schemaInput.schema.getValue(), "test", moreFields));
    iprops.beforeMappingInput();
    // 
    doThrow(new MarketoException("REST", "error")).when(client).executeGetRequest(LeadChangesResult.class);
    mktoRR = client.getLeadChanges(iprops, null);
    assertFalse(mktoRR.isSuccess());
    assertFalse(mktoRR.getErrorsString().isEmpty());
    // 
    doReturn(new LeadChangesResult()).when(client).executeGetRequest(LeadChangesResult.class);
    mktoRR = client.getLeadChanges(iprops, null);
    assertFalse(mktoRR.isSuccess());
    // 
    LeadChangesResult lcr = new LeadChangesResult();
    lcr.setSuccess(true);
    List<LeadChangeRecord> lcrs = new ArrayList<>();
    LeadChangeRecord lc = new LeadChangeRecord();
    lc.setId(123456);
    lc.setMarketoGUID("ABC-123-DEF");
    lc.setLeadId(12345);
    lc.setActivityTypeId(1);
    lc.setActivityTypeValue("Visit Webpage");
    lc.setActivityDate(new Date());
    lc.setCampaignId(456);
    List<Map<String, String>> fields = new ArrayList<>();
    Map<String, String> field = new HashMap<>();
    field.put("field1", "value1");
    fields.add(field);
    lc.setFields(fields);
    List<Map<String, Object>> attributes = new ArrayList<>();
    Map<String, Object> attribute = new HashMap<>();
    attribute.put("name", "attrName");
    attribute.put("value", "attrValue");
    attributes.add(attribute);
    lc.setAttributes(attributes);
    lcrs.add(lc);
    lcr.setResult(lcrs);
    // 
    doReturn(lcr).when(client).executeGetRequest(LeadChangesResult.class);
    mktoRR = client.getLeadChanges(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(123456, record.get(refSchema.getField("id").pos()));
    assertEquals("ABC-123-DEF", record.get(refSchema.getField("marketoGUID").pos()));
    assertEquals(12345, record.get(refSchema.getField("leadId").pos()));
    assertEquals(1, record.get(refSchema.getField("activityTypeId").pos()));
    assertEquals("Visit Webpage", record.get(refSchema.getField("activityTypeValue").pos()));
    assertEquals(456, record.get(refSchema.getField("campaignId").pos()));
    assertEquals("[{\"field1\":\"value1\"}]", record.get(refSchema.getField("fields").pos()));
    assertTrue(record.get(refSchema.getField("activityDate").pos()) instanceof Long);
    assertEquals("attrValue", record.get(refSchema.getField("attrName").pos()));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) HashMap(java.util.HashMap) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) LeadChangesResult(org.talend.components.marketo.runtime.client.rest.response.LeadChangesResult) LeadChangeRecord(org.talend.components.marketo.runtime.client.rest.type.LeadChangeRecord) Field(org.apache.avro.Schema.Field) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 32 with MarketoException

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

Example 33 with MarketoException

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

the class MarketoSOAPClientTest method testIsErrorRecoverable.

@Test
public void testIsErrorRecoverable() throws Exception {
    MarketoError error = new MarketoException("SOAP", "20016 Request Expired").toMarketoError();
    assertTrue(client.isErrorRecoverable(Arrays.asList(error)));
    for (String code : new String[] { "10001", "20011", "20023", "20024" }) {
        error = new MarketoException("SOAP", String.format("SOAP %s Concurrency Limit Exceeded", code)).toMarketoError();
        assertTrue(client.isErrorRecoverable(Arrays.asList(error)));
    }
    error = new MarketoException("SOAP", "404 Page not found").toMarketoError();
    assertFalse(client.isErrorRecoverable(Arrays.asList(error)));
}
Also used : MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) Test(org.junit.Test)

Example 34 with MarketoException

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

the class MarketoBaseRESTClientTest method testIsErrorRecoverable.

@Test
public void testIsErrorRecoverable() throws Exception {
    MarketoError error = new MarketoException("REST", "602", "Access token expired").toMarketoError();
    assertTrue(client.isErrorRecoverable(Arrays.asList(error)));
    for (String code : new String[] { "502", "604", "606", "608", "611", "614", "615" }) {
        error = new MarketoException("REST", code, "API Temporarily Unavailable").toMarketoError();
        assertTrue(client.isErrorRecoverable(Arrays.asList(error)));
    }
    error = new MarketoException("REST", "404", "Page not found").toMarketoError();
    assertFalse(client.isErrorRecoverable(Arrays.asList(error)));
}
Also used : MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) Test(org.junit.Test)

Example 35 with MarketoException

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

the class MarketoBaseRESTClientTest method testIsAccessTokenExpired.

@Test
public void testIsAccessTokenExpired() throws Exception {
    assertFalse(client.isAccessTokenExpired(null));
    MarketoError error = new MarketoException("REST", "602", "Access token expired").toMarketoError();
    assertTrue(client.isAccessTokenExpired(Arrays.asList(error)));
}
Also used : MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) 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