use of org.apache.camel.component.salesforce.dto.generated.Merchandise__c in project camel by apache.
the class RestApiIntegrationTest method testStatus300.
@Test
public void testStatus300() throws Exception {
// get test merchandise
// note that the header value overrides sObjectFields in endpoint
final Merchandise__c merchandise = template().requestBodyAndHeader("direct:getSObject", testId, "sObjectFields", "Name,Description__c,Price__c,Total_Inventory__c", Merchandise__c.class);
assertNotNull(merchandise);
assertNotNull(merchandise.getName());
assertNotNull(merchandise.getPrice__c());
assertNotNull(merchandise.getTotal_Inventory__c());
CreateSObjectResult result = null;
try {
merchandise.clearBaseFields();
result = template().requestBody("direct:createSObject", merchandise, CreateSObjectResult.class);
assertNotNull(result);
assertNotNull(result.getId());
// note that the request SObject overrides settings on the endpoint for LineItem__c
try {
template().requestBody("direct:getSObjectWithId", merchandise, Merchandise__c.class);
fail("Expected SalesforceException with statusCode 300");
} catch (final CamelExecutionException e) {
assertTrue(e.getCause() instanceof SalesforceException);
assertTrue(e.getCause().getCause() instanceof SalesforceMultipleChoicesException);
final SalesforceMultipleChoicesException cause = (SalesforceMultipleChoicesException) e.getCause().getCause();
assertEquals(300, cause.getStatusCode());
final List<String> choices = cause.getChoices();
assertNotNull(choices);
assertFalse(choices.isEmpty());
}
} finally {
// delete the test clone
if (result != null) {
template().requestBody("direct:deleteSObject", result.getId());
}
}
}
use of org.apache.camel.component.salesforce.dto.generated.Merchandise__c in project camel by apache.
the class RestApiIntegrationTest method testGetSObject.
@Test
public void testGetSObject() throws Exception {
final Merchandise__c merchandise = template().requestBody("direct:getSObject", testId, Merchandise__c.class);
assertNotNull(merchandise);
assertNull(merchandise.getTotal_Inventory__c());
assertNotNull(merchandise.getPrice__c());
}
use of org.apache.camel.component.salesforce.dto.generated.Merchandise__c in project camel by apache.
the class StreamingApiIntegrationTest method testSubscribeAndReceive.
@Test
public void testSubscribeAndReceive() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:CamelTestTopic");
mock.expectedMessageCount(1);
// assert expected static headers
mock.expectedHeaderReceived("CamelSalesforceTopicName", "CamelTestTopic");
mock.expectedHeaderReceived("CamelSalesforceChannel", "/topic/CamelTestTopic");
Merchandise__c merchandise = new Merchandise__c();
merchandise.setName("TestNotification");
merchandise.setDescription__c("Merchandise for testing Streaming API updated on " + ZonedDateTime.now().toString());
merchandise.setPrice__c(9.99);
merchandise.setTotal_Inventory__c(1000.0);
CreateSObjectResult result = template().requestBody("direct:upsertSObject", merchandise, CreateSObjectResult.class);
assertTrue("Merchandise test record not created", result == null || result.getSuccess());
try {
// wait for Salesforce notification
mock.assertIsSatisfied();
final Message in = mock.getExchanges().get(0).getIn();
merchandise = in.getMandatoryBody(Merchandise__c.class);
assertNotNull("Missing event body", merchandise);
log.info("Merchandise notification: {}", merchandise.toString());
assertNotNull("Missing field Id", merchandise.getId());
assertNotNull("Missing field Name", merchandise.getName());
// validate dynamic message headers
assertNotNull("Missing header CamelSalesforceClientId", in.getHeader("CamelSalesforceClientId"));
assertNotNull("Missing header CamelSalesforceEventType", in.getHeader("CamelSalesforceEventType"));
assertNotNull("Missing header CamelSalesforceCreatedDate", in.getHeader("CamelSalesforceCreatedDate"));
} finally {
// remove the test record
assertNull(template().requestBody("direct:deleteSObjectWithId", merchandise));
// remove the test topic
// find it using SOQL first
QueryRecordsPushTopic records = template().requestBody("direct:query", null, QueryRecordsPushTopic.class);
assertEquals("Test topic not found", 1, records.getTotalSize());
assertNull(template().requestBody("direct:deleteSObject", records.getRecords().get(0)));
}
}
Aggregations