From 744c9ff301ab74e3659d67817fa4791de93e07aa Mon Sep 17 00:00:00 2001 From: Zineb Bendhiba Date: Wed, 13 Sep 2023 15:23:27 +0200 Subject: [PATCH] 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 | 37 +++++++++++++++++++ .../component/telegram/it/TelegramTest.java | 2 + .../telegram/it/TelegramTestResource.java | 5 +-- 6 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/CustomWebhookCondition.java diff --git a/integration-tests/telegram/README.adoc b/integration-tests/telegram/README.adoc index 5521d1640bd8..39f63449bb2c 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 dab157826455..5153477c1f40 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 @@ 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 70f5b391cc62..ce05e229649d 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/test/java/org/apache/camel/quarkus/component/telegram/it/CustomWebhookCondition.java b/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/CustomWebhookCondition.java new file mode 100644 index 000000000000..9429229a3a02 --- /dev/null +++ b/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/CustomWebhookCondition.java @@ -0,0 +1,37 @@ +/* + * 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 org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; + +public class CustomWebhookCondition implements ExecutionCondition { + private static final String TELEGRAM_WEBHOOK_DISABLED = "TELEGRAM_WEBHOOK_DISABLED"; + + @Override + 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 9f2af1af52d5..44a918d3e716 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.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 void venue() throws IOException { } @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 092025061cde..1ffe6f34c607 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 start() { @@ -45,7 +43,6 @@ protected String getRecordTargetBaseUrl() { @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); } }