You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/01/07 14:14:07 UTC

[camel] branch camel-2.x updated (468889d -> cf39674)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 468889d  CAMEL-12995 - Remove Camel XmlJson
     new 2becd62  CAMEL-13035 update from telegram channel
     new 15afdbb  CAMEL-13035 - correcting style
     new cf39674  CAMEL-13035 - fix sc reported

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/telegram/TelegramEndpoint.java |  6 +++
 .../camel/component/telegram/model/Update.java     | 12 +++++
 ...t.java => TelegramConsumerChannelPostTest.java} | 55 ++++++++++++----------
 .../resources/messages/updates-channelMessage.json | 19 ++++++++
 4 files changed, 66 insertions(+), 26 deletions(-)
 copy components/camel-telegram/src/test/java/org/apache/camel/component/telegram/{TelegramConsumerMediaVideoTest.java => TelegramConsumerChannelPostTest.java} (65%)
 create mode 100644 components/camel-telegram/src/test/resources/messages/updates-channelMessage.json


[camel] 02/03: CAMEL-13035 - correcting style

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 15afdbb94d45e5446ce26d0a11b273ad2121dc55
Author: Gandhi <vg...@LAMU02W82E9HTD6.uhc.com>
AuthorDate: Fri Jan 4 19:22:57 2019 +0530

    CAMEL-13035 - correcting style
---
 .../main/java/org/apache/camel/component/telegram/model/Update.java    | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java
index e7c814a..ba0b392 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java
@@ -39,8 +39,7 @@ public class Update implements Serializable {
     @JsonProperty("channel_post")
     private IncomingMessage channelpost;
 
-   
-	public Update() {
+    public Update() {
     }
 
     public Long getUpdateId() {


[camel] 03/03: CAMEL-13035 - fix sc reported

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit cf39674dd93eca434eb89373ddab4ee623e106fa
Author: Gandhi <vg...@LAMU02W82E9HTD6.uhc.com>
AuthorDate: Mon Jan 7 15:27:19 2019 +0530

    CAMEL-13035 - fix sc reported
    
    Conflicts:
    	components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java
---
 .../camel/component/telegram/TelegramEndpoint.java |  4 +--
 .../camel/component/telegram/model/Update.java     | 17 +++++-------
 .../telegram/TelegramConsumerChannelPostTest.java  | 31 ++++++++++++++++++----
 3 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java
index d90702d..d901acf 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java
@@ -61,8 +61,8 @@ public class TelegramEndpoint extends ScheduledPollEndpoint {
             if (update.getMessage().getChat() != null) {
                 exchange.getIn().setHeader(TelegramConstants.TELEGRAM_CHAT_ID, update.getMessage().getChat().getId());
             }
-        }else if(update.getChannelPost() != null) {
-        	exchange.getIn().setBody(update.getChannelPost());
+        } else if (update.getChannelPost() != null) {
+            exchange.getIn().setBody(update.getChannelPost());
 
             if (update.getChannelPost().getChat() != null) {
                 exchange.getIn().setHeader(TelegramConstants.TELEGRAM_CHAT_ID, update.getChannelPost().getChat().getId());
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java
index ba0b392..d436bbb 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java
@@ -32,10 +32,8 @@ public class Update implements Serializable {
     @JsonProperty("update_id")
     private Long updateId;
 
-
     private IncomingMessage message;
-    
-    
+
     @JsonProperty("channel_post")
     private IncomingMessage channelpost;
 
@@ -57,15 +55,14 @@ public class Update implements Serializable {
     public void setMessage(IncomingMessage message) {
         this.message = message;
     }
-    
-    public IncomingMessage getChannelPost() {
-		return channelpost;
-	}
 
-	public void setChannelpost(IncomingMessage channelpost) {
-		this.channelpost = channelpost;
-	}
+    public IncomingMessage getChannelPost() {
+        return channelpost;
+    }
 
+    public void setChannelpost(IncomingMessage channelpost) {
+        this.channelpost = channelpost;
+    }
 
     @Override
     public String toString() {
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerChannelPostTest.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerChannelPostTest.java
index 22d15e7..124deb2 100644
--- a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerChannelPostTest.java
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerChannelPostTest.java
@@ -1,8 +1,21 @@
+/**
+ * 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.telegram;
 
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
-
 import java.time.Instant;
 
 import org.apache.camel.EndpointInject;
@@ -16,10 +29,18 @@ import org.apache.camel.component.telegram.model.UpdateResult;
 import org.apache.camel.component.telegram.util.TelegramTestSupport;
 import org.junit.Before;
 import org.junit.Test;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
 
-public class TelegramConsumerChannelPostTest extends TelegramTestSupport{
+/**
+ * 
+ * Test channel data updates are converted by camel application.
+ *
+ */
+public class TelegramConsumerChannelPostTest extends TelegramTestSupport {
 
-	@EndpointInject(uri = "mock:telegram")
+    @EndpointInject(uri = "mock:telegram")
     private MockEndpoint endpoint;
 
     @Before


[camel] 01/03: CAMEL-13035 update from telegram channel

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 2becd62a9f2930f81a22f9be5a7f4fe2f155170a
Author: Gandhi <vg...@LAMU02W82E9HTD6.uhc.com>
AuthorDate: Fri Jan 4 17:22:31 2019 +0530

    CAMEL-13035 update from telegram channel
---
 .../camel/component/telegram/TelegramEndpoint.java |  6 ++
 .../camel/component/telegram/model/Update.java     | 18 +++++-
 .../telegram/TelegramConsumerChannelPostTest.java  | 71 ++++++++++++++++++++++
 .../resources/messages/updates-channelMessage.json | 19 ++++++
 4 files changed, 113 insertions(+), 1 deletion(-)

diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java
index f98394c..d90702d 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java
@@ -61,6 +61,12 @@ public class TelegramEndpoint extends ScheduledPollEndpoint {
             if (update.getMessage().getChat() != null) {
                 exchange.getIn().setHeader(TelegramConstants.TELEGRAM_CHAT_ID, update.getMessage().getChat().getId());
             }
+        }else if(update.getChannelPost() != null) {
+        	exchange.getIn().setBody(update.getChannelPost());
+
+            if (update.getChannelPost().getChat() != null) {
+                exchange.getIn().setHeader(TelegramConstants.TELEGRAM_CHAT_ID, update.getChannelPost().getChat().getId());
+            }
         }
 
         return exchange;
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java
index 01b0a99..e7c814a 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Update.java
@@ -32,9 +32,15 @@ public class Update implements Serializable {
     @JsonProperty("update_id")
     private Long updateId;
 
+
     private IncomingMessage message;
+    
+    
+    @JsonProperty("channel_post")
+    private IncomingMessage channelpost;
 
-    public Update() {
+   
+	public Update() {
     }
 
     public Long getUpdateId() {
@@ -52,12 +58,22 @@ public class Update implements Serializable {
     public void setMessage(IncomingMessage message) {
         this.message = message;
     }
+    
+    public IncomingMessage getChannelPost() {
+		return channelpost;
+	}
+
+	public void setChannelpost(IncomingMessage channelpost) {
+		this.channelpost = channelpost;
+	}
+
 
     @Override
     public String toString() {
         final StringBuilder sb = new StringBuilder("Update{");
         sb.append("updateId=").append(updateId);
         sb.append(", message=").append(message);
+        sb.append(", channel_post=").append(channelpost);
         sb.append('}');
         return sb.toString();
     }
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerChannelPostTest.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerChannelPostTest.java
new file mode 100644
index 0000000..22d15e7
--- /dev/null
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerChannelPostTest.java
@@ -0,0 +1,71 @@
+package org.apache.camel.component.telegram;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import java.time.Instant;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.Chat;
+import org.apache.camel.component.telegram.model.IncomingMessage;
+import org.apache.camel.component.telegram.model.UpdateResult;
+import org.apache.camel.component.telegram.util.TelegramTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TelegramConsumerChannelPostTest extends TelegramTestSupport{
+
+	@EndpointInject(uri = "mock:telegram")
+    private MockEndpoint endpoint;
+
+    @Before
+    public void mockAPIs() {
+        TelegramService api = mockTelegramService();
+
+        UpdateResult res1 = getJSONResource("messages/updates-channelMessage.json", UpdateResult.class);
+
+        UpdateResult defaultRes = getJSONResource("messages/updates-empty.json", UpdateResult.class);
+
+        when(api.getUpdates(any(), any(), any(), any())).thenReturn(res1).thenAnswer((i) -> defaultRes);
+    }
+    
+    @Test
+    public void testReceptionOfMessageWithAMessage() throws Exception {
+        endpoint.expectedMinimumMessageCount(1);
+        endpoint.assertIsSatisfied();
+
+        Exchange mediaExchange = endpoint.getExchanges().get(0);
+        IncomingMessage msg = mediaExchange.getIn().getBody(IncomingMessage.class);
+        
+        assertEquals("-1001245756934", mediaExchange.getIn().getHeader(TelegramConstants.TELEGRAM_CHAT_ID));
+        
+        //checking body
+        assertNotNull(msg);
+        assertEquals("test", msg.getText());
+        assertEquals(Long.valueOf(67L), msg.getMessageId());
+        assertEquals(Instant.ofEpochSecond(1546505413L), msg.getDate());
+        
+        // checking chat
+        Chat chat = msg.getChat();
+        assertNotNull(chat);
+        assertEquals("-1001245756934", chat.getId());
+        assertEquals("cameltemp", chat.getTitle());
+        assertEquals("channel", chat.getType());
+
+    }
+    
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("telegram:bots/mock-token")
+                        .to("mock:telegram");
+            }
+        };
+    }
+}
diff --git a/components/camel-telegram/src/test/resources/messages/updates-channelMessage.json b/components/camel-telegram/src/test/resources/messages/updates-channelMessage.json
new file mode 100644
index 0000000..c1d3118
--- /dev/null
+++ b/components/camel-telegram/src/test/resources/messages/updates-channelMessage.json
@@ -0,0 +1,19 @@
+{
+    "ok": true,
+    "result": [
+        {
+            "update_id": 219398823,
+            "channel_post": {
+                "message_id": 67,
+                "chat": {
+                    "id": -1001245756934,
+                    "title": "cameltemp",
+                    "username": "cameltelegram",
+                    "type": "channel"
+                },
+                "date": 1546505413,
+                "text": "test"
+            }
+        }
+    ]
+}
\ No newline at end of file