use of org.apache.camel.component.salesforce.api.dto.CreateSObjectResult in project camel by apache.
the class AbstractApprovalIntegrationTest method createAccounts.
@Before
public void createAccounts() {
final List<Account> accountsToCreate = IntStream.range(0, accountCount + 1).mapToObj(idx -> {
final String name = "test-account-" + idx;
final Account account = new Account();
account.setName(name);
return account;
}).collect(Collectors.toList());
accountIds = accountsToCreate.stream().map(account -> template.requestBody("salesforce:createSObject?sObjectName=Account", account, CreateSObjectResult.class)).map(CreateSObjectResult::getId).collect(Collectors.toList());
}
use of org.apache.camel.component.salesforce.api.dto.CreateSObjectResult in project camel by apache.
the class PushTopicHelper method createTopic.
private void createTopic() throws CamelException {
final PushTopic topic = new PushTopic();
topic.setName(topicName);
topic.setApiVersion(Double.valueOf(config.getApiVersion()));
topic.setQuery(config.getSObjectQuery());
topic.setDescription("Topic created by Camel Salesforce component");
topic.setNotifyForFields(config.getNotifyForFields());
if (preApi29) {
topic.setNotifyForOperations(config.getNotifyForOperations());
} else {
topic.setNotifyForOperationCreate(config.getNotifyForOperationCreate());
topic.setNotifyForOperationDelete(config.getNotifyForOperationDelete());
topic.setNotifyForOperationUndelete(config.getNotifyForOperationUndelete());
topic.setNotifyForOperationUpdate(config.getNotifyForOperationUpdate());
}
LOG.info("Creating Topic {}: {}", topicName, topic);
final SyncResponseCallback callback = new SyncResponseCallback();
try {
restClient.createSObject(PUSH_TOPIC_OBJECT_NAME, new ByteArrayInputStream(OBJECT_MAPPER.writeValueAsBytes(topic)), callback);
if (!callback.await(API_TIMEOUT, TimeUnit.SECONDS)) {
throw new SalesforceException("API call timeout!", null);
}
final SalesforceException callbackException = callback.getException();
if (callbackException != null) {
throw callbackException;
}
CreateSObjectResult result = OBJECT_MAPPER.readValue(callback.getResponse(), CreateSObjectResult.class);
if (!result.getSuccess()) {
final SalesforceException salesforceException = new SalesforceException(result.getErrors(), HttpStatus.BAD_REQUEST_400);
throw new CamelException(String.format("Error creating Topic %s: %s", topicName, result.getErrors()), salesforceException);
}
} catch (SalesforceException e) {
throw new CamelException(String.format("Error creating Topic %s: %s", topicName, e.getMessage()), e);
} catch (IOException e) {
throw new CamelException(String.format("Un-marshaling error creating Topic %s: %s", topicName, e.getMessage()), e);
} catch (InterruptedException e) {
throw new CamelException(String.format("Un-marshaling error creating Topic %s: %s", topicName, e.getMessage()), e);
} finally {
if (callback.getResponse() != null) {
try {
callback.getResponse().close();
} catch (IOException e) {
// ignore
}
}
}
}
use of org.apache.camel.component.salesforce.api.dto.CreateSObjectResult in project camel by apache.
the class RestApiIntegrationTest method setupData.
@Before
public void setupData() {
final Merchandise__c merchandise = new Merchandise__c();
merchandise.setName("Test Merchandise");
merchandise.setPrice__c(10.0);
merchandise.setTotal_Inventory__c(100.0);
final CreateSObjectResult result = template().requestBody("salesforce:createSObject", merchandise, CreateSObjectResult.class);
testId = result.getId();
}
use of org.apache.camel.component.salesforce.api.dto.CreateSObjectResult in project camel by apache.
the class RestApiIntegrationTest method testStatus400.
@Test
public void testStatus400() throws Exception {
// get test merchandise
// note that the header value overrides sObjectFields in endpoint
final Merchandise__c merchandise = template().requestBodyAndHeader("direct:getSObject", testId, "sObjectFields", "Description__c,Price__c", Merchandise__c.class);
assertNotNull(merchandise);
assertNotNull(merchandise.getPrice__c());
assertNull(merchandise.getTotal_Inventory__c());
merchandise.clearBaseFields();
// required field Total_Inventory__c is missing
CreateSObjectResult result = null;
try {
result = template().requestBody("direct:createSObject", merchandise, CreateSObjectResult.class);
fail("Expected SalesforceException with statusCode 400");
} catch (final CamelExecutionException e) {
assertTrue(e.getCause() instanceof SalesforceException);
assertTrue(e.getCause().getCause() instanceof SalesforceException);
final SalesforceException cause = (SalesforceException) e.getCause().getCause();
assertEquals(400, cause.getStatusCode());
assertEquals(1, cause.getErrors().size());
assertEquals("[Total_Inventory__c]", cause.getErrors().get(0).getFields().toString());
} finally {
// delete the clone if created
if (result != null) {
template().requestBody("direct:deleteSObject", result.getId());
}
}
}
use of org.apache.camel.component.salesforce.api.dto.CreateSObjectResult in project camel by apache.
the class RestApiIntegrationTest method testCreateUpdateDelete.
@Test
public void testCreateUpdateDelete() throws Exception {
final Merchandise__c merchandise = new Merchandise__c();
merchandise.setName("Wee Wee Wee Plane");
merchandise.setDescription__c("Microlite plane");
merchandise.setPrice__c(2000.0);
merchandise.setTotal_Inventory__c(50.0);
final CreateSObjectResult result = template().requestBody("direct:createSObject", merchandise, CreateSObjectResult.class);
assertNotNull(result);
assertTrue("Create success", result.getSuccess());
// test JSON update
// make the plane cheaper
merchandise.setPrice__c(1500.0);
// change inventory to half
merchandise.setTotal_Inventory__c(25.0);
// also need to set the Id
merchandise.setId(result.getId());
assertNull(template().requestBodyAndHeader("direct:updateSObject", merchandise, SalesforceEndpointConfig.SOBJECT_ID, result.getId()));
// delete the newly created SObject
assertNull(template().requestBody("direct:deleteSObject", result.getId()));
}
Aggregations