Search in sources :

Example 6 with CreateSObjectResult

use of org.apache.camel.component.salesforce.api.dto.CreateSObjectResult in project camel by apache.

the class CompositeApiBatchIntegrationTest method setupRecords.

@Before
public void setupRecords() {
    final Account account = new Account();
    account.setName("Composite API Batch");
    final CreateSObjectResult result = template.requestBody("salesforce:createSObject", account, CreateSObjectResult.class);
    accountId = result.getId();
}
Also used : Account(org.apache.camel.component.salesforce.dto.generated.Account) CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) Before(org.junit.Before)

Example 7 with CreateSObjectResult

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

use of org.apache.camel.component.salesforce.api.dto.CreateSObjectResult in project camel by apache.

the class CompoundTypesIntegrationTest method doTestTypes.

private void doTestTypes(String suffix) {
    Account account = new Account();
    account.setName("Camel Test Account");
    account.setBillingCity("San Francisco");
    account.setBillingCountry("USA");
    account.setBillingPostalCode("94105");
    account.setBillingState("CA");
    account.setBillingStreet("1 Market St #300");
    account.setBillingLatitude(37.793779);
    account.setBillingLongitude(-122.39448);
    account.setShippingCity("San Francisco");
    account.setShippingCountry("USA");
    account.setShippingPostalCode("94105");
    account.setShippingState("CA");
    account.setShippingStreet("1 Market St #300");
    account.setShippingLatitude(37.793779);
    account.setShippingLongitude(-122.39448);
    account.setShipping_Location__Latitude__s(37.793779);
    account.setShipping_Location__Longitude__s(-122.39448);
    CreateSObjectResult result = template().requestBody("direct:createSObject" + suffix, account, CreateSObjectResult.class);
    assertNotNull(result);
    assertTrue("Create success", result.getSuccess());
    LOG.debug("Create: " + result);
    try {
        // get account with compound fields
        account = template().requestBody("direct:getSObject" + suffix, result.getId(), Account.class);
        assertNotNull(account);
        assertNotNull("Billing Address", account.getBillingAddress());
        assertNotNull("Shipping Address", account.getShippingAddress());
        assertNotNull("Shipping Location", account.getShippingAddress());
        LOG.debug("Retrieved fields billing address: {}, shipping location: {}", account.getBillingAddress(), account.getShipping_Location__c());
    } finally {
        // delete the test SObject
        assertNull(template().requestBody("direct:deleteSObject" + suffix, result.getId()));
        LOG.debug("Delete successful");
    }
}
Also used : Account(org.apache.camel.component.salesforce.dto.generated.Account) CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult)

Example 9 with CreateSObjectResult

use of org.apache.camel.component.salesforce.api.dto.CreateSObjectResult in project camel by apache.

the class RestApiIntegrationTest method testCreateUpdateDeleteTasks.

@Test
public void testCreateUpdateDeleteTasks() throws Exception {
    final Task taken = new Task();
    taken.setDescription("Task1");
    taken.setActivityDate(ZonedDateTime.of(1700, 1, 2, 3, 4, 5, 6, ZoneId.systemDefault()));
    final CreateSObjectResult result = template().requestBody("direct:createSObject", taken, CreateSObjectResult.class);
    assertNotNull(result);
    assertTrue("Create success", result.getSuccess());
    // test JSON update
    // make the plane cheaper
    taken.setId(result.getId());
    taken.setActivityDate(ZonedDateTime.of(1991, 1, 2, 3, 4, 5, 6, ZoneId.systemDefault()));
    assertNull(template().requestBodyAndHeader("direct:updateSObject", taken, SalesforceEndpointConfig.SOBJECT_ID, result.getId()));
    // delete the newly created SObject
    assertNull(template().requestBody("direct:deleteSObjectTaken", result.getId()));
}
Also used : Task(org.apache.camel.component.salesforce.dto.generated.Task) CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) Test(org.junit.Test)

Example 10 with CreateSObjectResult

use of org.apache.camel.component.salesforce.api.dto.CreateSObjectResult in project camel by apache.

the class RestApiIntegrationTest method testCreateUpdateDeleteWithId.

@Test
public void testCreateUpdateDeleteWithId() throws Exception {
    Line_Item__c lineItem = new Line_Item__c();
    final String lineItemId = String.valueOf(TEST_LINE_ITEM_ID.incrementAndGet());
    lineItem.setName(lineItemId);
    CreateSObjectResult result = template().requestBody("direct:createLineItem", lineItem, CreateSObjectResult.class);
    assertNotNull(result);
    assertTrue(result.getSuccess());
    // get line item with Name 1
    lineItem = template().requestBody("direct:getSObjectWithId", lineItemId, Line_Item__c.class);
    assertNotNull(lineItem);
    // test insert with id
    // set the unit price and sold
    lineItem.setUnit_Price__c(1000.0);
    lineItem.setUnits_Sold__c(50.0);
    // update line item with Name NEW_LINE_ITEM_ID
    final String newLineItemId = String.valueOf(NEW_LINE_ITEM_ID.incrementAndGet());
    lineItem.setName(newLineItemId);
    result = template().requestBodyAndHeader("direct:upsertSObject", lineItem, SalesforceEndpointConfig.SOBJECT_EXT_ID_VALUE, newLineItemId, CreateSObjectResult.class);
    assertNotNull(result);
    assertTrue(result.getSuccess());
    // clear read only parent type fields
    lineItem.setInvoice_Statement__c(null);
    lineItem.setMerchandise__c(null);
    // change the units sold
    lineItem.setUnits_Sold__c(25.0);
    // update line item with Name NEW_LINE_ITEM_ID
    result = template().requestBodyAndHeader("direct:upsertSObject", lineItem, SalesforceEndpointConfig.SOBJECT_EXT_ID_VALUE, newLineItemId, CreateSObjectResult.class);
    assertNull(result);
    // delete the SObject with Name NEW_LINE_ITEM_ID
    assertNull(template().requestBody("direct:deleteSObjectWithId", newLineItemId));
}
Also used : CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) QueryRecordsLine_Item__c(org.apache.camel.component.salesforce.dto.generated.QueryRecordsLine_Item__c) Line_Item__c(org.apache.camel.component.salesforce.dto.generated.Line_Item__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