Search in sources :

Example 21 with SyncStatus

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

the class MarketoClientCustomObjectsTestIT method testDeleteCustomObjectsByDedupeFields.

@Test
public void testDeleteCustomObjectsByDedupeFields() throws Exception {
    MarketoSyncResult rs = createCustomObjectRecords("");
    assertTrue(rs.isSuccess());
    // 
    oprops.customObjectName.setValue(TEST_CO_NAME_SMARTPHONE);
    Schema s = // 
    SchemaBuilder.record("sn").fields().name(FIELD_CO_SMARTPHONE_MODEL).type().stringType().noDefault().endRecord();
    List<IndexedRecord> records = new ArrayList<>();
    IndexedRecord r1;
    for (String m : TEST_SMARTPHONE_MODELS) {
        r1 = new Record(s);
        r1.put(0, m);
        records.add(r1);
    }
    MarketoSource source = new MarketoSource();
    oprops.customObjectDeleteBy.setValue(CustomObjectDeleteBy.dedupeFields);
    source.initialize(null, oprops);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    rs = client.deleteCustomObjects(oprops, records);
    assertTrue(rs.isSuccess());
    List<SyncStatus> changes = rs.getRecords();
    assertEquals(TEST_SMARTPHONE_MODELS.length, changes.size());
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getSeq());
        assertEquals(STATUS_DELETED, r.getStatus());
        LOG.debug("r = {}.", r);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 22 with SyncStatus

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

the class MarketoLeadClientTest method testSyncLead.

@Test
public void testSyncLead() throws Exception {
    oprops.afterOutputOperation();
    oprops.beforeMappingInput();
    IndexedRecord record = new Record(MarketoConstants.getRESTOutputSchemaForSyncLead());
    record.put(0, 12345);
    record.put(1, "t@t.com");
    // 
    doThrow(new MarketoException("REST", "error")).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.syncLead(oprops, record);
    assertFalse(mktoSR.isSuccess());
    assertFalse(mktoSR.getErrorsString().isEmpty());
    // 
    doReturn(new SyncResult()).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.syncLead(oprops, record);
    assertFalse(mktoSR.isSuccess());
    // 
    SyncResult sr = new SyncResult();
    sr.setSuccess(true);
    List<SyncStatus> ssr = new ArrayList<>();
    SyncStatus ss = new SyncStatus();
    ss.setStatus("created");
    ss.setMarketoGUID("mkto-123456");
    ss.setSeq(0);
    ss.setId(12345);
    ss.setErrorMessage("");
    ssr.add(ss);
    sr.setResult(ssr);
    doReturn(sr).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.syncLead(oprops, record);
    assertTrue(mktoSR.isSuccess());
    assertTrue(mktoSR.getErrorsString().isEmpty());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Record(org.apache.avro.generic.GenericData.Record) ListRecord(org.talend.components.marketo.runtime.client.rest.type.ListRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) LeadChangeRecord(org.talend.components.marketo.runtime.client.rest.type.LeadChangeRecord) LeadActivityRecord(org.talend.components.marketo.runtime.client.rest.type.LeadActivityRecord) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 23 with SyncStatus

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

the class MarketoLeadClientTest method testDeleteLeads.

@Test
public void testDeleteLeads() throws Exception {
    IndexedRecord record = new Record(MarketoConstants.getDeleteLeadsSchema());
    record.put(0, 12345);
    // 
    doThrow(new MarketoException("REST", "error")).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.deleteLeads(new Integer[] { 12345 });
    mktoSR = client.deleteLeads(Arrays.asList(record));
    assertFalse(mktoSR.isSuccess());
    assertFalse(mktoSR.getErrorsString().isEmpty());
    // 
    doReturn(new SyncResult()).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.deleteLeads(new Integer[] { 12345 });
    assertFalse(mktoSR.isSuccess());
    // 
    SyncResult sr = new SyncResult();
    sr.setSuccess(true);
    List<SyncStatus> ssr = new ArrayList<>();
    SyncStatus ss = new SyncStatus();
    ss.setStatus("created");
    ss.setMarketoGUID("mkto-123456");
    ss.setSeq(0);
    ss.setId(12345);
    ss.setErrorMessage("");
    ssr.add(ss);
    sr.setResult(ssr);
    doReturn(sr).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.deleteLeads(new Integer[] { 12345 });
    assertTrue(mktoSR.isSuccess());
    assertTrue(mktoSR.getErrorsString().isEmpty());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Record(org.apache.avro.generic.GenericData.Record) ListRecord(org.talend.components.marketo.runtime.client.rest.type.ListRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) LeadChangeRecord(org.talend.components.marketo.runtime.client.rest.type.LeadChangeRecord) LeadActivityRecord(org.talend.components.marketo.runtime.client.rest.type.LeadActivityRecord) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 24 with SyncStatus

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

the class MarketoLeadClientTest method getListOperationResult.

public SyncResult getListOperationResult(boolean isSuccess, String status) {
    SyncResult result = new SyncResult();
    List<SyncStatus> records = new ArrayList<>();
    if (isSuccess) {
        result.setSuccess(true);
        SyncStatus ss = new SyncStatus();
        ss.setSeq(0);
        ss.setMarketoGUID("mkto-123456");
        ss.setStatus(status);
        ss.setErrorMessage("");
        records.add(ss);
        result.setResult(records);
    } else {
        result.setSuccess(false);
        result.setErrors(Arrays.asList(new MarketoError("REST", "errorlist")));
    }
    return result;
}
Also used : SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError)

Example 25 with SyncStatus

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

the class MarketoRuntimeTestBase method getFailedSyncResult.

public MarketoSyncResult getFailedSyncResult(boolean withSyncRecord) {
    MarketoSyncResult mkto = new MarketoSyncResult();
    mkto.setSuccess(false);
    mkto.setErrors(Arrays.asList(new MarketoError("REST", "error")));
    if (withSyncRecord) {
        SyncStatus sts1 = new SyncStatus();
        sts1.setId(12345);
        sts1.setStatus("failed");
        sts1.setMarketoGUID("mktoGUID");
        sts1.setSeq(0);
        List<SyncStatus> stl = new ArrayList<>();
        stl.add(sts1);
        mkto.setRecords(stl);
    }
    return mkto;
}
Also used : SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError)

Aggregations

SyncStatus (org.talend.components.marketo.runtime.client.rest.type.SyncStatus)25 MarketoSyncResult (org.talend.components.marketo.runtime.client.type.MarketoSyncResult)23 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)13 MarketoSource (org.talend.components.marketo.runtime.MarketoSource)13 IndexedRecord (org.apache.avro.generic.IndexedRecord)11 ListOperationParameters (org.talend.components.marketo.runtime.client.type.ListOperationParameters)8 Schema (org.apache.avro.Schema)7 Record (org.apache.avro.generic.GenericData.Record)5 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)5 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)5 MalformedURLException (java.net.MalformedURLException)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ParseException (java.text.ParseException)3 JAXBContext (javax.xml.bind.JAXBContext)3 JAXBException (javax.xml.bind.JAXBException)3 Marshaller (javax.xml.bind.Marshaller)3 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)3 WebServiceException (javax.xml.ws.WebServiceException)3