You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ff...@apache.org on 2022/03/10 19:41:14 UTC
[camel-spring-boot] branch main updated: [CAMEL-17770] add tests in camel-telegram-starter (#460)
This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push:
new 349df5c [CAMEL-17770] add tests in camel-telegram-starter (#460)
349df5c is described below
commit 349df5c2e539d67218cdc60856f1dc36e0b9f4f0
Author: Freeman(Yue) Fang <fr...@gmail.com>
AuthorDate: Thu Mar 10 14:41:06 2022 -0500
[CAMEL-17770] add tests in camel-telegram-starter (#460)
---
components-starter/camel-telegram-starter/pom.xml | 25 ++
.../telegram/springboot/TelegramApiConfig.java | 60 +++
.../telegram/springboot/TelegramChatBotTest.java | 149 +++++++
.../TelegramComponentParametersTest.java | 104 +++++
.../springboot/TelegramConfigurationTest.java | 95 +++++
.../TelegramConsumerChannelPostTest.java | 113 +++++
.../TelegramConsumerEmptyResponseTest.java | 102 +++++
.../TelegramConsumerFallbackConversionTest.java | 131 ++++++
...nsumerHealthCheckErrorDisabledConsumerTest.java | 130 ++++++
.../TelegramConsumerHealthCheckErrorTest.java | 141 +++++++
.../TelegramConsumerHealthCheckOkTest.java | 126 ++++++
.../TelegramConsumerIncomingInlineQueryTest.java | 105 +++++
.../springboot/TelegramConsumerMappingTest.java | 158 +++++++
.../TelegramConsumerMediaDocumentTest.java | 111 +++++
.../springboot/TelegramConsumerMediaGameTest.java | 120 ++++++
.../springboot/TelegramConsumerMediaPhotoTest.java | 104 +++++
.../TelegramConsumerMediaStickerTest.java | 122 ++++++
.../springboot/TelegramConsumerMediaVideoTest.java | 112 +++++
.../springboot/TelegramConsumerMultipleTest.java | 104 +++++
.../TelegramConsumerServiceErrorTest.java | 104 +++++
.../springboot/TelegramConsumerSingleTest.java | 100 +++++
.../telegram/springboot/TelegramMockRoutes.java | 145 +++++++
.../TelegramProducerChatIdResolutionTest.java | 121 ++++++
.../springboot/TelegramProducerLocationTest.java | 154 +++++++
.../springboot/TelegramProducerMediaTest.java | 459 +++++++++++++++++++++
.../telegram/springboot/TelegramTestSupport.java | 142 +++++++
.../telegram/springboot/TelegramTestUtil.java | 97 +++++
.../springboot/TelegramWebhookCallTest.java | 109 +++++
.../src/test/resources/application.properties | 1 +
.../src/test/resources/attachments/sample.jpg | Bin 0 -> 19314 bytes
.../src/test/resources/attachments/sample.mp3 | Bin 0 -> 30439 bytes
.../src/test/resources/attachments/sample.mp4 | Bin 0 -> 299284 bytes
.../src/test/resources/attachments/sample.png | Bin 0 -> 28947 bytes
.../src/test/resources/attachments/sample.txt | 1 +
.../src/test/resources/attachments/sample.webp | Bin 0 -> 5298 bytes
.../messages/edit-message-live-location.json | 24 ++
.../src/test/resources/messages/send-audio.json | 25 ++
.../src/test/resources/messages/send-document.json | 24 ++
.../src/test/resources/messages/send-game.json | 42 ++
.../src/test/resources/messages/send-location.json | 23 ++
.../src/test/resources/messages/send-message.json | 20 +
.../src/test/resources/messages/send-photo.json | 27 ++
.../src/test/resources/messages/send-venue.json | 31 ++
.../src/test/resources/messages/send-video.json | 33 ++
.../messages/stop-message-live-location.json | 24 ++
.../resources/messages/updates-channelMessage.json | 19 +
.../src/test/resources/messages/updates-empty.json | 4 +
.../messages/updates-inline-query-message.json | 17 +
.../resources/messages/updates-media-document.json | 35 ++
.../resources/messages/updates-media-game.json | 47 +++
.../resources/messages/updates-media-sticker.json | 44 ++
.../resources/messages/updates-media-video.json | 36 ++
.../src/test/resources/messages/updates-media.json | 67 +++
.../test/resources/messages/updates-multiple.json | 41 ++
.../resources/messages/updates-sendLocation.json | 23 ++
.../test/resources/messages/updates-single.json | 23 ++
.../src/test/resources/messages/webhook-call.json | 23 ++
57 files changed, 4197 insertions(+)
diff --git a/components-starter/camel-telegram-starter/pom.xml b/components-starter/camel-telegram-starter/pom.xml
index 03bae79..845f7ce 100644
--- a/components-starter/camel-telegram-starter/pom.xml
+++ b/components-starter/camel-telegram-starter/pom.xml
@@ -39,6 +39,31 @@
<artifactId>camel-telegram</artifactId>
<version>${camel-version}</version>
</dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-health</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-netty-http</artifactId>
+ <scope>test</scope>
+ </dependency>
<!--START OF GENERATED CODE-->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramApiConfig.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramApiConfig.java
new file mode 100644
index 0000000..34f7dfa
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramApiConfig.java
@@ -0,0 +1,60 @@
+/*
+ * 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.springboot;
+
+import org.apache.camel.component.telegram.TelegramComponent;
+
+public class TelegramApiConfig {
+
+ private final String authorizationToken;
+ private final int port;
+ private final String baseUri;
+ private final String chatId;
+
+ public TelegramApiConfig(String baseUri, int port, String authorizationToken, String chatId) {
+ this.baseUri = baseUri;
+ this.port = port;
+ this.authorizationToken = authorizationToken;
+ this.chatId = chatId;
+ }
+
+ public static TelegramApiConfig fromEnv() {
+ final String authorizationToken = System.getenv("TELEGRAM_AUTHORIZATION_TOKEN");
+ final String chatId = System.getenv("TELEGRAM_CHAT_ID");
+ return new TelegramApiConfig(TelegramComponent.BOT_API_DEFAULT_URL, 443, authorizationToken, chatId);
+ }
+
+ public static TelegramApiConfig mock(int port) {
+ return new TelegramApiConfig("http://localhost:" + port, port, "mock-token", "-1");
+ }
+
+ public String getAuthorizationToken() {
+ return authorizationToken;
+ }
+
+ public String getBaseUri() {
+ return baseUri;
+ }
+
+ public String getChatId() {
+ return chatId;
+ }
+
+ public int getPort() {
+ return port;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramChatBotTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramChatBotTest.java
new file mode 100644
index 0000000..4abd1ee
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramChatBotTest.java
@@ -0,0 +1,149 @@
+/*
+ * 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.springboot;
+
+
+import static org.apache.camel.test.junit5.TestSupport.assertCollectionSize;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.OutgoingTextMessage;
+import org.apache.camel.component.telegram.model.UpdateResult;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.awaitility.Awaitility;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramChatBotTest.class,
+ TelegramChatBotTest.TestConfiguration.class
+ }
+)
+public class TelegramChatBotTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testChatBotResult() {
+
+ List<OutgoingTextMessage> msgs = Awaitility.await().atMost(5, TimeUnit.SECONDS)
+ .until(() -> mockRoutes.getMock("sendMessage").getRecordedMessages(),
+ rawMessages -> rawMessages.size() >= 2)
+ .stream()
+ .map(message -> (OutgoingTextMessage) message)
+ .collect(Collectors.toList());
+
+ assertCollectionSize(msgs, 2);
+ assertTrue(msgs.stream().anyMatch(m -> "echo from the bot: Hello World!".equals(m.getText())));
+ assertTrue(msgs.stream().anyMatch(m -> "echo from the bot: taken".equals(m.getText())));
+ assertTrue(msgs.stream().noneMatch(m -> m.getParseMode() != null));
+ }
+
+ /**
+ * This method simulates the first step of the chat-bot logic.
+ *
+ * @param exchange the current exchange originating from the telegram bot
+ */
+ public void chatBotProcess1(Exchange exchange) {
+ if (exchange.getIn().getBody(String.class).equals("intercept")) {
+ exchange.getIn().setBody("taken");
+ }
+ }
+
+ /**
+ * This method simulates the second step of the chat-bot logic.
+ *
+ * @param message the message coming from the telegram bot
+ * @return the reply, if any
+ */
+ public String chatBotProcess2(String message) {
+ return "echo from the bot: " + message;
+ }
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
+ from("telegram:bots?authorizationToken=mock-token")
+ .bean(TelegramChatBotTest.this, "chatBotProcess1")
+ .bean(TelegramChatBotTest.this, "chatBotProcess2")
+ .to("telegram:bots?authorizationToken=mock-token");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ UpdateResult request = getJSONResource("messages/updates-single.json", UpdateResult.class);
+ request.getUpdates().get(0).getMessage().setText("Hello World!");
+ request.getUpdates().get(0).getMessage().getChat().setId("my-chat-id");
+
+ UpdateResult request2 = getJSONResource("messages/updates-single.json", UpdateResult.class);
+ request2.getUpdates().get(0).getMessage().setText("intercept");
+ request2.getUpdates().get(0).getMessage().getChat().setId("my-chat-id");
+
+ mockRoutes = new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.serialize(request),
+ TelegramTestUtil.serialize(request2),
+ TelegramTestUtil.stringResource("messages/updates-empty.json"))
+ .addEndpoint(
+ "sendMessage",
+ "POST",
+ OutgoingTextMessage.class,
+ TelegramTestUtil.stringResource("messages/send-message.json"),
+ TelegramTestUtil.stringResource("messages/send-message.json"),
+ TelegramTestUtil.stringResource("messages/send-message.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramComponentParametersTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramComponentParametersTest.java
new file mode 100644
index 0000000..abb1e78
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramComponentParametersTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.PropertyBindingException;
+import org.apache.camel.component.telegram.TelegramComponent;
+import org.apache.camel.component.telegram.TelegramEndpoint;
+import org.apache.camel.component.telegram.TelegramProxyType;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramComponentParametersTest.class
+ }
+)
+public class TelegramComponentParametersTest extends TelegramTestSupport {
+
+
+
+ @Test
+ public void testDefaultsAndOverrides() throws Exception {
+ TelegramComponent component = (TelegramComponent) context.getComponent("telegram");
+ component.setAuthorizationToken("DEFAULT");
+
+ TelegramEndpoint ep1 = (TelegramEndpoint) component.createEndpoint("telegram:bots");
+ assertEquals("DEFAULT", ep1.getConfiguration().getAuthorizationToken());
+ assertEquals(TelegramProxyType.HTTP, ep1.getConfiguration().getProxyType());
+
+ TelegramEndpoint ep2 = (TelegramEndpoint) component.createEndpoint("telegram:bots?authorizationToken=CUSTOM");
+ assertEquals("CUSTOM", ep2.getConfiguration().getAuthorizationToken());
+
+ TelegramEndpoint ep3 = (TelegramEndpoint) component
+ .createEndpoint("telegram:bots?authorizationToken=ANOTHER&chatId=123");
+ assertEquals("ANOTHER", ep3.getConfiguration().getAuthorizationToken());
+ }
+
+ @Test
+ public void testNonDefaultConfig() {
+ TelegramComponent component = (TelegramComponent) context.getComponent("telegram");
+ component.setAuthorizationToken(null);
+
+ assertThrows(IllegalArgumentException.class, () -> {
+ component.createEndpoint("telegram:bots");
+ });
+ }
+
+ @Test
+ public void testWrongURI1() {
+ TelegramComponent component = (TelegramComponent) context.getComponent("telegram");
+ component.setAuthorizationToken("ANY");
+
+ assertThrows(IllegalArgumentException.class, () -> {
+ component.createEndpoint("telegram:bots/ ");
+ });
+ }
+
+ @Test
+ public void testWrongURI2() {
+ TelegramComponent component = (TelegramComponent) context.getComponent("telegram");
+ component.setAuthorizationToken("ANY");
+
+ assertThrows(IllegalArgumentException.class, () -> {
+ component.createEndpoint("telegram:bots/token/s");
+ });
+ }
+
+ @Test
+ public void testWrongURI3() {
+ TelegramComponent component = (TelegramComponent) context.getComponent("telegram");
+ component.setAuthorizationToken("ANY");
+
+ assertThrows(PropertyBindingException.class, () -> {
+ component.createEndpoint("telegram:bots?proxyType=ANY");
+ });
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConfigurationTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConfigurationTest.java
new file mode 100644
index 0000000..3d18113
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConfigurationTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.TelegramConfiguration;
+import org.apache.camel.component.telegram.TelegramEndpoint;
+import org.apache.camel.component.telegram.TelegramProxyType;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConfigurationTest.class,
+ TelegramConfigurationTest.TestConfiguration.class
+ }
+)
+public class TelegramConfigurationTest extends TelegramTestSupport {
+
+
+
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testChatBotResult() {
+ TelegramEndpoint endpoint = (TelegramEndpoint)context.getEndpoints().stream()
+ .filter(e -> e instanceof TelegramEndpoint).findAny().get();
+ TelegramConfiguration config = endpoint.getConfiguration();
+
+ assertEquals("bots", config.getType());
+ assertEquals("mock-token", config.getAuthorizationToken());
+ assertEquals("12345", config.getChatId());
+ assertEquals(2000L, endpoint.getDelay());
+ assertEquals(Integer.valueOf(10), config.getTimeout());
+ assertEquals(Integer.valueOf(60), config.getLimit());
+ assertEquals("127.0.0.1", config.getProxyHost());
+ assertEquals(Integer.valueOf(1234), config.getProxyPort());
+ assertEquals(TelegramProxyType.SOCKS5, config.getProxyType());
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
+ from("direct:telegram")
+ .to("telegram:bots/?authorizationToken=mock-token&chatId=12345&delay=2000&timeout=10&limit=60&proxyHost=127.0.0.1&proxyPort=1234&proxyType=SOCKS5");
+ }
+ };
+ }
+
+ }
+
+
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerChannelPostTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerChannelPostTest.java
new file mode 100644
index 0000000..04a003d
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerChannelPostTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.IncomingMessage;
+import org.apache.camel.component.telegram.model.IncomingPhotoSize;
+import org.apache.camel.component.telegram.model.IncomingVideo;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerChannelPostTest.class,
+ TelegramConsumerChannelPostTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerChannelPostTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testReceptionOfAMessageWithAVideo() throws Exception {
+ endpoint.expectedMinimumMessageCount(1);
+ endpoint.assertIsSatisfied(5000);
+
+ Exchange mediaExchange = endpoint.getExchanges().get(0);
+ IncomingMessage msg = mediaExchange.getIn().getBody(IncomingMessage.class);
+
+ IncomingVideo video = msg.getVideo();
+
+ assertNotNull(video);
+ assertEquals(Integer.valueOf(2), video.getDurationSeconds());
+ assertEquals(Integer.valueOf(360), video.getHeight());
+ assertEquals(Integer.valueOf(640), video.getWidth());
+ assertEquals(Long.valueOf(299284), video.getFileSize());
+ assertEquals("BAADBAADAgADyzvwCC7_4AyvdAXXXX", video.getFileId());
+
+ IncomingPhotoSize thumb = video.getThumb();
+ assertNotNull(thumb);
+
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token")
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.stringResource("messages/updates-media-video.json"),
+ TelegramTestUtil.stringResource("messages/updates-empty.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerEmptyResponseTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerEmptyResponseTest.java
new file mode 100644
index 0000000..29fd3ee
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerEmptyResponseTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.springboot;
+
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.awaitility.Awaitility;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerEmptyResponseTest.class,
+ TelegramConsumerEmptyResponseTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerEmptyResponseTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testBehaviourWithEmptyUpdates() {
+ /* First make sure the message containing zero updates was sent by the API */
+ Awaitility.await().atMost(5, TimeUnit.SECONDS)
+ .until(() -> mockRoutes.getMock("getUpdates").getRecordedMessages().size() >= 1);
+
+ endpoint.setResultWaitTime(500L);
+ endpoint.expectedMinimumMessageCount(1);
+
+ /* Then make sure that the consumer has sent zero exchanges to the route */
+ assertThrows(AssertionError.class, () -> {
+ endpoint.assertIsSatisfied();
+ });
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token").to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.stringResource("messages/updates-empty.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerFallbackConversionTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerFallbackConversionTest.java
new file mode 100644
index 0000000..daff435
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerFallbackConversionTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.springboot;
+
+
+import static org.apache.camel.test.junit5.TestSupport.assertCollectionSize;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.OutgoingTextMessage;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.awaitility.Awaitility;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerFallbackConversionTest.class,
+ TelegramConsumerFallbackConversionTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerFallbackConversionTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("direct:message")
+ protected ProducerTemplate template;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testEverythingOk() {
+
+ template.sendBody(new BrandNewType("wrapped message"));
+
+ List<OutgoingTextMessage> msgs = Awaitility.await().atMost(5, TimeUnit.SECONDS)
+ .until(() -> mockRoutes.getMock("sendMessage").getRecordedMessages(),
+ rawMessages -> rawMessages.size() == 1)
+ .stream()
+ .map(message -> (OutgoingTextMessage) message)
+ .collect(Collectors.toList());
+
+ assertCollectionSize(msgs, 1);
+ String text = msgs.get(0).getText();
+ assertEquals("wrapped message", text);
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:message")
+ .to("telegram:bots?authorizationToken=mock-token&chatId=1234");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "sendMessage",
+ "POST",
+ OutgoingTextMessage.class,
+ TelegramTestUtil.stringResource("messages/send-message.json"),
+ TelegramTestUtil.stringResource("messages/send-message.json"),
+ TelegramTestUtil.stringResource("messages/send-message.json"));
+ return mockRoutes;
+ }
+
+ private static class BrandNewType {
+
+ String message;
+
+ BrandNewType(String message) {
+ this.message = message;
+ }
+
+ @Override
+ public String toString() {
+ // to use default conversion from Object to String
+ return message;
+ }
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerHealthCheckErrorDisabledConsumerTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerHealthCheckErrorDisabledConsumerTest.java
new file mode 100644
index 0000000..efabaf3
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerHealthCheckErrorDisabledConsumerTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.springboot;
+
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.health.HealthCheckRepository;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.awaitility.Awaitility;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerHealthCheckErrorDisabledConsumerTest.class,
+ TelegramConsumerHealthCheckErrorDisabledConsumerTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerHealthCheckErrorDisabledConsumerTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Override
+ protected void configureCamelContext(CamelContext context) {
+ // enabling routes health check is a bit cumbersome via low-level Java code
+ super.configureCamelContext(context);
+ HealthCheckRegistry hcr = context.getExtension(HealthCheckRegistry.class);
+ HealthCheckRepository repo = hcr.getRepository("routes").orElse((HealthCheckRepository) hcr.resolveById("routes"));
+ repo.setEnabled(true);
+ hcr.register(repo);
+ // enabling consumers health check is a bit cumbersome via low-level Java code
+ repo = hcr.getRepository("consumers").orElse((HealthCheckRepository) hcr.resolveById("consumers"));
+ // turn off all consumer health checks
+ repo.setEnabled(true);
+ hcr.register(repo);
+ }
+
+ @Test
+ public void testReceptionOfTwoMessages() {
+ HealthCheckRegistry hcr = context.getExtension(HealthCheckRegistry.class);
+ HealthCheckRepository repo = hcr.getRepository("routes").get();
+
+ // should not be UP from the start as routes can be started
+ boolean down = repo.stream().anyMatch(h -> h.call().getState().equals(HealthCheck.State.DOWN));
+ Assertions.assertFalse(down, "None health-check should be DOWN");
+
+ // wait until HC is UP
+ Awaitility.waitAtMost(5, TimeUnit.SECONDS).until(
+ () -> repo.stream().anyMatch(h -> h.call().getState().equals(HealthCheck.State.UP)));
+
+ // if we grab the health check by id, we can also check it afterwards
+ HealthCheck hc = hcr.getCheck("telegram").get();
+ HealthCheck.Result rc = hc.call();
+
+ // so routes health check just check the status of the route which is started (UP)
+ // but the telegram consumer is not healthy as it keeps getting 401 errors
+ // to detect this we needed the consumer health check which has been disabled
+ Assertions.assertEquals(HealthCheck.State.UP, rc.getState());
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token").routeId("telegram")
+ .convertBodyTo(String.class)
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addErrorEndpoint(
+ "getUpdates",
+ "GET",
+ 401);
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerHealthCheckErrorTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerHealthCheckErrorTest.java
new file mode 100644
index 0000000..4b1f605
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerHealthCheckErrorTest.java
@@ -0,0 +1,141 @@
+/*
+ * 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.springboot;
+
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.health.HealthCheckRepository;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.awaitility.Awaitility;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerHealthCheckErrorTest.class,
+ TelegramConsumerHealthCheckErrorTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerHealthCheckErrorTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Override
+ protected void configureCamelContext(CamelContext context) {
+ // enabling consumers health check is a bit cumbersome via low-level Java code
+ super.configureCamelContext(context);
+ HealthCheckRegistry hcr = context.getExtension(HealthCheckRegistry.class);
+ HealthCheckRepository repo
+ = hcr.getRepository("consumers").orElse((HealthCheckRepository) hcr.resolveById("consumers"));
+ repo.setEnabled(true);
+ hcr.register(repo);
+ }
+
+ @Test
+ public void testReceptionOfTwoMessages() {
+ HealthCheckRegistry hcr = context.getExtension(HealthCheckRegistry.class);
+ HealthCheckRepository repo = hcr.getRepository("consumers").get();
+
+ // wait until HC is DOWN
+ Awaitility.waitAtMost(5, TimeUnit.SECONDS).until(
+ () -> repo.stream().anyMatch(h -> h.call().getState().equals(HealthCheck.State.DOWN)));
+
+ // if we grab the health check by id, we can also check it afterwards
+ HealthCheck hc = hcr.getCheck("consumer:telegram").get();
+
+ // wait until we have the error
+ Awaitility.waitAtMost(5, TimeUnit.SECONDS).until(
+ () -> {
+ HealthCheck.Result rc = hc.call();
+ Long count = (Long) rc.getDetails().get(HealthCheck.FAILURE_ERROR_COUNT);
+ return count != null && count > 0;
+ });
+
+ HealthCheck.Result rc = hc.call();
+
+ // and get the detailed error message (and exception)
+ Assertions.assertEquals(HealthCheck.State.DOWN, rc.getState());
+ String msg = rc.getMessage().get();
+ long count = (long) rc.getDetails().get(HealthCheck.FAILURE_ERROR_COUNT);
+ Assertions.assertEquals("Consumer failed polling " + count + " times route: telegram (telegram://bots)", msg);
+ // test that the uri is masked
+ Assertions.assertEquals("telegram://bots?authorizationToken=xxxxxx",
+ rc.getDetails().get(HealthCheck.ENDPOINT_URI));
+
+ Throwable e = rc.getError().get();
+ Assertions.assertTrue(e.getMessage().contains("401 Unauthorized"));
+ Assertions.assertEquals(401, rc.getDetails().get(HealthCheck.HTTP_RESPONSE_CODE));
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token").routeId("telegram")
+ .convertBodyTo(String.class)
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addErrorEndpoint(
+ "getUpdates",
+ "GET",
+ 401);
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerHealthCheckOkTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerHealthCheckOkTest.java
new file mode 100644
index 0000000..041aa93
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerHealthCheckOkTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.UpdateResult;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.health.HealthCheckRepository;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerHealthCheckOkTest.class,
+ TelegramConsumerHealthCheckOkTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerHealthCheckOkTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Override
+ protected void configureCamelContext(CamelContext context) {
+ // enabling consumers health check is a bit cumbersome via low-level Java code
+ super.configureCamelContext(context);
+ HealthCheckRegistry hcr = context.getExtension(HealthCheckRegistry.class);
+ HealthCheckRepository repo
+ = hcr.getRepository("consumers").orElse((HealthCheckRepository) hcr.resolveById("consumers"));
+ repo.setEnabled(true);
+ hcr.register(repo);
+ }
+
+ @Test
+ public void testReceptionOfTwoMessages() throws Exception {
+ HealthCheckRegistry hcr = context.getExtension(HealthCheckRegistry.class);
+ HealthCheckRepository repo = hcr.getRepository("consumers").get();
+
+ endpoint.expectedMinimumMessageCount(2);
+ endpoint.expectedBodiesReceived("message1", "message2");
+
+ endpoint.assertIsSatisfied(5000);
+
+ repo.stream().forEach(h -> Assertions.assertEquals(HealthCheck.State.UP, h.call().getState()));
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token")
+ .convertBodyTo(String.class)
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ UpdateResult res1 = getJSONResource("messages/updates-single.json", UpdateResult.class);
+ res1.getUpdates().get(0).getMessage().setText("message1");
+
+ UpdateResult res2 = getJSONResource("messages/updates-single.json", UpdateResult.class);
+ res2.getUpdates().get(0).getMessage().setText("message2");
+
+ UpdateResult defaultRes = getJSONResource("messages/updates-empty.json", UpdateResult.class);
+
+ mockRoutes = new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.serialize(res1),
+ TelegramTestUtil.serialize(res2),
+ TelegramTestUtil.serialize(defaultRes));
+
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerIncomingInlineQueryTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerIncomingInlineQueryTest.java
new file mode 100644
index 0000000..2bf5b48
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerIncomingInlineQueryTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.IncomingInlineQuery;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerIncomingInlineQueryTest.class,
+ TelegramConsumerIncomingInlineQueryTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerIncomingInlineQueryTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testReceptionOfMessageWithAnInlineQueryMessage() throws Exception {
+ endpoint.expectedMinimumMessageCount(1);
+ endpoint.assertIsSatisfied(5000);
+
+ Exchange mediaExchange = endpoint.getExchanges().get(0);
+ IncomingInlineQuery msg = mediaExchange.getIn().getBody(IncomingInlineQuery.class);
+
+ //checking body
+ assertNotNull(msg);
+ assertEquals("test", msg.getQuery());
+ assertEquals("Doe", msg.getFrom().getLastName());
+ assertEquals("John", msg.getFrom().getFirstName());
+
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token")
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.stringResource("messages/updates-inline-query-message.json"),
+ TelegramTestUtil.stringResource("messages/updates-empty.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMappingTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMappingTest.java
new file mode 100644
index 0000000..7f17761
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMappingTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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.springboot;
+
+
+import java.time.Instant;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.TelegramConstants;
+import org.apache.camel.component.telegram.model.Chat;
+import org.apache.camel.component.telegram.model.IncomingMessage;
+import org.apache.camel.component.telegram.model.MessageResult;
+import org.apache.camel.component.telegram.model.User;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerMappingTest.class,
+ TelegramConsumerMappingTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerMappingTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testMessageMapping() throws Exception {
+ endpoint.expectedMinimumMessageCount(1);
+ endpoint.expectedMessageCount(1);
+ endpoint.assertIsSatisfied(5000);
+
+ Exchange ex = endpoint.getExchanges().get(0);
+ Message m = ex.getIn();
+
+ assertNotNull(m);
+
+ // checking headers
+ assertEquals("-45658", m.getHeader(TelegramConstants.TELEGRAM_CHAT_ID));
+
+ // checking body
+ assertNotNull(m.getBody());
+ assertTrue(m.getBody() instanceof IncomingMessage);
+ IncomingMessage body = (IncomingMessage) m.getBody();
+
+ assertEquals("a message", body.getText());
+ assertEquals(Long.valueOf(179L), body.getMessageId());
+ assertEquals(Instant.ofEpochSecond(1463436626L), body.getDate());
+
+ // checking from
+ User user = body.getFrom();
+ assertNotNull(user);
+ assertEquals("John", user.getFirstName());
+ assertEquals("Doe", user.getLastName());
+ assertEquals(Long.valueOf(1585844777), user.getId());
+
+ // checking chat
+ Chat chat = body.getChat();
+ assertNotNull(chat);
+ assertEquals("-45658", chat.getId());
+ assertEquals("A chat group", chat.getTitle());
+ assertEquals("group", chat.getType());
+
+ }
+
+ @Test
+ public void testMessageResultMapping() {
+ MessageResult messageResult = getJSONResource("messages/updates-sendLocation.json", MessageResult.class);
+
+ assertEquals(true, messageResult.isOk());
+ assertEquals(true, messageResult.isOk());
+ assertEquals((Long) 33L, messageResult.getMessage().getMessageId());
+ assertEquals(Instant.ofEpochSecond(1548091564).getEpochSecond(), messageResult.getMessage().getDate().getEpochSecond());
+ assertEquals((Long) 665977497L, messageResult.getMessage().getFrom().getId());
+ assertEquals(true, messageResult.getMessage().getFrom().isBot());
+ assertEquals("camelbot", messageResult.getMessage().getFrom().getFirstName());
+ assertEquals("camel_component_bot", messageResult.getMessage().getFrom().getUsername());
+
+ assertEquals("-182520913", messageResult.getMessage().getChat().getId());
+ assertEquals("testgroup", messageResult.getMessage().getChat().getTitle());
+ assertEquals("group", messageResult.getMessage().getChat().getType());
+ assertEquals(true, messageResult.getMessage().getChat().isAllMembersAreAdministrators());
+
+ assertEquals(59.9386292, messageResult.getMessage().getLocation().getLatitude(), 1.0E-07);
+ assertEquals(30.3141308, messageResult.getMessage().getLocation().getLongitude(), 1.0E-07);
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token").to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.stringResource("messages/updates-single.json"),
+ TelegramTestUtil.stringResource("messages/updates-empty.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaDocumentTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaDocumentTest.java
new file mode 100644
index 0000000..9bb2b21
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaDocumentTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.IncomingDocument;
+import org.apache.camel.component.telegram.model.IncomingMessage;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerMediaDocumentTest.class,
+ TelegramConsumerMediaDocumentTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerMediaDocumentTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testReceptionOfMessageWithADocument() throws Exception {
+ endpoint.expectedMinimumMessageCount(1);
+ endpoint.assertIsSatisfied(5000);
+
+ Exchange mediaExchange = endpoint.getExchanges().get(0);
+ IncomingMessage msg = mediaExchange.getIn().getBody(IncomingMessage.class);
+
+ IncomingDocument document = msg.getDocument();
+
+ assertNotNull(document);
+ assertEquals("AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABLXiiSI1vzZK8XXXXXXX", document.getFileId());
+ assertEquals(Long.valueOf(12530), document.getFileSize());
+ assertEquals("file.png", document.getFileName());
+ assertEquals("image/png", document.getMimeType());
+ assertNotNull(document.getThumb());
+ assertEquals(Integer.valueOf(90), document.getThumb().getWidth());
+ assertEquals(Integer.valueOf(80), document.getThumb().getHeight());
+ assertEquals(Long.valueOf(1253), document.getThumb().getFileSize());
+ assertEquals("AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABLXiiSI1vzZK9XXXXXXX", document.getThumb().getFileId());
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token")
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.stringResource("messages/updates-media-document.json"),
+ TelegramTestUtil.stringResource("messages/updates-empty.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaGameTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaGameTest.java
new file mode 100644
index 0000000..b630c16
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaGameTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.IncomingGame;
+import org.apache.camel.component.telegram.model.IncomingMessage;
+import org.apache.camel.component.telegram.model.InlineKeyboardMarkup;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerMediaGameTest.class,
+ TelegramConsumerMediaGameTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerMediaGameTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testReceptionOfAMessageWithAGame() throws Exception {
+ endpoint.expectedMinimumMessageCount(1);
+ endpoint.assertIsSatisfied(5000);
+
+ Exchange mediaExchange = endpoint.getExchanges().get(0);
+ IncomingMessage msg = mediaExchange.getIn().getBody(IncomingMessage.class);
+
+ IncomingGame game = msg.getGame();
+ InlineKeyboardMarkup inlineKeyboardMarkup = (InlineKeyboardMarkup) msg.getReplyMarkup();
+
+ Assertions.assertNotNull(game);
+ Assertions.assertEquals("test_game", game.getTitle());
+ Assertions.assertEquals("test", game.getDescription());
+ Assertions.assertEquals("game text", game.getText());
+ Assertions.assertEquals(1, game.getPhoto().size());
+ Assertions.assertEquals("AgADBAADnrAxG1rhiVAsV1IghUpUwn4eqhsABAEAAwIAA20AA32sBQABFgQ",
+ game.getPhoto().get(0).getFileId());
+ Assertions.assertEquals(2469, game.getPhoto().get(0).getFileSize());
+ Assertions.assertEquals(180, game.getPhoto().get(0).getHeight());
+ Assertions.assertEquals(320, game.getPhoto().get(0).getWidth());
+ Assertions.assertEquals("AQADfh6qGwAEfawFAAE", game.getPhoto().get(0).getFileUniqueId());
+
+ Assertions.assertNotNull(inlineKeyboardMarkup);
+ Assertions.assertEquals("Play test_game", inlineKeyboardMarkup.getInlineKeyboard().get(0).get(0).getText());
+
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token")
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.stringResource("messages/updates-media-game.json"),
+ TelegramTestUtil.stringResource("messages/updates-empty.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaPhotoTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaPhotoTest.java
new file mode 100644
index 0000000..c53252f
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaPhotoTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.springboot;
+
+
+import static org.apache.camel.test.junit5.TestSupport.assertCollectionSize;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.IncomingMessage;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerMediaPhotoTest.class,
+ TelegramConsumerMediaPhotoTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerMediaPhotoTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testReceptionOfTwoMessagesOneWithMedia() throws Exception {
+ endpoint.expectedMinimumMessageCount(2);
+ endpoint.assertIsSatisfied(5000);
+
+ Exchange mediaExchange = endpoint.getExchanges().get(1);
+ IncomingMessage msg = mediaExchange.getIn().getBody(IncomingMessage.class);
+
+ assertNotNull(msg.getPhoto());
+ assertCollectionSize(msg.getPhoto(), 4);
+ assertEquals(4, msg.getPhoto().stream().map(ph -> ph.getFileId()).distinct().count());
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token")
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.stringResource("messages/updates-media.json"),
+ TelegramTestUtil.stringResource("messages/updates-empty.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaStickerTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaStickerTest.java
new file mode 100644
index 0000000..16a11db
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaStickerTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.IncomingMaskPosition;
+import org.apache.camel.component.telegram.model.IncomingMessage;
+import org.apache.camel.component.telegram.model.IncomingPhotoSize;
+import org.apache.camel.component.telegram.model.IncomingSticker;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerMediaStickerTest.class,
+ TelegramConsumerMediaStickerTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerMediaStickerTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testReceptionOfAMessageWithASticker() throws Exception {
+ endpoint.expectedMinimumMessageCount(1);
+ endpoint.assertIsSatisfied(5000);
+
+ Exchange mediaExchange = endpoint.getExchanges().get(0);
+ IncomingMessage msg = mediaExchange.getIn().getBody(IncomingMessage.class);
+
+ IncomingSticker sticker = msg.getSticker();
+
+ assertNotNull(sticker);
+ assertEquals(Integer.valueOf(512), sticker.getHeight());
+ assertEquals(Integer.valueOf(512), sticker.getWidth());
+ assertEquals("\ud83d\ude28", sticker.getEmoji());
+ assertEquals("CAADBAADEQADmDVxAkmg3XnDZam0FgQ", sticker.getFileId());
+ assertEquals("GreatMindsColor", sticker.getSetName());
+ assertFalse(sticker.getAnimated());
+
+ IncomingMaskPosition incomingMaskPosition = sticker.getMaskPosition();
+ assertEquals("forehead", incomingMaskPosition.getPoint());
+ assertEquals(2.0f, incomingMaskPosition.getScale());
+ assertEquals(-1.0f, incomingMaskPosition.getxShift());
+ assertEquals(1.0f, incomingMaskPosition.getyShift());
+
+ IncomingPhotoSize thumb = sticker.getThumb();
+ assertNotNull(thumb);
+
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token")
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.stringResource("messages/updates-media-sticker.json"),
+ TelegramTestUtil.stringResource("messages/updates-empty.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaVideoTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaVideoTest.java
new file mode 100644
index 0000000..b4ea435
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMediaVideoTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.IncomingMessage;
+import org.apache.camel.component.telegram.model.IncomingPhotoSize;
+import org.apache.camel.component.telegram.model.IncomingVideo;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerMediaVideoTest.class,
+ TelegramConsumerMediaVideoTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerMediaVideoTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testReceptionOfAMessageWithAVideo() throws Exception {
+ endpoint.expectedMinimumMessageCount(1);
+ endpoint.assertIsSatisfied(5000);
+
+ Exchange mediaExchange = endpoint.getExchanges().get(0);
+ IncomingMessage msg = mediaExchange.getIn().getBody(IncomingMessage.class);
+
+ IncomingVideo video = msg.getVideo();
+
+ assertNotNull(video);
+ assertEquals(Integer.valueOf(2), video.getDurationSeconds());
+ assertEquals(Integer.valueOf(360), video.getHeight());
+ assertEquals(Integer.valueOf(640), video.getWidth());
+ assertEquals(Long.valueOf(299284), video.getFileSize());
+ assertEquals("BAADBAADAgADyzvwCC7_4AyvdAXXXX", video.getFileId());
+
+ IncomingPhotoSize thumb = video.getThumb();
+ assertNotNull(thumb);
+
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token")
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.stringResource("messages/updates-media-video.json"),
+ TelegramTestUtil.stringResource("messages/updates-empty.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMultipleTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMultipleTest.java
new file mode 100644
index 0000000..88105df
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerMultipleTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.UpdateResult;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerMultipleTest.class,
+ TelegramConsumerMultipleTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerMultipleTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testReceptionOfThreeMessagesFromTwoUpdates() throws Exception {
+ endpoint.expectedMinimumMessageCount(3);
+ endpoint.expectedBodiesReceived("message1", "message2", "message3");
+
+ endpoint.assertIsSatisfied(5000);
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token")
+ .convertBodyTo(String.class)
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ UpdateResult res1 = getJSONResource("messages/updates-single.json", UpdateResult.class);
+ res1.getUpdates().get(0).getMessage().setText("message1");
+
+ UpdateResult res2 = getJSONResource("messages/updates-multiple.json", UpdateResult.class);
+ res2.getUpdates().get(0).getMessage().setText("message2");
+ res2.getUpdates().get(1).getMessage().setText("message3");
+
+ UpdateResult defaultRes = getJSONResource("messages/updates-empty.json", UpdateResult.class);
+
+ mockRoutes = new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.serialize(res1),
+ TelegramTestUtil.serialize(res2),
+ TelegramTestUtil.serialize(defaultRes));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerServiceErrorTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerServiceErrorTest.java
new file mode 100644
index 0000000..21a986e
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerServiceErrorTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.UpdateResult;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerServiceErrorTest.class,
+ TelegramConsumerServiceErrorTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerServiceErrorTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testConsumerRecovery() throws Exception {
+ endpoint.expectedMinimumMessageCount(1);
+ endpoint.expectedBodiesReceived("message1");
+
+ endpoint.assertIsSatisfied(5000);
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("telegram:bots?authorizationToken=mock-token")
+ .convertBodyTo(String.class)
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ UpdateResult res1 = getJSONResource("messages/updates-single.json", UpdateResult.class);
+ res1.getUpdates().get(0).getMessage().setText("message1");
+
+ UpdateResult logicalErrorRes = getJSONResource("messages/updates-empty.json", UpdateResult.class);
+ logicalErrorRes.setOk(false);
+
+ UpdateResult defaultRes = getJSONResource("messages/updates-empty.json", UpdateResult.class);
+
+ mockRoutes = new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.serialize(res1),
+ TelegramTestUtil.serialize(logicalErrorRes),
+ TelegramTestUtil.serialize(defaultRes));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerSingleTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerSingleTest.java
new file mode 100644
index 0000000..3dab436
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramConsumerSingleTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.UpdateResult;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramConsumerSingleTest.class,
+ TelegramConsumerSingleTest.TestConfiguration.class
+ }
+)
+public class TelegramConsumerSingleTest extends TelegramTestSupport {
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ @Test
+ public void testReceptionOfTwoMessages() throws Exception {
+ endpoint.expectedMinimumMessageCount(2);
+ endpoint.expectedBodiesReceived("message1", "message2");
+
+ endpoint.assertIsSatisfied(5000);
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("telegram:bots?authorizationToken=mock-token")
+ .convertBodyTo(String.class)
+ .to("mock:telegram");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+
+ UpdateResult res1 = getJSONResource("messages/updates-single.json", UpdateResult.class);
+ res1.getUpdates().get(0).getMessage().setText("message1");
+
+ UpdateResult res2 = getJSONResource("messages/updates-single.json", UpdateResult.class);
+ res2.getUpdates().get(0).getMessage().setText("message2");
+
+ UpdateResult defaultRes = getJSONResource("messages/updates-empty.json", UpdateResult.class);
+
+ return new TelegramMockRoutes(port)
+ .addEndpoint(
+ "getUpdates",
+ "GET",
+ String.class,
+ TelegramTestUtil.serialize(res1),
+ TelegramTestUtil.serialize(res2),
+ TelegramTestUtil.serialize(defaultRes));
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramMockRoutes.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramMockRoutes.java
new file mode 100644
index 0000000..a3357c8
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramMockRoutes.java
@@ -0,0 +1,145 @@
+/*
+ * 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.springboot;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TelegramMockRoutes extends RouteBuilder {
+ private static final Logger LOG = LoggerFactory.getLogger(TelegramMockRoutes.class);
+
+ private final int port;
+ private final Map<String, MockProcessor<?>> mocks = new LinkedHashMap<>();
+
+ public TelegramMockRoutes(int port) {
+ this.port = port;
+ }
+
+ public TelegramMockRoutes addEndpoint(String path, String method, Class<?> returnType, String... responseBodies) {
+ this.mocks.put(path, new MockProcessor<>(method, path, returnType, responseBodies));
+ return this;
+ }
+
+ public TelegramMockRoutes addErrorEndpoint(String path, String method, int errorCode) {
+ this.mocks.put(path, new MockProcessor<>(method, path, errorCode));
+ return this;
+ }
+
+ @Override
+ public void configure() {
+
+ mocks.forEach((key, value) -> {
+ from("netty-http:http://localhost:" + port + "/botmock-token/" + key + "?httpMethodRestrict=" + value.method)
+ .process(value);
+ });
+
+ }
+
+ public static class MockProcessor<T> implements Processor {
+ private final String method;
+ private final String path;
+ private final List<T> recordedMessages = new ArrayList<>();
+ private int errorCode;
+ private final String[] responseBodies;
+ private final Object lock = new Object();
+ private final Class<?> returnType;
+
+ public MockProcessor(String method, String path, Class<T> returnType, String... responseBodies) {
+ this.method = method;
+ this.path = path;
+ this.returnType = returnType;
+ this.responseBodies = responseBodies;
+ }
+
+ public MockProcessor(String method, String path, int errorCode) {
+ this.method = method;
+ this.path = path;
+ this.returnType = String.class;
+ this.responseBodies = null;
+ this.errorCode = errorCode;
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ synchronized (lock) {
+ final Message m = exchange.getMessage();
+ if (errorCode > 0) {
+ m.setHeader(Exchange.HTTP_RESPONSE_CODE, errorCode);
+ } else {
+ final int responseIndex = Math.min(recordedMessages.size(), responseBodies.length - 1);
+ if (returnType == byte[].class) {
+ recordedMessages.add((T) m.getBody(byte[].class));
+ } else {
+ final String rawBody = m.getBody(String.class);
+ LOG.debug("Recording {} {} body {}", method, path, rawBody);
+ @SuppressWarnings("unchecked")
+ final T body
+ = returnType != String.class
+ ? (T) new ObjectMapper().readValue(rawBody, returnType) : (T) rawBody;
+ recordedMessages.add(body);
+ final byte[] bytes = responseBodies[responseIndex].getBytes(StandardCharsets.UTF_8);
+ m.setBody(bytes);
+ m.setHeader("Content-Length", bytes.length);
+ m.setHeader("Content-Type", "application/json; charset=UTF-8");
+ }
+ }
+ }
+ }
+
+ public void clearRecordedMessages() {
+ synchronized (lock) {
+ recordedMessages.clear();
+ }
+ }
+
+ public List<T> getRecordedMessages() {
+ synchronized (lock) {
+ return new ArrayList<T>(recordedMessages);
+ }
+ }
+
+ public List<T> awaitRecordedMessages(int count, long timeoutMillis) {
+ return Awaitility.await()
+ .atMost(timeoutMillis, TimeUnit.MILLISECONDS)
+ .until(this::getRecordedMessages, msgs -> msgs.size() >= count);
+ }
+
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> MockProcessor<T> getMock(String path) {
+ return (MockProcessor<T>) mocks.get(path);
+ }
+
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramProducerChatIdResolutionTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramProducerChatIdResolutionTest.java
new file mode 100644
index 0000000..549c064
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramProducerChatIdResolutionTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.springboot;
+
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.telegram.TelegramConstants;
+import org.apache.camel.component.telegram.model.OutgoingTextMessage;
+import org.apache.camel.component.telegram.springboot.TelegramMockRoutes.MockProcessor;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramProducerChatIdResolutionTest.class,
+ TelegramProducerChatIdResolutionTest.TestConfiguration.class
+ }
+)
+public class TelegramProducerChatIdResolutionTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("direct:telegram")
+ private Endpoint endpoint;
+
+ @Test
+ public void testRouteWithFixedChatId() {
+ final MockProcessor<OutgoingTextMessage> mockProcessor = mockRoutes.getMock("sendMessage");
+ mockProcessor.clearRecordedMessages();
+
+ template.sendBody(endpoint, "Hello");
+
+ final OutgoingTextMessage message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+ assertEquals("my-id", message.getChatId());
+ assertEquals("Hello", message.getText());
+ assertNull(message.getParseMode());
+ }
+
+ @Test
+ public void testRouteWithOverridenChatId() {
+ final MockProcessor<OutgoingTextMessage> mockProcessor = mockRoutes.getMock("sendMessage");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setBody("Hello 2");
+ exchange.getIn().setHeader(TelegramConstants.TELEGRAM_CHAT_ID, "my-second-id");
+
+ template.send(endpoint, exchange);
+
+ final OutgoingTextMessage message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+ assertEquals("my-second-id", message.getChatId());
+ assertEquals("Hello 2", message.getText());
+ assertNull(message.getParseMode());
+
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:telegram")
+ .to("telegram:bots?authorizationToken=mock-token&chatId=my-id");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "sendMessage",
+ "POST",
+ OutgoingTextMessage.class,
+ TelegramTestUtil.stringResource("messages/send-message.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramProducerLocationTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramProducerLocationTest.java
new file mode 100644
index 0000000..a52d3b3
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramProducerLocationTest.java
@@ -0,0 +1,154 @@
+/*
+ * 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.springboot;
+
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.EditMessageLiveLocationMessage;
+import org.apache.camel.component.telegram.model.MessageResult;
+import org.apache.camel.component.telegram.model.SendLocationMessage;
+import org.apache.camel.component.telegram.model.SendVenueMessage;
+import org.apache.camel.component.telegram.model.StopMessageLiveLocationMessage;
+import org.apache.camel.component.telegram.springboot.TelegramMockRoutes.MockProcessor;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramProducerLocationTest.class,
+ TelegramProducerLocationTest.TestConfiguration.class
+ }
+)
+public class TelegramProducerLocationTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("mock:telegram")
+ private MockEndpoint endpoint;
+
+ private final double latitude = 59.9386292;
+ private final double longitude = 30.3141308;
+
+ @Test
+ public void testSendLocation() {
+ SendLocationMessage msg = new SendLocationMessage(latitude, longitude);
+ template.requestBody("direct:telegram", msg, MessageResult.class);
+
+ final MockProcessor<SendLocationMessage> mockProcessor = mockRoutes.getMock("sendLocation");
+ assertThat(mockProcessor.awaitRecordedMessages(1, 5000).get(0))
+ .usingRecursiveComparison()
+ .isEqualTo(msg);
+ }
+
+ @Test
+ public void testSendVenue() {
+ SendVenueMessage msg = new SendVenueMessage(latitude, longitude, "title", "address");
+ template.requestBody("direct:telegram", msg, MessageResult.class);
+
+ final MockProcessor<SendVenueMessage> mockProcessor = mockRoutes.getMock("sendVenue");
+ assertThat(mockProcessor.awaitRecordedMessages(1, 5000).get(0))
+ .usingRecursiveComparison()
+ .isEqualTo(msg);
+ }
+
+ @Test
+ public void testEditMessageLiveLocation() {
+ EditMessageLiveLocationMessage msg = new EditMessageLiveLocationMessage(latitude, longitude);
+ template.requestBody("direct:telegram", msg, MessageResult.class);
+
+ final MockProcessor<EditMessageLiveLocationMessage> mockProcessor = mockRoutes.getMock("editMessageLiveLocation");
+ assertThat(mockProcessor.awaitRecordedMessages(1, 5000).get(0))
+ .usingRecursiveComparison()
+ .isEqualTo(msg);
+ }
+
+ @Test
+ public void testStopMessageLiveLocation() {
+ StopMessageLiveLocationMessage msg = new StopMessageLiveLocationMessage();
+ template.requestBody("direct:telegram", msg, MessageResult.class);
+
+ final MockProcessor<StopMessageLiveLocationMessage> mockProcessor = mockRoutes.getMock("stopMessageLiveLocation");
+ assertThat(mockProcessor.awaitRecordedMessages(1, 5000).get(0))
+ .usingRecursiveComparison()
+ .isEqualTo(msg);
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:telegram").to("telegram:bots?authorizationToken=mock-token&chatId=" + chatId);
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "sendLocation",
+ "POST",
+ SendLocationMessage.class,
+ TelegramTestUtil.stringResource("messages/send-location.json"))
+ .addEndpoint(
+ "sendVenue",
+ "POST",
+ SendVenueMessage.class,
+ TelegramTestUtil.stringResource("messages/send-venue.json"))
+ .addEndpoint(
+ "editMessageLiveLocation",
+ "POST",
+ EditMessageLiveLocationMessage.class,
+ TelegramTestUtil.stringResource("messages/edit-message-live-location.json"))
+ .addEndpoint(
+ "stopMessageLiveLocation",
+ "POST",
+ StopMessageLiveLocationMessage.class,
+ TelegramTestUtil.stringResource("messages/stop-message-live-location.json"));
+ return mockRoutes;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramProducerMediaTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramProducerMediaTest.java
new file mode 100644
index 0000000..8b5fd50
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramProducerMediaTest.java
@@ -0,0 +1,459 @@
+/*
+ * 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.springboot;
+
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.telegram.TelegramConstants;
+import org.apache.camel.component.telegram.TelegramMediaType;
+import org.apache.camel.component.telegram.TelegramParseMode;
+import org.apache.camel.component.telegram.model.ForceReply;
+import org.apache.camel.component.telegram.model.InlineKeyboardButton;
+import org.apache.camel.component.telegram.model.InlineKeyboardMarkup;
+import org.apache.camel.component.telegram.model.OutgoingGameMessage;
+import org.apache.camel.component.telegram.model.OutgoingTextMessage;
+import org.apache.camel.component.telegram.model.ReplyKeyboardMarkup;
+import org.apache.camel.component.telegram.model.ReplyKeyboardRemove;
+import org.apache.camel.component.telegram.springboot.TelegramMockRoutes.MockProcessor;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramProducerMediaTest.class,
+ TelegramProducerMediaTest.TestConfiguration.class
+ }
+)
+public class TelegramProducerMediaTest extends TelegramTestSupport {
+
+
+ static TelegramMockRoutes mockRoutes;
+
+ @EndpointInject("direct:telegram")
+ private Endpoint endpoint;
+
+ @Test
+ public void testRouteWithPngImage() throws Exception {
+
+ final MockProcessor<byte[]> mockProcessor = mockRoutes.getMock("sendPhoto");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION, "Photo");
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.PHOTO_PNG.name());
+ byte[] image = TelegramTestUtil.createSampleImage("PNG");
+ ex.getIn().setBody(image);
+
+ template.send(endpoint, ex);
+
+ /* message contains a multipart body */
+ final byte[] message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+ assertMultipartText(message, "chat_id", "my-id");
+ assertTrue(contains(message, image));
+ assertMultipartFilename(message, "photo", "photo.png");
+ assertMultipartText(message, "caption", "Photo");
+ }
+
+ @Test
+ public void testRouteWithJpgImage() throws Exception {
+
+ final MockProcessor<byte[]> mockProcessor = mockRoutes.getMock("sendPhoto");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION, "Photo");
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.PHOTO_JPG); // without using
+ // .name()
+ byte[] image = TelegramTestUtil.createSampleImage("JPG");
+ ex.getIn().setBody(image);
+
+ template.send(endpoint, ex);
+
+ final byte[] message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+ assertMultipartText(message, "chat_id", "my-id");
+ assertTrue(contains(message, image));
+ assertMultipartFilename(message, "photo", "photo.jpg");
+ assertMultipartText(message, "caption", "Photo");
+ }
+
+ @Test
+ public void testRouteWithJpgImageAndForceReply() throws IOException {
+ final MockProcessor<byte[]> mockProcessor = mockRoutes.getMock("sendPhoto");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION, "Photo");
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.PHOTO_JPG);
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_MARKUP, new ForceReply(true));
+
+ byte[] image = TelegramTestUtil.createSampleImage("JPG");
+ ex.getIn().setBody(image);
+
+ template.send(endpoint, ex);
+
+ final byte[] message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+
+ assertMultipartText(message, "chat_id", "my-id");
+ assertTrue(contains(message, image));
+ assertMultipartFilename(message, "photo", "photo.jpg");
+ assertMultipartText(message, "caption", "Photo");
+ assertMultipartText(message, "reply_markup", new ForceReply(true).toJson());
+ }
+
+ @Test
+ public void testRouteWithJpgAndReplyKeyboardRemove() throws IOException {
+ final MockProcessor<byte[]> mockProcessor = mockRoutes.getMock("sendPhoto");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION, "Photo");
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.PHOTO_JPG);
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_MARKUP, new ReplyKeyboardRemove(true));
+
+ byte[] image = TelegramTestUtil.createSampleImage("JPG");
+ ex.getIn().setBody(image);
+
+ template.send(endpoint, ex);
+
+ final byte[] message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+
+ assertMultipartText(message, "chat_id", "my-id");
+ assertTrue(contains(message, image));
+ assertMultipartFilename(message, "photo", "photo.jpg");
+ assertMultipartText(message, "caption", "Photo");
+ assertMultipartText(message, "reply_markup", new ReplyKeyboardRemove(true).toJson());
+ }
+
+ @Test
+ public void testRouteWithJpgAndInlineKeyboardMarkup() throws IOException {
+ final MockProcessor<byte[]> mockProcessor = mockRoutes.getMock("sendPhoto");
+ mockProcessor.clearRecordedMessages();
+
+ InlineKeyboardMarkup ik = InlineKeyboardMarkup.builder()
+ .addRow(Collections.singletonList(InlineKeyboardButton.builder().text("test")
+ .url("https://camel.apache.org").build()))
+ .build();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION, "Photo");
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.PHOTO_JPG);
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_MARKUP, ik);
+
+ byte[] image = TelegramTestUtil.createSampleImage("JPG");
+ ex.getIn().setBody(image);
+
+ template.send(endpoint, ex);
+
+ final byte[] message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+
+ assertMultipartText(message, "chat_id", "my-id");
+ assertTrue(contains(message, image));
+ assertMultipartFilename(message, "photo", "photo.jpg");
+ assertMultipartText(message, "caption", "Photo");
+ assertMultipartText(message, "reply_markup", ik.toJson());
+ }
+
+ @Test
+ public void testRouteWithAudio() throws Exception {
+ final MockProcessor<byte[]> mockProcessor = mockRoutes.getMock("sendAudio");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION, "Audio");
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.AUDIO);
+ byte[] audio = TelegramTestUtil.createSampleAudio();
+ ex.getIn().setBody(audio);
+
+ template.send(endpoint, ex);
+
+ final byte[] message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+
+ assertMultipartText(message, "chat_id", "my-id");
+ assertTrue(contains(message, audio));
+ assertMultipartFilename(message, "audio", "audio.mp3");
+ assertMultipartText(message, "title", "Audio");
+ }
+
+ @Test
+ public void testRouteWithAudioAndReplyMarkup() throws Exception {
+ final MockProcessor<byte[]> mockProcessor = mockRoutes.getMock("sendAudio");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION, "Audio");
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.AUDIO);
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_MARKUP, new ForceReply(true));
+ byte[] audio = TelegramTestUtil.createSampleAudio();
+ ex.getIn().setBody(audio);
+
+ template.send(endpoint, ex);
+
+ final byte[] message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+
+ assertMultipartText(message, "chat_id", "my-id");
+ assertTrue(contains(message, audio));
+ assertMultipartFilename(message, "audio", "audio.mp3");
+ assertMultipartText(message, "title", "Audio");
+ assertMultipartText(message, "reply_markup", new ForceReply(true).toJson());
+ }
+
+ @Test
+ public void testRouteWithVideo() throws Exception {
+ final MockProcessor<byte[]> mockProcessor = mockRoutes.getMock("sendVideo");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION, "Video");
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.VIDEO.name());
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_MARKUP, new ForceReply(true));
+ byte[] video = TelegramTestUtil.createSampleVideo();
+ ex.getIn().setBody(video);
+
+ template.send(endpoint, ex);
+
+ final byte[] message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+ assertMultipartText(message, "chat_id", "my-id");
+ assertTrue(contains(message, video));
+ assertMultipartFilename(message, "video", "video.mp4");
+ assertMultipartText(message, "caption", "Video");
+ assertMultipartText(message, "reply_markup", new ForceReply(true).toJson());
+ }
+
+ @Test
+ public void testRouteWithDocument() throws Exception {
+ final MockProcessor<byte[]> mockProcessor = mockRoutes.getMock("sendDocument");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION, "Document");
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.DOCUMENT);
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_MARKUP, new ForceReply(true));
+ byte[] document = TelegramTestUtil.createSampleDocument();
+ ex.getIn().setBody(document);
+
+ template.send(endpoint, ex);
+
+ final byte[] message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+ assertMultipartText(message, "chat_id", "my-id");
+ assertTrue(contains(message, document));
+ assertMultipartFilename(message, "document", "file");
+ assertMultipartText(message, "caption", "Document");
+ assertMultipartText(message, "reply_markup", new ForceReply(true).toJson());
+ }
+
+ @Test
+ public void testRouteWithText() {
+ final MockProcessor<OutgoingTextMessage> mockProcessor = mockRoutes.getMock("sendMessage");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.TEXT.name());
+ ex.getIn().setBody("Hello");
+
+ template.send(endpoint, ex);
+
+ final OutgoingTextMessage message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+ assertEquals("my-id", message.getChatId());
+ assertEquals("Hello", message.getText());
+ assertNull(message.getParseMode());
+ }
+
+ @Test
+ @Disabled
+ public void testRouteWithTextAndCustomKeyBoard() {
+ final MockProcessor<OutgoingTextMessage> mockProcessor = mockRoutes.getMock("sendMessage");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+
+ OutgoingTextMessage msg = new OutgoingTextMessage.Builder().text("Hello").build();
+ withInlineKeyboardContainingTwoRows(msg);
+
+ ex.getIn().setBody(msg);
+
+ template.send(endpoint, ex);
+
+ final OutgoingTextMessage message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+ assertEquals("my-id", message.getChatId());
+ assertEquals("Hello", message.getText());
+ assertEquals(2, ((ReplyKeyboardMarkup) message.getReplyMarkup()).getKeyboard().size());
+ assertEquals(true, ((ReplyKeyboardMarkup) message.getReplyMarkup()).getOneTimeKeyboard());
+ assertNull(message.getParseMode());
+ }
+
+ @Test
+ public void testRouteWithTextHtml() {
+ final MockProcessor<OutgoingTextMessage> mockProcessor = mockRoutes.getMock("sendMessage");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.TEXT.name());
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_PARSE_MODE, TelegramParseMode.HTML.name());
+ ex.getIn().setBody("Hello");
+
+ template.send(endpoint, ex);
+
+ final OutgoingTextMessage message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+ assertEquals("my-id", message.getChatId());
+ assertEquals("Hello", message.getText());
+ assertEquals("HTML", message.getParseMode());
+ }
+
+ @Test
+ public void testRouteWithTextMarkdown() {
+ final MockProcessor<OutgoingTextMessage> mockProcessor = mockRoutes.getMock("sendMessage");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.TEXT.name());
+ ex.getIn().setHeader(TelegramConstants.TELEGRAM_PARSE_MODE, TelegramParseMode.MARKDOWN);
+ ex.getIn().setBody("Hello");
+
+ template.send(endpoint, ex);
+
+ final OutgoingTextMessage message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+ assertEquals("my-id", message.getChatId());
+ assertEquals("Hello", message.getText());
+ assertEquals("Markdown", message.getParseMode());
+ }
+
+ @Test
+ public void testRouteWithGame() {
+ final MockProcessor<OutgoingGameMessage> mockProcessor = mockRoutes.getMock("sendGame");
+ mockProcessor.clearRecordedMessages();
+
+ Exchange ex = endpoint.createExchange();
+
+ OutgoingGameMessage msg = new OutgoingGameMessage();
+ msg.setGameShortName("shortName");
+
+ ex.getIn().setBody(msg);
+
+ template.send(endpoint, ex);
+
+ final OutgoingGameMessage message = mockProcessor.awaitRecordedMessages(1, 5000).get(0);
+ assertNotNull("my-id", message.getChatId());
+ assertNotNull("shortName", message.getGameShortName());
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:telegram").to("telegram:bots?authorizationToken=mock-token&chatId=my-id");
+ }
+ };
+ }
+
+ }
+
+ @Override
+ @Bean
+ protected TelegramMockRoutes createMockRoutes() {
+ mockRoutes =
+ new TelegramMockRoutes(port)
+ .addEndpoint(
+ "sendPhoto",
+ "POST",
+ byte[].class,
+ TelegramTestUtil.stringResource("messages/send-photo.json"))
+ .addEndpoint(
+ "sendAudio",
+ "POST",
+ byte[].class,
+ TelegramTestUtil.stringResource("messages/send-audio.json"))
+ .addEndpoint(
+ "sendVideo",
+ "POST",
+ byte[].class,
+ TelegramTestUtil.stringResource("messages/send-video.json"))
+ .addEndpoint(
+ "sendDocument",
+ "POST",
+ byte[].class,
+ TelegramTestUtil.stringResource("messages/send-document.json"))
+ .addEndpoint(
+ "sendMessage",
+ "POST",
+ OutgoingTextMessage.class,
+ TelegramTestUtil.stringResource("messages/send-message.json"))
+ .addEndpoint(
+ "sendGame",
+ "POST",
+ OutgoingGameMessage.class,
+ TelegramTestUtil.stringResource("messages/send-game.json"));
+ return mockRoutes;
+
+ }
+
+ static void assertMultipartFilename(byte[] message, String name, String filename) {
+ assertTrue(
+ contains(message, ("name=\"" + name + "\"; filename=\"" + filename + "\"").getBytes(StandardCharsets.UTF_8)));
+ }
+
+ static void assertMultipartText(byte[] message, String key, String value) {
+ assertTrue(contains(message, ("name=\"" + key + "\"\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\n" + value)
+ .getBytes(StandardCharsets.UTF_8)));
+ }
+
+ static boolean contains(byte[] array, byte[] target) {
+ if (target.length == 0) {
+ return true;
+ }
+ OUTER_FOR: for (int i = 0; i < array.length - target.length + 1; i++) {
+ for (int j = 0; j < target.length; j++) {
+ if (array[i + j] != target[j]) {
+ continue OUTER_FOR;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramTestSupport.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramTestSupport.java
new file mode 100644
index 0000000..39f42d1
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramTestSupport.java
@@ -0,0 +1,142 @@
+/*
+ * 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.springboot;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.telegram.TelegramComponent;
+import org.apache.camel.component.telegram.model.InlineKeyboardButton;
+import org.apache.camel.component.telegram.model.OutgoingTextMessage;
+import org.apache.camel.component.telegram.model.ReplyKeyboardMarkup;
+import org.apache.camel.spring.boot.CamelContextConfiguration;
+import org.apache.camel.test.AvailablePortFinder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+
+import org.junit.jupiter.api.BeforeAll;
+
+/**
+ * A support test class for Telegram tests.
+ */
+public class TelegramTestSupport {
+
+ protected static volatile int port;
+
+ protected String chatId;
+
+
+ @Autowired
+ protected ProducerTemplate template;
+
+ @Autowired
+ protected CamelContext context;
+
+ @BeforeAll
+ public static void initPort() {
+ port = AvailablePortFinder.getNextAvailable();
+ }
+
+ /**
+ * Construct an inline keyboard sample to be used with an OutgoingTextMessage.
+ *
+ * @param message OutgoingTextMessage previously created
+ * @return OutgoingTextMessage set with an inline keyboard
+ */
+ public OutgoingTextMessage withInlineKeyboardContainingTwoRows(OutgoingTextMessage message) {
+
+ InlineKeyboardButton buttonOptionOneI = InlineKeyboardButton.builder()
+ .text("Option One - I").build();
+
+ InlineKeyboardButton buttonOptionOneII = InlineKeyboardButton.builder()
+ .text("Option One - II").build();
+
+ InlineKeyboardButton buttonOptionTwoI = InlineKeyboardButton.builder()
+ .text("Option Two - I").build();
+
+ ReplyKeyboardMarkup replyMarkup = ReplyKeyboardMarkup.builder()
+ .keyboard()
+ .addRow(Arrays.asList(buttonOptionOneI, buttonOptionOneII))
+ .addRow(Arrays.asList(buttonOptionTwoI))
+ .close()
+ .oneTimeKeyboard(true)
+ .build();
+ message.setReplyMarkup(replyMarkup);
+
+ return message;
+ }
+
+ /**
+ * Retrieves a response from a JSON file on classpath.
+ *
+ * @param fileName the filename in the classpath
+ * @param clazz the target class
+ * @param <T> the type of the returned object
+ * @return the object representation of the JSON file
+ */
+ public static <T> T getJSONResource(String fileName, Class<T> clazz) {
+ ObjectMapper mapper = new ObjectMapper();
+ try (InputStream stream = TelegramTestSupport.class.getClassLoader().getResourceAsStream(fileName)) {
+ T value = mapper.readValue(stream, clazz);
+ return value;
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Unable to load file " + fileName, e);
+ }
+ }
+
+
+ @Bean
+ CamelContextConfiguration contextConfiguration() {
+ return new CamelContextConfiguration() {
+ @Override
+ public void beforeApplicationStart(CamelContext context) {
+ configureCamelContext(context);
+ }
+ @Override
+ public void afterApplicationStart(CamelContext camelContext) {
+ //do nothing here
+ }
+
+ };
+ }
+
+ protected void configureCamelContext(CamelContext context) {
+ final TelegramComponent component = new TelegramComponent();
+
+ TelegramApiConfig apiConfig = getTelegramApiConfig();
+ component.setBaseUri(apiConfig.getBaseUri());
+ component.setAuthorizationToken(apiConfig.getAuthorizationToken());
+ chatId = apiConfig.getChatId();
+
+ context.addComponent("telegram", component);
+ }
+
+ protected TelegramApiConfig getTelegramApiConfig() {
+ return TelegramApiConfig.mock(port);
+ }
+
+
+
+ protected TelegramMockRoutes createMockRoutes() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramTestUtil.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramTestUtil.java
new file mode 100644
index 0000000..f0bdedb
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramTestUtil.java
@@ -0,0 +1,97 @@
+/*
+ * 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.springboot;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.util.IOHelper;
+
+/**
+ * Utility functions for telegram tests.
+ */
+public final class TelegramTestUtil {
+
+ private TelegramTestUtil() {
+ }
+
+ /**
+ * Creates a sample image.
+ *
+ * @param imageIOType the image-io code of the image type (eg. PNG, JPG)
+ * @return a sample image
+ * @throws IOException if anything goes wrong
+ */
+ public static byte[] createSampleImage(String imageIOType) throws IOException {
+ byte[] img;
+ if (imageIOType.equalsIgnoreCase("png")) {
+ img = readBytesFromStream(TelegramTestUtil.class.getResourceAsStream("/attachments/sample.png"));
+ } else if (imageIOType.equalsIgnoreCase("jpg")) {
+ img = readBytesFromStream(TelegramTestUtil.class.getResourceAsStream("/attachments/sample.jpg"));
+ } else if ("webp".equalsIgnoreCase(imageIOType)) {
+ img = readBytesFromStream(TelegramTestUtil.class.getResourceAsStream("/attachments/sample.webp"));
+ } else {
+ throw new IllegalArgumentException("Unknown format " + imageIOType);
+ }
+ return img;
+ }
+
+ private static byte[] readBytesFromStream(InputStream in) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream(IOHelper.DEFAULT_BUFFER_SIZE);
+ IOHelper.copy(in, out, IOHelper.DEFAULT_BUFFER_SIZE);
+ return out.toByteArray();
+ }
+
+ public static byte[] createSampleAudio() throws IOException {
+ byte[] audio = readBytesFromStream(TelegramTestUtil.class.getResourceAsStream("/attachments/sample.mp3"));
+ return audio;
+ }
+
+ public static byte[] createSampleVideo() throws IOException {
+ byte[] video = readBytesFromStream(TelegramTestUtil.class.getResourceAsStream("/attachments/sample.mp4"));
+ return video;
+ }
+
+ public static byte[] createSampleDocument() throws IOException {
+ byte[] document = readBytesFromStream(TelegramTestUtil.class.getResourceAsStream("/attachments/sample.txt"));
+ return document;
+ }
+
+ public static String stringResource(String path) {
+ try (Reader r = new InputStreamReader(
+ TelegramTestUtil.class.getClassLoader().getResourceAsStream(path), StandardCharsets.UTF_8)) {
+ return IOHelper.toString(r);
+ } catch (IOException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
+
+ public static String serialize(Object result) {
+ try {
+ return new ObjectMapper().writeValueAsString(result);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramWebhookCallTest.java b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramWebhookCallTest.java
new file mode 100644
index 0000000..2d86c64
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/java/org/apache/camel/component/telegram/springboot/TelegramWebhookCallTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.springboot;
+
+
+import java.io.InputStream;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.webhook.WebhookConfiguration;
+import org.apache.camel.component.webhook.WebhookEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ TelegramWebhookCallTest.class,
+ TelegramWebhookCallTest.TestConfiguration.class
+ }
+)
+public class TelegramWebhookCallTest extends TelegramTestSupport {
+
+
+
+ private static int port;
+
+ @EndpointInject("mock:endpoint")
+ private MockEndpoint mock;
+
+ @Test
+ public void testWebhookCall() throws Exception {
+ WebhookConfiguration config
+ = ((WebhookEndpoint) context.getRoute("webhook").getConsumer().getEndpoint()).getConfiguration();
+ String url = config.computeFullExternalUrl();
+
+ try (InputStream content = getClass().getClassLoader().getResourceAsStream("messages/webhook-call.json")) {
+
+ mock.expectedBodiesReceived("aho");
+ mock.expectedMinimumMessageCount(1);
+
+ template.sendBodyAndHeader("netty-http:" + url, content, Exchange.CONTENT_TYPE, "application/json");
+ mock.assertIsSatisfied();
+ }
+ }
+
+ @BeforeAll
+ protected static void doPreSetup() {
+ port = AvailablePortFinder.getNextAvailable();
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public class TestConfiguration {
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ restConfiguration()
+ .host("localhost")
+ .port(port);
+
+ from("webhook:telegram:bots?authorizationToken=mock-token&webhookAutoRegister=false")
+ .id("webhook")
+ .convertBodyTo(String.class)
+ .to("mock:endpoint");
+ }
+ };
+ }
+
+ }
+
+
+}
diff --git a/components-starter/camel-telegram-starter/src/test/resources/application.properties b/components-starter/camel-telegram-starter/src/test/resources/application.properties
new file mode 100644
index 0000000..14b5d92
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/application.properties
@@ -0,0 +1 @@
+logging.level.org.apache.camel.component.telegram: DEBUG
diff --git a/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.jpg b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.jpg
new file mode 100644
index 0000000..30f2c24
Binary files /dev/null and b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.jpg differ
diff --git a/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.mp3 b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.mp3
new file mode 100644
index 0000000..3904c08
Binary files /dev/null and b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.mp3 differ
diff --git a/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.mp4 b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.mp4
new file mode 100644
index 0000000..467aa73
Binary files /dev/null and b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.mp4 differ
diff --git a/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.png b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.png
new file mode 100644
index 0000000..69b662b
Binary files /dev/null and b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.png differ
diff --git a/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.txt b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.txt
new file mode 100644
index 0000000..85dbcfc
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.txt
@@ -0,0 +1 @@
+A sample text file.
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.webp b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.webp
new file mode 100644
index 0000000..2cadf19
Binary files /dev/null and b/components-starter/camel-telegram-starter/src/test/resources/attachments/sample.webp differ
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/edit-message-live-location.json b/components-starter/camel-telegram-starter/src/test/resources/messages/edit-message-live-location.json
new file mode 100644
index 0000000..a6a060d3
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/edit-message-live-location.json
@@ -0,0 +1,24 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 938,
+ "from": {
+ "id": 770882310,
+ "is_bot": true,
+ "first_name": "camelDemoBot",
+ "username": "camelDemoBot"
+ },
+ "chat": {
+ "id": 434822960,
+ "first_name": "Peter",
+ "last_name": "Palaga",
+ "type": "private"
+ },
+ "date": 1576249600,
+ "edit_date": 1576249601,
+ "location": {
+ "latitude": 29.974934,
+ "longitude": 31.131109
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/send-audio.json b/components-starter/camel-telegram-starter/src/test/resources/messages/send-audio.json
new file mode 100644
index 0000000..ed4ac2d
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/send-audio.json
@@ -0,0 +1,25 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 932,
+ "from": {
+ "id": 770882310,
+ "is_bot": true,
+ "first_name": "camelDemoBot",
+ "username": "camelDemoBot"
+ },
+ "chat": {
+ "id": 434822960,
+ "first_name": "Peter",
+ "last_name": "Palaga",
+ "type": "private"
+ },
+ "date": 1576249599,
+ "audio": {
+ "duration": 1,
+ "mime_type": "audio/mpeg",
+ "file_id": "CQADBAAD5QUAAmcaoVMYrfWhEfLFTBYE",
+ "file_size": 9657
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/send-document.json b/components-starter/camel-telegram-starter/src/test/resources/messages/send-document.json
new file mode 100644
index 0000000..f352d13
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/send-document.json
@@ -0,0 +1,24 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 934,
+ "from": {
+ "id": 770882310,
+ "is_bot": true,
+ "first_name": "camelDemoBot",
+ "username": "camelDemoBot"
+ },
+ "chat": {
+ "id": 434822960,
+ "first_name": "Peter",
+ "last_name": "Palaga",
+ "type": "private"
+ },
+ "date": 1576249600,
+ "document": {
+ "file_name": "file",
+ "file_id": "BQADBAAD5wUAAmcaoVNbRjnV8IcCmhYE",
+ "file_size": 7638
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/send-game.json b/components-starter/camel-telegram-starter/src/test/resources/messages/send-game.json
new file mode 100644
index 0000000..ecd9722
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/send-game.json
@@ -0,0 +1,42 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 935,
+ "from": {
+ "id": 770882310,
+ "is_bot": true,
+ "first_name": "camelDemoBot",
+ "username": "camelDemoBot"
+ },
+ "chat": {
+ "id": 434822960,
+ "first_name": "Peter",
+ "last_name": "Palaga",
+ "type": "private"
+ },
+ "date": 1576249600,
+ "game": {
+ "title": "test_game",
+ "description": "test",
+ "photo": [
+ {
+ "file_id": "AgADBAADnrAxG1rhiVAsV1IghUpUwn4eqhsABAEAAwIAA20AA32sBQABFgQ",
+ "file_unique_id": "AQADfh6qGwAEfawFAAE",
+ "file_size": 2469,
+ "width": 320,
+ "height": 180
+ }
+ ]
+ },
+ "reply_markup": {
+ "inline_keyboard": [
+ [
+ {
+ "text": "Play test_game",
+ "callback_game": {}
+ }
+ ]
+ ]
+ }
+ }
+}
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/send-location.json b/components-starter/camel-telegram-starter/src/test/resources/messages/send-location.json
new file mode 100644
index 0000000..5b645a1
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/send-location.json
@@ -0,0 +1,23 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 938,
+ "from": {
+ "id": 770882310,
+ "is_bot": true,
+ "first_name": "camelDemoBot",
+ "username": "camelDemoBot"
+ },
+ "chat": {
+ "id": 434822960,
+ "first_name": "Peter",
+ "last_name": "Palaga",
+ "type": "private"
+ },
+ "date": 1576249600,
+ "location": {
+ "latitude": 29.974830,
+ "longitude": 31.138579
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/send-message.json b/components-starter/camel-telegram-starter/src/test/resources/messages/send-message.json
new file mode 100644
index 0000000..8f37da2
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/send-message.json
@@ -0,0 +1,20 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 937,
+ "from": {
+ "id": 770882310,
+ "is_bot": true,
+ "first_name": "camelDemoBot",
+ "username": "camelDemoBot"
+ },
+ "chat": {
+ "id": 434822960,
+ "first_name": "Peter",
+ "last_name": "Palaga",
+ "type": "private"
+ },
+ "date": 1576249600,
+ "text": "A message from camel-quarkus-telegram ffdcc8ef72a34053a3e75daec74676a9"
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/send-photo.json b/components-starter/camel-telegram-starter/src/test/resources/messages/send-photo.json
new file mode 100644
index 0000000..8523d11
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/send-photo.json
@@ -0,0 +1,27 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 935,
+ "from": {
+ "id": 770882310,
+ "is_bot": true,
+ "first_name": "camelDemoBot",
+ "username": "camelDemoBot"
+ },
+ "chat": {
+ "id": 434822960,
+ "first_name": "Peter",
+ "last_name": "Palaga",
+ "type": "private"
+ },
+ "date": 1576249600,
+ "photo": [
+ {
+ "file_id": "AgADBAADYbExG2caoVPPY5I2XKLPM3lKqBsABAEAAwIAA20AA80nBQABFgQ",
+ "file_size": 1005,
+ "width": 108,
+ "height": 10
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/send-venue.json b/components-starter/camel-telegram-starter/src/test/resources/messages/send-venue.json
new file mode 100644
index 0000000..f098ac2
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/send-venue.json
@@ -0,0 +1,31 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 936,
+ "from": {
+ "id": 770882310,
+ "is_bot": true,
+ "first_name": "camelDemoBot",
+ "username": "camelDemoBot"
+ },
+ "chat": {
+ "id": 434822960,
+ "first_name": "Peter",
+ "last_name": "Palaga",
+ "type": "private"
+ },
+ "date": 1576249600,
+ "location": {
+ "latitude": 29.977826,
+ "longitude": 31.136330
+ },
+ "venue": {
+ "location": {
+ "latitude": 29.977826,
+ "longitude": 31.136330
+ },
+ "title": "Pyramid of Queen Henutsen",
+ "address": "El-Hussein Ibn Ali Ln, Nazlet El-Semman, Al Haram, Giza Governorate, Egypt"
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/send-video.json b/components-starter/camel-telegram-starter/src/test/resources/messages/send-video.json
new file mode 100644
index 0000000..4f8d0ef
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/send-video.json
@@ -0,0 +1,33 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 933,
+ "from": {
+ "id": 770882310,
+ "is_bot": true,
+ "first_name": "camelDemoBot",
+ "username": "camelDemoBot"
+ },
+ "chat": {
+ "id": 434822960,
+ "first_name": "Peter",
+ "last_name": "Palaga",
+ "type": "private"
+ },
+ "date": 1576249600,
+ "video": {
+ "duration": 4,
+ "width": 108,
+ "height": 10,
+ "mime_type": "video/mp4",
+ "thumb": {
+ "file_id": "AAQEAAPmBQACZxqhU8LAVawXPI5dMWO3GwAEAQAHbQADcxQAAhYE",
+ "file_size": 991,
+ "width": 108,
+ "height": 10
+ },
+ "file_id": "BAADBAAD5gUAAmcaoVPCwFWsFzyOXRYE",
+ "file_size": 27845
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/stop-message-live-location.json b/components-starter/camel-telegram-starter/src/test/resources/messages/stop-message-live-location.json
new file mode 100644
index 0000000..a6a060d3
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/stop-message-live-location.json
@@ -0,0 +1,24 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 938,
+ "from": {
+ "id": 770882310,
+ "is_bot": true,
+ "first_name": "camelDemoBot",
+ "username": "camelDemoBot"
+ },
+ "chat": {
+ "id": 434822960,
+ "first_name": "Peter",
+ "last_name": "Palaga",
+ "type": "private"
+ },
+ "date": 1576249600,
+ "edit_date": 1576249601,
+ "location": {
+ "latitude": 29.974934,
+ "longitude": 31.131109
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/updates-channelMessage.json b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-channelMessage.json
new file mode 100644
index 0000000..c1d3118
--- /dev/null
+++ b/components-starter/camel-telegram-starter/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
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/updates-empty.json b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-empty.json
new file mode 100644
index 0000000..7cc5971
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-empty.json
@@ -0,0 +1,4 @@
+{
+ "ok": true,
+ "result": []
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/updates-inline-query-message.json b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-inline-query-message.json
new file mode 100644
index 0000000..ba232aa
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-inline-query-message.json
@@ -0,0 +1,17 @@
+{
+ "ok": true,
+ "result": [
+ {
+ "update_id": 219398823,
+ "inline_query": {
+ "id": 67,
+ "from": {
+ "id": 1585844777,
+ "first_name": "John",
+ "last_name": "Doe"
+ },
+ "query": "test"
+ }
+ }
+ ]
+}
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-document.json b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-document.json
new file mode 100644
index 0000000..31891b6
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-document.json
@@ -0,0 +1,35 @@
+{
+ "ok": true,
+ "result": [
+ {
+ "update_id": 525704899,
+ "message": {
+ "message_id": 180,
+ "from": {
+ "id": 1585844777,
+ "first_name": "John",
+ "last_name": "Doe"
+ },
+ "chat": {
+ "id": 158584478,
+ "first_name": "John",
+ "last_name": "Doe",
+ "type": "private"
+ },
+ "date": 1463479642,
+ "document": {
+ "file_id": "AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABLXiiSI1vzZK8XXXXXXX",
+ "file_size": 12530,
+ "file_name": "file.png",
+ "mime_type": "image/png",
+ "thumb": {
+ "file_id": "AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABLXiiSI1vzZK9XXXXXXX",
+ "width": 90,
+ "height": 80,
+ "file_size": 1253
+ }
+ }
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-game.json b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-game.json
new file mode 100644
index 0000000..b543546
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-game.json
@@ -0,0 +1,47 @@
+{
+ "ok": true,
+ "result": [
+ {
+ "update_id": 525704899,
+ "message": {
+ "message_id": 180,
+ "from": {
+ "id": 1585844777,
+ "first_name": "John",
+ "last_name": "Doe"
+ },
+ "chat": {
+ "id": 158584478,
+ "first_name": "John",
+ "last_name": "Doe",
+ "type": "private"
+ },
+ "date": 1463479642,
+ "game": {
+ "title": "test_game",
+ "text": "game text",
+ "description": "test",
+ "photo": [
+ {
+ "file_id": "AgADBAADnrAxG1rhiVAsV1IghUpUwn4eqhsABAEAAwIAA20AA32sBQABFgQ",
+ "file_unique_id": "AQADfh6qGwAEfawFAAE",
+ "file_size": 2469,
+ "width": 320,
+ "height": 180
+ }
+ ]
+ },
+ "reply_markup": {
+ "inline_keyboard": [
+ [
+ {
+ "text": "Play test_game",
+ "callback_game": {}
+ }
+ ]
+ ]
+ }
+ }
+ }
+ ]
+}
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-sticker.json b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-sticker.json
new file mode 100644
index 0000000..63e318e
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-sticker.json
@@ -0,0 +1,44 @@
+{
+ "ok": true,
+ "result": [
+ {
+ "update_id": 525704899,
+ "message": {
+ "message_id": 180,
+ "from": {
+ "id": 1585844777,
+ "first_name": "John",
+ "last_name": "Doe"
+ },
+ "chat": {
+ "id": 158584478,
+ "first_name": "John",
+ "last_name": "Doe",
+ "type": "private"
+ },
+ "date": 1463479642,
+ "sticker": {
+ "file_id":"CAADBAADEQADmDVxAkmg3XnDZam0FgQ",
+ "file_size":42112,
+ "width":512,
+ "height":512,
+ "emoji":"\ud83d\ude28",
+ "set_name":"GreatMindsColor",
+ "is_animated":false,
+ "mask_position": {
+ "point": "forehead",
+ "x_shift": "-1.0 ",
+ "y_shift": "1.0",
+ "scale": "2.0"
+ },
+ "thumb": {
+ "file_id":"AAQCAAPfCAACCLcZAnLSRFdZiNzlpSg5DwAEAQAHbQADXxgAAhYE",
+ "file_size":6316,
+ "width":128,
+ "height":128
+ }
+ }
+ }
+ }
+ ]
+}
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-video.json b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-video.json
new file mode 100644
index 0000000..6515ae8
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media-video.json
@@ -0,0 +1,36 @@
+{
+ "ok": true,
+ "result": [
+ {
+ "update_id": 525704123,
+ "message": {
+ "message_id": 2311,
+ "from": {
+ "id": 149961111,
+ "first_name": "John",
+ "last_name": "Doe"
+ },
+ "chat": {
+ "id": 149961666,
+ "first_name": "John",
+ "last_name": "Doe",
+ "type": "private"
+ },
+ "date": 1463668803,
+ "video": {
+ "duration": 2,
+ "width": 640,
+ "height": 360,
+ "thumb": {
+ "file_id": "AAQEABMlaUQZAAT1dG3FV4N-WhUrXXXX",
+ "file_size": 1958,
+ "width": 90,
+ "height": 50
+ },
+ "file_id": "BAADBAADAgADyzvwCC7_4AyvdAXXXX",
+ "file_size": 299284
+ }
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media.json b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media.json
new file mode 100644
index 0000000..c98ea10
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-media.json
@@ -0,0 +1,67 @@
+{
+ "ok": true,
+ "result": [
+ {
+ "update_id": 525704898,
+ "message": {
+ "message_id": 179,
+ "from": {
+ "id": 1585844777,
+ "first_name": "John",
+ "last_name": "Doe"
+ },
+ "chat": {
+ "id": -45658,
+ "title": "A chat group",
+ "type": "group"
+ },
+ "date": 1463436626,
+ "text": "a message"
+ }
+ },
+ {
+ "update_id": 525704899,
+ "message": {
+ "message_id": 180,
+ "from": {
+ "id": 1585844777,
+ "first_name": "John",
+ "last_name": "Doe"
+ },
+ "chat": {
+ "id": 158584478,
+ "first_name": "John",
+ "last_name": "Doe",
+ "type": "private"
+ },
+ "date": 1463479642,
+ "photo": [
+ {
+ "file_id": "AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABLXiiSI1vzZK8XXXXXXX",
+ "file_size": 1253,
+ "width": 67,
+ "height": 90
+ },
+ {
+ "file_id": "AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABO89ObzhYdRo7XXXXXXX",
+ "file_size": 14901,
+ "width": 240,
+ "height": 320
+ },
+ {
+ "file_id": "AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABP0k5b4ZzS4-7XXXXXXX",
+ "file_size": 66807,
+ "width": 600,
+ "height": 800
+ },
+ {
+ "file_id": "AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABDnWBzFwvqpw7XXXXXXX",
+ "file_size": 120343,
+ "width": 960,
+ "height": 1280
+ }
+ ]
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/updates-multiple.json b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-multiple.json
new file mode 100644
index 0000000..85fbd55
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-multiple.json
@@ -0,0 +1,41 @@
+{
+ "ok": true,
+ "result": [
+ {
+ "update_id": 525704898,
+ "message": {
+ "message_id": 179,
+ "from": {
+ "id": 1585844777,
+ "first_name": "John",
+ "last_name": "Doe"
+ },
+ "chat": {
+ "id": -45658,
+ "title": "A chat group",
+ "type": "group"
+ },
+ "date": 1463436626,
+ "text": "a message"
+ }
+ },
+ {
+ "update_id": 525704899,
+ "message": {
+ "message_id": 180,
+ "from": {
+ "id": 1585844777,
+ "first_name": "John",
+ "last_name": "Doe"
+ },
+ "chat": {
+ "id": -45658,
+ "title": "A chat group",
+ "type": "group"
+ },
+ "date": 1463466626,
+ "text": "another message"
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/updates-sendLocation.json b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-sendLocation.json
new file mode 100644
index 0000000..ae4c091
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-sendLocation.json
@@ -0,0 +1,23 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 33,
+ "from": {
+ "id": 665977497,
+ "is_bot": true,
+ "first_name": "camelbot",
+ "username": "camel_component_bot"
+ },
+ "chat": {
+ "id": -182520913,
+ "title": "testgroup",
+ "type": "group",
+ "all_members_are_administrators": true
+ },
+ "date": 1548091564,
+ "location": {
+ "latitude": 59.9386292,
+ "longitude": 30.3141308
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/updates-single.json b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-single.json
new file mode 100644
index 0000000..f6a9dd5
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/updates-single.json
@@ -0,0 +1,23 @@
+{
+ "ok": true,
+ "result": [
+ {
+ "update_id": 525704898,
+ "message": {
+ "message_id": 179,
+ "from": {
+ "id": 1585844777,
+ "first_name": "John",
+ "last_name": "Doe"
+ },
+ "chat": {
+ "id": -45658,
+ "title": "A chat group",
+ "type": "group"
+ },
+ "date": 1463436626,
+ "text": "a message"
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/components-starter/camel-telegram-starter/src/test/resources/messages/webhook-call.json b/components-starter/camel-telegram-starter/src/test/resources/messages/webhook-call.json
new file mode 100644
index 0000000..9710a71
--- /dev/null
+++ b/components-starter/camel-telegram-starter/src/test/resources/messages/webhook-call.json
@@ -0,0 +1,23 @@
+{
+ "update_id": 178312874,
+ "message": {
+ "message_id": 22,
+ "from": {
+ "id": 158584902,
+ "is_bot": false,
+ "first_name": "Nicola",
+ "last_name": "Ferraro",
+ "username": "nferraro",
+ "language_code": "en"
+ },
+ "chat": {
+ "id": 158584902,
+ "first_name": "Nicola",
+ "last_name": "Ferraro",
+ "username": "nferraro",
+ "type": "private"
+ },
+ "date": 1554890836,
+ "text": "aho"
+ }
+}
\ No newline at end of file