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());
}
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());
}
}
Aggregations