Search in sources :

Example 1 with Merchandise__c

use of org.apache.camel.component.salesforce.dto.generated.Merchandise__c 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 2 with Merchandise__c

use of org.apache.camel.component.salesforce.dto.generated.Merchandise__c 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 3 with Merchandise__c

use of org.apache.camel.component.salesforce.dto.generated.Merchandise__c 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)

Example 4 with Merchandise__c

use of org.apache.camel.component.salesforce.dto.generated.Merchandise__c in project camel by apache.

the class RestApiIntegrationTest method testApexCall.

@Test
public void testApexCall() throws Exception {
    // request merchandise with id in URI template
    Merchandise__c merchandise = template().requestBodyAndHeader("direct:apexCallGet", null, "id", testId, Merchandise__c.class);
    assertNotNull(merchandise);
    // request merchandise with id as query param
    merchandise = template().requestBodyAndHeader("direct:apexCallGetWithId", null, SalesforceEndpointConfig.APEX_QUERY_PARAM_PREFIX + "id", testId, Merchandise__c.class);
    assertNotNull(merchandise);
    // patch merchandise
    // clear fields that won't be modified
    merchandise.clearBaseFields();
    merchandise.setId(testId);
    merchandise.setPrice__c(null);
    merchandise.setTotal_Inventory__c(null);
    merchandise = template().requestBody("direct:apexCallPatch", new MerchandiseRequest(merchandise), Merchandise__c.class);
    assertNotNull(merchandise);
}
Also used : Merchandise__c(org.apache.camel.component.salesforce.dto.generated.Merchandise__c) Test(org.junit.Test)

Example 5 with Merchandise__c

use of org.apache.camel.component.salesforce.dto.generated.Merchandise__c in project camel by apache.

the class SalesforceComponentConfigurationIntegrationTest method testEndpointCompletion.

@Test
public void testEndpointCompletion() throws Exception {
    Component component = context().getComponent(componentName);
    ComponentConfiguration configuration = component.createComponentConfiguration();
    // get operation names
    assertCompletionOptions(configuration.completeEndpointPath(""), "getVersions", "getResources", "getGlobalObjects", "getBasicInfo", "getDescription", "getSObject", "createSObject", "updateSObject", "deleteSObject", "getSObjectWithId", "upsertSObject", "deleteSObjectWithId", "getBlobField", "query", "queryMore", "queryAll", "search", "apexCall", "recent", "createJob", "getJob", "closeJob", "abortJob", "createBatch", "getBatch", "getAllBatches", "getRequest", "getResults", "createBatchQuery", "getQueryResultIds", "getQueryResult", "getRecentReports", "getReportDescription", "executeSyncReport", "executeAsyncReport", "getReportInstances", "getReportResults", "limits", "approval", "approvals", "composite-batch", "composite-tree", "[PushTopicName]");
    // get filtered operation names
    assertCompletionOptions(configuration.completeEndpointPath("get"), "getVersions", "getResources", "getGlobalObjects", "getBasicInfo", "getDescription", "getSObject", "getSObjectWithId", "getBlobField", "getJob", "getBatch", "getAllBatches", "getRequest", "getResults", "getQueryResultIds", "getQueryResult", "getRecentReports", "getReportDescription", "getReportInstances", "getReportResults");
    /* TODO support parameter completion
        // get ALL REST operation parameters
        // TODO support operation specific parameter completion
        assertCompletionOptions(configuration.completeEndpointPath("getSObject?"),
            "apiVersion", "httpClient", "format", "sObjectName", "sObjectId", "sObjectFields",
            "sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch");

        // get filtered REST parameters
        assertCompletionOptions(configuration.completeEndpointPath("getSObject?format=XML&"),
            "apiVersion", "httpClient", "sObjectName", "sObjectId", "sObjectFields",
            "sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch");

        // get ALL Bulk operation parameters
        // TODO support operation specific parameter completion
        assertCompletionOptions(configuration.completeEndpointPath("createJob?"),
            "apiVersion", "httpClient", "sObjectQuery", "contentType", "jobId", "batchId", "resultId");

        // get filtered Bulk operation parameters
        assertCompletionOptions(configuration.completeEndpointPath("createJob?contentType=XML&"),
            "apiVersion", "httpClient", "sObjectQuery", "jobId", "batchId", "resultId");

        // get ALL topic parameters for consumers
        assertCompletionOptions(configuration.completeEndpointPath("myTopic?"),
            "apiVersion", "httpClient", "updateTopic", "notifyForFields", "notifyForOperations");

        // get filtered topic parameters for consumers
        assertCompletionOptions(configuration.completeEndpointPath("myTopic?updateTopic=true&"),
            "apiVersion", "httpClient", "notifyForFields", "notifyForOperations");

        // get parameters from partial name
        assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObject"),
            "sObjectName", "sObjectId", "sObjectFields",
            "sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch");
*/
    // get sObjectName values, from scanned DTO packages
    assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObjectName="), "Account", "Asset", "Contact", "Task", "Line_Item__c", "Merchandise__c", "Document", "MSPTest");
    // get sObjectFields values, from scanned DTO
    assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObjectName=Merchandise__c&sObjectFields="), "Description__c", "Price__c", "Total_Inventory__c", "attributes", "Id", "OwnerId", "IsDeleted", "Name", "CreatedDate", "CreatedById", "LastModifiedDate", "LastModifiedById", "SystemModstamp", "LastActivityDate", "LastViewedDate", "LastReferencedDate");
    // get sObjectClass values, from scanned DTO packages
    assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObjectClass="), Account.class.getName(), Asset.class.getName(), Contact.class.getName(), Task.class.getName(), Line_Item__c.class.getName(), Merchandise__c.class.getName(), Document.class.getName(), MSPTest.class.getName(), QueryRecordsLine_Item__c.class.getName());
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) Account(org.apache.camel.component.salesforce.dto.generated.Account) Task(org.apache.camel.component.salesforce.dto.generated.Task) Line_Item__c(org.apache.camel.component.salesforce.dto.generated.Line_Item__c) QueryRecordsLine_Item__c(org.apache.camel.component.salesforce.dto.generated.QueryRecordsLine_Item__c) Asset(org.apache.camel.component.salesforce.dto.generated.Asset) Merchandise__c(org.apache.camel.component.salesforce.dto.generated.Merchandise__c) Component(org.apache.camel.Component) Document(org.apache.camel.component.salesforce.dto.generated.Document) MSPTest(org.apache.camel.component.salesforce.dto.generated.MSPTest) Contact(org.apache.camel.component.salesforce.dto.generated.Contact) QueryRecordsLine_Item__c(org.apache.camel.component.salesforce.dto.generated.QueryRecordsLine_Item__c) Test(org.junit.Test) MSPTest(org.apache.camel.component.salesforce.dto.generated.MSPTest)

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