Search in sources :

Example 6 with Merchandise__c

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());
        }
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) Merchandise__c(org.apache.camel.component.salesforce.dto.generated.Merchandise__c) SalesforceMultipleChoicesException(org.apache.camel.component.salesforce.api.SalesforceMultipleChoicesException) List(java.util.List) Test(org.junit.Test)

Example 7 with Merchandise__c

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());
}
Also used : Merchandise__c(org.apache.camel.component.salesforce.dto.generated.Merchandise__c) Test(org.junit.Test)

Example 8 with Merchandise__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)));
    }
}
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

Merchandise__c (org.apache.camel.component.salesforce.dto.generated.Merchandise__c)8 Test (org.junit.Test)7 CreateSObjectResult (org.apache.camel.component.salesforce.api.dto.CreateSObjectResult)5 CamelExecutionException (org.apache.camel.CamelExecutionException)2 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)2 List (java.util.List)1 Component (org.apache.camel.Component)1 ComponentConfiguration (org.apache.camel.ComponentConfiguration)1 Message (org.apache.camel.Message)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 SalesforceMultipleChoicesException (org.apache.camel.component.salesforce.api.SalesforceMultipleChoicesException)1 Account (org.apache.camel.component.salesforce.dto.generated.Account)1 Asset (org.apache.camel.component.salesforce.dto.generated.Asset)1 Contact (org.apache.camel.component.salesforce.dto.generated.Contact)1 Document (org.apache.camel.component.salesforce.dto.generated.Document)1 Line_Item__c (org.apache.camel.component.salesforce.dto.generated.Line_Item__c)1 MSPTest (org.apache.camel.component.salesforce.dto.generated.MSPTest)1 QueryRecordsLine_Item__c (org.apache.camel.component.salesforce.dto.generated.QueryRecordsLine_Item__c)1 Task (org.apache.camel.component.salesforce.dto.generated.Task)1 QueryRecordsPushTopic (org.apache.camel.component.salesforce.internal.dto.QueryRecordsPushTopic)1