You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2020/09/24 09:44:34 UTC

[GitHub] [camel-quarkus] ppalaga commented on a change in pull request #1818: Improve mock backend logging

ppalaga commented on a change in pull request #1818:
URL: https://github.com/apache/camel-quarkus/pull/1818#discussion_r494180715



##########
File path: integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramRoutes.java
##########
@@ -21,37 +21,80 @@
 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_FALLBACK_MOCK=false */

Review comment:
       I do not see an issue. What would you expect there?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org