camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject [1/3] git commit: CAMEL-6493 - enable limiting of messages consumed per poll
Date Fri, 28 Jun 2013 19:23:16 GMT
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 <janstey@gmail.com>
Authored: Fri Jun 28 16:36:42 2013 -0230
Committer: Jonathan Anstey <janstey@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");
+            }
+        };
+    }
+}


Mime
View raw message