You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zb...@apache.org on 2023/03/01 09:41:42 UTC
[camel-quarkus] 01/02: Telegram : improve integration tests with Telegram credentials
This is an automated email from the ASF dual-hosted git repository.
zbendhiba pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 77a5999cea7244e444f9df6a58c3df38d0c678db
Author: Zineb Bendhiba <be...@gmail.com>
AuthorDate: Tue Feb 28 16:30:33 2023 +0100
Telegram : improve integration tests with Telegram credentials
---
integration-tests/telegram/README.adoc | 4 ++++
.../org/apache/camel/quarkus/component/telegram/it/Routes.java | 2 +-
.../telegram/src/main/resources/application.properties | 5 +++++
.../apache/camel/quarkus/component/telegram/it/TelegramTest.java | 8 ++++----
.../camel/quarkus/component/telegram/it/TelegramTestResource.java | 6 +++++-
.../src/test/resources/mappings/telegramWebhook-register.json | 2 +-
6 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/integration-tests/telegram/README.adoc b/integration-tests/telegram/README.adoc
index a62d745c8b..5521d1640b 100644
--- a/integration-tests/telegram/README.adoc
+++ b/integration-tests/telegram/README.adoc
@@ -12,6 +12,8 @@ Then set the following environment variables:
----
export TELEGRAM_AUTHORIZATION_TOKEN=my-authorization-token
export TELEGRAM_CHAT_ID=my-chatId
+export TELEGRAM_WEBHOOK_EXTERNAL_URL=https://your-webhook-url
+export TELEGRAM_WEBHOOK_AUTHORIZATION_TOKEN=my-webhook_authorization-token
----
If the WireMock stub recordings need updating, then remove the existing files from `src/test/resources/mappings` and run tests with either:
@@ -21,3 +23,5 @@ System property `-Dwiremock.record=true`
Or
Set environment variable `WIREMOCK_RECORD=true`
+
+Note that you'll need 2 differents bots, one dedicated to the webhook consumer only.
\ No newline at end of file
diff --git a/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/Routes.java b/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/Routes.java
index 520d42af26..1dda144808 100644
--- a/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/Routes.java
+++ b/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/Routes.java
@@ -24,7 +24,7 @@ public class Routes extends RouteBuilder {
@Override
public void configure() throws Exception {
- from("webhook:telegram:bots?webhookPath=/my-test&webhook-external-url=http://localhost:8080")
+ from("webhook:telegram:bots?webhookPath=/my-test&webhook-external-url={{webhook-external-url}}&authorization-token={{webhook-authorization-token}}")
.log("webhook message : ${body}");
}
}
diff --git a/integration-tests/telegram/src/main/resources/application.properties b/integration-tests/telegram/src/main/resources/application.properties
index a394805b78..70f5b391cc 100644
--- a/integration-tests/telegram/src/main/resources/application.properties
+++ b/integration-tests/telegram/src/main/resources/application.properties
@@ -27,5 +27,10 @@ quarkus.http.body.uploads-directory=target/uploads
# Camel :: Telegram
#
+# For basic Telegram consumer and producer
camel.component.telegram.authorization-token=${TELEGRAM_AUTHORIZATION_TOKEN:fake-token}
telegram.chatId=${TELEGRAM_CHAT_ID:1426416050}
+
+#for webhook Telegram consumer
+webhook-external-url=${TELEGRAM_WEBHOOK_EXTERNAL_URL:https://my-external-link}
+webhook-authorization-token=${TELEGRAM_WEBHOOK_AUTHORIZATION_TOKEN:fake-token}
\ 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 940cce81dc..6c636f7dd6 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
@@ -35,8 +35,8 @@ 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.Disabled;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
@@ -112,7 +112,7 @@ public class TelegramTest {
}
@Test
- @Disabled("https://github.com/apache/camel-quarkus/issues/4513")
+ @EnabledIfEnvironmentVariable(named = "TELEGRAM_AUTHORIZATION_TOKEN", matches = ".+") //https://github.com/apache/camel-quarkus/issues/4513
public void mp3() throws IOException {
try (InputStream in = getClass().getClassLoader().getResourceAsStream("camel-quarkus-rocks.mp3")) {
/* Send a message */
@@ -126,7 +126,7 @@ public class TelegramTest {
}
@Test
- @Disabled("https://github.com/apache/camel-quarkus/issues/4513")
+ @EnabledIfEnvironmentVariable(named = "TELEGRAM_AUTHORIZATION_TOKEN", matches = ".+") //https://github.com/apache/camel-quarkus/issues/4513
public void mp4() throws IOException {
try (InputStream in = getClass().getClassLoader().getResourceAsStream("camel-quarkus-rocks.mp4")) {
/* Send a message */
@@ -140,7 +140,7 @@ public class TelegramTest {
}
@Test
- @Disabled("https://github.com/apache/camel-quarkus/issues/4513")
+ @EnabledIfEnvironmentVariable(named = "TELEGRAM_AUTHORIZATION_TOKEN", matches = ".+") //https://github.com/apache/camel-quarkus/issues/4513
public void pdf() throws IOException {
try (InputStream in = getClass().getClassLoader().getResourceAsStream("camel-quarkus-rocks.pdf")) {
/* Send a message */
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
index a93ee6c997..092025061c 100644
--- 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
@@ -25,6 +25,9 @@ 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";
+ private static final String TELEGRAM_ENV_CHAT_ID = "TELEGRAM_CHAT_ID";
+ private static final String TELEGRAM_ENV_WEBHOOK_EXTERNAL_URL = "TELEGRAM_WEBHOOK_EXTERNAL_URL";
+ private static final String TELEGRAM_ENV_WEBHOOK_AUTHORIZATION_TOKEN = "TELEGRAM_WEBHOOK_AUTHORIZATION_TOKEN";
@Override
public Map<String, String> start() {
@@ -42,6 +45,7 @@ public class TelegramTestResource extends WireMockTestResourceLifecycleManager {
@Override
protected boolean isMockingEnabled() {
- return !envVarsPresent(TELEGRAM_ENV_AUTHORIZATION_TOKEN);
+ return !envVarsPresent(TELEGRAM_ENV_AUTHORIZATION_TOKEN, TELEGRAM_ENV_CHAT_ID, TELEGRAM_ENV_WEBHOOK_EXTERNAL_URL,
+ TELEGRAM_ENV_WEBHOOK_AUTHORIZATION_TOKEN);
}
}
diff --git a/integration-tests/telegram/src/test/resources/mappings/telegramWebhook-register.json b/integration-tests/telegram/src/test/resources/mappings/telegramWebhook-register.json
index 9152c9ff70..00e143103a 100644
--- a/integration-tests/telegram/src/test/resources/mappings/telegramWebhook-register.json
+++ b/integration-tests/telegram/src/test/resources/mappings/telegramWebhook-register.json
@@ -2,7 +2,7 @@
"id" : "70c0a770-2a98-4f46-ba01-8ba3a71d8e3d",
"name": "botfake-webhook",
"request": {
- "url": "/botfake-token/setWebhook?url=http://localhost:8080/my-test",
+ "url": "/botfake-token/setWebhook?url=https://my-external-link/my-test",
"method": "GET"
},
"response": {