Search in sources :

Example 1 with SObjectBatchResult

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

the class CompositeApiBatchIntegrationTest method shouldSupportRelatedObjectRetrieval.

@Test
public void shouldSupportRelatedObjectRetrieval() throws IOException {
    if (Version.create(version).compareTo(Version.create("36.0")) < 0) {
        return;
    }
    final SObjectBatch batch = new SObjectBatch("36.0");
    batch.addGetRelated("Account", accountId, "CreatedBy");
    final SObjectBatchResponse response = testBatch(batch);
    final List<SObjectBatchResult> results = response.getResults();
    final SObjectBatchResult batchResult = results.get(0);
    @SuppressWarnings("unchecked") final Map<String, Object> result = (Map<String, Object>) batchResult.getResult();
    // JSON and XML structure are different, XML has `User` node, JSON does not
    @SuppressWarnings("unchecked") final Map<String, String> data = (Map<String, String>) result.getOrDefault("User", result);
    final SalesforceLoginConfig loginConfig = LoginConfigHelper.getLoginConfig();
    assertEquals(loginConfig.getUserName(), data.get("Username"));
}
Also used : SObjectBatchResponse(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResponse) SObjectBatch(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatch) SObjectBatchResult(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResult) Map(java.util.Map) Test(org.junit.Test)

Example 2 with SObjectBatchResult

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

the class CompositeApiBatchIntegrationTest method shouldSupportObjectCreation.

@Test
public void shouldSupportObjectCreation() {
    final SObjectBatch batch = new SObjectBatch(version);
    final Account newAccount = new Account();
    newAccount.setName("Account created from Composite batch API");
    batch.addCreate(newAccount);
    final SObjectBatchResponse response = testBatch(batch);
    final List<SObjectBatchResult> results = response.getResults();
    final SObjectBatchResult batchResult = results.get(0);
    @SuppressWarnings("unchecked") final Map<String, Object> result = (Map<String, Object>) batchResult.getResult();
    // JSON and XML structure are different, XML has `Result` node, JSON does not
    @SuppressWarnings("unchecked") final Map<String, Object> creationOutcome = (Map<String, Object>) result.getOrDefault("Result", result);
    assertNotNull(creationOutcome.get("id"));
}
Also used : Account(org.apache.camel.component.salesforce.dto.generated.Account) SObjectBatchResponse(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResponse) SObjectBatch(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatch) SObjectBatchResult(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResult) Map(java.util.Map) Test(org.junit.Test)

Example 3 with SObjectBatchResult

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

the class CompositeApiBatchIntegrationTest method shouldSupportSearch.

@Test
public void shouldSupportSearch() {
    final SObjectBatch batch = new SObjectBatch(version);
    // we cannot rely on search returning the `Composite API Batch` account as the search indexer runs
    // asynchronously to object creation, so that account might not be indexed at this time, so we search for
    // `United` Account that should be created with developer instance
    batch.addSearch("FIND {United} IN Name Fields RETURNING Account (Name)");
    final SObjectBatchResponse response = testBatch(batch);
    final List<SObjectBatchResult> results = response.getResults();
    final SObjectBatchResult batchResult = results.get(0);
    final Object firstBatchResult = batchResult.getResult();
    final Object searchResult;
    if (firstBatchResult instanceof Map) {
        // the JSON and XML responses differ, XML has a root node which can be either SearchResults or
        // SearchResultWithMetadata
        // furthermore version 37.0 search results are no longer array, but dictionary of {
        // "searchRecords": [<array>] } and the XML output changed to <SearchResultWithMetadata><searchRecords>, so
        // we have:
        // @formatter:off
        // | version | format | response syntax                                                       |
        // |    34   |  JSON  | {attributes={type=Account...                                          |
        // |    34   |  XML   | {SearchResults={attributes={type=Account...                           |
        // |    37   |  JSON  | {searchRecords=[{attributes={type=Account...                          |
        // |    37   |  XML   | {SearchResultWithMetadata={searchRecords={attributes={type=Account... |
        // @formatter:on
        @SuppressWarnings("unchecked") final Map<String, Object> tmp = (Map<String, Object>) firstBatchResult;
        @SuppressWarnings("unchecked") final Map<String, Object> nested = (Map<String, Object>) tmp.getOrDefault("SearchResultWithMetadata", tmp);
        // JSON and XML structure are different, XML has `SearchResults` node, JSON does not
        searchResult = nested.getOrDefault("searchRecords", nested.getOrDefault("SearchResults", nested));
    } else {
        searchResult = firstBatchResult;
    }
    final Map<String, Object> result;
    if (searchResult instanceof List) {
        @SuppressWarnings("unchecked") final Map<String, Object> tmp = (Map<String, Object>) ((List) searchResult).get(0);
        result = tmp;
    } else {
        @SuppressWarnings("unchecked") final Map<String, Object> tmp = (Map<String, Object>) searchResult;
        result = tmp;
    }
    assertNotNull(result.get("Name"));
}
Also used : SObjectBatchResponse(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResponse) SObjectBatch(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatch) SObjectBatchResult(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResult) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 4 with SObjectBatchResult

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

the class CompositeApiBatchIntegrationTest method shouldSupportLimits.

@Test
public void shouldSupportLimits() {
    final SObjectBatch batch = new SObjectBatch(version);
    batch.addLimits();
    final SObjectBatchResponse response = testBatch(batch);
    final List<SObjectBatchResult> results = response.getResults();
    final SObjectBatchResult batchResult = results.get(0);
    @SuppressWarnings("unchecked") final Map<String, Object> result = (Map<String, Object>) batchResult.getResult();
    // JSON and XML structure are different, XML has `LimitsSnapshot` node, JSON does not
    @SuppressWarnings("unchecked") final Map<String, Object> limits = (Map<String, Object>) result.getOrDefault("LimitsSnapshot", result);
    @SuppressWarnings("unchecked") final Map<String, String> apiRequests = (Map<String, String>) limits.get("DailyApiRequests");
    // for JSON value will be Integer, for XML (no type information) it will be String
    assertEquals("15000", String.valueOf(apiRequests.get("Max")));
}
Also used : SObjectBatchResponse(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResponse) SObjectBatch(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatch) SObjectBatchResult(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResult) Map(java.util.Map) Test(org.junit.Test)

Example 5 with SObjectBatchResult

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

the class CompositeApiBatchIntegrationTest method shouldSupportQuery.

@Test
public void shouldSupportQuery() {
    final SObjectBatch batch = new SObjectBatch(version);
    batch.addQuery("SELECT Id, Name FROM Account");
    final SObjectBatchResponse response = testBatch(batch);
    final List<SObjectBatchResult> results = response.getResults();
    final SObjectBatchResult batchResult = results.get(0);
    @SuppressWarnings("unchecked") final Map<String, Object> result = (Map<String, Object>) batchResult.getResult();
    // JSON and XML structure are different, XML has `QueryResult` node, JSON does not
    @SuppressWarnings("unchecked") final Map<String, String> data = (Map<String, String>) result.getOrDefault("QueryResult", result);
    assertNotNull(data.get("totalSize"));
}
Also used : SObjectBatchResponse(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResponse) SObjectBatch(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatch) SObjectBatchResult(org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResult) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Map (java.util.Map)7 SObjectBatch (org.apache.camel.component.salesforce.api.dto.composite.SObjectBatch)7 SObjectBatchResponse (org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResponse)7 SObjectBatchResult (org.apache.camel.component.salesforce.api.dto.composite.SObjectBatchResult)7 Test (org.junit.Test)7 List (java.util.List)1 Account (org.apache.camel.component.salesforce.dto.generated.Account)1