You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2013/06/28 21:23:16 UTC

[1/3] git commit: CAMEL-6493 - enable limiting of messages consumed per poll

Updated Branches:
  refs/heads/master 247ced1dc -> 6c0c2c170


CAMEL-6493 - enable limiting of messages consumed per poll


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

Branch: refs/heads/master
Commit: 3ec23b55191c08a0e9a19943763def3da5486d8b
Parents: 53e6e89
Author: Jonathan Anstey <ja...@gmail.com>
Authored: Fri Jun 28 16:36:42 2013 -0230
Committer: Jonathan Anstey <ja...@gmail.com>
Committed: Fri Jun 28 16:38:08 2013 -0230

----------------------------------------------------------------------
 .../component/yammer/YammerConfiguration.java   | 37 ++++++++++++++--
 .../component/yammer/YammerComponentTest.java   | 21 +---------
 .../yammer/YammerComponentTestSupport.java      | 32 ++++++++++++++
 .../yammer/YammerConsumerMessageLimitTest.java  | 44 ++++++++++++++++++++
 4 files changed, 110 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3ec23b55/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/YammerConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/YammerConfiguration.java b/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/YammerConfiguration.java
index 3ab6f81b..f3e3117 100644
--- a/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/YammerConfiguration.java
+++ b/components/camel-yammer/src/main/java/org/apache/camel/component/yammer/YammerConfiguration.java
@@ -36,6 +36,10 @@ public class YammerConfiguration {
     
     @UriParam
     private long delay = 3000 + 2000; // 3 sec per poll is enforced by yammer; add 2 sec for safety 
+    
+    @UriParam
+    private int limit = -1; // default is unlimited
+    
     private ApiRequestor requestor;
     
     public String getConsumerKey() {
@@ -78,19 +82,36 @@ public class YammerConfiguration {
         this.function = function;
     }
 
-    public String getApiUrl() throws Exception {        
+    public String getApiUrl() throws Exception {    
+        StringBuilder sb = new StringBuilder();
+        
         switch (YammerFunctionType.fromUri(function)) {
         case MESSAGES:
-            return String.format("%s%s.json", YammerConstants.YAMMER_BASE_API_URL, function);
+            sb.append(YammerConstants.YAMMER_BASE_API_URL);
+            sb.append(function);
+            sb.append(".json");
+            break;
         case ALGO:
         case FOLLOWING:
         case MY_FEED:
         case PRIVATE:
         case SENT:
-            return String.format("%smessages/%s.json", YammerConstants.YAMMER_BASE_API_URL, function);
+            sb.append(YammerConstants.YAMMER_BASE_API_URL);
+            sb.append("messages/");
+            sb.append(function);
+            sb.append(".json");
+            break;
         default:
             throw new Exception(String.format("%s is not a valid Yammer function type.", function));
-        }
+        }        
+        
+        if (limit > 0) {
+            sb.append("?");
+            sb.append("limit=");
+            sb.append(limit);
+        }        
+        
+        return sb.toString();
     }
 
     public boolean isUseJson() {
@@ -112,4 +133,12 @@ public class YammerConfiguration {
         this.requestor = requestor;
     }
 
+    public int getLimit() {
+        return limit;
+    }
+
+    public void setLimit(int limit) {
+        this.limit = limit;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/3ec23b55/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTest.java b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTest.java
index aa3e9f8..1306459 100644
--- a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTest.java
+++ b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTest.java
@@ -16,33 +16,14 @@
  */
 package org.apache.camel.component.yammer;
 
-import java.io.InputStream;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.component.yammer.model.Message;
 import org.apache.camel.component.yammer.model.Messages;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Before;
 import org.junit.Test;
 
-public class YammerComponentTest extends CamelTestSupport {
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-
-        // All this is to mock out the bit that is actually hitting the yammer.com 
-        // rest api. We just return a bit of static json that was retrieved from 
-        // my own account.
-        YammerComponent yc = context.getComponent("yammer", YammerComponent.class);
-        YammerConfiguration config = yc.getConfig();
-        InputStream is = getClass().getResourceAsStream("/messages.json");
-        String messages = context.getTypeConverter().convertTo(String.class, is);
-        config.setRequestor(new TestApiRequestor(messages));
-    }
+public class YammerComponentTest extends YammerComponentTestSupport {
 
     @Test
     public void testConsumeAllMessages() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/3ec23b55/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTestSupport.java b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTestSupport.java
new file mode 100644
index 0000000..b0813e3
--- /dev/null
+++ b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTestSupport.java
@@ -0,0 +1,32 @@
+package org.apache.camel.component.yammer;
+
+import java.io.InputStream;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
+
+public abstract class YammerComponentTestSupport extends CamelTestSupport {
+
+    protected YammerComponent yammerComponent;
+
+    public YammerComponentTestSupport() {
+        super();
+    }
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+    
+        yammerComponent = context.getComponent("yammer", YammerComponent.class);
+        YammerConfiguration config = yammerComponent.getConfig();
+        InputStream is = getClass().getResourceAsStream(jsonFile());
+        String messages = context.getTypeConverter().convertTo(String.class, is);
+        config.setRequestor(new TestApiRequestor(messages));
+    }
+
+    protected String jsonFile() {
+        return "/messages.json";
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/3ec23b55/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java
----------------------------------------------------------------------
diff --git a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java
new file mode 100644
index 0000000..3aeed4c
--- /dev/null
+++ b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java
@@ -0,0 +1,44 @@
+package org.apache.camel.component.yammer;
+/**
+ * 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.
+ */
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class YammerConsumerMessageLimitTest extends YammerComponentTestSupport {
+
+    @Test
+    public void testConsumerMessageLimit() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMinimumMessageCount(1);
+        assertMockEndpointsSatisfied();
+        
+        // now check if limit option got applied
+        assertEquals(1, yammerComponent.getConfig().getLimit());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                // using dummy keys here since we are mocking out calls to yammer.com with static json; in a real app, please use your own keys!
+                from("yammer:messages?consumerKey=aConsumerKey&consumerSecret=aConsumerSecretKey&accessToken=aAccessToken&limit=1").to("mock:result");
+            }
+        };
+    }
+}


[3/3] git commit: Fix checkstyle errors

Posted by ja...@apache.org.
Fix checkstyle errors


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

Branch: refs/heads/master
Commit: 6c0c2c1709e3fec18d61e1f84caecf2910814580
Parents: 3ec23b5
Author: Jonathan Anstey <ja...@gmail.com>
Authored: Fri Jun 28 16:42:15 2013 -0230
Committer: Jonathan Anstey <ja...@gmail.com>
Committed: Fri Jun 28 16:42:15 2013 -0230

----------------------------------------------------------------------
 .../yammer/YammerComponentTestSupport.java         | 17 +++++++++++++++++
 .../yammer/YammerConsumerMessageLimitTest.java     |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6c0c2c17/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTestSupport.java b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTestSupport.java
index b0813e3..39dce59 100644
--- a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTestSupport.java
+++ b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTestSupport.java
@@ -1,3 +1,20 @@
+/**
+ * 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.yammer;
 
 import java.io.InputStream;

http://git-wip-us.apache.org/repos/asf/camel/blob/6c0c2c17/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java
----------------------------------------------------------------------
diff --git a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java
index 3aeed4c..f014d17 100644
--- a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java
+++ b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerConsumerMessageLimitTest.java
@@ -1,4 +1,3 @@
-package org.apache.camel.component.yammer;
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -15,6 +14,7 @@ package org.apache.camel.component.yammer;
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.camel.component.yammer;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;


[2/3] git commit: Add comment to yammer testcase

Posted by ja...@apache.org.
Add comment to yammer testcase


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

Branch: refs/heads/master
Commit: 53e6e89935011fb79722def975aac07dc082f250
Parents: 247ced1
Author: Jonathan Anstey <ja...@gmail.com>
Authored: Fri Jun 28 15:12:39 2013 -0230
Committer: Jonathan Anstey <ja...@gmail.com>
Committed: Fri Jun 28 16:38:08 2013 -0230

----------------------------------------------------------------------
 .../org/apache/camel/component/yammer/YammerComponentTest.java   | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/53e6e899/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTest.java b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTest.java
index a900728..aa3e9f8 100644
--- a/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTest.java
+++ b/components/camel-yammer/src/test/java/org/apache/camel/component/yammer/YammerComponentTest.java
@@ -34,6 +34,9 @@ public class YammerComponentTest extends CamelTestSupport {
     public void setUp() throws Exception {
         super.setUp();
 
+        // All this is to mock out the bit that is actually hitting the yammer.com 
+        // rest api. We just return a bit of static json that was retrieved from 
+        // my own account.
         YammerComponent yc = context.getComponent("yammer", YammerComponent.class);
         YammerConfiguration config = yc.getConfig();
         InputStream is = getClass().getResourceAsStream("/messages.json");
@@ -59,6 +62,7 @@ public class YammerComponentTest extends CamelTestSupport {
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
+                // using dummy keys here since we are mocking out calls to yammer.com with static json; in a real app, please use your own keys!
                 from("yammer:messages?consumerKey=aConsumerKey&consumerSecret=aConsumerSecretKey&accessToken=aAccessToken").to("mock:result");
             }
         };