camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] camel git commit: CAMEL-8396 Update Salesforce component to support new REST APIs in Sa...
Date Thu, 24 Nov 2016 08:31:57 GMT
http://git-wip-us.apache.org/repos/asf/camel/blob/b47de2b4/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/ApprovalIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/ApprovalIntegrationTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/ApprovalIntegrationTest.java
new file mode 100644
index 0000000..47d71d5
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/ApprovalIntegrationTest.java
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.salesforce.api.dto.approval.ApprovalRequest;
+import org.apache.camel.component.salesforce.api.dto.approval.ApprovalRequest.Action;
+import org.apache.camel.component.salesforce.api.dto.approval.ApprovalResult;
+import org.apache.camel.component.salesforce.api.dto.approval.Approvals;
+import org.apache.camel.component.salesforce.api.dto.approval.Approvals.Info;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class ApprovalIntegrationTest extends AbstractApprovalIntegrationTest {
+
+    private final String format;
+
+    public ApprovalIntegrationTest(final String format) {
+        super(5);
+        this.format = format;
+    }
+
+    @Parameters(name = "format = {0}")
+    public static Iterable<String> formats() {
+        return Arrays.asList("JSON", "XML");
+    }
+
+    @Test
+    public void shouldSubmitAndFetchApprovals() {
+        final ApprovalResult approvalResult = template.requestBody(
+                String.format(
+                        "salesforce:approval?"//
+                            + "format=%s"//
+                            + "&approvalActionType=Submit"//
+                            + "&approvalContextId=%s"//
+                            + "&approvalNextApproverIds=%s"//
+                            + "&approvalComments=Integration test"//
+                            + "&approvalProcessDefinitionNameOrId=Test_Account_Process",
+                        format, accountIds.get(0), userId),
+                NOT_USED, ApprovalResult.class);
+
+        assertNotNull("Approval should have resulted in value", approvalResult);
+
+        assertEquals("There should be one Account waiting approval", 1, approvalResult.size());
+
+        assertEquals("Instance status of the item in approval result should be `Pending`",
"Pending",
+                approvalResult.iterator().next().getInstanceStatus());
+
+        // as it stands on 18.11.2016. the GET method on /vXX.X/process/approvals/ with Accept
other than
+        // `application/json` results in HTTP status 500, so only JSON is supported
+        final Approvals approvals = template.requestBody("salesforce:approvals", NOT_USED,
Approvals.class);
+
+        assertNotNull("Approvals should be fetched", approvals);
+
+        final List<Info> accountApprovals = approvals.approvalsFor("Account");
+        assertEquals("There should be one Account waiting approval", 1, accountApprovals.size());
+    }
+
+    @Test
+    public void shouldSubmitBulkApprovals() {
+        final List<ApprovalRequest> approvalRequests = accountIds.stream().map(id ->
{
+            final ApprovalRequest request = new ApprovalRequest();
+            request.setContextId(id);
+            request.setComments("Approval for " + id);
+            request.setActionType(Action.Submit);
+
+            return request;
+        }).collect(Collectors.toList());
+
+        final ApprovalResult approvalResult = template.requestBody(
+                String.format("salesforce:approval?"//
+                    + "format=%s"//
+                    + "&approvalActionType=Submit"//
+                    + "&approvalNextApproverIds=%s"//
+                    + "&approvalProcessDefinitionNameOrId=Test_Account_Process", format,
userId),
+                approvalRequests, ApprovalResult.class);
+
+        assertEquals("Should have same number of approval results as requests", approvalRequests.size(),
+                approvalResult.size());
+    }
+
+    @Override
+    protected RouteBuilder doCreateRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b47de2b4/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentConfigurationIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentConfigurationIntegrationTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentConfigurationIntegrationTest.java
index db9acc8..92c353d 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentConfigurationIntegrationTest.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentConfigurationIntegrationTest.java
@@ -103,10 +103,10 @@ public class SalesforceComponentConfigurationIntegrationTest extends
CamelTestSu
         assertCompletionOptions(configuration.completeEndpointPath(""),
             "getVersions", "getResources", "getGlobalObjects", "getBasicInfo", "getDescription",
"getSObject", "createSObject",
             "updateSObject", "deleteSObject", "getSObjectWithId", "upsertSObject", "deleteSObjectWithId",
"getBlobField",
-            "query", "queryMore", "queryAll", "search", "apexCall", "createJob", "getJob",
"closeJob", "abortJob",
+            "query", "queryMore", "queryAll", "search", "apexCall", "recent", "createJob",
"getJob", "closeJob", "abortJob",
             "createBatch", "getBatch", "getAllBatches", "getRequest", "getResults", "createBatchQuery",
"getQueryResultIds",
             "getQueryResult", "getRecentReports", "getReportDescription", "executeSyncReport",
"executeAsyncReport",
-            "getReportInstances", "getReportResults", "[PushTopicName]"
+            "getReportInstances", "getReportResults", "limits", "approval", "approvals",
"[PushTopicName]"
         );
 
         // get filtered operation names

http://git-wip-us.apache.org/repos/asf/camel/blob/b47de2b4/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalRequestTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalRequestTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalRequestTest.java
new file mode 100644
index 0000000..b331952
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalRequestTest.java
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.dto.approval;
+
+import java.util.Collections;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.thoughtworks.xstream.XStream;
+
+import org.apache.camel.component.salesforce.api.dto.approval.ApprovalRequest.Action;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.hamcrest.core.CombinableMatcher.both;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+public class ApprovalRequestTest {
+
+    private final ApprovalRequest sampleRequest;
+
+    public ApprovalRequestTest() {
+        sampleRequest = new ApprovalRequest();
+
+        sampleRequest.setActionType(Action.Submit);
+        sampleRequest.setContextId("001D000000I8mIm");
+        sampleRequest.addNextApproverId("005D00000015rY9");
+        sampleRequest.setComments("this is a test");
+        sampleRequest.setContextActorId("005D00000015rZy");
+        sampleRequest.setProcessDefinitionNameOrId("PTO_Request_Process");
+        sampleRequest.setSkipEntryCriteria(true);
+
+    }
+
+    @Test
+    public void shouldApplyValuesFromTemplate() {
+        final ApprovalRequest request = new ApprovalRequest();
+        request.setActionType(Action.Approve);
+        request.setComments("Comment");
+        request.setContextId("Context Id");
+
+        final ApprovalRequest template = new ApprovalRequest();
+        template.setActionType(Action.Reject);
+        template.setComments("Template comment");
+        template.setNextApproverIds(Collections.singletonList("Next approver "));
+
+        final ApprovalRequest combined = request.applyTemplate(template);
+
+        assertThat("Combined approval request should be a new instance", combined,
+                both(not(sameInstance(request))).and(not(sameInstance(template))));
+
+        assertEquals("Action type should not be overwriten", request.getActionType(), combined.getActionType());
+        assertEquals("Comment should not be overwriten", request.getComments(), combined.getComments());
+        assertEquals("Context id should not be overwriten", request.getContextId(), combined.getContextId());
+        assertEquals("Next approver id should be taken from template", template.getNextApproverIds(),
+                combined.getNextApproverIds());
+    }
+
+    @Test
+    public void shouldSerializeAsJson() throws JsonProcessingException {
+        final ObjectMapper mapper = new ObjectMapper();
+
+        final String json = mapper.writerFor(ApprovalRequest.class).writeValueAsString(sampleRequest);
+
+        assertEquals("ApprovalRequest should serialize as JSON from Salesforce examples",
+                "{\"actionType\":\"Submit\",\"contextActorId\":\"005D00000015rZy\",\"contextId\":\"001D000000I8mIm\""
+                    + ",\"comments\":\"this is a test\",\"nextApproverIds\":[\"005D00000015rY9\"],"
+                    + "\"processDefinitionNameOrId\":\"PTO_Request_Process\",\"skipEntryCriteria\":true}",
+                json);
+    }
+
+    @Test
+    public void shouldSerializeAsXml() {
+        final XStream xStream = new XStream();
+        xStream.processAnnotations(ApprovalRequest.class);
+
+        final String xml = xStream.toXML(sampleRequest);
+
+        assertEquals("ApprovalRequest should serialize as XML",
+                "<requests>\n"//
+                    + "  <actionType>Submit</actionType>\n"//
+                    + "  <contextActorId>005D00000015rZy</contextActorId>\n"//
+                    + "  <contextId>001D000000I8mIm</contextId>\n"//
+                    + "  <comments>this is a test</comments>\n"//
+                    + "  <nextApproverIds>005D00000015rY9</nextApproverIds>\n"//
+                    + "  <processDefinitionNameOrId>PTO_Request_Process</processDefinitionNameOrId>\n"//
+                    + "  <skipEntryCriteria>true</skipEntryCriteria>\n"//
+                    + "</requests>",
+                xml);
+    }
+
+    @Test
+    public void shouldTolerateNullTemplates() {
+        final ApprovalRequest request = new ApprovalRequest();
+
+        final ApprovalRequest appliedTo = request.applyTemplate(null);
+
+        assertThat("For null templates applyTemplate should return same object", appliedTo,
sameInstance(request));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b47de2b4/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalRequestsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalRequestsTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalRequestsTest.java
new file mode 100644
index 0000000..a63959b
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalRequestsTest.java
@@ -0,0 +1,133 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.dto.approval;
+
+import java.io.Writer;
+import java.util.Arrays;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+import com.thoughtworks.xstream.io.naming.NoNameCoder;
+import com.thoughtworks.xstream.io.xml.CompactWriter;
+import com.thoughtworks.xstream.io.xml.XppDriver;
+
+import org.apache.camel.component.salesforce.api.dto.approval.ApprovalRequest.Action;
+import org.apache.camel.component.salesforce.api.utils.DateTimeConverter;
+import org.apache.camel.component.salesforce.internal.client.XStreamUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ApprovalRequestsTest {
+
+    private final ApprovalRequests requests;
+
+    public ApprovalRequestsTest() {
+        final String actorId = "005D00000015rZy";
+
+        final ApprovalRequest request1 = new ApprovalRequest();
+        request1.setActionType(Action.Submit);
+        request1.setContextId("001D000000I8mIm");
+        request1.setNextApproverIds("005D00000015rY9");
+        request1.setComments("this is a test 1");
+        request1.setContextActorId(actorId);
+        request1.setProcessDefinitionNameOrId("PTO_Request_Process");
+        request1.setSkipEntryCriteria(true);
+
+        final ApprovalRequest request2 = new ApprovalRequest();
+        request2.setActionType(Action.Submit);
+        request2.setContextId("001D000000I8dIm");
+        request2.setNextApproverIds("005D00000015xY9");
+        request2.setComments("this is a test 2");
+        request2.setContextActorId(actorId);
+        request2.setProcessDefinitionNameOrId("PTO_Request_Process");
+        request2.setSkipEntryCriteria(true);
+
+        requests = new ApprovalRequests(Arrays.asList(request1, request2));
+    }
+
+    @Test
+    public void shouldSerializeAsJson() throws JsonProcessingException {
+        final String json = "{\"requests\":["//
+            + "{"//
+            + "\"actionType\":\"Submit\","//
+            + "\"contextActorId\":\"005D00000015rZy\","//
+            + "\"contextId\":\"001D000000I8mIm\","//
+            + "\"comments\":\"this is a test 1\","//
+            + "\"nextApproverIds\":[\"005D00000015rY9\"],"//
+            + "\"processDefinitionNameOrId\":\"PTO_Request_Process\","//
+            + "\"skipEntryCriteria\":true"//
+            + "},{"//
+            + "\"actionType\":\"Submit\","//
+            + "\"contextActorId\":\"005D00000015rZy\","//
+            + "\"contextId\":\"001D000000I8dIm\","//
+            + "\"comments\":\"this is a test 2\","//
+            + "\"nextApproverIds\":[\"005D00000015xY9\"],"//
+            + "\"processDefinitionNameOrId\":\"PTO_Request_Process\","//
+            + "\"skipEntryCriteria\":true"//
+            + "}"//
+            + "]}";
+
+        final ObjectMapper mapper = new ObjectMapper();
+
+        final String serialized = mapper.writerFor(ApprovalRequests.class).writeValueAsString(requests);
+
+        assertEquals("Approval requests should serialize as JSON", json, serialized);
+    }
+
+    @Test
+    public void shouldSerializeAsXml() {
+        final String xml = "<ProcessApprovalRequest>"//
+            + "<requests>"//
+            + "<actionType>Submit</actionType>"//
+            + "<contextActorId>005D00000015rZy</contextActorId>"//
+            + "<contextId>001D000000I8mIm</contextId>"//
+            + "<comments>this is a test 1</comments>"//
+            + "<nextApproverIds>005D00000015rY9</nextApproverIds>"//
+            + "<processDefinitionNameOrId>PTO_Request_Process</processDefinitionNameOrId>"//
+            + "<skipEntryCriteria>true</skipEntryCriteria>"//
+            + "</requests>"//
+            + "<requests>"//
+            + "<actionType>Submit</actionType>"//
+            + "<contextActorId>005D00000015rZy</contextActorId>"//
+            + "<contextId>001D000000I8dIm</contextId>"//
+            + "<comments>this is a test 2</comments>"//
+            + "<nextApproverIds>005D00000015xY9</nextApproverIds>"//
+            + "<processDefinitionNameOrId>PTO_Request_Process</processDefinitionNameOrId>"//
+            + "<skipEntryCriteria>true</skipEntryCriteria>"//
+            + "</requests>"//
+            + "</ProcessApprovalRequest>";
+
+        final XStream xStream = new XStream(new XppDriver(new NoNameCoder()) {
+            @Override
+            public HierarchicalStreamWriter createWriter(final Writer out) {
+                return new CompactWriter(out, getNameCoder());
+            }
+
+        });
+        xStream.ignoreUnknownElements();
+        XStreamUtils.addDefaultPermissions(xStream);
+        xStream.registerConverter(new DateTimeConverter());
+        xStream.processAnnotations(ApprovalRequests.class);
+
+        final String serialized = xStream.toXML(requests);
+
+        assertEquals("Approval requests should serialize as XML", xml, serialized);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b47de2b4/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalResultTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalResultTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalResultTest.java
new file mode 100644
index 0000000..a1d315e
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalResultTest.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.dto.approval;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.thoughtworks.xstream.XStream;
+
+import org.apache.camel.component.salesforce.api.dto.approval.ApprovalResult.Result;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsCollectionContaining.hasItems;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public class ApprovalResultTest {
+
+    private static void assertResponseReadCorrectly(final ApprovalResult results) {
+        final Iterator<Result> resultsIterator = results.iterator();
+        assertTrue("Should deserialize one approval result result", resultsIterator.hasNext());
+
+        final ApprovalResult.Result result = resultsIterator.next();
+
+        assertThat("Should deserialize actorIds", result.getActorIds(), hasItems("0050Y000000u5NOQAY"));
+        assertEquals("Should deserialize entityId", "0010Y000005BYrZQAW", result.getEntityId());
+        assertEquals("Should deserialize instanceId", "04g0Y000000PL53QAG", result.getInstanceId());
+        assertEquals("Should deserialize instanceStatus", "Pending", result.getInstanceStatus());
+        assertThat("Should deserialize newWorkitemIds", result.getNewWorkitemIds(), hasItems("04i0Y000000L0fkQAC"));
+        assertTrue("Should deserialize success", result.isSuccess());
+
+        assertFalse("Should be no more results", resultsIterator.hasNext());
+    }
+
+    @Test
+    public void shouldDeserializeFromJson() throws JsonProcessingException, IOException {
+        final String json = "["//
+            + "{"//
+            + "\"actorIds\":[\"0050Y000000u5NOQAY\"],"//
+            + "\"entityId\":\"0010Y000005BYrZQAW\","//
+            + "\"errors\":null,"//
+            + "\"instanceId\":\"04g0Y000000PL53QAG\","//
+            + "\"instanceStatus\":\"Pending\","//
+            + "\"newWorkitemIds\":[\"04i0Y000000L0fkQAC\"],"//
+            + "\"success\":true"//
+            + "}"//
+            + "]";
+
+        final ObjectMapper mapper = new ObjectMapper();
+
+        final ApprovalResult results = mapper.readerFor(ApprovalResult.class).readValue(json);
+
+        assertResponseReadCorrectly(results);
+    }
+
+    @Test
+    public void shouldDeserializeFromXml() throws InstantiationException, IllegalAccessException
{
+        final ApprovalResult results = new ApprovalResult();
+
+        final XStream xStream = new XStream();
+        xStream.processAnnotations(ApprovalResult.class);
+
+        xStream.fromXML("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"//
+            + "<ProcessApprovalResult>"//
+            + "<ProcessApprovalResult>"//
+            + "<actorIds>0050Y000000u5NOQAY</actorIds>"//
+            + "<entityId>0010Y000005BYrZQAW</entityId>"//
+            + "<instanceId>04g0Y000000PL53QAG</instanceId>"//
+            + "<instanceStatus>Pending</instanceStatus>"//
+            + "<newWorkitemIds>04i0Y000000L0fkQAC</newWorkitemIds>"//
+            + "<success>true</success>"//
+            + "</ProcessApprovalResult>"//
+            + "</ProcessApprovalResult>", results);
+
+        assertResponseReadCorrectly(results);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b47de2b4/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalsTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalsTest.java
new file mode 100644
index 0000000..0943983
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/approval/ApprovalsTest.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.api.dto.approval;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.apache.camel.component.salesforce.api.dto.approval.Approvals.Info;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+public class ApprovalsTest {
+
+    @Test
+    public void shouldDeserialize() throws JsonProcessingException, IOException {
+        final ObjectMapper mapper = new ObjectMapper();
+
+        final Object read = mapper.readerFor(Approvals.class)
+                .readValue("{\n" + //
+                    "  \"approvals\" : {\n" + //
+                    "   \"Account\" : [ {\n" + //
+                    "     \"description\" : null,\n" + //
+                    "     \"id\" : \"04aD00000008Py9\",\n" + //
+                    "     \"name\" : \"Account Approval Process\",\n" + //
+                    "     \"object\" : \"Account\",\n" + //
+                    "     \"sortOrder\" : 1\n" + //
+                    "   } ]\n" + //
+                    "  }\n" + //
+                    "}");
+
+        assertThat("Should deserialize Approvals", read, instanceOf(Approvals.class));
+
+        final Approvals approvals = (Approvals) read;
+
+        final Map<String, List<Info>> approvalsMap = approvals.getApprovals();
+        assertEquals("Deserialized approvals should have one entry", 1, approvalsMap.size());
+
+        final List<Info> accountApprovals = approvalsMap.get("Account");
+        assertNotNull("Deserialized approvals should contain list of `Account` type approvals",
accountApprovals);
+
+        assertEquals("There should be one approval of `Account` type", 1, accountApprovals.size());
+
+        final Info accountInfo = accountApprovals.get(0);
+
+        assertNull("Deserialized `Account` approval should have null description", accountInfo.getDescription());
+        assertEquals("Deserialized `Account` approval should have defined id", "04aD00000008Py9",
accountInfo.getId());
+        assertEquals("Deserialized `Account` approval should have defined name", "Account
Approval Process",
+                accountInfo.getName());
+        assertEquals("Deserialized `Account` approval should have defined object", "Account",
accountInfo.getObject());
+        assertEquals("Deserialized `Account` approval should have defined sortOrder", 1,
accountInfo.getSortOrder());
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b47de2b4/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/internal/processor/AbstractRestProcessorApprovalTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/internal/processor/AbstractRestProcessorApprovalTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/internal/processor/AbstractRestProcessorApprovalTest.java
new file mode 100644
index 0000000..30a7768
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/internal/processor/AbstractRestProcessorApprovalTest.java
@@ -0,0 +1,271 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce.internal.processor;
+
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.salesforce.SalesforceComponent;
+import org.apache.camel.component.salesforce.SalesforceEndpoint;
+import org.apache.camel.component.salesforce.SalesforceEndpointConfig;
+import org.apache.camel.component.salesforce.api.SalesforceException;
+import org.apache.camel.component.salesforce.api.dto.approval.ApprovalRequest;
+import org.apache.camel.component.salesforce.api.dto.approval.ApprovalRequest.Action;
+import org.apache.camel.component.salesforce.api.dto.approval.ApprovalRequests;
+import org.apache.camel.component.salesforce.internal.client.RestClient;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.impl.DefaultMessage;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+public class AbstractRestProcessorApprovalTest {
+
+    static class TestRestProcessor extends AbstractRestProcessor {
+
+        RestClient client;
+
+        TestRestProcessor() throws SalesforceException {
+            this(endpoint(), mock(RestClient.class));
+        }
+
+        TestRestProcessor(final SalesforceEndpoint endpoint, final RestClient client) {
+            super(endpoint, client, Collections.emptyMap());
+            this.client = client;
+        }
+
+        static SalesforceComponent component() {
+            return new SalesforceComponent();
+        }
+
+        static SalesforceEndpointConfig configuration() {
+            return new SalesforceEndpointConfig();
+        }
+
+        static SalesforceEndpoint endpoint() {
+            return new SalesforceEndpoint(notUsed(), component(), configuration(), notUsed(),
notUsed());
+        }
+
+        @Override
+        protected InputStream getRequestStream(final Exchange exchange) throws SalesforceException
{
+            return null;
+        }
+
+        @Override
+        protected InputStream getRequestStream(final Object object) throws SalesforceException
{
+            return null;
+        }
+
+        @Override
+        protected void processRequest(final Exchange exchange) throws SalesforceException
{
+        }
+
+        @Override
+        protected void processResponse(final Exchange exchange, final InputStream responseEntity,
+                final SalesforceException ex, final AsyncCallback callback) {
+        }
+    }
+
+    private static <T> T notUsed() {
+        return null;
+    }
+
+    static ApprovalRequest requestWithComment(final String comment) {
+        final ApprovalRequest approvalRequest = new ApprovalRequest();
+        approvalRequest.setComments(comment);
+
+        return approvalRequest;
+    }
+
+    @Test
+    public void shouldApplyTemplateToRequestFromBody() throws SalesforceException {
+        final ApprovalRequest template = new ApprovalRequest();
+        template.setActionType(Action.Submit);
+
+        final ApprovalRequest approvalRequest = new ApprovalRequest();
+        approvalRequest.setComments("it should be me");
+
+        final TestRestProcessor processor = sendBodyAndHeader(approvalRequest, template);
+
+        verify(processor).getRequestStream(new ApprovalRequests(approvalRequest.applyTemplate(template)));
+    }
+
+    @Test
+    public void shouldApplyTemplateToRequestsFromBody() throws SalesforceException {
+        final ApprovalRequest template = new ApprovalRequest();
+        template.setActionType(Action.Submit);
+
+        final ApprovalRequest approvalRequest1 = new ApprovalRequest();
+        approvalRequest1.setComments("it should be me first");
+
+        final ApprovalRequest approvalRequest2 = new ApprovalRequest();
+        approvalRequest2.setComments("it should be me second");
+
+        final TestRestProcessor processor = sendBodyAndHeader(Arrays.asList(approvalRequest1,
approvalRequest2),
+                template);
+
+        verify(processor).getRequestStream(new ApprovalRequests(
+                Arrays.asList(approvalRequest1.applyTemplate(template), approvalRequest2.applyTemplate(template))));
+    }
+
+    @Test
+    public void shouldComplainIfNoHeaderGivenOrBodyIsEmptyIterable() {
+        try {
+            sendBodyAndHeader(Collections.EMPTY_LIST, null);
+            fail("SalesforceException should be thrown");
+        } catch (final SalesforceException e) {
+            assertEquals("Exception should be about not giving a body or a header",
+                    "Missing approval parameter in header or ApprovalRequest or List of ApprovalRequests
body",
+                    e.getMessage());
+        }
+    }
+
+    @Test
+    public void shouldComplainIfNoHeaderOrBodyIsGiven() {
+        try {
+            sendBodyAndHeader(null, null);
+            fail("SalesforceException should be thrown");
+        } catch (final SalesforceException e) {
+            assertEquals("Exception should be about not giving a body or a header",
+                    "Missing approval parameter in header or ApprovalRequest or List of ApprovalRequests
body",
+                    e.getMessage());
+        }
+    }
+
+    @Test
+    public void shouldFetchApprovalRequestFromBody() throws SalesforceException {
+        final ApprovalRequest approvalRequest = new ApprovalRequest();
+        approvalRequest.setComments("it should be me");
+
+        final TestRestProcessor processor = sendBody(approvalRequest);
+
+        verify(processor).getRequestStream(new ApprovalRequests(approvalRequest));
+    }
+
+    @Test
+    public void shouldFetchApprovalRequestFromHeader() throws SalesforceException {
+        final ApprovalRequest request = new ApprovalRequest();
+        request.setComments("hi there");
+        final TestRestProcessor processor = sendBodyAndHeader(null, request);
+
+        verify(processor).getRequestStream(new ApprovalRequests(request));
+    }
+
+    @Test
+    public void shouldFetchApprovalRequestFromHeaderEvenIfBodyIsDefinedButNotConvertable()
throws SalesforceException {
+        final ApprovalRequest request = new ApprovalRequest();
+        request.setComments("hi there");
+
+        final TestRestProcessor processor = sendBodyAndHeaders("Nothing to see here", request,
+                Collections.singletonMap("approval.ContextId", "context-id"));
+
+        final ApprovalRequest combined = new ApprovalRequest();
+        combined.setComments("hi there");
+        combined.setContextId("context-id");
+
+        verify(processor).getRequestStream(new ApprovalRequests(combined));
+    }
+
+    @Test
+    public void shouldFetchApprovalRequestsFromBody() throws SalesforceException {
+        final ApprovalRequest approvalRequest1 = new ApprovalRequest();
+        approvalRequest1.setComments("it should be me first");
+
+        final ApprovalRequest approvalRequest2 = new ApprovalRequest();
+        approvalRequest2.setComments("it should be me second");
+
+        final TestRestProcessor processor = sendBody(Arrays.asList(approvalRequest1, approvalRequest2));
+
+        verify(processor).getRequestStream(new ApprovalRequests(Arrays.asList(approvalRequest1,
approvalRequest2)));
+    }
+
+    @Test
+    public void shouldFetchApprovalRequestsFromMultiplePropertiesInMessageHeaders() throws
SalesforceException {
+        final Map<String, Object> headers = new HashMap<>();
+        headers.put("approval.ContextId", "contextId");
+
+        final TestRestProcessor processor = sendBodyAndHeaders(notUsed(), notUsed(), headers);
+
+        final ApprovalRequest request = new ApprovalRequest();
+        request.setContextId("contextId");
+
+        verify(processor).getRequestStream(new ApprovalRequests(request));
+    }
+
+    @Test
+    public void shouldHonorPriorities() throws SalesforceException {
+        final ApprovalRequest template = new ApprovalRequest();
+        template.setComments("third priority");
+
+        final ApprovalRequest body = new ApprovalRequest();
+        body.setComments("first priority");
+
+        final Map<String, Object> headers = Collections.singletonMap("approval.Comments",
"second priority");
+
+        final TestRestProcessor processor1 = sendBodyAndHeaders(null, template, null);
+
+        verify(processor1).getRequestStream(new ApprovalRequests(requestWithComment("third
priority")));
+
+        final TestRestProcessor processor2 = sendBodyAndHeaders(null, template, headers);
+        verify(processor2).getRequestStream(new ApprovalRequests(requestWithComment("second
priority")));
+
+        final TestRestProcessor processor3 = sendBodyAndHeaders(body, template, headers);
+        verify(processor3).getRequestStream(new ApprovalRequests(requestWithComment("first
priority")));
+    }
+
+    TestRestProcessor sendBody(final Object body) throws SalesforceException {
+        return sendBodyAndHeader(body, null);
+    }
+
+    TestRestProcessor sendBodyAndHeader(final Object body, final ApprovalRequest template)
throws SalesforceException {
+        return sendBodyAndHeaders(body, template, Collections.emptyMap());
+    }
+
+    TestRestProcessor sendBodyAndHeaders(final Object body, final ApprovalRequest template,
+            final Map<String, Object> headers) throws SalesforceException {
+        final TestRestProcessor processor = spy(new TestRestProcessor());
+
+        final CamelContext context = new DefaultCamelContext();
+        final Exchange exchange = new DefaultExchange(context);
+
+        final Message message = new DefaultMessage();
+        if (headers != null) {
+            message.setHeaders(headers);
+        }
+        message.setHeader(SalesforceEndpointConfig.APPROVAL, template);
+
+        message.setBody(body);
+
+        exchange.setIn(message);
+
+        processor.processApproval(exchange, notUsed());
+
+        return processor;
+    }
+}


Mime
View raw message