Search in sources :

Example 36 with MarketoException

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

the class MarketoCustomObjectClientTest method testDeleteCustomObjects.

@Test
public void testDeleteCustomObjects() throws Exception {
    oprops.customObjectDeleteBy.setValue(CustomObjectDeleteBy.idField);
    // 
    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.deleteCustomObjects(oprops, records);
    assertFalse(mktoSR.isSuccess());
    assertFalse(mktoSR.getErrorsString().isEmpty());
    // 
    doReturn(new SyncResult()).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.deleteCustomObjects(oprops, records);
    assertFalse(mktoSR.isSuccess());
    // 
    doReturn(getListOperationResult(true, "deleted")).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
    mktoSR = client.deleteCustomObjects(oprops, records);
    assertTrue(mktoSR.isSuccess());
    assertTrue(mktoSR.getErrorsString().isEmpty());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) Test(org.junit.Test)

Example 37 with MarketoException

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

the class MarketoRESTClient method connect.

public MarketoRESTClient connect() throws MarketoException {
    try {
        if (endpoint == null) {
            throw new MarketoException(REST, messages.getMessage("error.rest.endpoint.null"));
        }
        URL url = new URL(endpoint);
        if (url.getPath() != null) {
            basicPath = url.toString();
            // check if endpoint is valid
            if (!basicPath.equals(String.format("%s://%s/rest", url.getProtocol(), url.getHost()))) {
                throw new MarketoException(REST, messages.getMessage("error.rest.endpoint.invalid"));
            }
            bulkPath = basicPath.replaceAll("rest$", "bulk");
        }
        // check credentials
        getToken();
        // dummy call to finally check the connection
        getPageToken("2017-01-01 00:00:00");
        return this;
    } catch (MalformedURLException e) {
        LOG.error(e.toString());
        throw new MarketoException(REST, e.getMessage());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) URL(java.net.URL)

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