You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/10/07 15:37:45 UTC

[camel] branch master updated: CAMEL-15632: add possibility to set google maps config for component (#4383)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new cc4fb51  CAMEL-15632: add possibility to set google maps config for component (#4383)
cc4fb51 is described below

commit cc4fb5165b70705eb1afc0055c96ad8a348483ce
Author: Zineb BENDHIBA <be...@gmail.com>
AuthorDate: Wed Oct 7 17:37:22 2020 +0200

    CAMEL-15632: add possibility to set google maps config for component (#4383)
---
 .../apache/camel/catalog/components/geocoder.json  |  3 +-
 .../camel/catalog/docs/geocoder-component.adoc     |  3 +-
 components/camel-geocoder/pom.xml                  | 38 ----------------------
 .../geocoder/GeoCoderComponentConfigurer.java      |  5 +++
 .../apache/camel/component/geocoder/geocoder.json  |  3 +-
 .../src/main/docs/geocoder-component.adoc          |  3 +-
 .../component/geocoder/GeoCoderComponent.java      | 18 ++++++++++
 .../camel/component/geocoder/GeoCoderEndpoint.java |  7 +++-
 .../component/geocoder/GeoCoderApiKeyTestBase.java |  8 -----
 .../geocoder/GeoCoderComponentAddressTest.java     |  2 ++
 .../geocoder/GeoCoderCurrentAddressTest.java       |  2 ++
 .../geocoder/GeoCoderEmptyAddressTest.java         |  2 ++
 .../geocoder/GeoCoderLatLngComponentTest.java      |  2 ++
 .../dsl/GeocoderComponentBuilderFactory.java       | 13 ++++++++
 .../modules/ROOT/pages/geocoder-component.adoc     |  3 +-
 15 files changed, 60 insertions(+), 52 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/geocoder.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/geocoder.json
index 37aa53d..0688952 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/geocoder.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/geocoder.json
@@ -23,7 +23,8 @@
   },
   "componentProperties": {
     "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the r [...]
-    "basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": true, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" }
+    "basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": true, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" },
+    "geoApiContext": { "kind": "property", "displayName": "Geo Api Context", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.google.maps.GeoApiContext", "deprecated": false, "secret": false, "description": "Configuration for Google maps API" }
   },
   "properties": {
     "address": { "kind": "path", "displayName": "Address", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "The geo address which should be prefixed with address:" },
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/geocoder-component.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/geocoder-component.adoc
index e6994bd..c9772b1 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/geocoder-component.adoc
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/geocoder-component.adoc
@@ -43,7 +43,7 @@ geocoder:latlng:latitude,longitude[?options]
 
 
 // component options: START
-The Geocoder component supports 2 options, which are listed below.
+The Geocoder component supports 3 options, which are listed below.
 
 
 
@@ -52,6 +52,7 @@ The Geocoder component supports 2 options, which are listed below.
 | Name | Description | Default | Type
 | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...]
 | *basicPropertyBinding* (advanced) | *Deprecated* Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
+| *geoApiContext* (advanced) | Configuration for Google maps API |  | GeoApiContext
 |===
 // component options: END
 
diff --git a/components/camel-geocoder/pom.xml b/components/camel-geocoder/pom.xml
index cc046b0..ca931c3 100644
--- a/components/camel-geocoder/pom.xml
+++ b/components/camel-geocoder/pom.xml
@@ -78,42 +78,4 @@
         </dependency>
     </dependencies>
 
-    <build>
-        <plugins>
-            <plugin>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <configuration>
-                    <childDelegation>false</childDelegation>
-                    <useFile>true</useFile>
-                    <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds>
-                    <excludes>
-                        <!-- exclude all tests as they require online internet -->
-                        <exclude>**/*Test.java</exclude>
-                    </excludes>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
-
-    <profiles>
-        <profile>
-            <id>geo-test</id>
-            <build>
-                <plugins>
-                    <plugin>
-                        <artifactId>maven-surefire-plugin</artifactId>
-                        <configuration>
-                            <childDelegation>false</childDelegation>
-                            <useFile>true</useFile>
-                            <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds>
-                            <includes>
-                                <include>**/*Test.java</include>
-                            </includes>
-                        </configuration>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-    </profiles>
-
 </project>
diff --git a/components/camel-geocoder/src/generated/java/org/apache/camel/component/geocoder/GeoCoderComponentConfigurer.java b/components/camel-geocoder/src/generated/java/org/apache/camel/component/geocoder/GeoCoderComponentConfigurer.java
index 1a27c1b..182e062 100644
--- a/components/camel-geocoder/src/generated/java/org/apache/camel/component/geocoder/GeoCoderComponentConfigurer.java
+++ b/components/camel-geocoder/src/generated/java/org/apache/camel/component/geocoder/GeoCoderComponentConfigurer.java
@@ -20,6 +20,7 @@ public class GeoCoderComponentConfigurer extends PropertyConfigurerSupport imple
         Map<String, Object> map = new CaseInsensitiveMap();
         map.put("lazyStartProducer", boolean.class);
         map.put("basicPropertyBinding", boolean.class);
+        map.put("geoApiContext", com.google.maps.GeoApiContext.class);
         ALL_OPTIONS = map;
     }
 
@@ -29,6 +30,8 @@ public class GeoCoderComponentConfigurer extends PropertyConfigurerSupport imple
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "basicpropertybinding":
         case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true;
+        case "geoapicontext":
+        case "geoApiContext": target.setGeoApiContext(property(camelContext, com.google.maps.GeoApiContext.class, value)); return true;
         case "lazystartproducer":
         case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
         default: return false;
@@ -46,6 +49,8 @@ public class GeoCoderComponentConfigurer extends PropertyConfigurerSupport imple
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "basicpropertybinding":
         case "basicPropertyBinding": return target.isBasicPropertyBinding();
+        case "geoapicontext":
+        case "geoApiContext": return target.getGeoApiContext();
         case "lazystartproducer":
         case "lazyStartProducer": return target.isLazyStartProducer();
         default: return null;
diff --git a/components/camel-geocoder/src/generated/resources/org/apache/camel/component/geocoder/geocoder.json b/components/camel-geocoder/src/generated/resources/org/apache/camel/component/geocoder/geocoder.json
index 37aa53d..0688952 100644
--- a/components/camel-geocoder/src/generated/resources/org/apache/camel/component/geocoder/geocoder.json
+++ b/components/camel-geocoder/src/generated/resources/org/apache/camel/component/geocoder/geocoder.json
@@ -23,7 +23,8 @@
   },
   "componentProperties": {
     "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the r [...]
-    "basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": true, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" }
+    "basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": true, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" },
+    "geoApiContext": { "kind": "property", "displayName": "Geo Api Context", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.google.maps.GeoApiContext", "deprecated": false, "secret": false, "description": "Configuration for Google maps API" }
   },
   "properties": {
     "address": { "kind": "path", "displayName": "Address", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "The geo address which should be prefixed with address:" },
diff --git a/components/camel-geocoder/src/main/docs/geocoder-component.adoc b/components/camel-geocoder/src/main/docs/geocoder-component.adoc
index e6994bd..c9772b1 100644
--- a/components/camel-geocoder/src/main/docs/geocoder-component.adoc
+++ b/components/camel-geocoder/src/main/docs/geocoder-component.adoc
@@ -43,7 +43,7 @@ geocoder:latlng:latitude,longitude[?options]
 
 
 // component options: START
-The Geocoder component supports 2 options, which are listed below.
+The Geocoder component supports 3 options, which are listed below.
 
 
 
@@ -52,6 +52,7 @@ The Geocoder component supports 2 options, which are listed below.
 | Name | Description | Default | Type
 | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...]
 | *basicPropertyBinding* (advanced) | *Deprecated* Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
+| *geoApiContext* (advanced) | Configuration for Google maps API |  | GeoApiContext
 |===
 // component options: END
 
diff --git a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderComponent.java b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderComponent.java
index 614a4ae..78332a1 100644
--- a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderComponent.java
+++ b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderComponent.java
@@ -18,7 +18,9 @@ package org.apache.camel.component.geocoder;
 
 import java.util.Map;
 
+import com.google.maps.GeoApiContext;
 import org.apache.camel.Endpoint;
+import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.Component;
 import org.apache.camel.support.DefaultComponent;
 
@@ -28,6 +30,9 @@ import org.apache.camel.support.DefaultComponent;
 @Component("geocoder")
 public class GeoCoderComponent extends DefaultComponent {
 
+    @Metadata(label = "advanced")
+    private GeoApiContext geoApiContext;
+
     public GeoCoderComponent() {
     }
 
@@ -49,4 +54,17 @@ public class GeoCoderComponent extends DefaultComponent {
         setProperties(endpoint, parameters);
         return endpoint;
     }
+
+    public GeoApiContext getGeoApiContext() {
+        return geoApiContext;
+    }
+
+    /**
+     * Configuration for Google maps API
+     *
+     * @param geoApiContext
+     */
+    public void setGeoApiContext(GeoApiContext geoApiContext) {
+        this.geoApiContext = geoApiContext;
+    }
 }
diff --git a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java
index d415876..97c7f8a 100644
--- a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java
+++ b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java
@@ -76,6 +76,7 @@ public class GeoCoderEndpoint extends DefaultEndpoint {
 
     public GeoCoderEndpoint(String uri, GeoCoderComponent component) {
         super(uri, component);
+
     }
 
     @Override
@@ -274,10 +275,14 @@ public class GeoCoderEndpoint extends DefaultEndpoint {
 
     /**
      * Specific Google required
-     * 
+     *
      * @return
      */
     protected GeoApiContext createGeoApiContext() {
+        GeoCoderComponent geoCoderComponent = (GeoCoderComponent) this.getComponent();
+        if (geoCoderComponent.getGeoApiContext() != null) {
+            return geoCoderComponent.getGeoApiContext();
+        }
         GeoApiContext.Builder builder = new GeoApiContext.Builder();
         if (clientId != null) {
             builder = builder.enterpriseCredentials(clientId, clientKey);
diff --git a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderApiKeyTestBase.java b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderApiKeyTestBase.java
index 02dbfce..c0a6ccf 100644
--- a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderApiKeyTestBase.java
+++ b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderApiKeyTestBase.java
@@ -17,17 +17,9 @@
 package org.apache.camel.component.geocoder;
 
 import org.apache.camel.test.junit5.CamelTestSupport;
-import org.junit.jupiter.api.BeforeEach;
-
-import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 public class GeoCoderApiKeyTestBase extends CamelTestSupport {
 
-    @BeforeEach
-    public void before() {
-        assumeTrue(getApiKey() != null, "API key not found in CAMEL_GEOCODER_APIKEY environment variable, skipping this test");
-    }
-
     protected String getApiKey() {
         return System.getenv("CAMEL_GEOCODER_APIKEY");
     }
diff --git a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderComponentAddressTest.java b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderComponentAddressTest.java
index b5a852f..9611918 100644
--- a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderComponentAddressTest.java
+++ b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderComponentAddressTest.java
@@ -19,7 +19,9 @@ package org.apache.camel.component.geocoder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
 
+@EnabledIfEnvironmentVariable(named = "CAMEL_GEOCODER_APIKEY", matches = ".+")
 public class GeoCoderComponentAddressTest extends GeoCoderApiKeyTestBase {
 
     @Test
diff --git a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderCurrentAddressTest.java b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderCurrentAddressTest.java
index d406d14..017691e 100644
--- a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderCurrentAddressTest.java
+++ b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderCurrentAddressTest.java
@@ -19,7 +19,9 @@ package org.apache.camel.component.geocoder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
 
+@EnabledIfEnvironmentVariable(named = "CAMEL_GEOCODER_APIKEY", matches = ".+")
 public class GeoCoderCurrentAddressTest extends GeoCoderApiKeyTestBase {
 
     @Test
diff --git a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderEmptyAddressTest.java b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderEmptyAddressTest.java
index 6413f20..28974cd 100644
--- a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderEmptyAddressTest.java
+++ b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderEmptyAddressTest.java
@@ -19,7 +19,9 @@ package org.apache.camel.component.geocoder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
 
+@EnabledIfEnvironmentVariable(named = "CAMEL_GEOCODER_APIKEY", matches = ".+")
 public class GeoCoderEmptyAddressTest extends GeoCoderApiKeyTestBase {
 
     @Test
diff --git a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderLatLngComponentTest.java b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderLatLngComponentTest.java
index 0bfa371..99da30b 100644
--- a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderLatLngComponentTest.java
+++ b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderLatLngComponentTest.java
@@ -19,7 +19,9 @@ package org.apache.camel.component.geocoder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
 
+@EnabledIfEnvironmentVariable(named = "CAMEL_GEOCODER_APIKEY", matches = ".+")
 public class GeoCoderLatLngComponentTest extends GeoCoderApiKeyTestBase {
 
     @Test
diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/GeocoderComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/GeocoderComponentBuilderFactory.java
index d31ca37..391e57f 100644
--- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/GeocoderComponentBuilderFactory.java
+++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/GeocoderComponentBuilderFactory.java
@@ -86,6 +86,18 @@ public interface GeocoderComponentBuilderFactory {
             doSetProperty("basicPropertyBinding", basicPropertyBinding);
             return this;
         }
+        /**
+         * Configuration for Google maps API.
+         * 
+         * The option is a: <code>com.google.maps.GeoApiContext</code> type.
+         * 
+         * Group: advanced
+         */
+        default GeocoderComponentBuilder geoApiContext(
+                com.google.maps.GeoApiContext geoApiContext) {
+            doSetProperty("geoApiContext", geoApiContext);
+            return this;
+        }
     }
 
     class GeocoderComponentBuilderImpl
@@ -105,6 +117,7 @@ public interface GeocoderComponentBuilderFactory {
             switch (name) {
             case "lazyStartProducer": ((GeoCoderComponent) component).setLazyStartProducer((boolean) value); return true;
             case "basicPropertyBinding": ((GeoCoderComponent) component).setBasicPropertyBinding((boolean) value); return true;
+            case "geoApiContext": ((GeoCoderComponent) component).setGeoApiContext((com.google.maps.GeoApiContext) value); return true;
             default: return false;
             }
         }
diff --git a/docs/components/modules/ROOT/pages/geocoder-component.adoc b/docs/components/modules/ROOT/pages/geocoder-component.adoc
index 39f45d8..495760b 100644
--- a/docs/components/modules/ROOT/pages/geocoder-component.adoc
+++ b/docs/components/modules/ROOT/pages/geocoder-component.adoc
@@ -45,7 +45,7 @@ geocoder:latlng:latitude,longitude[?options]
 
 
 // component options: START
-The Geocoder component supports 2 options, which are listed below.
+The Geocoder component supports 3 options, which are listed below.
 
 
 
@@ -54,6 +54,7 @@ The Geocoder component supports 2 options, which are listed below.
 | Name | Description | Default | Type
 | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...]
 | *basicPropertyBinding* (advanced) | *Deprecated* Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
+| *geoApiContext* (advanced) | Configuration for Google maps API |  | GeoApiContext
 |===
 // component options: END