You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2020/11/04 16:43:33 UTC
[camel-quarkus] 07/07: Stub Telegram tests with WireMock
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 5302af6af071b2a156454c9cc042fb2d62269273
Author: James Netherton <ja...@gmail.com>
AuthorDate: Tue Nov 3 14:41:31 2020 +0000
Stub Telegram tests with WireMock
---
integration-tests/telegram/README.adoc | 16 +--
integration-tests/telegram/pom.xml | 9 +-
.../component/telegram/it/TelegramResource.java | 2 +-
.../component/telegram/it/TelegramRoutes.java | 110 ---------------------
.../src/main/resources/application.properties | 12 +--
.../mock-messages/editMessageLiveLocation.json | 24 -----
.../main/resources/mock-messages/getUpdates.json | 41 --------
.../main/resources/mock-messages/sendAudio.json | 25 -----
.../main/resources/mock-messages/sendDocument.json | 24 -----
.../main/resources/mock-messages/sendLocation.json | 23 -----
.../main/resources/mock-messages/sendMessage.json | 20 ----
.../main/resources/mock-messages/sendPhoto.json | 27 -----
.../main/resources/mock-messages/sendVenue.json | 31 ------
.../main/resources/mock-messages/sendVideo.json | 33 -------
.../mock-messages/stopMessageLiveLocation.json | 24 -----
.../component/telegram/it/TelegramTest.java | 26 ++++-
.../telegram/it/TelegramTestResource.java | 47 +++++++++
.../mappings/telegramEditMessageLiveLocation.json | 26 +++++
.../test/resources/mappings/telegramSendAudio.json | 24 +++++
.../resources/mappings/telegramSendDocument.json | 24 +++++
.../resources/mappings/telegramSendLocation.json | 26 +++++
.../resources/mappings/telegramSendMessage.json | 26 +++++
.../test/resources/mappings/telegramSendPhoto.json | 24 +++++
.../test/resources/mappings/telegramSendVenue.json | 26 +++++
.../test/resources/mappings/telegramSendVideo.json | 24 +++++
.../mappings/telegramStopMessageLiveAction.json | 26 +++++
26 files changed, 316 insertions(+), 404 deletions(-)
diff --git a/integration-tests/telegram/README.adoc b/integration-tests/telegram/README.adoc
index e735210..a62d745 100644
--- a/integration-tests/telegram/README.adoc
+++ b/integration-tests/telegram/README.adoc
@@ -1,5 +1,7 @@
== Camel Quarkus Telegram Integration Tests
+By default the Telegram integration tests use WireMock to stub the API interactions.
+
To run `camel-quarkus-telegram` integration tests against the real remote Telegram API, you must first create
a Telegram bot following this guide:
https://www.nicolaferraro.me/2016/05/27/creating-a-telegram-bot-in-5-minutes-with-apache-camel/
@@ -8,12 +10,14 @@ Then set the following environment variables:
[source,shell]
----
-$ export TELEGRAM_AUTHORIZATION_TOKEN=my-authorization-token
-$ export TELEGRAM_CHAT_ID=my-chatId
+export TELEGRAM_AUTHORIZATION_TOKEN=my-authorization-token
+export TELEGRAM_CHAT_ID=my-chatId
----
-If you do not set `TELEGRAM_AUTHORIZATION_TOKEN` environment variable, the test will be run against a mock
-Telegram API started on `localhost`.
+If the WireMock stub recordings need updating, then remove the existing files from `src/test/resources/mappings` and run tests with either:
+
+System property `-Dwiremock.record=true`
+
+Or
-You may want to `export CAMEL_QUARKUS_START_MOCK_BACKEND=false` to avoid starting he the mock Telegram API
-to make sure that you test against the real remote Telegram API.
+Set environment variable `WIREMOCK_RECORD=true`
diff --git a/integration-tests/telegram/pom.xml b/integration-tests/telegram/pom.xml
index bda7807..4de58fc 100644
--- a/integration-tests/telegram/pom.xml
+++ b/integration-tests/telegram/pom.xml
@@ -56,10 +56,6 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-attachments</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-integration-test-support-mock-backend</artifactId>
- </dependency>
<!-- test dependencies -->
<dependency>
@@ -68,6 +64,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-integration-wiremock-support</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
diff --git a/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramResource.java b/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramResource.java
index 52b929c..a6dc6fe 100644
--- a/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramResource.java
+++ b/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramResource.java
@@ -59,7 +59,7 @@ public class TelegramResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getMessages() {
- final String messages = consumerTemplate.receiveBodyNoWait("telegram://bots", String.class);
+ final String messages = consumerTemplate.receiveBody("telegram://bots", 5000L, String.class);
log.infof("Received telegram messages: %s", messages);
return messages;
}
diff --git a/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramRoutes.java b/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramRoutes.java
deleted file mode 100644
index a56da2c..0000000
--- a/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramRoutes.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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.quarkus.component.telegram.it;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.stream.Stream;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Produces;
-import javax.inject.Named;
-
-import io.quarkus.arc.Unremovable;
-import org.apache.camel.Exchange;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.telegram.TelegramComponent;
-import org.apache.camel.quarkus.test.mock.backend.MockBackendUtils;
-import org.apache.camel.support.ResourceHelper;
-import org.apache.camel.util.IOHelper;
-import org.eclipse.microprofile.config.inject.ConfigProperty;
-
-@ApplicationScoped
-public class TelegramRoutes extends RouteBuilder {
-
- @ConfigProperty(name = "telegram.authorization-token", defaultValue = "default-dummy-token")
- String authToken;
-
- @ConfigProperty(name = "quarkus.http.test-port")
- int httpTestPort;
- @ConfigProperty(name = "quarkus.http.port")
- int httpPort;
-
- private String getBaseUri() {
- final boolean isNativeMode = "executable".equals(System.getProperty("org.graalvm.nativeimage.kind"));
- return "default-dummy-token".equals(authToken)
- ? "http://localhost:" + (isNativeMode ? httpPort : httpTestPort)
- : "https://api.telegram.org";
- }
-
- /**
- * We need to implement some conditional configuration of the {@link TelegramComponent} thus we create it
- * programmatically and publish via CDI.
- *
- * @return a configured {@link TelegramComponent}
- */
- @Produces
- @ApplicationScoped
- @Unremovable
- @Named
- TelegramComponent telegram() {
- final TelegramComponent result = new TelegramComponent();
- result.setCamelContext(getContext());
- result.setBaseUri(getBaseUri());
- result.setAuthorizationToken(authToken);
- return result;
- }
-
- @Override
- public void configure() throws Exception {
- if (MockBackendUtils.startMockBackend(true)) {
- /* Start the mock Telegram API unless the user did export CAMEL_QUARKUS_START_MOCK_BACKEND=false */
- from("platform-http:/bot" + authToken + "/getUpdates?httpMethodRestrict=GET")
- .process(e -> load("mock-messages/getUpdates.json", e));
-
- Stream.of(
- "sendMessage",
- "sendAudio",
- "sendVideo",
- "sendDocument",
- "sendPhoto",
- "sendVenue",
- "sendLocation",
- "stopMessageLiveLocation")
- .forEach(endpoint -> {
- from("platform-http:/bot" + authToken + "/" + endpoint + "?httpMethodRestrict=POST")
- .process(e -> load("mock-messages/" + endpoint + ".json", e));
- });
- }
-
- }
-
- private void load(String path, Exchange exchange) {
- try (ByteArrayOutputStream out = new ByteArrayOutputStream(IOHelper.DEFAULT_BUFFER_SIZE);
- InputStream in = ResourceHelper.resolveMandatoryResourceAsInputStream(exchange.getContext(), path)) {
- IOHelper.copy(in, out, IOHelper.DEFAULT_BUFFER_SIZE);
-
- final byte[] bytes = out.toByteArray();
- exchange.getMessage().setBody(bytes);
- exchange.getMessage().setHeader("Content-Length", bytes.length);
- exchange.getMessage().setHeader("Content-Type", "application/json; charset=UTF-8");
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/integration-tests/telegram/src/main/resources/application.properties b/integration-tests/telegram/src/main/resources/application.properties
index 8443bf9..a394805 100644
--- a/integration-tests/telegram/src/main/resources/application.properties
+++ b/integration-tests/telegram/src/main/resources/application.properties
@@ -17,21 +17,15 @@
#
# Quarkus
#
-quarkus.log.category."org.apache.camel.support.DefaultComponent".level = TRACE
+#quarkus.log.category."org.apache.camel.support.DefaultComponent".level = TRACE
#quarkus.log.category."org.asynchttpclient".level = TRACE
#quarkus.log.category."org.apache.camel.component.telegram.TelegramComponent".level = TRACE
# You can check in this directory what requests the client is sending when you run against the mock Telegram API
quarkus.http.body.uploads-directory=target/uploads
-quarkus.native.additional-build-args = -H:IncludeResources=.*mock-messages/.*
#
# Camel :: Telegram
#
-# Set the authorization token here or via environment variable TELEGRAM_AUTHORIZATION_TOKEN
-#telegram.authorization-token=...
-telegram.chatId=${TELEGRAM_CHAT_ID:-1}
-
-# You may want to export CAMEL_QUARKUS_START_MOCK_BACKEND=false to avoid starting he the mock Telegram API
-# to make sure that you test against the real remote Telegram API
-camel.quarkus.start-mock-backend=true
\ No newline at end of file
+camel.component.telegram.authorization-token=${TELEGRAM_AUTHORIZATION_TOKEN:fake-token}
+telegram.chatId=${TELEGRAM_CHAT_ID:1426416050}
diff --git a/integration-tests/telegram/src/main/resources/mock-messages/editMessageLiveLocation.json b/integration-tests/telegram/src/main/resources/mock-messages/editMessageLiveLocation.json
deleted file mode 100644
index a6a060d..0000000
--- a/integration-tests/telegram/src/main/resources/mock-messages/editMessageLiveLocation.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "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/integration-tests/telegram/src/main/resources/mock-messages/getUpdates.json b/integration-tests/telegram/src/main/resources/mock-messages/getUpdates.json
deleted file mode 100644
index 85fbd55..0000000
--- a/integration-tests/telegram/src/main/resources/mock-messages/getUpdates.json
+++ /dev/null
@@ -1,41 +0,0 @@
-{
- "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/integration-tests/telegram/src/main/resources/mock-messages/sendAudio.json b/integration-tests/telegram/src/main/resources/mock-messages/sendAudio.json
deleted file mode 100644
index ed4ac2d..0000000
--- a/integration-tests/telegram/src/main/resources/mock-messages/sendAudio.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "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/integration-tests/telegram/src/main/resources/mock-messages/sendDocument.json b/integration-tests/telegram/src/main/resources/mock-messages/sendDocument.json
deleted file mode 100644
index f352d13..0000000
--- a/integration-tests/telegram/src/main/resources/mock-messages/sendDocument.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "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/integration-tests/telegram/src/main/resources/mock-messages/sendLocation.json b/integration-tests/telegram/src/main/resources/mock-messages/sendLocation.json
deleted file mode 100644
index 5b645a1..0000000
--- a/integration-tests/telegram/src/main/resources/mock-messages/sendLocation.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "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/integration-tests/telegram/src/main/resources/mock-messages/sendMessage.json b/integration-tests/telegram/src/main/resources/mock-messages/sendMessage.json
deleted file mode 100644
index 8f37da2..0000000
--- a/integration-tests/telegram/src/main/resources/mock-messages/sendMessage.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "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/integration-tests/telegram/src/main/resources/mock-messages/sendPhoto.json b/integration-tests/telegram/src/main/resources/mock-messages/sendPhoto.json
deleted file mode 100644
index 8523d11..0000000
--- a/integration-tests/telegram/src/main/resources/mock-messages/sendPhoto.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "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/integration-tests/telegram/src/main/resources/mock-messages/sendVenue.json b/integration-tests/telegram/src/main/resources/mock-messages/sendVenue.json
deleted file mode 100644
index f098ac2..0000000
--- a/integration-tests/telegram/src/main/resources/mock-messages/sendVenue.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "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/integration-tests/telegram/src/main/resources/mock-messages/sendVideo.json b/integration-tests/telegram/src/main/resources/mock-messages/sendVideo.json
deleted file mode 100644
index 4f8d0ef..0000000
--- a/integration-tests/telegram/src/main/resources/mock-messages/sendVideo.json
+++ /dev/null
@@ -1,33 +0,0 @@
-{
- "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/integration-tests/telegram/src/main/resources/mock-messages/stopMessageLiveLocation.json b/integration-tests/telegram/src/main/resources/mock-messages/stopMessageLiveLocation.json
deleted file mode 100644
index a6a060d..0000000
--- a/integration-tests/telegram/src/main/resources/mock-messages/stopMessageLiveLocation.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "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/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramTest.java b/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramTest.java
index 38e40ff..c797f6f 100644
--- a/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramTest.java
+++ b/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramTest.java
@@ -21,6 +21,7 @@ import java.io.InputStream;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
+import com.github.tomakehurst.wiremock.WireMockServer;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
@@ -31,10 +32,15 @@ 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.quarkus.test.TrustStoreResource;
+import org.apache.camel.quarkus.test.wiremock.MockServer;
import org.awaitility.Awaitility;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.Test;
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.request;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
@@ -42,14 +48,19 @@ import static org.hamcrest.Matchers.lessThan;
@QuarkusTest
@QuarkusTestResource(TrustStoreResource.class)
+@QuarkusTestResource(TelegramTestResource.class)
public class TelegramTest {
private static final Logger LOG = Logger.getLogger(TelegramTest.class);
+ @MockServer
+ WireMockServer server;
+
@Test
public void postText() {
final String uuid = UUID.randomUUID().toString().replace("-", "");
- final String msg = String.format("A message from camel-quarkus-telegram %s", uuid);
+ final String msg = "A message from camel-quarkus-telegram"
+ + (System.getenv("TELEGRAM_AUTHORIZATION_TOKEN") != null ? " " + uuid : "");
/* Send a message */
RestAssured.given()
@@ -63,6 +74,17 @@ public class TelegramTest {
@Test
public void getText() {
+ // Manually stub the getUpdates response as the addition of the offset query param seems to confuse WireMock
+ if (server != null) {
+ server.stubFor(request("GET", urlPathMatching("/.*/getUpdates"))
+ .withQueryParam("limit", equalTo("100"))
+ .withQueryParam("timeout", equalTo("30"))
+ .willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBody(
+ "{\"ok\":true,\"result\":[{\"update_id\":123488937,\n\"message\":{\"message_id\":37,\"from\":{\"id\":1426416050,\"is_bot\":false,\"first_name\":\"Apache\",\"last_name\":\"Camel\",\"language_code\":\"en\"},\"chat\":{\"id\":1426416050,\"first_name\":\"Apache\",\"last_name\":\"Camel\",\"type\":\"private\"},\"date\":1604406332,\"text\":\"test\"}}]}")));
+ }
+
/* Telegram bots by design see neither their own messages nor other bots' messages.
* So receiving messages is currently possible only if you ping the bot manually.
* If you do so, you should see your messages in the test log. */
@@ -155,7 +177,7 @@ public class TelegramTest {
.post("/telegram/edit-location")
.then()
.extract().statusCode();
- return code != 201;
+ return code == 201;
});
/* Stop updating */
diff --git a/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramTestResource.java b/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramTestResource.java
new file mode 100644
index 0000000..a93ee6c
--- /dev/null
+++ b/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramTestResource.java
@@ -0,0 +1,47 @@
+/*
+ * 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.quarkus.component.telegram.it;
+
+import java.util.Map;
+
+import org.apache.camel.quarkus.test.wiremock.WireMockTestResourceLifecycleManager;
+import org.apache.camel.util.CollectionHelper;
+
+public class TelegramTestResource extends WireMockTestResourceLifecycleManager {
+
+ private static final String TELEGRAM_API_BASE_URL = "https://api.telegram.org";
+ private static final String TELEGRAM_ENV_AUTHORIZATION_TOKEN = "TELEGRAM_AUTHORIZATION_TOKEN";
+
+ @Override
+ public Map<String, String> start() {
+ Map<String, String> properties = super.start();
+ String wireMockUrl = properties.get("wiremock.url");
+ String baseUri = wireMockUrl != null ? wireMockUrl : TELEGRAM_API_BASE_URL;
+ return CollectionHelper.mergeMaps(properties,
+ CollectionHelper.mapOf("camel.component.telegram.base-uri", baseUri));
+ }
+
+ @Override
+ protected String getRecordTargetBaseUrl() {
+ return TELEGRAM_API_BASE_URL;
+ }
+
+ @Override
+ protected boolean isMockingEnabled() {
+ return !envVarsPresent(TELEGRAM_ENV_AUTHORIZATION_TOKEN);
+ }
+}
diff --git a/integration-tests/telegram/src/test/resources/mappings/telegramEditMessageLiveLocation.json b/integration-tests/telegram/src/test/resources/mappings/telegramEditMessageLiveLocation.json
new file mode 100644
index 0000000..ce73094
--- /dev/null
+++ b/integration-tests/telegram/src/test/resources/mappings/telegramEditMessageLiveLocation.json
@@ -0,0 +1,26 @@
+{
+ "id" : "7ebe6ed5-1c57-48f9-8d7f-9972e1acf6e7",
+ "name" : "botfake-token_editmessagelivelocation",
+ "request" : {
+ "url" : "/botfake-token/editMessageLiveLocation",
+ "method" : "POST",
+ "bodyPatterns" : [ {
+ "equalToJson" : "{\"chat_id\":\"1426416050\",\"latitude\":29.974928,\"longitude\":31.131115,\"message_id\":44}",
+ "ignoreArrayOrder" : true,
+ "ignoreExtraElements" : true
+ } ]
+ },
+ "response" : {
+ "status" : 200,
+ "body" : "{\"ok\":true,\"result\":{\"message_id\":44,\"from\":{\"id\":1459045600,\"is_bot\":true,\"first_name\":\"camel-quarkus-test\",\"username\":\"CamelQuarkusTestBot\"},\"chat\":{\"id\":1426416050,\"first_name\":\"Apache\",\"last_name\":\"Camel\",\"type\":\"private\"},\"date\":1604406366,\"edit_date\":1604406367,\"location\":{\"latitude\":29.974934,\"longitude\":31.131109,\"live_period\":120}}}",
+ "headers" : {
+ "Server" : "nginx/1.16.1",
+ "Date" : "Tue, 03 Nov 2020 12:26:07 GMT",
+ "Content-Type" : "application/json",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload"
+ }
+ },
+ "uuid" : "7ebe6ed5-1c57-48f9-8d7f-9972e1acf6e7",
+ "persistent" : true,
+ "insertionIndex" : 9
+}
\ No newline at end of file
diff --git a/integration-tests/telegram/src/test/resources/mappings/telegramSendAudio.json b/integration-tests/telegram/src/test/resources/mappings/telegramSendAudio.json
new file mode 100644
index 0000000..a2e5404
--- /dev/null
+++ b/integration-tests/telegram/src/test/resources/mappings/telegramSendAudio.json
@@ -0,0 +1,24 @@
+{
+ "id" : "7a3286d0-9606-4ee2-a0c0-85fdd4f15f8b",
+ "name" : "botfake-token_sendaudio",
+ "request" : {
+ "url" : "/botfake-token/sendAudio",
+ "method" : "POST",
+ "bodyPatterns" : [ {
+ "anything" : "anything"
+ } ]
+ },
+ "response" : {
+ "status" : 200,
+ "body" : "{\"ok\":true,\"result\":{\"message_id\":38,\"from\":{\"id\":1459045600,\"is_bot\":true,\"first_name\":\"camel-quarkus-test\",\"username\":\"CamelQuarkusTestBot\"},\"chat\":{\"id\":1426416050,\"first_name\":\"Apache\",\"last_name\":\"Camel\",\"type\":\"private\"},\"date\":1604406365,\"audio\":{\"duration\":1,\"file_name\":\"audio.mp3\",\"mime_type\":\"audio/mpeg\",\"file_id\":\"CQACAgQAAxkDAAMmX6FMXVbf-mYVeRWmBctoH0OAXlkAAu8GAAJd1glRHPsZNTQzO4YeBA\",\"file_unique_id\":\"AgAD [...]
+ "headers" : {
+ "Server" : "nginx/1.16.1",
+ "Date" : "Tue, 03 Nov 2020 12:26:05 GMT",
+ "Content-Type" : "application/json",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload"
+ }
+ },
+ "uuid" : "7a3286d0-9606-4ee2-a0c0-85fdd4f15f8b",
+ "persistent" : true,
+ "insertionIndex" : 2
+}
\ No newline at end of file
diff --git a/integration-tests/telegram/src/test/resources/mappings/telegramSendDocument.json b/integration-tests/telegram/src/test/resources/mappings/telegramSendDocument.json
new file mode 100644
index 0000000..afaf3e2
--- /dev/null
+++ b/integration-tests/telegram/src/test/resources/mappings/telegramSendDocument.json
@@ -0,0 +1,24 @@
+{
+ "id" : "cfbaf69c-3be7-45e9-8512-f3769a98611a",
+ "name" : "botfake-token_senddocument",
+ "request" : {
+ "url" : "/botfake-token/sendDocument",
+ "method" : "POST",
+ "bodyPatterns" : [ {
+ "anything" : "anything"
+ } ]
+ },
+ "response" : {
+ "status" : 200,
+ "body" : "{\"ok\":true,\"result\":{\"message_id\":40,\"from\":{\"id\":1459045600,\"is_bot\":true,\"first_name\":\"camel-quarkus-test\",\"username\":\"CamelQuarkusTestBot\"},\"chat\":{\"id\":1426416050,\"first_name\":\"Apache\",\"last_name\":\"Camel\",\"type\":\"private\"},\"date\":1604406366,\"document\":{\"file_name\":\"file\",\"file_id\":\"BQACAgQAAxkDAAMoX6FMXo_mepgCTW_GwQQHyXl00NwAAvEGAAJd1glRq8h45cblYl0eBA\",\"file_unique_id\":\"AgAD8QYAAl3WCVE\",\"file_size\":7638}}}",
+ "headers" : {
+ "Server" : "nginx/1.16.1",
+ "Date" : "Tue, 03 Nov 2020 12:26:06 GMT",
+ "Content-Type" : "application/json",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload"
+ }
+ },
+ "uuid" : "cfbaf69c-3be7-45e9-8512-f3769a98611a",
+ "persistent" : true,
+ "insertionIndex" : 4
+}
\ No newline at end of file
diff --git a/integration-tests/telegram/src/test/resources/mappings/telegramSendLocation.json b/integration-tests/telegram/src/test/resources/mappings/telegramSendLocation.json
new file mode 100644
index 0000000..3bdc635
--- /dev/null
+++ b/integration-tests/telegram/src/test/resources/mappings/telegramSendLocation.json
@@ -0,0 +1,26 @@
+{
+ "id" : "f47c81d1-def8-4246-b14f-2a0555829f7d",
+ "name" : "botfake-token_sendlocation",
+ "request" : {
+ "url" : "/botfake-token/sendLocation",
+ "method" : "POST",
+ "bodyPatterns" : [ {
+ "equalToJson" : "{\"chat_id\":\"1426416050\",\"longitude\":31.138577,\"latitude\":29.974834,\"live_period\":120}",
+ "ignoreArrayOrder" : true,
+ "ignoreExtraElements" : true
+ } ]
+ },
+ "response" : {
+ "status" : 200,
+ "body" : "{\"ok\":true,\"result\":{\"message_id\":44,\"from\":{\"id\":1459045600,\"is_bot\":true,\"first_name\":\"camel-quarkus-test\",\"username\":\"CamelQuarkusTestBot\"},\"chat\":{\"id\":1426416050,\"first_name\":\"Apache\",\"last_name\":\"Camel\",\"type\":\"private\"},\"date\":1604406366,\"location\":{\"latitude\":29.974830,\"longitude\":31.138579,\"live_period\":120}}}",
+ "headers" : {
+ "Server" : "nginx/1.16.1",
+ "Date" : "Tue, 03 Nov 2020 12:26:06 GMT",
+ "Content-Type" : "application/json",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload"
+ }
+ },
+ "uuid" : "f47c81d1-def8-4246-b14f-2a0555829f7d",
+ "persistent" : true,
+ "insertionIndex" : 8
+}
\ No newline at end of file
diff --git a/integration-tests/telegram/src/test/resources/mappings/telegramSendMessage.json b/integration-tests/telegram/src/test/resources/mappings/telegramSendMessage.json
new file mode 100644
index 0000000..eb561fd
--- /dev/null
+++ b/integration-tests/telegram/src/test/resources/mappings/telegramSendMessage.json
@@ -0,0 +1,26 @@
+{
+ "id" : "99cc4134-7c83-446f-83db-5d9fb6886e08",
+ "name" : "botfake-token_sendmessage",
+ "request" : {
+ "url" : "/botfake-token/sendMessage",
+ "method" : "POST",
+ "bodyPatterns" : [ {
+ "equalToJson" : "{\"text\":\"A message from camel-quarkus-telegram\",\"chat_id\":\"1426416050\"}",
+ "ignoreArrayOrder" : true,
+ "ignoreExtraElements" : true
+ } ]
+ },
+ "response" : {
+ "status" : 200,
+ "body" : "{\"ok\":true,\"result\":{\"message_id\":43,\"from\":{\"id\":1459045600,\"is_bot\":true,\"first_name\":\"camel-quarkus-test\",\"username\":\"CamelQuarkusTestBot\"},\"chat\":{\"id\":1426416050,\"first_name\":\"Apache\",\"last_name\":\"Camel\",\"type\":\"private\"},\"date\":1604406366,\"text\":\"A message from camel-quarkus-telegram\"}}",
+ "headers" : {
+ "Server" : "nginx/1.16.1",
+ "Date" : "Tue, 03 Nov 2020 12:26:06 GMT",
+ "Content-Type" : "application/json",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload"
+ }
+ },
+ "uuid" : "99cc4134-7c83-446f-83db-5d9fb6886e08",
+ "persistent" : true,
+ "insertionIndex" : 7
+}
\ No newline at end of file
diff --git a/integration-tests/telegram/src/test/resources/mappings/telegramSendPhoto.json b/integration-tests/telegram/src/test/resources/mappings/telegramSendPhoto.json
new file mode 100644
index 0000000..0877a37
--- /dev/null
+++ b/integration-tests/telegram/src/test/resources/mappings/telegramSendPhoto.json
@@ -0,0 +1,24 @@
+{
+ "id" : "009be0d0-2a9f-42d9-8e59-e10e4c21e658",
+ "name" : "botfake-token_sendphoto",
+ "request" : {
+ "url" : "/botfake-token/sendPhoto",
+ "method" : "POST",
+ "bodyPatterns" : [ {
+ "anything" : "anything"
+ } ]
+ },
+ "response" : {
+ "status" : 200,
+ "body" : "{\"ok\":true,\"result\":{\"message_id\":41,\"from\":{\"id\":1459045600,\"is_bot\":true,\"first_name\":\"camel-quarkus-test\",\"username\":\"CamelQuarkusTestBot\"},\"chat\":{\"id\":1426416050,\"first_name\":\"Apache\",\"last_name\":\"Camel\",\"type\":\"private\"},\"date\":1604406366,\"photo\":[{\"file_id\":\"AgACAgQAAxkDAAMpX6FMXuAp6zF9JdQ0RT2yUzp3Kc4AAgWzMRtd1glRWa9enePW3hnwkAYnXQADAQADAgADbQADhucBAAEeBA\",\"file_unique_id\":\"AQAD8JAGJ10AA4bnAQAB\",\"file_size\":1005,\"wid [...]
+ "headers" : {
+ "Server" : "nginx/1.16.1",
+ "Date" : "Tue, 03 Nov 2020 12:26:06 GMT",
+ "Content-Type" : "application/json",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload"
+ }
+ },
+ "uuid" : "009be0d0-2a9f-42d9-8e59-e10e4c21e658",
+ "persistent" : true,
+ "insertionIndex" : 5
+}
\ No newline at end of file
diff --git a/integration-tests/telegram/src/test/resources/mappings/telegramSendVenue.json b/integration-tests/telegram/src/test/resources/mappings/telegramSendVenue.json
new file mode 100644
index 0000000..669ad30
--- /dev/null
+++ b/integration-tests/telegram/src/test/resources/mappings/telegramSendVenue.json
@@ -0,0 +1,26 @@
+{
+ "id" : "ddf71eec-1f76-4467-8611-d8ec74edc885",
+ "name" : "botfake-token_sendvenue",
+ "request" : {
+ "url" : "/botfake-token/sendVenue",
+ "method" : "POST",
+ "bodyPatterns" : [ {
+ "equalToJson" : "{\"chat_id\":\"1426416050\",\"longitude\":31.136329,\"latitude\":29.977818,\"title\":\"Pyramid of Queen Henutsen\",\"address\":\"El-Hussein Ibn Ali Ln, Nazlet El-Semman, Al Haram, Giza Governorate, Egypt\"}",
+ "ignoreArrayOrder" : true,
+ "ignoreExtraElements" : true
+ } ]
+ },
+ "response" : {
+ "status" : 200,
+ "body" : "{\"ok\":true,\"result\":{\"message_id\":42,\"from\":{\"id\":1459045600,\"is_bot\":true,\"first_name\":\"camel-quarkus-test\",\"username\":\"CamelQuarkusTestBot\"},\"chat\":{\"id\":1426416050,\"first_name\":\"Apache\",\"last_name\":\"Camel\",\"type\":\"private\"},\"date\":1604406366,\"location\":{\"latitude\":29.977826,\"longitude\":31.136330},\"venue\":{\"location\":{\"latitude\":29.977826,\"longitude\":31.136330},\"title\":\"Pyramid of Queen Henutsen\",\"address\":\"El-Hus [...]
+ "headers" : {
+ "Server" : "nginx/1.16.1",
+ "Date" : "Tue, 03 Nov 2020 12:26:06 GMT",
+ "Content-Type" : "application/json",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload"
+ }
+ },
+ "uuid" : "ddf71eec-1f76-4467-8611-d8ec74edc885",
+ "persistent" : true,
+ "insertionIndex" : 6
+}
\ No newline at end of file
diff --git a/integration-tests/telegram/src/test/resources/mappings/telegramSendVideo.json b/integration-tests/telegram/src/test/resources/mappings/telegramSendVideo.json
new file mode 100644
index 0000000..0b30364
--- /dev/null
+++ b/integration-tests/telegram/src/test/resources/mappings/telegramSendVideo.json
@@ -0,0 +1,24 @@
+{
+ "id" : "5a3b6a9a-8043-4612-8144-b7db9d42a481",
+ "name" : "botfake-token_sendvideo",
+ "request" : {
+ "url" : "/botfake-token/sendVideo",
+ "method" : "POST",
+ "bodyPatterns" : [ {
+ "anything" : "anything"
+ } ]
+ },
+ "response" : {
+ "status" : 200,
+ "body" : "{\"ok\":true,\"result\":{\"message_id\":39,\"from\":{\"id\":1459045600,\"is_bot\":true,\"first_name\":\"camel-quarkus-test\",\"username\":\"CamelQuarkusTestBot\"},\"chat\":{\"id\":1426416050,\"first_name\":\"Apache\",\"last_name\":\"Camel\",\"type\":\"private\"},\"date\":1604406365,\"video\":{\"duration\":4,\"width\":108,\"height\":10,\"file_name\":\"video.mp4\",\"mime_type\":\"video/mp4\",\"thumb\":{\"file_id\":\"AAMCBAADGQMAAydfoUxdmnzfbyDrFSbggnNcxC62vgAC8AYAAl3WCVEmSbAa [...]
+ "headers" : {
+ "Server" : "nginx/1.16.1",
+ "Date" : "Tue, 03 Nov 2020 12:26:05 GMT",
+ "Content-Type" : "application/json",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload"
+ }
+ },
+ "uuid" : "5a3b6a9a-8043-4612-8144-b7db9d42a481",
+ "persistent" : true,
+ "insertionIndex" : 3
+}
\ No newline at end of file
diff --git a/integration-tests/telegram/src/test/resources/mappings/telegramStopMessageLiveAction.json b/integration-tests/telegram/src/test/resources/mappings/telegramStopMessageLiveAction.json
new file mode 100644
index 0000000..8d86009
--- /dev/null
+++ b/integration-tests/telegram/src/test/resources/mappings/telegramStopMessageLiveAction.json
@@ -0,0 +1,26 @@
+{
+ "id" : "70c0a770-2a98-4f46-ba01-8ba3a71d8e3d",
+ "name" : "botfake-token_stopmessagelivelocation",
+ "request" : {
+ "url" : "/botfake-token/stopMessageLiveLocation",
+ "method" : "POST",
+ "bodyPatterns" : [ {
+ "equalToJson" : "{\"chat_id\":\"1426416050\",\"message_id\":44}",
+ "ignoreArrayOrder" : true,
+ "ignoreExtraElements" : true
+ } ]
+ },
+ "response" : {
+ "status" : 200,
+ "body" : "{\"ok\":true,\"result\":{\"message_id\":44,\"from\":{\"id\":1459045600,\"is_bot\":true,\"first_name\":\"camel-quarkus-test\",\"username\":\"CamelQuarkusTestBot\"},\"chat\":{\"id\":1426416050,\"first_name\":\"Apache\",\"last_name\":\"Camel\",\"type\":\"private\"},\"date\":1604406366,\"edit_date\":1604406367,\"location\":{\"latitude\":29.974934,\"longitude\":31.131109}}}",
+ "headers" : {
+ "Server" : "nginx/1.16.1",
+ "Date" : "Tue, 03 Nov 2020 12:26:07 GMT",
+ "Content-Type" : "application/json",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload"
+ }
+ },
+ "uuid" : "70c0a770-2a98-4f46-ba01-8ba3a71d8e3d",
+ "persistent" : true,
+ "insertionIndex" : 11
+}
\ No newline at end of file