use of org.apache.camel.component.salesforce.api.dto.CreateSObjectResult 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