Search in sources :

Example 11 with MarketoRecordResult

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

the class MarketoBulkExecReaderTest method testRetryOperationSuccess.

@Test
public void testRetryOperationSuccess() throws Exception {
    IndexedRecord record = new GenericData.Record(MarketoConstants.getEmptySchema());
    MarketoRecordResult mkto = new MarketoRecordResult();
    mkto.setSuccess(true);
    mkto.setRecords(Arrays.asList(record));
    when(client.bulkImport(any(TMarketoBulkExecProperties.class))).thenReturn(mkto);
    assertTrue(reader.start());
    assertFalse(reader.advance());
    int result = (int) reader.getReturnValues().get(RETURN_NB_CALL);
    assertEquals(1, result);
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) TMarketoBulkExecProperties(org.talend.components.marketo.tmarketobulkexec.TMarketoBulkExecProperties) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 12 with MarketoRecordResult

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

the class MarketoResultTest method testToString.

@Test
public void testToString() throws Exception {
    IndexedRecord ir = new Record(MarketoConstants.getRESTSchemaForGetLeadOrGetMultipleLeads());
    result = new MarketoRecordResult(true, "POS", 0, 0, Arrays.asList(ir));
    String s = "MarketoRecordResult{requestId='', success=true, errors=null, recordCount=0, remainCount=0, " + "streamPosition='POS', records=[{\"id\": null, \"email\": null, \"firstName\": null, \"lastName\": " + "null, \"createdAt\": null, \"updatedAt\": null}]}";
    assertEquals(s, result.toString());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 13 with MarketoRecordResult

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

the class MarketoResultTest method testMarketoResultConstruct.

@Test
public void testMarketoResultConstruct() {
    result = new MarketoRecordResult();
    assertEquals(emptyList(), result.getRecords());
    assertEquals(0, result.getRecordCount());
    assertEquals(0, result.getRemainCount());
    assertEquals("", result.getStreamPosition());
    assertEquals("", result.getRequestId());
    assertFalse(result.isSuccess());
    assertNotNull(result.getErrors());
    assertEquals(0, result.getErrors().size());
    result.setRecordCount(100);
    result.setRemainCount(100);
    result.setStreamPosition("100");
    result.setRecords(new ArrayList<IndexedRecord>());
    result.setRequestId("REST::666");
    result.setSuccess(true);
    result.setErrors(Arrays.asList(new MarketoError("REST")));
    assertEquals(emptyList(), result.getRecords());
    assertEquals(100, result.getRecordCount());
    assertEquals(100, result.getRemainCount());
    assertEquals("100", result.getStreamPosition());
    assertEquals("REST::666", result.getRequestId());
    assertTrue(result.isSuccess());
    assertNotNull(result.getErrors());
    result = new MarketoRecordResult("200", 200, 200, null);
    assertEquals(Collections.emptyList(), result.getRecords());
    assertEquals(200, result.getRecordCount());
    assertEquals(200, result.getRemainCount());
    assertEquals("200", result.getStreamPosition());
    result.setErrors(Arrays.asList(new MarketoError("REST", "101", "error"), new MarketoError("error2")));
    assertNotNull(result.getErrorsString());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) Test(org.junit.Test)

Example 14 with MarketoRecordResult

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

the class MarketoInputReaderTest method testStart.

@Test
public void testStart() throws Exception {
    MarketoRecordResult mkto = new MarketoRecordResult();
    mkto.setSuccess(false);
    mkto.setErrors(Arrays.asList(new MarketoError("REST", "error")));
    when(client.bulkImport(any(TMarketoBulkExecProperties.class))).thenReturn(mkto);
    when(client.getLead(any(TMarketoInputProperties.class), any(String.class))).thenReturn(mkto);
    when(client.getMultipleLeads(any(TMarketoInputProperties.class), any(String.class))).thenReturn(mkto);
    when(client.getLeadActivity(any(TMarketoInputProperties.class), any(String.class))).thenReturn(mkto);
    when(client.getLeadChanges(any(TMarketoInputProperties.class), any(String.class))).thenReturn(mkto);
    when(client.describeCustomObject(any(TMarketoInputProperties.class))).thenReturn(mkto);
    when(client.listCustomObjects(any(TMarketoInputProperties.class))).thenReturn(mkto);
    when(client.getCustomObjects(any(TMarketoInputProperties.class), any(String.class))).thenReturn(mkto);
    try {
        assertFalse(reader.start());
        fail("Should not be here");
    } catch (Exception e) {
    }
    IndexedRecord record = new GenericData.Record(MarketoConstants.getEmptySchema());
    mkto.setSuccess(true);
    mkto.setRecords(Arrays.asList(record));
    when(client.bulkImport(any(TMarketoBulkExecProperties.class))).thenReturn(mkto);
    when(client.getLead(any(TMarketoInputProperties.class), any(String.class))).thenReturn(mkto);
    when(client.getMultipleLeads(any(TMarketoInputProperties.class), any(String.class))).thenReturn(mkto);
    when(client.getLeadActivity(any(TMarketoInputProperties.class), any(String.class))).thenReturn(mkto);
    when(client.getLeadChanges(any(TMarketoInputProperties.class), any(String.class))).thenReturn(mkto);
    when(client.describeCustomObject(any(TMarketoInputProperties.class))).thenReturn(mkto);
    when(client.listCustomObjects(any(TMarketoInputProperties.class))).thenReturn(mkto);
    when(client.getCustomObjects(any(TMarketoInputProperties.class), any(String.class))).thenReturn(mkto);
    assertFalse(reader.start());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) TMarketoInputProperties(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) TMarketoBulkExecProperties(org.talend.components.marketo.tmarketobulkexec.TMarketoBulkExecProperties) IOException(java.io.IOException) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) Test(org.junit.Test)

Example 15 with MarketoRecordResult

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

the class MarketoSourceOrSink method getSchemaNames.

@Override
public List<NamedThing> getSchemaNames(RuntimeContainer container) throws IOException {
    List<NamedThing> customObjects = new ArrayList<>();
    MarketoClientServiceExtended client = (MarketoClientServiceExtended) getClientService(null);
    TMarketoInputProperties ip = new TMarketoInputProperties("COSchemas");
    ip.init();
    ip.connection = properties.getConnectionProperties();
    ip.inputOperation.setValue(InputOperation.CustomObject);
    ip.customObjectAction.setValue(CustomObjectAction.list);
    ip.customObjectNames.setValue("");
    ip.schemaInput.schema.setValue(MarketoConstants.getCustomObjectDescribeSchema());
    MarketoRecordResult r = client.listCustomObjects(ip);
    for (IndexedRecord co : r.getRecords()) {
        // name cannot be null
        String name = co.get(0).toString();
        Object displayName = co.get(1);
        if (displayName == null) {
            displayName = name;
        }
        customObjects.add(new SimpleNamedThing(name, displayName.toString()));
    }
    // 
    return customObjects;
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) MarketoClientServiceExtended(org.talend.components.marketo.runtime.client.MarketoClientServiceExtended) TMarketoInputProperties(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult)

Aggregations

MarketoRecordResult (org.talend.components.marketo.runtime.client.type.MarketoRecordResult)83 Test (org.junit.Test)61 MarketoSource (org.talend.components.marketo.runtime.MarketoSource)49 IndexedRecord (org.apache.avro.generic.IndexedRecord)47 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)16 Schema (org.apache.avro.Schema)15 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)14 ArrayList (java.util.ArrayList)7 TMarketoBulkExecProperties (org.talend.components.marketo.tmarketobulkexec.TMarketoBulkExecProperties)6 IOException (java.io.IOException)5 Date (java.util.Date)5 Gson (com.google.gson.Gson)4 JsonObject (com.google.gson.JsonObject)4 ArrayOfString (com.marketo.mktows.ArrayOfString)4 MalformedURLException (java.net.MalformedURLException)4 InvalidKeyException (java.security.InvalidKeyException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 ParseException (java.text.ParseException)4 List (java.util.List)4 JAXBException (javax.xml.bind.JAXBException)4