Search in sources :

Example 11 with CreateSObjectResult

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)));
    }
}
Also used : CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) QueryRecordsPushTopic(org.apache.camel.component.salesforce.internal.dto.QueryRecordsPushTopic) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Merchandise__c(org.apache.camel.component.salesforce.dto.generated.Merchandise__c) Test(org.junit.Test)

Aggregations

CreateSObjectResult (org.apache.camel.component.salesforce.api.dto.CreateSObjectResult)11 Test (org.junit.Test)6 Merchandise__c (org.apache.camel.component.salesforce.dto.generated.Merchandise__c)5 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)3 Account (org.apache.camel.component.salesforce.dto.generated.Account)3 Before (org.junit.Before)3 IOException (java.io.IOException)2 List (java.util.List)2 CamelExecutionException (org.apache.camel.CamelExecutionException)2 QueryRecordsPushTopic (org.apache.camel.component.salesforce.internal.dto.QueryRecordsPushTopic)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Collections (java.util.Collections)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 CamelException (org.apache.camel.CamelException)1 Message (org.apache.camel.Message)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 SalesforceMultipleChoicesException (org.apache.camel.component.salesforce.api.SalesforceMultipleChoicesException)1 QueryRecordsReport (org.apache.camel.component.salesforce.api.dto.analytics.reports.QueryRecordsReport)1 Line_Item__c (org.apache.camel.component.salesforce.dto.generated.Line_Item__c)1