[camel] branch master updated: camel-microprofile-config: fix filtered loading

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated: camel-microprofile-config: fix filtered loading

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

lburgazzoli 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 ea03405  camel-microprofile-config: fix filtered loading
ea03405 is described below

commit ea03405cc5b3a5361057980a408d8492196ffe1b
Author: lburgazzoli <[hidden email]>
AuthorDate: Tue Aug 13 15:25:35 2019 +0200

    camel-microprofile-config: fix filtered loading
---
 .../config/CamelMicroProfilePropertiesSource.java           | 13 +++++++++++--
 .../config/CamelMicroProfilePropertiesSourceTest.java       | 10 ++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java b/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
index 88624e6..cf0a213 100644
--- a/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
+++ b/components/camel-microprofile-config/src/main/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSource.java
@@ -32,6 +32,13 @@ public class CamelMicroProfilePropertiesSource extends ServiceSupport implements
 
     private Config config;
 
+    public CamelMicroProfilePropertiesSource() {
+    }
+
+    public CamelMicroProfilePropertiesSource(Config config) {
+        this.config = config;
+    }
+
     @Override
     public String getName() {
         return "CamelMicroProfilePropertiesSource";
@@ -68,7 +75,7 @@ public class CamelMicroProfilePropertiesSource extends ServiceSupport implements
 
         Properties answer = new Properties();
 
-        for (String name: answer.stringPropertyNames()) {
+        for (String name: config.getPropertyNames()) {
             if (filter.test(name)) {
                 config.getOptionalValue(name, String.class).ifPresent(v -> answer.put(name, v));
             }
@@ -79,7 +86,9 @@ public class CamelMicroProfilePropertiesSource extends ServiceSupport implements
 
     @Override
     protected void doInit() throws Exception {
-        config = ConfigProvider.getConfig();
+        if (config == null) {
+            config = ConfigProvider.getConfig();
+        }
     }
 
     @Override
diff --git a/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java b/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
index 3ac6ff2..d557ade 100644
--- a/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
+++ b/components/camel-microprofile-config/src/test/java/org/apache/camel/component/microprofile/config/CamelMicroProfilePropertiesSourceTest.java
@@ -80,6 +80,16 @@ public class CamelMicroProfilePropertiesSourceTest extends CamelTestSupport {
     }
 
     @Test
+    public void testLoadFiltered() throws Exception {
+        PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
+        Properties properties = pc.loadProperties(k -> k.length()> 2);
+
+        Assertions.assertThat(properties).hasSize(2);
+        Assertions.assertThat(properties.get("start")).isEqualTo("direct:start");
+        Assertions.assertThat(properties.get("my-mock")).isEqualTo("result");
+    }
+
+    @Test
     public void testMicroProfileConfig() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Hello World from Camel");