Search in sources :

Example 1 with CreateSObjectResult

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

the class AbstractApprovalIntegrationTest method createAccounts.

@Before
public void createAccounts() {
    final List<Account> accountsToCreate = IntStream.range(0, accountCount + 1).mapToObj(idx -> {
        final String name = "test-account-" + idx;
        final Account account = new Account();
        account.setName(name);
        return account;
    }).collect(Collectors.toList());
    accountIds = accountsToCreate.stream().map(account -> template.requestBody("salesforce:createSObject?sObjectName=Account", account, CreateSObjectResult.class)).map(CreateSObjectResult::getId).collect(Collectors.toList());
}
Also used : IntStream(java.util.stream.IntStream) List(java.util.List) After(org.junit.After) IOException(java.io.IOException) CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) QueryRecordsReport(org.apache.camel.component.salesforce.api.dto.analytics.reports.QueryRecordsReport) Account(org.apache.camel.component.salesforce.dto.generated.Account) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Before(org.junit.Before) Account(org.apache.camel.component.salesforce.dto.generated.Account) CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) Before(org.junit.Before)

Example 2 with CreateSObjectResult

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

the class PushTopicHelper method createTopic.

private void createTopic() throws CamelException {
    final PushTopic topic = new PushTopic();
    topic.setName(topicName);
    topic.setApiVersion(Double.valueOf(config.getApiVersion()));
    topic.setQuery(config.getSObjectQuery());
    topic.setDescription("Topic created by Camel Salesforce component");
    topic.setNotifyForFields(config.getNotifyForFields());
    if (preApi29) {
        topic.setNotifyForOperations(config.getNotifyForOperations());
    } else {
        topic.setNotifyForOperationCreate(config.getNotifyForOperationCreate());
        topic.setNotifyForOperationDelete(config.getNotifyForOperationDelete());
        topic.setNotifyForOperationUndelete(config.getNotifyForOperationUndelete());
        topic.setNotifyForOperationUpdate(config.getNotifyForOperationUpdate());
    }
    LOG.info("Creating Topic {}: {}", topicName, topic);
    final SyncResponseCallback callback = new SyncResponseCallback();
    try {
        restClient.createSObject(PUSH_TOPIC_OBJECT_NAME, new ByteArrayInputStream(OBJECT_MAPPER.writeValueAsBytes(topic)), callback);
        if (!callback.await(API_TIMEOUT, TimeUnit.SECONDS)) {
            throw new SalesforceException("API call timeout!", null);
        }
        final SalesforceException callbackException = callback.getException();
        if (callbackException != null) {
            throw callbackException;
        }
        CreateSObjectResult result = OBJECT_MAPPER.readValue(callback.getResponse(), CreateSObjectResult.class);
        if (!result.getSuccess()) {
            final SalesforceException salesforceException = new SalesforceException(result.getErrors(), HttpStatus.BAD_REQUEST_400);
            throw new CamelException(String.format("Error creating Topic %s: %s", topicName, result.getErrors()), salesforceException);
        }
    } catch (SalesforceException e) {
        throw new CamelException(String.format("Error creating Topic %s: %s", topicName, e.getMessage()), e);
    } catch (IOException e) {
        throw new CamelException(String.format("Un-marshaling error creating Topic %s: %s", topicName, e.getMessage()), e);
    } catch (InterruptedException e) {
        throw new CamelException(String.format("Un-marshaling error creating Topic %s: %s", topicName, e.getMessage()), e);
    } finally {
        if (callback.getResponse() != null) {
            try {
                callback.getResponse().close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
}
Also used : PushTopic(org.apache.camel.component.salesforce.internal.dto.PushTopic) QueryRecordsPushTopic(org.apache.camel.component.salesforce.internal.dto.QueryRecordsPushTopic) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) ByteArrayInputStream(java.io.ByteArrayInputStream) CamelException(org.apache.camel.CamelException) IOException(java.io.IOException) SyncResponseCallback(org.apache.camel.component.salesforce.internal.client.SyncResponseCallback)

Example 3 with CreateSObjectResult

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

the class RestApiIntegrationTest method setupData.

@Before
public void setupData() {
    final Merchandise__c merchandise = new Merchandise__c();
    merchandise.setName("Test Merchandise");
    merchandise.setPrice__c(10.0);
    merchandise.setTotal_Inventory__c(100.0);
    final CreateSObjectResult result = template().requestBody("salesforce:createSObject", merchandise, CreateSObjectResult.class);
    testId = result.getId();
}
Also used : CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) Merchandise__c(org.apache.camel.component.salesforce.dto.generated.Merchandise__c) Before(org.junit.Before)

Example 4 with CreateSObjectResult

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

the class RestApiIntegrationTest method testStatus400.

@Test
public void testStatus400() throws Exception {
    // get test merchandise
    // note that the header value overrides sObjectFields in endpoint
    final Merchandise__c merchandise = template().requestBodyAndHeader("direct:getSObject", testId, "sObjectFields", "Description__c,Price__c", Merchandise__c.class);
    assertNotNull(merchandise);
    assertNotNull(merchandise.getPrice__c());
    assertNull(merchandise.getTotal_Inventory__c());
    merchandise.clearBaseFields();
    // required field Total_Inventory__c is missing
    CreateSObjectResult result = null;
    try {
        result = template().requestBody("direct:createSObject", merchandise, CreateSObjectResult.class);
        fail("Expected SalesforceException with statusCode 400");
    } catch (final CamelExecutionException e) {
        assertTrue(e.getCause() instanceof SalesforceException);
        assertTrue(e.getCause().getCause() instanceof SalesforceException);
        final SalesforceException cause = (SalesforceException) e.getCause().getCause();
        assertEquals(400, cause.getStatusCode());
        assertEquals(1, cause.getErrors().size());
        assertEquals("[Total_Inventory__c]", cause.getErrors().get(0).getFields().toString());
    } finally {
        // delete the clone if created
        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) Test(org.junit.Test)

Example 5 with CreateSObjectResult

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

the class RestApiIntegrationTest method testCreateUpdateDelete.

@Test
public void testCreateUpdateDelete() throws Exception {
    final Merchandise__c merchandise = new Merchandise__c();
    merchandise.setName("Wee Wee Wee Plane");
    merchandise.setDescription__c("Microlite plane");
    merchandise.setPrice__c(2000.0);
    merchandise.setTotal_Inventory__c(50.0);
    final CreateSObjectResult result = template().requestBody("direct:createSObject", merchandise, CreateSObjectResult.class);
    assertNotNull(result);
    assertTrue("Create success", result.getSuccess());
    // test JSON update
    // make the plane cheaper
    merchandise.setPrice__c(1500.0);
    // change inventory to half
    merchandise.setTotal_Inventory__c(25.0);
    // also need to set the Id
    merchandise.setId(result.getId());
    assertNull(template().requestBodyAndHeader("direct:updateSObject", merchandise, SalesforceEndpointConfig.SOBJECT_ID, result.getId()));
    // delete the newly created SObject
    assertNull(template().requestBody("direct:deleteSObject", result.getId()));
}
Also used : CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) 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