You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2020/10/01 15:45:48 UTC
[camel-quarkus] branch master updated: Geocoder native support
fixes #1645 (#1856)
This is an automated email from the ASF dual-hosted git repository.
ppalaga pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new da5b9be Geocoder native support fixes #1645 (#1856)
da5b9be is described below
commit da5b9beeca80977c90b45da7fd795e3ea9cbc3a2
Author: Zineb BENDHIBA <be...@gmail.com>
AuthorDate: Thu Oct 1 17:45:34 2020 +0200
Geocoder native support fixes #1645 (#1856)
* Geocoder native support fixes #1645
---
.../ROOT/pages/reference/extensions/geocoder.adoc | 19 +++-
.../partials/reference/components/geocoder.adoc | 6 +-
.../geocoder/deployment/GeocoderProcessor.java | 46 --------
.../component/geocoder/it/GeocoderResource.java | 51 ---------
extensions-jvm/pom.xml | 1 -
.../geocoder/deployment/pom.xml | 8 ++
.../geocoder/deployment/GeocoderProcessor.java | 55 ++++++++++
{extensions-jvm => extensions}/geocoder/pom.xml | 1 -
.../geocoder/runtime/pom.xml | 19 ++++
.../runtime/src/main/doc/configuration.adoc | 1 +
.../main/resources/META-INF/quarkus-extension.yaml | 3 +-
extensions/pom.xml | 1 +
integration-tests/geocoder/README.adoc | 10 ++
.../geocoder}/pom.xml | 67 +++++++++---
.../quarkus/component/geocoder/it/Country.java | 23 ++--
.../geocoder/it/GeocoderGoogleResource.java | 77 ++++++++++++++
.../geocoder/it/GeocoderNominationResource.java | 99 ++++++++++++++++++
.../component/geocoder/it/GeocoderResult.java | 116 +++++++++++++++++++++
.../quarkus/component/geocoder/it/Region.java | 23 ++--
.../src/main/resources/application.properties | 24 +++++
.../component/geocoder/it/GeocoderGoogleIT.java | 18 +---
.../component/geocoder/it/GeocoderGoogleTest.java | 33 +++++-
.../geocoder/it/GeocoderNominationIT.java | 17 +--
.../geocoder/it/GeocoderNominationTest.java | 27 ++++-
integration-tests/pom.xml | 1 +
tooling/scripts/test-categories.yaml | 1 +
26 files changed, 566 insertions(+), 181 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/geocoder.adoc b/docs/modules/ROOT/pages/reference/extensions/geocoder.adoc
index 15af8d4..4339ccd 100644
--- a/docs/modules/ROOT/pages/reference/extensions/geocoder.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/geocoder.adoc
@@ -2,15 +2,15 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
= Geocoder
:cq-artifact-id: camel-quarkus-geocoder
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
:cq-description: Find geocodes (latitude and longitude) for a given address or the other way round.
:cq-deprecated: false
:cq-jvm-since: 1.1.0
-:cq-native-since: n/a
+:cq-native-since: 1.2.0
[.badges]
-[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
+[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native since##[.badge-supported]##1.2.0##
Find geocodes (latitude and longitude) for a given address or the other way round.
@@ -31,3 +31,14 @@ Please refer to the above link for usage and configuration details.
----
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
+
+== SSL in native mode
+
+This extension auto-enables SSL support in native mode. Hence you do not need to add
+`quarkus.ssl.native=true` to your `application.properties` yourself. See also
+https://quarkus.io/guides/native-and-ssl[Quarkus SSL guide].
+
+== Additional Camel Quarkus configuration
+
+Locales different from the build machine's default locale do not work well in native mode due to https://github.com/oracle/graal/issues/1645[this GraalVM bug]. The `google-maps-services` library this extension depends on uses `Locale.English` to format double latitude and longitude values. As a consequence of these two facts, the locale on the building machine must be set to some English locale, such as `en_US.UTF-8`, `en_GB.UTF-8` or `en_IE.UTF-8` so that the calls to the Google Maps AP [...]
+
diff --git a/docs/modules/ROOT/partials/reference/components/geocoder.adoc b/docs/modules/ROOT/partials/reference/components/geocoder.adoc
index 45aedaf..035a8de 100644
--- a/docs/modules/ROOT/partials/reference/components/geocoder.adoc
+++ b/docs/modules/ROOT/partials/reference/components/geocoder.adoc
@@ -2,11 +2,11 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
:cq-artifact-id: camel-quarkus-geocoder
:cq-artifact-id-base: geocoder
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.1.0
-:cq-native-since: n/a
+:cq-native-since: 1.2.0
:cq-camel-part-name: geocoder
:cq-camel-part-title: Geocoder
:cq-camel-part-description: Find geocodes (latitude and longitude) for a given address or the other way round.
diff --git a/extensions-jvm/geocoder/deployment/src/main/java/org/apache/camel/quarkus/component/geocoder/deployment/GeocoderProcessor.java b/extensions-jvm/geocoder/deployment/src/main/java/org/apache/camel/quarkus/component/geocoder/deployment/GeocoderProcessor.java
deleted file mode 100644
index c631a22..0000000
--- a/extensions-jvm/geocoder/deployment/src/main/java/org/apache/camel/quarkus/component/geocoder/deployment/GeocoderProcessor.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.deployment;
-
-import io.quarkus.deployment.annotations.BuildStep;
-import io.quarkus.deployment.annotations.ExecutionTime;
-import io.quarkus.deployment.annotations.Record;
-import io.quarkus.deployment.builditem.FeatureBuildItem;
-import io.quarkus.deployment.pkg.steps.NativeBuild;
-import org.apache.camel.quarkus.core.JvmOnlyRecorder;
-import org.jboss.logging.Logger;
-
-class GeocoderProcessor {
-
- private static final Logger LOG = Logger.getLogger(GeocoderProcessor.class);
- private static final String FEATURE = "camel-geocoder";
-
- @BuildStep
- FeatureBuildItem feature() {
- return new FeatureBuildItem(FEATURE);
- }
-
- /**
- * Remove this once this extension starts supporting the native mode.
- */
- @BuildStep(onlyIf = NativeBuild.class)
- @Record(value = ExecutionTime.RUNTIME_INIT)
- void warnJvmInNative(JvmOnlyRecorder recorder) {
- JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
- recorder.warnJvmInNative(FEATURE); // warn at runtime
- }
-}
diff --git a/extensions-jvm/geocoder/integration-test/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderResource.java b/extensions-jvm/geocoder/integration-test/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderResource.java
deleted file mode 100644
index ab36304..0000000
--- a/extensions-jvm/geocoder/integration-test/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderResource.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.inject.Inject;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.apache.camel.CamelContext;
-import org.jboss.logging.Logger;
-
-@Path("/geocoder")
-@ApplicationScoped
-public class GeocoderResource {
-
- private static final Logger LOG = Logger.getLogger(GeocoderResource.class);
-
- private static final String COMPONENT_GEOCODER = "geocoder";
- @Inject
- CamelContext context;
-
- @Path("/load/component/geocoder")
- @GET
- @Produces(MediaType.TEXT_PLAIN)
- public Response loadComponentGeocoder() throws Exception {
- /* This is an autogenerated test */
- if (context.getComponent(COMPONENT_GEOCODER) != null) {
- return Response.ok().build();
- }
- LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_GEOCODER);
- return Response.status(500, COMPONENT_GEOCODER + " could not be loaded from the Camel context").build();
- }
-}
diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml
index 9cd0b87..4aa1692 100644
--- a/extensions-jvm/pom.xml
+++ b/extensions-jvm/pom.xml
@@ -72,7 +72,6 @@
<module>flink</module>
<module>freemarker</module>
<module>ganglia</module>
- <module>geocoder</module>
<module>google-bigquery</module>
<module>google-pubsub</module>
<module>groovy</module>
diff --git a/extensions-jvm/geocoder/deployment/pom.xml b/extensions/geocoder/deployment/pom.xml
similarity index 87%
rename from extensions-jvm/geocoder/deployment/pom.xml
rename to extensions/geocoder/deployment/pom.xml
index 9b9889c..2a02417 100644
--- a/extensions-jvm/geocoder/deployment/pom.xml
+++ b/extensions/geocoder/deployment/pom.xml
@@ -40,6 +40,14 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-geocoder</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-support-httpclient-deployment</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-jsonpath-deployment</artifactId>
+ </dependency>
</dependencies>
<build>
diff --git a/extensions/geocoder/deployment/src/main/java/org/apache/camel/quarkus/component/geocoder/deployment/GeocoderProcessor.java b/extensions/geocoder/deployment/src/main/java/org/apache/camel/quarkus/component/geocoder/deployment/GeocoderProcessor.java
new file mode 100644
index 0000000..c5fbdf1
--- /dev/null
+++ b/extensions/geocoder/deployment/src/main/java/org/apache/camel/quarkus/component/geocoder/deployment/GeocoderProcessor.java
@@ -0,0 +1,55 @@
+/*
+ * 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.deployment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+
+class GeocoderProcessor {
+
+ private static final String FEATURE = "camel-geocoder";
+
+ @BuildStep
+ FeatureBuildItem feature() {
+ return new FeatureBuildItem(FEATURE);
+ }
+
+ @BuildStep
+ ExtensionSslNativeSupportBuildItem activateSslNativeSupport() {
+ return new ExtensionSslNativeSupportBuildItem(FEATURE);
+ }
+
+ @BuildStep
+ List<ReflectiveClassBuildItem> registerReflectiveClasses() {
+ List<ReflectiveClassBuildItem> items = new ArrayList<ReflectiveClassBuildItem>();
+ items.add(new ReflectiveClassBuildItem(false, true, "com.google.maps.GeocodingApi$Response"));
+ items.add(new ReflectiveClassBuildItem(false, true, "com.google.maps.model.GeocodingResult"));
+ items.add(new ReflectiveClassBuildItem(false, true, "com.google.maps.model.AddressComponent"));
+ items.add(new ReflectiveClassBuildItem(false, true, "com.google.maps.model.Geometry"));
+ items.add(new ReflectiveClassBuildItem(false, true, "com.google.maps.model.AddressType"));
+ items.add(new ReflectiveClassBuildItem(false, true, "com.google.maps.model.PlusCode"));
+ items.add(new ReflectiveClassBuildItem(false, true, "com.google.maps.model.Bounds"));
+ items.add(new ReflectiveClassBuildItem(false, true, "com.google.maps.model.LatLng"));
+ items.add(new ReflectiveClassBuildItem(false, true, "com.google.maps.model.LocationType"));
+ return items;
+ }
+}
diff --git a/extensions-jvm/geocoder/pom.xml b/extensions/geocoder/pom.xml
similarity index 97%
rename from extensions-jvm/geocoder/pom.xml
rename to extensions/geocoder/pom.xml
index 8d62ebf..fa5cb9d 100644
--- a/extensions-jvm/geocoder/pom.xml
+++ b/extensions/geocoder/pom.xml
@@ -35,6 +35,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
- <module>integration-test</module>
</modules>
</project>
diff --git a/extensions-jvm/geocoder/runtime/pom.xml b/extensions/geocoder/runtime/pom.xml
similarity index 82%
rename from extensions-jvm/geocoder/runtime/pom.xml
rename to extensions/geocoder/runtime/pom.xml
index 680f505..faaf4db 100644
--- a/extensions-jvm/geocoder/runtime/pom.xml
+++ b/extensions/geocoder/runtime/pom.xml
@@ -34,6 +34,7 @@
<properties>
<camel.quarkus.jvmSince>1.1.0</camel.quarkus.jvmSince>
+ <camel.quarkus.nativeSince>1.2.0</camel.quarkus.nativeSince>
</properties>
<dependencyManagement>
@@ -56,6 +57,24 @@
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-geocoder</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.jayway.jsonpath</groupId>
+ <artifactId>json-path</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-support-httpclient</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-jsonpath</artifactId>
</dependency>
</dependencies>
diff --git a/extensions/geocoder/runtime/src/main/doc/configuration.adoc b/extensions/geocoder/runtime/src/main/doc/configuration.adoc
new file mode 100644
index 0000000..2b8d79a
--- /dev/null
+++ b/extensions/geocoder/runtime/src/main/doc/configuration.adoc
@@ -0,0 +1 @@
+Locales different from the build machine's default locale do not work well in native mode due to https://github.com/oracle/graal/issues/1645[this GraalVM bug]. The `google-maps-services` library this extension depends on uses `Locale.English` to format double latitude and longitude values. As a consequence of these two facts, the locale on the building machine must be set to some English locale, such as `en_US.UTF-8`, `en_GB.UTF-8` or `en_IE.UTF-8` so that the calls to the Google Maps AP [...]
diff --git a/extensions-jvm/geocoder/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/geocoder/runtime/src/main/resources/META-INF/quarkus-extension.yaml
similarity index 97%
rename from extensions-jvm/geocoder/runtime/src/main/resources/META-INF/quarkus-extension.yaml
rename to extensions/geocoder/runtime/src/main/resources/META-INF/quarkus-extension.yaml
index 6992008..125245d 100644
--- a/extensions-jvm/geocoder/runtime/src/main/resources/META-INF/quarkus-extension.yaml
+++ b/extensions/geocoder/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -24,9 +24,8 @@
name: "Camel Geocoder"
description: "Find geocodes (latitude and longitude) for a given address or the other way round"
metadata:
- unlisted: true
guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/geocoder.html"
categories:
- "integration"
status:
- - "preview"
+ - "stable"
diff --git a/extensions/pom.xml b/extensions/pom.xml
index 1f0b45e..12fe0df 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -104,6 +104,7 @@
<module>flatpack</module>
<module>fop</module>
<module>ftp</module>
+ <module>geocoder</module>
<module>git</module>
<module>github</module>
<module>google-calendar</module>
diff --git a/integration-tests/geocoder/README.adoc b/integration-tests/geocoder/README.adoc
new file mode 100644
index 0000000..a47b4b2
--- /dev/null
+++ b/integration-tests/geocoder/README.adoc
@@ -0,0 +1,10 @@
+== Camel Quarkus Geocoder Integration Tests
+
+To run `camel-quarkus-geocoder` integration tests using google maps service, you will need a google cloud https://developers.google.com/maps/documentation/javascript/get-api-key[API key].
+
+Then set the following environment variable:
+
+[source,shell]
+----
+GOOGLE_API_KEY=your-api-id
+----
diff --git a/extensions-jvm/geocoder/integration-test/pom.xml b/integration-tests/geocoder/pom.xml
similarity index 59%
rename from extensions-jvm/geocoder/integration-test/pom.xml
rename to integration-tests/geocoder/pom.xml
index 8a8e1c3..a649903 100644
--- a/extensions-jvm/geocoder/integration-test/pom.xml
+++ b/integration-tests/geocoder/pom.xml
@@ -23,25 +23,14 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-build-parent-it</artifactId>
+ <artifactId>camel-quarkus-integration-tests</artifactId>
<version>1.2.0-SNAPSHOT</version>
- <relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
</parent>
- <artifactId>camel-quarkus-geocoder-integration-test</artifactId>
- <name>Camel Quarkus :: Geocoder :: Integration Test</name>
+ <artifactId>camel-quarkus-integration-test-geocoder</artifactId>
+ <name>Camel Quarkus :: Integration Tests :: Geocoder</name>
<description>Integration tests for Camel Quarkus Geocoder extension</description>
- <properties>
- <!-- mvnd, a.k.a. Maven Daemon: https://github.com/mvndaemon/mvnd -->
- <!-- The following rule tells mvnd to build the listed deployment modules before this module. -->
- <!-- This is important because mvnd builds modules in parallel by default. The deployment modules are not -->
- <!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. -->
- <!-- Please update the rule whenever you change the dependencies of this module by running -->
- <!-- mvn process-resources -Pformat from the root directory -->
- <mvnd.builder.rule>camel-quarkus-geocoder-deployment,camel-quarkus-support-policy-deployment</mvnd.builder.rule>
- </properties>
-
<dependencyManagement>
<dependencies>
<dependency>
@@ -63,6 +52,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy-jsonb</artifactId>
+ </dependency>
+
<!-- test dependencies -->
<dependency>
@@ -75,6 +69,21 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
+
+ <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-geocoder-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<build>
@@ -92,4 +101,34 @@
</plugin>
</plugins>
</build>
+
+ <profiles>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <properties>
+ <quarkus.package.type>native</quarkus.package.type>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
diff --git a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java b/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/Country.java
similarity index 70%
copy from extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
copy to integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/Country.java
index 45c5083..95a023a 100644
--- a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
+++ b/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/Country.java
@@ -16,19 +16,20 @@
*/
package org.apache.camel.quarkus.component.geocoder.it;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+public class Country {
+ private String shortCode;
+ private String longCode;
-@QuarkusTest
-class GeocoderTest {
+ public Country(String shortCode, String longCode) {
+ this.shortCode = shortCode;
+ this.longCode = longCode;
+ }
- @Test
- public void loadComponentGeocoder() {
- /* A simple autogenerated test */
- RestAssured.get("/geocoder/load/component/geocoder")
- .then()
- .statusCode(200);
+ public String getShortCode() {
+ return shortCode;
}
+ public String getLongCode() {
+ return longCode;
+ }
}
diff --git a/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderGoogleResource.java b/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderGoogleResource.java
new file mode 100644
index 0000000..0bd2e2b
--- /dev/null
+++ b/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderGoogleResource.java
@@ -0,0 +1,77 @@
+/*
+ * 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.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import com.google.maps.model.GeocodingResult;
+import org.apache.camel.ProducerTemplate;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+import org.jboss.logging.Logger;
+
+@Path("/google")
+@ApplicationScoped
+public class GeocoderGoogleResource {
+ private static final Logger LOG = Logger.getLogger(GeocoderGoogleResource.class);
+
+ @Inject
+ ProducerTemplate producerTemplate;
+
+ @ConfigProperty(name = "google.api.key")
+ String apiKey;
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public GeocodingResult[] getByCurrentLocation() {
+ LOG.infof("Retrieve info from current location");
+ final GeocodingResult[] response = producerTemplate.requestBody(
+ "geocoder:address:current?headersOnly=false&apiKey=" + apiKey,
+ "Hello World", GeocodingResult[].class);
+ LOG.infof("Response : %s", response);
+ return response;
+ }
+
+ @Path("address/{address}")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public GeocodingResult[] getByAddress(@PathParam("address") String address) {
+ LOG.infof("Retrieve info from address : %s", address);
+ final GeocodingResult[] response = producerTemplate.requestBody(
+ "geocoder:address:" + address + "?apiKey=" + apiKey,
+ "Hello World", GeocodingResult[].class);
+ LOG.infof("Response: %s", response);
+ return response;
+ }
+
+ @Path("lat/{lat}/lon/{lon}")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public GeocodingResult[] getByCoordinate(@PathParam("lat") String latitude, @PathParam("lon") String longitude) {
+ LOG.infof("Retrieve info from georgraphic coordinates latitude : %s, longitude %s", latitude, longitude);
+ final GeocodingResult[] response = producerTemplate.requestBody(
+ "geocoder:latlng:" + latitude + "," + longitude + "?apiKey=" + apiKey,
+ "Hello World", GeocodingResult[].class);
+ LOG.infof("Response : %s", response);
+ return response;
+ }
+}
diff --git a/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderNominationResource.java b/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderNominationResource.java
new file mode 100644
index 0000000..44f4ebb
--- /dev/null
+++ b/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderNominationResource.java
@@ -0,0 +1,99 @@
+/*
+ * 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.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.geocoder.GeoCoderConstants;
+import org.apache.camel.component.geocoder.GeocoderStatus;
+import org.jboss.logging.Logger;
+
+@Path("/nomination")
+@ApplicationScoped
+public class GeocoderNominationResource {
+ private static final Logger LOG = Logger.getLogger(GeocoderNominationResource.class);
+
+ @Inject
+ ProducerTemplate producerTemplate;
+
+ @Path("address/{address}")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public GeocoderResult getByCurrentLocation(@PathParam("address") String address) {
+ LOG.infof("Retrieve info from address %s", address);
+ Exchange result = producerTemplate.request("geocoder:address:" + address +
+ "?type=NOMINATIM&serverUrl=RAW(https://nominatim.openstreetmap.org)", exchange -> {
+ exchange.getMessage().setBody("Hello Body");
+ });
+ return extractResult(result);
+ }
+
+ @Path("lat/{lat}/lon/{lon}")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public GeocoderResult getByCoordinate(@PathParam("lat") String latitude, @PathParam("lon") String longitude) {
+ LOG.infof("Retrieve info from georgraphic coordinates latitude : %s, longitude %s", latitude, longitude);
+ Exchange result = producerTemplate.request("geocoder:latlng:" + latitude + "," + longitude +
+ "?type=NOMINATIM&serverUrl=RAW(https://nominatim.openstreetmap.org)", exchange -> {
+ exchange.getMessage().setBody("Hello Body");
+ });
+ return extractResult(result);
+ }
+
+ /**
+ * Creates result from exchange headers
+ *
+ * @param exchange
+ * @return
+ */
+ private GeocoderResult extractResult(Exchange exchange) {
+ Message message = exchange.getIn();
+ return new GeocoderResult()
+ .withLat(extractString(message, GeoCoderConstants.LAT))
+ .withLng(extractString(message, GeoCoderConstants.LNG))
+ .withLatLng(extractString(message, GeoCoderConstants.LATLNG))
+ .withAddress(extractString(message, GeoCoderConstants.ADDRESS))
+ .withStatus(message.getHeader(GeoCoderConstants.STATUS, GeocoderStatus.class))
+ .withCountry(extractString(message, GeoCoderConstants.COUNTRY_SHORT),
+ extractString(message, GeoCoderConstants.COUNTRY_LONG))
+ .withCity(extractString(message, GeoCoderConstants.CITY))
+ .withPostalCode(extractString(message, GeoCoderConstants.POSTAL_CODE))
+ .withRegion(extractString(message, GeoCoderConstants.REGION_CODE),
+ extractString(message, GeoCoderConstants.REGION_NAME));
+ }
+
+ /**
+ * extracts a String from header
+ *
+ * @param message
+ * @param name
+ * @return
+ */
+ private String extractString(Message message, String name) {
+ return message.getHeader(name, String.class);
+ }
+
+}
diff --git a/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderResult.java b/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderResult.java
new file mode 100644
index 0000000..887a4d8
--- /dev/null
+++ b/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderResult.java
@@ -0,0 +1,116 @@
+/*
+ * 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 org.apache.camel.component.geocoder.GeocoderStatus;
+
+public class GeocoderResult {
+
+ private GeocoderStatus status;
+ private String lat;
+ private String lng;
+ private String latLng;
+ private String address;
+ private Country country;
+ private String city;
+ private String postalCode;
+ private Region region;
+
+ public GeocoderResult() {
+ }
+
+ public GeocoderResult withLat(String lat) {
+ this.lat = lat;
+ return this;
+ }
+
+ public GeocoderResult withLng(String lng) {
+ this.lng = lng;
+ return this;
+ }
+
+ public GeocoderResult withLatLng(String latLng) {
+ this.latLng = latLng;
+ return this;
+ }
+
+ public GeocoderResult withAddress(String address) {
+ this.address = address;
+ return this;
+ }
+
+ public GeocoderResult withStatus(GeocoderStatus status) {
+ this.status = status;
+ return this;
+ }
+
+ public GeocoderResult withCountry(String shortCode, String longCode) {
+ this.country = new Country(shortCode, longCode);
+ return this;
+ }
+
+ public GeocoderResult withCity(String city) {
+ this.city = city;
+ return this;
+ }
+
+ public GeocoderResult withPostalCode(String postalCode) {
+ this.postalCode = postalCode;
+ return this;
+ }
+
+ public GeocoderResult withRegion(String code, String name) {
+ this.region = new Region(code, name);
+ return this;
+ }
+
+ public GeocoderStatus getStatus() {
+ return status;
+ }
+
+ public String getLat() {
+ return lat;
+ }
+
+ public String getLng() {
+ return lng;
+ }
+
+ public String getLatLng() {
+ return latLng;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public Country getCountry() {
+ return country;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+ public Region getRegion() {
+ return region;
+ }
+}
diff --git a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java b/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/Region.java
similarity index 70%
copy from extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
copy to integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/Region.java
index 45c5083..42e6cbb 100644
--- a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
+++ b/integration-tests/geocoder/src/main/java/org/apache/camel/quarkus/component/geocoder/it/Region.java
@@ -16,19 +16,20 @@
*/
package org.apache.camel.quarkus.component.geocoder.it;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+public class Region {
+ private String code;
+ private String name;
-@QuarkusTest
-class GeocoderTest {
+ public Region(String code, String name) {
+ this.code = code;
+ this.name = name;
+ }
- @Test
- public void loadComponentGeocoder() {
- /* A simple autogenerated test */
- RestAssured.get("/geocoder/load/component/geocoder")
- .then()
- .statusCode(200);
+ public String getCode() {
+ return code;
}
+ public String getName() {
+ return name;
+ }
}
diff --git a/integration-tests/geocoder/src/main/resources/application.properties b/integration-tests/geocoder/src/main/resources/application.properties
new file mode 100644
index 0000000..e30c662
--- /dev/null
+++ b/integration-tests/geocoder/src/main/resources/application.properties
@@ -0,0 +1,24 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+
+################################
+#### properties for Google maps services
+# add your API KEY to run the examples
+google.api.key={{env.GOOGLE_API_KEY}}
+
+
diff --git a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java b/integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderGoogleIT.java
similarity index 70%
copy from extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
copy to integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderGoogleIT.java
index 45c5083..1104d79 100644
--- a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
+++ b/integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderGoogleIT.java
@@ -16,19 +16,11 @@
*/
package org.apache.camel.quarkus.component.geocoder.it;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+import io.quarkus.test.junit.NativeImageTest;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
-@QuarkusTest
-class GeocoderTest {
-
- @Test
- public void loadComponentGeocoder() {
- /* A simple autogenerated test */
- RestAssured.get("/geocoder/load/component/geocoder")
- .then()
- .statusCode(200);
- }
+@NativeImageTest
+@EnabledIfEnvironmentVariable(named = "GOOGLE_API_KEY", matches = ".+")
+class GeocoderGoogleIT extends GeocoderGoogleTest {
}
diff --git a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java b/integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderGoogleTest.java
similarity index 51%
copy from extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
copy to integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderGoogleTest.java
index 45c5083..dbd8fb6 100644
--- a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
+++ b/integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderGoogleTest.java
@@ -16,19 +16,42 @@
*/
package org.apache.camel.quarkus.component.geocoder.it;
+import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+
+import static org.hamcrest.Matchers.hasKey;
@QuarkusTest
-class GeocoderTest {
+@TestHTTPEndpoint(GeocoderGoogleResource.class)
+@EnabledIfEnvironmentVariable(named = "GOOGLE_API_KEY", matches = ".+")
+class GeocoderGoogleTest {
+
+ @Test
+ public void loadCurrentLocation() {
+ // disable test if no API KEY
+ RestAssured.get()
+ .then()
+ .statusCode(200)
+ .body("[0]", hasKey("addressComponents"));
+ }
+
+ @Test
+ public void loadAddress() {
+ RestAssured.get("/address/calle marie curie, sevilla, sevilla")
+ .then()
+ .statusCode(200)
+ .body("[0]", hasKey("addressComponents"));
+ }
@Test
- public void loadComponentGeocoder() {
- /* A simple autogenerated test */
- RestAssured.get("/geocoder/load/component/geocoder")
+ public void loadLatLong() {
+ RestAssured.get("/lat/40.714224/lon/-73.961452")
.then()
- .statusCode(200);
+ .statusCode(200)
+ .body("[0]", hasKey("addressComponents"));
}
}
diff --git a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java b/integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderNominationIT.java
similarity index 70%
copy from extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
copy to integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderNominationIT.java
index 45c5083..0226082 100644
--- a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
+++ b/integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderNominationIT.java
@@ -16,19 +16,8 @@
*/
package org.apache.camel.quarkus.component.geocoder.it;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
-
-@QuarkusTest
-class GeocoderTest {
-
- @Test
- public void loadComponentGeocoder() {
- /* A simple autogenerated test */
- RestAssured.get("/geocoder/load/component/geocoder")
- .then()
- .statusCode(200);
- }
+import io.quarkus.test.junit.NativeImageTest;
+@NativeImageTest
+public class GeocoderNominationIT extends GeocoderNominationTest {
}
diff --git a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java b/integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderNominationTest.java
similarity index 53%
rename from extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
rename to integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderNominationTest.java
index 45c5083..f3cd27c 100644
--- a/extensions-jvm/geocoder/integration-test/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderTest.java
+++ b/integration-tests/geocoder/src/test/java/org/apache/camel/quarkus/component/geocoder/it/GeocoderNominationTest.java
@@ -16,19 +16,36 @@
*/
package org.apache.camel.quarkus.component.geocoder.it;
+import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
+import static org.hamcrest.Matchers.equalTo;
+
@QuarkusTest
-class GeocoderTest {
+@TestHTTPEndpoint(GeocoderNominationResource.class)
+public class GeocoderNominationTest {
@Test
- public void loadComponentGeocoder() {
- /* A simple autogenerated test */
- RestAssured.get("/geocoder/load/component/geocoder")
+ public void loadAddress() {
+ RestAssured.get("/address/calle marie curie, sevilla, sevilla")
.then()
- .statusCode(200);
+ .statusCode(200)
+ .body("status", equalTo("OK"))
+ .body("postalCode", equalTo("41092"))
+ .body("city", equalTo("Sevilla"))
+ .body("country.shortCode", equalTo("ES"));
}
+ @Test
+ public void loadLatLong() {
+ RestAssured.get("/lat/40.714224/lon/-73.961452")
+ .then()
+ .statusCode(200)
+ .body("status", equalTo("OK"))
+ .body("postalCode", equalTo("11211"))
+ .body("city", equalTo("New York"))
+ .body("country.shortCode", equalTo("US"));
+ }
}
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 18a9bc9..bacf3a0 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -93,6 +93,7 @@
<module>fop</module>
<module>foundation</module>
<module>ftp</module>
+ <module>geocoder</module>
<module>git</module>
<module>github</module>
<module>google</module>
diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml
index e116f12..046ae28 100644
--- a/tooling/scripts/test-categories.yaml
+++ b/tooling/scripts/test-categories.yaml
@@ -77,6 +77,7 @@ xml-json-olingo4:
- jing
- olingo4
- weather
+ - geocoder
dozer-social:
- dozer
- telegram