ppalaga commented on a change in pull request #1888: URL: https://github.com/apache/camel-quarkus/pull/1888#discussion_r501535956
########## File path: integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/Routes.java ########## @@ -0,0 +1,129 @@ +/* + * 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.geocoder.it; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.inject.Inject; +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.geocoder.GeoCoderComponent; +import org.apache.camel.quarkus.test.mock.backend.MockBackendUtils; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@ApplicationScoped +public class Routes extends RouteBuilder { + + @ConfigProperty(name = "google.api.key") + String googleApiKey; + @ConfigProperty(name = "quarkus.http.test-port") + int httpTestPort; + @ConfigProperty(name = "quarkus.http.port") + int httpPort; + @Inject + MockApiService mockApiService; + + private String getBaseUri() { + final boolean isNativeMode = "executable".equals(System.getProperty("org.graalvm.nativeimage.kind")); + return "AIzaFakeKey".equals(googleApiKey) + ? "http://localhost:" + (isNativeMode ? httpPort : httpTestPort) Review comment: Knowledge sharing: one day this may become easier if Quarkus folks fix https://github.com/quarkusio/quarkus/issues/9287 for us. ########## File path: integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/Routes.java ########## @@ -0,0 +1,129 @@ +/* + * 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.geocoder.it; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.inject.Inject; +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.geocoder.GeoCoderComponent; +import org.apache.camel.quarkus.test.mock.backend.MockBackendUtils; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@ApplicationScoped +public class Routes extends RouteBuilder { + + @ConfigProperty(name = "google.api.key") + String googleApiKey; + @ConfigProperty(name = "quarkus.http.test-port") + int httpTestPort; + @ConfigProperty(name = "quarkus.http.port") + int httpPort; + @Inject + MockApiService mockApiService; + + private String getBaseUri() { + final boolean isNativeMode = "executable".equals(System.getProperty("org.graalvm.nativeimage.kind")); + return "AIzaFakeKey".equals(googleApiKey) + ? "http://localhost:" + (isNativeMode ? httpPort : httpTestPort) + : "https://maps.googleapis.com"; + } + + /** + * We need to implement some conditional configuration of the {@link GeoCoderComponent} thus we create it + * programmatically and publish via CDI. + * + * @return a configured {@link GeoCoderComponent} + */ + @Produces + @ApplicationScoped + @Unremovable + @Named("geocoder") + GeoCoderComponent geocoderComponent() throws IllegalAccessException, NoSuchFieldException, InstantiationException { + final GeoCoderComponent result = new GeoCoderComponent(); + result.setCamelContext(getContext()); + result.setGeoApiContext(mockApiService.createGeoApiContext(getBaseUri(), googleApiKey)); + return result; + } + + @Override + public void configure() throws Exception { + if (MockBackendUtils.startMockBackend(true)) { Review comment: @llowinge will love this! ---------------------------------------------------------------- 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: us...@infra.apache.org