Search in sources :

Example 1 with MarketoSource

use of org.talend.components.marketo.runtime.MarketoSource in project components by Talend.

the class MarketoClientCustomObjectsTestIT method testDescribeFields.

@Test
public void testDescribeFields() throws Exception {
    MarketoSource source = new MarketoSource();
    source.initialize(null, irProps);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    List<Field> fieldList = client.getAllLeadFields();
    assertTrue(fieldList.size() > 500);
    for (Field f : fieldList) {
        // LOG.debug("f [{}] = {} {}.", f.doc(), f, f.getObjectProps());
        assertNotNull(f.doc());
        assertNotNull(f.schema().getType());
    }
}
Also used : Field(org.apache.avro.Schema.Field) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) Test(org.junit.Test)

Example 2 with MarketoSource

use of org.talend.components.marketo.runtime.MarketoSource in project components by Talend.

the class MarketoRESTClientBulkExecTestIT method testBulkExecCustomObject.

@Test
public void testBulkExecCustomObject() throws Exception {
    props.bulkImportTo.setValue(BulkImportTo.CustomObjects);
    props.customObjectName.setValue("car_c");
    props.bulkFilePath.setValue(coCSV);
    props.logDownloadPath.setValue(downloadPath);
    props.pollWaitTime.setValue(5);
    props.afterBulkImportTo();
    Schema s = MarketoConstants.getBulkImportCustomObjectSchema();
    MarketoSource source = new MarketoSource();
    source.initialize(null, props);
    assertEquals(Result.OK, source.validate(null).getStatus());
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    MarketoRecordResult result = client.bulkImport(props);
    assertTrue(result.isSuccess());
    assertEquals(1, result.getRecordCount());
    IndexedRecord r = result.getRecords().get(0);
    assertNotNull(r);
    assertEquals(1, r.get(s.getField("numOfObjectsProcessed").pos()));
    assertEquals(2, r.get(s.getField("numOfRowsFailed").pos()));
    assertEquals(0, r.get(s.getField("numOfRowsWithWarning").pos()));
    assertEquals("car_c", r.get(s.getField("objectApiName").pos()));
    assertEquals("import", r.get(s.getField("operation").pos()));
    assertEquals("Complete", r.get(s.getField("status").pos()));
    Object batchId = r.get(s.getField("batchId").pos());
    assertNotNull(batchId);
    Path logf = Paths.get(downloadPath, String.format("bulk_customobjects_car_c_%d_failures.csv", Integer.valueOf(batchId.toString())));
    assertEquals(logf.toString(), r.get(s.getField("failuresLogFile").pos()));
    assertTrue(Files.exists(logf));
    assertEquals(216, Files.readAllBytes(logf).length);
}
Also used : Path(java.nio.file.Path) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 3 with MarketoSource

use of org.talend.components.marketo.runtime.MarketoSource in project components by Talend.

the class MarketoRESTClientBulkExecTestIT method testBulkExecLead.

@Test
public void testBulkExecLead() throws Exception {
    props.bulkImportTo.setValue(BulkImportTo.Leads);
    props.bulkFilePath.setValue(leadCSV);
    props.logDownloadPath.setValue(downloadPath);
    props.pollWaitTime.setValue(1);
    props.afterBulkImportTo();
    Schema s = MarketoConstants.getBulkImportLeadSchema();
    MarketoSource source = new MarketoSource();
    source.initialize(null, props);
    assertEquals(Result.OK, source.validate(null).getStatus());
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    MarketoRecordResult result = client.bulkImport(props);
    assertTrue(result.isSuccess());
    assertEquals(1, result.getRecordCount());
    IndexedRecord r = result.getRecords().get(0);
    assertNotNull(r);
    assertEquals(2, r.get(s.getField("numOfLeadsProcessed").pos()));
    assertEquals(0, r.get(s.getField("numOfRowsFailed").pos()));
    assertEquals(1, r.get(s.getField("numOfRowsWithWarning").pos()));
    assertEquals("Complete", r.get(s.getField("status").pos()));
    Object batchId = r.get(s.getField("batchId").pos());
    assertNotNull(batchId);
    Path logf = Paths.get(downloadPath, String.format("bulk_leads_%d_warnings.csv", Integer.valueOf(batchId.toString())));
    assertEquals(logf.toString(), r.get(s.getField("warningsLogFile").pos()));
    assertTrue(Files.exists(logf));
    assertEquals(86, Files.readAllBytes(logf).length);
}
Also used : Path(java.nio.file.Path) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 4 with MarketoSource

use of org.talend.components.marketo.runtime.MarketoSource in project components by Talend.

the class MarketoSOAPClientTestIT method testAddToList.

/*
     * 
     * 
     * ListOperations
     * 
     * 
     */
@Test
public void testAddToList() throws Exception {
    MarketoSource source = new MarketoSource();
    source.initialize(null, listProperties);
    MarketoClientService client = source.getClientService(null);
    // 
    ListOperationParameters parms = new ListOperationParameters();
    parms.setApiMode(SOAP.name());
    parms.setListKeyValue(UNDX_TEST_LIST_SMALL);
    parms.setLeadKeyValue(new String[] { createdLeads.get(10).toString() });
    // first make sure to remove lead
    MarketoSyncResult result = client.removeFromList(parms);
    LOG.debug("result = {}.", result);
    List<SyncStatus> changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        LOG.debug("r = {}.", r);
    }
    // then add it
    result = client.addToList(parms);
    LOG.debug("result = {}.", result);
    changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertTrue(Boolean.parseBoolean(r.getStatus()));
        LOG.debug("r = {}.", r);
    }
}
Also used : ListOperationParameters(org.talend.components.marketo.runtime.client.type.ListOperationParameters) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 5 with MarketoSource

use of org.talend.components.marketo.runtime.MarketoSource in project components by Talend.

the class MarketoSOAPClientTestIT method testGetLeadFailWrongHost.

@Test(expected = IOException.class)
public void testGetLeadFailWrongHost() throws Exception {
    inputProperties.inputOperation.setValue(getLead);
    inputProperties.leadKeyTypeSOAP.setValue(EMAIL);
    inputProperties.connection.endpoint.setValue(ENDPOINT_URL_INEXISTANT);
    inputProperties.afterInputOperation();
    // 
    inputProperties.leadKeyValue.setValue(EMAIL_INEXISTANT);
    MarketoSource source = new MarketoSource();
    source.initialize(null, inputProperties);
    MarketoClientService client = source.getClientService(null);
    // 
    MarketoRecordResult result = client.getLead(inputProperties, null);
    List<IndexedRecord> records = result.getRecords();
    assertEquals(emptyList(), records);
    LOG.debug("record = " + records);
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Aggregations

MarketoSource (org.talend.components.marketo.runtime.MarketoSource)73 Test (org.junit.Test)72 MarketoRecordResult (org.talend.components.marketo.runtime.client.type.MarketoRecordResult)49 IndexedRecord (org.apache.avro.generic.IndexedRecord)37 MarketoSyncResult (org.talend.components.marketo.runtime.client.type.MarketoSyncResult)17 Schema (org.apache.avro.Schema)14 SyncStatus (org.talend.components.marketo.runtime.client.rest.type.SyncStatus)13 ArrayList (java.util.ArrayList)9 ListOperationParameters (org.talend.components.marketo.runtime.client.type.ListOperationParameters)7 Field (org.apache.avro.Schema.Field)5 Record (org.apache.avro.generic.GenericData.Record)4 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)3 LeadRecord (com.marketo.mktows.LeadRecord)2 Path (java.nio.file.Path)2 GenericData (org.apache.avro.generic.GenericData)1