This is an automated email from the ASF dual-hosted git repository. zbendhiba pushed a commit to branch 3.2.x in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 19e64b2b6251660a624671e0d05e89b3b0e036d5 Author: Zineb Bendhiba <bendhiba.zi...@gmail.com> AuthorDate: Wed Sep 13 15:23:27 2023 +0200 Telegram integration tests: add the possibility to disable running webhook test Fixes #5298 --- integration-tests/telegram/README.adoc | 9 ++++++++- .../quarkus/component/telegram/it/Routes.java | 13 ++++++++++--- .../src/main/resources/application.properties | 3 ++- .../telegram/it/CustomWebhookCondition.java} | 22 ++++++++++++++-------- .../component/telegram/it/TelegramTest.java | 2 ++ .../telegram/it/TelegramTestResource.java | 5 +---- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/integration-tests/telegram/README.adoc b/integration-tests/telegram/README.adoc index 5521d1640b..39f63449bb 100644 --- a/integration-tests/telegram/README.adoc +++ b/integration-tests/telegram/README.adoc @@ -24,4 +24,11 @@ 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 +Note that you'll need 2 different bots, one dedicated to the webhook consumer only. + +If you want to disable the webhook test, you can set the environment property + +[source,shell] +---- +export TELEGRAM_WEBHOOK_DISABLED=true +---- \ 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 dab1578264..5153477c1f 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 @@ -18,14 +18,21 @@ package org.apache.camel.quarkus.component.telegram.it; import jakarta.enterprise.context.ApplicationScoped; import org.apache.camel.builder.RouteBuilder; +import org.eclipse.microprofile.config.inject.ConfigProperty; @ApplicationScoped public class Routes extends RouteBuilder { + @ConfigProperty(name = "webhook.disabled") + String webhookDisabled; + @Override public void configure() throws Exception { - from("webhook:telegram:bots?webhookPath=/my-test&webhook-external-url={{webhook-external-url}}&authorization-token={{webhook-authorization-token}}") - .log("webhook message : ${body}") - .to("mock:webhook"); + boolean isWebhookDisabled = Boolean.parseBoolean(webhookDisabled); + if (!isWebhookDisabled) { + from("webhook:telegram:bots?webhookPath=/my-test&webhook-external-url={{webhook-external-url}}&authorization-token={{webhook-authorization-token}}") + .log("webhook message : ${body}") + .to("mock:webhook"); + } } } diff --git a/integration-tests/telegram/src/main/resources/application.properties b/integration-tests/telegram/src/main/resources/application.properties index 70f5b391cc..ce05e22964 100644 --- a/integration-tests/telegram/src/main/resources/application.properties +++ b/integration-tests/telegram/src/main/resources/application.properties @@ -33,4 +33,5 @@ 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 +webhook-authorization-token=${TELEGRAM_WEBHOOK_AUTHORIZATION_TOKEN:fake-token} +webhook.disabled=${TELEGRAM_WEBHOOK_DISABLED:false} \ 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/test/java/org/apache/camel/quarkus/component/telegram/it/CustomWebhookCondition.java similarity index 52% copy from integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/Routes.java copy to integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/CustomWebhookCondition.java index dab1578264..9429229a3a 100644 --- a/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/Routes.java +++ b/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/CustomWebhookCondition.java @@ -16,16 +16,22 @@ */ package org.apache.camel.quarkus.component.telegram.it; -import jakarta.enterprise.context.ApplicationScoped; -import org.apache.camel.builder.RouteBuilder; +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; -@ApplicationScoped -public class Routes extends RouteBuilder { +public class CustomWebhookCondition implements ExecutionCondition { + private static final String TELEGRAM_WEBHOOK_DISABLED = "TELEGRAM_WEBHOOK_DISABLED"; @Override - public void configure() throws Exception { - from("webhook:telegram:bots?webhookPath=/my-test&webhook-external-url={{webhook-external-url}}&authorization-token={{webhook-authorization-token}}") - .log("webhook message : ${body}") - .to("mock:webhook"); + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) { + boolean isWebhookDisabled = System.getenv(TELEGRAM_WEBHOOK_DISABLED) != null + && Boolean.parseBoolean(System.getenv(TELEGRAM_WEBHOOK_DISABLED)); + + if (isWebhookDisabled) { + return ConditionEvaluationResult.disabled("Webhook test is disabled"); + } + + return ConditionEvaluationResult.enabled("Webhook test is enabled"); } } 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 9f2af1af52..44a918d3e7 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,6 +35,7 @@ import org.apache.camel.quarkus.test.TrustStoreResource; import org.apache.camel.quarkus.test.wiremock.MockServer; import org.jboss.logging.Logger; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; @@ -212,6 +213,7 @@ public class TelegramTest { } @Test + @ExtendWith(CustomWebhookCondition.class) void testWebhookEndpoint() { //simulate POST messages from Telegram final var message = "{\n" + 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 092025061c..1ffe6f34c6 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 @@ -26,8 +26,6 @@ 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() { @@ -45,7 +43,6 @@ public class TelegramTestResource extends WireMockTestResourceLifecycleManager { @Override protected boolean isMockingEnabled() { - return !envVarsPresent(TELEGRAM_ENV_AUTHORIZATION_TOKEN, TELEGRAM_ENV_CHAT_ID, TELEGRAM_ENV_WEBHOOK_EXTERNAL_URL, - TELEGRAM_ENV_WEBHOOK_AUTHORIZATION_TOKEN); + return !envVarsPresent(TELEGRAM_ENV_AUTHORIZATION_TOKEN, TELEGRAM_ENV_CHAT_ID); } }