camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhira...@apache.org
Subject [3/9] camel git commit: CAMEL-8269: added support for APEX REST calls, also updated Salesforce API version to 33.0
Date Fri, 20 Mar 2015 21:07:43 GMT
http://git-wip-us.apache.org/repos/asf/camel/blob/c89e21f4/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/RestApiIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/RestApiIntegrationTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/RestApiIntegrationTest.java
index 9f51bbd..52a95f6 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/RestApiIntegrationTest.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/RestApiIntegrationTest.java
@@ -24,7 +24,12 @@ import java.nio.channels.ReadableByteChannel;
 import java.util.HashMap;
 import java.util.List;
 
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+import org.apache.camel.CamelExecutionException;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.salesforce.api.SalesforceException;
+import org.apache.camel.component.salesforce.api.dto.AbstractDTOBase;
 import org.apache.camel.component.salesforce.api.dto.CreateSObjectResult;
 import org.apache.camel.component.salesforce.api.dto.GlobalObjects;
 import org.apache.camel.component.salesforce.api.dto.RestResources;
@@ -38,6 +43,7 @@ import org.apache.camel.component.salesforce.dto.generated.Document;
 import org.apache.camel.component.salesforce.dto.generated.Line_Item__c;
 import org.apache.camel.component.salesforce.dto.generated.Merchandise__c;
 import org.apache.camel.component.salesforce.dto.generated.QueryRecordsLine_Item__c;
+import org.eclipse.jetty.http.HttpStatus;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -297,6 +303,94 @@ public class RestApiIntegrationTest extends AbstractSalesforceTestBase
{
         LOG.debug("ExecuteSearch: {}", searchResults);
     }
 
+    @Test
+    public void testApexCall() throws Exception {
+        try {
+            doTestApexCall("");
+            doTestApexCall("Xml");
+        } catch (CamelExecutionException e) {
+            if (e.getCause() instanceof SalesforceException) {
+                SalesforceException cause = (SalesforceException) e.getCause();
+                if (cause.getStatusCode() == HttpStatus.NOT_FOUND_404) {
+                    LOG.error("Make sure test REST resource MerchandiseRestResource.apxc
has been loaded: "
+                        + e.getMessage());
+                }
+            }
+            throw e;
+        }
+    }
+
+    private void doTestApexCall(String suffix) throws Exception {
+
+        if (testId == null) {
+            // execute getBasicInfo to get test id from recent items
+            doTestGetBasicInfo("");
+        }
+
+        // request merchandise with id in URI template
+        Merchandise__c merchandise = template().requestBodyAndHeader("direct:apexCallGet"
+ suffix, null,
+            "id", testId, Merchandise__c.class);
+        assertNotNull(merchandise);
+        LOG.debug("ApexCallGet: {}", merchandise);
+
+        // request merchandise with id as query param
+        merchandise = template().requestBodyAndHeader("direct:apexCallGetWithId" + suffix,
null,
+            SalesforceEndpointConfig.APEX_QUERY_PARAM_PREFIX + "id", testId, Merchandise__c.class);
+        assertNotNull(merchandise);
+        LOG.debug("ApexCallGetWithId: {}", 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" + suffix,
+            new MerchandiseRequest(merchandise), Merchandise__c.class);
+        assertNotNull(merchandise);
+        LOG.debug("ApexCallPatch: {}", merchandise);
+    }
+
+    /**
+     * Request DTO for Salesforce APEX REST calls.
+     * See https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_rest_methods.htm.
+     */
+    @XStreamAlias("request")
+    public static class MerchandiseRequest extends AbstractDTOBase {
+        private Merchandise__c merchandise;
+
+        public MerchandiseRequest(Merchandise__c merchandise) {
+            this.merchandise = merchandise;
+        }
+
+        public Merchandise__c getMerchandise() {
+            return merchandise;
+        }
+
+        public void setMerchandise(Merchandise__c merchandise) {
+            this.merchandise = merchandise;
+        }
+    }
+
+    /**
+     * Response DTO for Salesforce APEX REST calls.
+     * See https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_rest_methods.htm.
+     */
+    @XStreamAlias("response")
+    public static class MerchandiseXmlResponse extends Merchandise__c {
+        // XML response contains a type string with the SObject type name
+        private String type;
+
+        public String getType() {
+            return type;
+        }
+
+        public void setType(String type) {
+            this.type = type;
+        }
+    }
+
     @Override
     protected RouteBuilder doCreateRouteBuilder() throws Exception {
 
@@ -409,6 +503,25 @@ public class RestApiIntegrationTest extends AbstractSalesforceTestBase
{
 
                 from("direct:searchXml")
                     .to("salesforce:search?format=XML&sObjectSearch=FIND {Wee}");
+
+                // testApexCall
+                from("direct:apexCallGet")
+                    .to("salesforce:apexCall?apexMethod=GET&apexUrl=Merchandise/{id}&sObjectName=Merchandise__c");
+
+                from("direct:apexCallGetXml")
+                    .to("salesforce:apexCall/Merchandise/{id}?format=XML&apexMethod=GET&sObjectClass="
+ MerchandiseXmlResponse.class.getName());
+
+                from("direct:apexCallGetWithId")
+                    .to("salesforce:apexCall/Merchandise/?apexMethod=GET&id=dummyId&sObjectClass="
+ Merchandise__c.class.getName());
+
+                from("direct:apexCallGetWithIdXml")
+                    .to("salesforce:apexCall?format=XML&apexMethod=GET&apexUrl=Merchandise/&id=dummyId&sObjectClass="
+ MerchandiseXmlResponse.class.getName());
+
+                from("direct:apexCallPatch")
+                    .to("salesforce:apexCall?apexMethod=PATCH&apexUrl=Merchandise/&sObjectName=Merchandise__c");
+
+                from("direct:apexCallPatchXml")
+                    .to("salesforce:apexCall/Merchandise/?format=XML&apexMethod=PATCH&sObjectClass="
+ MerchandiseXmlResponse.class.getName());
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/c89e21f4/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/StreamingApiIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/StreamingApiIntegrationTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/StreamingApiIntegrationTest.java
index 66628eb..0123b05 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/StreamingApiIntegrationTest.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/StreamingApiIntegrationTest.java
@@ -81,7 +81,9 @@ public class StreamingApiIntegrationTest extends AbstractSalesforceTestBase
{
             public void configure() throws Exception {
 
                 // test topic subscription
-                from("salesforce:CamelTestTopic?notifyForFields=ALL&notifyForOperations=ALL&"
+                //from("salesforce:CamelTestTopic?notifyForFields=ALL&notifyForOperations=ALL&"
+                from("salesforce:CamelTestTopic?notifyForFields=ALL&"
+                    + "notifyForOperationCreate=true&notifyForOperationDelete=true&notifyForOperationUpdate=true&"
                     + "sObjectName=Merchandise__c&"
                     + "updateTopic=true&sObjectQuery=SELECT Id, Name FROM Merchandise__c").
                     to("mock:CamelTestTopic");

http://git-wip-us.apache.org/repos/asf/camel/blob/c89e21f4/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/dto/generated/Document.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/dto/generated/Document.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/dto/generated/Document.java
index 794b752..67e4b30 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/dto/generated/Document.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/dto/generated/Document.java
@@ -1,18 +1,3 @@
-//CHECKSTYLE:OFF
-/*
- * Salesforce DTO generated by camel-salesforce-maven-plugin
- * Generated on: Tue May 14 21:15:54 PDT 2013
- */
-package org.apache.camel.component.salesforce.dto.generated;
-
-import com.thoughtworks.xstream.annotations.XStreamAlias;
-import org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase;
-import org.codehaus.jackson.annotate.JsonProperty;
-
-/**
- * Salesforce DTO for SObject Document
- */
-@XStreamAlias("Document")
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -29,6 +14,17 @@ import org.codehaus.jackson.annotate.JsonProperty;
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.camel.component.salesforce.dto.generated;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+//CHECKSTYLE:OFF
+/**
+ * Salesforce DTO for SObject Document
+ */
+@XStreamAlias("Document")
 public class Document extends AbstractSObjectBase {
 
     // FolderId

http://git-wip-us.apache.org/repos/asf/camel/blob/c89e21f4/components/camel-salesforce/camel-salesforce-component/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/resources/log4j.properties
b/components/camel-salesforce/camel-salesforce-component/src/test/resources/log4j.properties
index 7ddaf0f..d0a193a 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/test/resources/log4j.properties
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/resources/log4j.properties
@@ -22,6 +22,7 @@ log4j.rootLogger=INFO, file
 
 # uncomment the following to enable camel debugging
 #log4j.logger.org.apache.camel.component.salesforce=DEBUG
+#log4j.logger.org.eclipse.jetty=DEBUG
 
 # CONSOLE appender not used by default
 log4j.appender.out=org.apache.log4j.ConsoleAppender


Mime
View raw message