Skip to content

Commit

Permalink
Stub Telegram tests with WireMock
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Nov 4, 2020
1 parent be675db commit 5302af6
Show file tree
Hide file tree
Showing 26 changed files with 316 additions and 404 deletions.
16 changes: 10 additions & 6 deletions integration-tests/telegram/README.adoc
Original file line number Diff line number Diff line change
@@ -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/
Expand All @@ -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`
9 changes: 5 additions & 4 deletions integration-tests/telegram/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,18 @@
<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>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-test-support</artifactId>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
camel.component.telegram.authorization-token=${TELEGRAM_AUTHORIZATION_TOKEN:fake-token}
telegram.chatId=${TELEGRAM_CHAT_ID:1426416050}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 5302af6

Please sign in to comment.