camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [06/15] git commit: CAMEL-6676Applied the patch with thanks to Dhiraj
Date Mon, 02 Sep 2013 04:18:16 GMT
CAMEL-6676Applied the patch with thanks to Dhiraj


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3623066b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3623066b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3623066b

Branch: refs/heads/camel-2.12.x
Commit: 3623066bfd83145cd58926df03b324cc71f2f268
Parents: 9137357
Author: Willem Jiang <ningjiang@apache.org>
Authored: Mon Sep 2 09:25:01 2013 +0800
Committer: Willem Jiang <ningjiang@apache.org>
Committed: Mon Sep 2 09:47:11 2013 +0800

----------------------------------------------------------------------
 .../component/facebook/FacebookConstants.java   |   3 -
 .../component/facebook/FacebookConsumer.java    |   4 +-
 .../component/facebook/FacebookEndpoint.java    |  18 ++
 .../component/facebook/FacebookProducer.java    |   5 +-
 .../config/FacebookEndpointConfiguration.java   |  32 +---
 .../data/FacebookMethodsTypeHelper.java         |   4 -
 .../facebook/data/FacebookPropertiesHelper.java |   4 +
 .../facebook/CamelFacebookTestSupport.java      |  16 +-
 .../component/facebook/TestUserMethodsTest.java | 172 +++++++++++++++++++
 9 files changed, 213 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3623066b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookConstants.java
b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookConstants.java
index eec85dc..e7f9f3d 100644
--- a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookConstants.java
+++ b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookConstants.java
@@ -28,9 +28,6 @@ public interface FacebookConstants {
     // property name prefix for exchange 'in' headers
     String FACEBOOK_PROPERTY_PREFIX = "CamelFacebook.";
 
-    // property name for exchange 'in' body
-    String IN_BODY_PROPERTY = "inBody";
-
     String FACEBOOK_THREAD_PROFILE_NAME = "CamelFacebook";
 
     // date format used by Facebook Reading since and until fields

http://git-wip-us.apache.org/repos/asf/camel/blob/3623066b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookConsumer.java
b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookConsumer.java
index 2666167..459768e 100644
--- a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookConsumer.java
+++ b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookConsumer.java
@@ -69,7 +69,7 @@ public class FacebookConsumer extends ScheduledPollConsumer {
         this.endpoint = endpoint;
 
         // determine the consumer method to invoke
-        this.method = findMethod(endpoint.getCandidates());
+        this.method = findMethod();
 
         // get endpoint properties in a map
         final HashMap<String, Object> properties = new HashMap<String, Object>();
@@ -96,7 +96,7 @@ public class FacebookConsumer extends ScheduledPollConsumer {
         this.endpointProperties = Collections.unmodifiableMap(properties);
     }
 
-    private FacebookMethodsType findMethod(List<FacebookMethodsType> candidates) {
+    private FacebookMethodsType findMethod() {
 
         FacebookMethodsType result;
         // find one that takes the largest subset of endpoint parameters

http://git-wip-us.apache.org/repos/asf/camel/blob/3623066b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookEndpoint.java
b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookEndpoint.java
index 0031421..51eb324 100644
--- a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookEndpoint.java
+++ b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookEndpoint.java
@@ -28,6 +28,7 @@ import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.util.EndpointHelper;
+import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -48,6 +49,10 @@ public class FacebookEndpoint extends DefaultEndpoint implements FacebookConstan
     @UriParam
     private FacebookEndpointConfiguration configuration;
 
+    // property name for Exchange 'In' message body
+    @UriParam
+    private String inBody;
+
     // Facebook4J method name
     private final String methodName;
     private FacebookNameStyle nameStyle;
@@ -162,4 +167,17 @@ public class FacebookEndpoint extends DefaultEndpoint implements FacebookConstan
         return Collections.unmodifiableList(candidates);
     }
 
+    public String getInBody() {
+        return inBody;
+    }
+
+    public void setInBody(String inBody) {
+        // validate property name
+        ObjectHelper.notNull(inBody, "inBody");
+        if (!FacebookPropertiesHelper.getValidEndpointProperties().contains(inBody)) {
+            throw new IllegalArgumentException("Unknown property " + inBody);
+        }
+        this.inBody = inBody;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/3623066b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookProducer.java
b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookProducer.java
index cb585f7..15f1035 100644
--- a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookProducer.java
+++ b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/FacebookProducer.java
@@ -137,13 +137,13 @@ public class FacebookProducer extends DefaultAsyncProducer {
 
     // returns false on exception, which is set in exchange
     private boolean processInBody(Exchange exchange, Map<String, Object> properties)
{
-        final String inBodyProperty = (String) properties.remove(FacebookConstants.IN_BODY_PROPERTY);
+        final String inBodyProperty = endpoint.getInBody();
         if (inBodyProperty != null) {
 
             Object value = exchange.getIn().getBody();
             try {
                 value = getEndpoint().getCamelContext().getTypeConverter().mandatoryConvertTo(
-                    FacebookEndpointConfiguration.class.getDeclaredField(inBodyProperty).getClass(),
+                    FacebookEndpointConfiguration.class.getDeclaredField(inBodyProperty).getType(),
                     exchange, value);
             } catch (Exception e) {
                 exchange.setException(new RuntimeCamelException(String.format(
@@ -152,6 +152,7 @@ public class FacebookProducer extends DefaultAsyncProducer {
                 return false;
             }
 
+            LOG.debug("Property [{}] has message body value {}", inBodyProperty, value);
             properties.put(inBodyProperty, value);
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/3623066b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/config/FacebookEndpointConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/config/FacebookEndpointConfiguration.java
b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/config/FacebookEndpointConfiguration.java
index 812d4eb..eaa4262 100644
--- a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/config/FacebookEndpointConfiguration.java
+++ b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/config/FacebookEndpointConfiguration.java
@@ -16,9 +16,7 @@
  */
 package org.apache.camel.component.facebook.config;
 
-import java.lang.reflect.Field;
 import java.net.URL;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -34,18 +32,12 @@ import facebook4j.Reading;
 import facebook4j.TagUpdate;
 import facebook4j.TestUser;
 
-import org.apache.camel.component.facebook.FacebookConstants;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
-import org.apache.camel.util.ObjectHelper;
 
 @UriParams
 public class FacebookEndpointConfiguration extends FacebookConfiguration {
 
-    // property name for Exchange 'In' message body
-    @UriParam
-    private String inBody;
-
     @UriParam
     private URL achievementURL;
     @UriParam
@@ -177,22 +169,6 @@ public class FacebookEndpointConfiguration extends FacebookConfiguration
{
     @UriParam
     private String videoId;
 
-    public String getInBody() {
-        return inBody;
-    }
-
-    public void setInBody(String inBody) {
-        ObjectHelper.notNull(inBody, "inBody");
-        this.inBody = inBody;
-
-        // validate name
-        final List<Field> fields = Arrays.asList(getClass().getDeclaredFields());
-        fields.remove(FacebookConstants.IN_BODY_PROPERTY);
-        if (!fields.contains(inBody)) {
-            throw new IllegalArgumentException("Unknown property " + inBody);
-        }
-    }
-
     public URL getAchievementURL() {
         return achievementURL;
     }
@@ -225,11 +201,11 @@ public class FacebookEndpointConfiguration extends FacebookConfiguration
{
         this.allowNewOptions = allowNewOptions;
     }
 
-    public String getoAuthAppId() {
+    public String getAppId() {
         return appId;
     }
 
-    public void setoAuthAppId(String appId) {
+    public void setAppId(String appId) {
         this.appId = appId;
     }
 
@@ -489,11 +465,11 @@ public class FacebookEndpointConfiguration extends FacebookConfiguration
{
         this.permissionName = permissionName;
     }
 
-    public String getoAuthPermissions() {
+    public String getPermissions() {
         return permissions;
     }
 
-    public void setoAuthPermissions(String permissions) {
+    public void setPermissions(String permissions) {
         this.permissions = permissions;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/3623066b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelper.java
b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelper.java
index aaf1685..4cdf4c2 100644
--- a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelper.java
+++ b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelper.java
@@ -31,7 +31,6 @@ import facebook4j.Facebook;
 import facebook4j.FacebookException;
 
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.component.facebook.FacebookConstants;
 import org.apache.camel.component.facebook.config.FacebookNameStyle;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -102,9 +101,6 @@ public final class FacebookMethodsTypeHelper {
 
         }
 
-        // add endpoint parameter inBody for producers
-        VALID_ARGUMENTS.put(FacebookConstants.IN_BODY_PROPERTY, String.class);
-
         LOG.debug("Found {} unique method names in {} methods", METHOD_MAP.size(), methods.length);
 
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/3623066b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookPropertiesHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookPropertiesHelper.java
b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookPropertiesHelper.java
index b17a120..39505a1 100644
--- a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookPropertiesHelper.java
+++ b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookPropertiesHelper.java
@@ -134,4 +134,8 @@ public final class FacebookPropertiesHelper {
         return Collections.unmodifiableSet(properties.keySet());
     }
 
+    public static Set<String> getValidEndpointProperties() {
+        return Collections.unmodifiableSet(ENDPOINT_CONFIG_FIELDS);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/3623066b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/CamelFacebookTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/CamelFacebookTestSupport.java
b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/CamelFacebookTestSupport.java
index 98d28fb..7cbca2d 100644
--- a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/CamelFacebookTestSupport.java
+++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/CamelFacebookTestSupport.java
@@ -26,12 +26,12 @@ import org.apache.camel.component.facebook.config.FacebookConfiguration;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.util.IntrospectionSupport;
 
-public class CamelFacebookTestSupport extends CamelTestSupport {
+public abstract class CamelFacebookTestSupport extends CamelTestSupport {
 
-    private final Properties properties;
-    private FacebookConfiguration configuration;
+    protected final Properties properties;
+    protected final FacebookConfiguration configuration;
 
-    public CamelFacebookTestSupport() throws Exception {
+    protected CamelFacebookTestSupport() throws Exception {
         URL url = getClass().getResource("/test-options.properties");
 
         InputStream inStream;
@@ -59,15 +59,19 @@ public class CamelFacebookTestSupport extends CamelTestSupport {
         IntrospectionSupport.setProperties(configuration, options);
     }
 
-    public FacebookConfiguration getConfiguration() {
+    protected FacebookConfiguration getConfiguration() {
         return configuration;
     }
 
-    public String getOauthParams() {
+    protected String getOauthParams() {
         return "oAuthAppId=" + properties.get("oAuthAppId") + "&oAuthAppSecret=" + properties.get("oAuthAppSecret")
             + (properties.get("oAuthAccessToken") != null
             ? ("&oAuthAccessToken=" + properties.get("oAuthAccessToken")) : "");
     }
+    
+    protected String getAppOauthParams() {
+         return "oAuthAppId=" + properties.get("oAuthAppId") + "&oAuthAppSecret=" + properties.get("oAuthAppSecret");
+    }
 
     protected String getShortName(String name) {
         if (name.startsWith("get")) {

http://git-wip-us.apache.org/repos/asf/camel/blob/3623066b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/TestUserMethodsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/TestUserMethodsTest.java
b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/TestUserMethodsTest.java
new file mode 100644
index 0000000..bb5182d
--- /dev/null
+++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/TestUserMethodsTest.java
@@ -0,0 +1,172 @@
+/**
+ * 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.facebook;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+import facebook4j.TestUser;
+
+/**
+ * Test methods in {@link facebook4j.api.TestUserMethods}
+ */
+public class TestUserMethodsTest extends CamelFacebookTestSupport {
+
+    private static final String TEST_USER1 = "test one";
+    private static final String TEST_USER2 = "test two";
+
+    public TestUserMethodsTest() throws Exception {
+    }
+
+    @Test
+    public void testTestUsers() {
+
+        // create a test user with exchange properties
+        final TestUser testUser1 = template().requestBody("direct:createTestUser", TEST_USER1,
TestUser.class);
+        assertNotNull("Test User1", testUser1);
+
+        // create a test user with exchange properties
+        final TestUser testUser2 = template().requestBody("direct:createTestUser", TEST_USER2,
TestUser.class);
+        assertNotNull("Test User2", testUser2);
+
+        // make friends, not enemies
+        final Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put("CamelFacebook.testUser2", testUser2);
+        Boolean worked = template().requestBodyAndHeaders("direct:makeFriendTestUser"
+            , testUser1, headers, Boolean.class);
+        assertTrue("Friends not made", worked);
+
+        // get app test users
+        final List testUsers = template().requestBody("direct:testUsers", null, List.class);
+        assertNotNull("Test users", testUsers);
+        assertFalse("Empty test user list", testUsers.isEmpty());
+
+        // delete test users
+        for (Object user : testUsers) {
+            final TestUser testUser = (TestUser) user;
+            if (testUser.equals(testUser1) || testUser.equals(testUser2)) {
+                final String id = testUser.getId();
+                worked = template().requestBody("direct:deleteTestUser", id, Boolean.class);
+                assertTrue("Test user not deleted for id " + id, worked);
+            }
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:createTestUser")
+                    .to("facebook://createTestUser?inBody=name&appId=" + properties.get("oAuthAppId")
+                        + "&userLocale=" + Locale.getDefault().toString()
+                        + "&permissions=" + getTestPermissions()
+                        + "&" + getAppOauthParams());
+
+                // note short form testUsers instead of getTestUsers
+                from("direct:testUsers")
+                    .to("facebook://testUsers?appId=" + properties.get("oAuthAppId") + "&"
+ getAppOauthParams());
+
+                from("direct:makeFriendTestUser")
+                    .to("facebook://makeFriendTestUser?inBody=testUser1&" + getAppOauthParams());
+
+                from("direct:deleteTestUser")
+                    .to("facebook://deleteTestUser?inBody=testUserId&" + getAppOauthParams());
+            }
+        };
+    }
+
+    public String getTestPermissions() {
+        return "email"
+            + ",publish_actions"
+            + ",user_about_me"
+            + ",user_activities"
+            + ",user_birthday"
+            + ",user_checkins"
+            + ",user_education_history"
+            + ",user_events"
+            + ",user_games_activity"
+            + ",user_groups"
+            + ",user_hometown"
+            + ",user_interests"
+            + ",user_likes"
+            + ",user_location"
+            + ",user_notes"
+            + ",user_photos"
+            + ",user_questions"
+            + ",user_relationship_details"
+            + ",user_relationships"
+            + ",user_religion_politics"
+            + ",user_status"
+            + ",user_subscriptions"
+            + ",user_videos"
+            + ",user_website"
+            + ",user_work_history"
+            + ",friends_about_me"
+            + ",friends_activities"
+            + ",friends_birthday"
+            + ",friends_checkins"
+            + ",friends_education_history"
+            + ",friends_events"
+            + ",friends_games_activity"
+            + ",friends_groups"
+            + ",friends_hometown"
+            + ",friends_interests"
+            + ",friends_likes"
+            + ",friends_location"
+            + ",friends_notes"
+            + ",friends_photos"
+            + ",friends_questions"
+            + ",friends_relationship_details"
+            + ",friends_relationships"
+            + ",friends_religion_politics"
+            + ",friends_status"
+            + ",friends_subscriptions"
+            + ",friends_videos"
+            + ",friends_website"
+            + ",friends_work_history"
+            + ",ads_management"
+            + ",create_event"
+            + ",create_note"
+            + ",export_stream"
+            + ",friends_online_presence"
+            + ",manage_friendlists"
+            + ",manage_notifications"
+            + ",manage_pages"
+            + ",photo_upload"
+            + ",publish_checkins"
+            + ",publish_stream"
+            + ",read_friendlists"
+            + ",read_insights"
+            + ",read_mailbox"
+            + ",read_page_mailboxes"
+            + ",read_requests"
+            + ",read_stream"
+            + ",rsvp_event"
+            + ",share_item"
+            + ",sms"
+            + ",status_update"
+            + ",user_online_presence"
+            + ",video_upload"
+            + ",xmpp_login";
+    }
+
+}


Mime
View raw message