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-quarkus.git


The following commit(s) were added to refs/heads/master by this push:
     new a16a6ce  Add workaroud for MP Config profile awarness
a16a6ce is described below

commit a16a6ce9cb67bd9168eb15176bd2ebe46650737b
Author: lburgazzoli <lburgazz...@gmail.com>
AuthorDate: Wed Nov 27 12:40:38 2019 +0100

    Add workaroud for MP Config profile awarness
---
 .../camel/quarkus/core/FastCamelContext.java       | 59 +++++++++++++++++++++-
 integration-tests/core-main/test/pom.xml           |  9 ++++
 .../test/src/main/resources/application.properties | 12 ++++-
 .../org/apache/camel/quarkus/core/CamelTest.java   | 14 +++++
 4 files changed, 90 insertions(+), 4 deletions(-)

diff --git 
a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java
 
b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java
index 57d9741..bcca279 100644
--- 
a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java
+++ 
b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java
@@ -18,7 +18,9 @@ package org.apache.camel.quarkus.core;
 
 import java.util.Collection;
 import java.util.Map;
+import java.util.Properties;
 import java.util.concurrent.ExecutorService;
+import java.util.function.Predicate;
 
 import org.apache.camel.AsyncProcessor;
 import org.apache.camel.CamelContext;
@@ -28,7 +30,6 @@ import org.apache.camel.PollingConsumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.TypeConverter;
-import 
org.apache.camel.component.microprofile.config.CamelMicroProfilePropertiesSource;
 import org.apache.camel.health.HealthCheckRegistry;
 import org.apache.camel.impl.DefaultExecutorServiceManager;
 import org.apache.camel.impl.engine.AbstractCamelContext;
@@ -84,6 +85,7 @@ import org.apache.camel.spi.InflightRepository;
 import org.apache.camel.spi.Injector;
 import org.apache.camel.spi.Language;
 import org.apache.camel.spi.LanguageResolver;
+import org.apache.camel.spi.LoadablePropertiesSource;
 import org.apache.camel.spi.ManagementNameStrategy;
 import org.apache.camel.spi.MessageHistoryFactory;
 import org.apache.camel.spi.ModelJAXBContextFactory;
@@ -104,6 +106,8 @@ import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.spi.UnitOfWorkFactory;
 import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.spi.ValidatorRegistry;
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
 
 public class FastCamelContext extends AbstractCamelContext {
     private Model model;
@@ -316,9 +320,60 @@ public class FastCamelContext extends AbstractCamelContext 
{
     protected PropertiesComponent createPropertiesComponent() {
         org.apache.camel.component.properties.PropertiesComponent pc = new 
org.apache.camel.component.properties.PropertiesComponent();
         pc.setAutoDiscoverPropertiesSources(false);
-        pc.addPropertiesSource(new CamelMicroProfilePropertiesSource());
+        //
+        // The CamelMicroProfilePropertiesSource obtains a reference to the 
Config object using
+        // ConfigProvider.getConfig() but in 1.0.0.Final there's that make the 
instance retrieved
+        // not profile aware that should be solved by 
https://github.com/quarkusio/quarkus/pull/5387
+        // which will be available in Quarkus 1.1.0.
+        //
+        // As a workaround the instance can be obtained with:
+        //
+        //    ConfigProviderResolver.instance().getConfig()
+        //
+        // so I've replace the CamelMicroProfilePropertiesSource with a 
temporary custom implementation.
+        //
+        // TODO: remove this workaround once 1.1.0 si out
+        //
+        pc.addPropertiesSource(new LoadablePropertiesSource() {
+            @Override
+            public String getName() {
+                return "mp-properties-source";
+            }
+
+            @Override
+            public String getProperty(String name) {
+                return 
ConfigProviderResolver.instance().getConfig().getOptionalValue(name, 
String.class).orElse(null);
+            }
+
+            @Override
+            public Properties loadProperties() {
+                final Properties answer = new Properties();
+                final Config config = 
ConfigProviderResolver.instance().getConfig();
+
+                for (String name : config.getPropertyNames()) {
+                    answer.put(name, config.getValue(name, String.class));
+                }
+
+                return answer;
+            }
+
+            @Override
+            public Properties loadProperties(Predicate<String> filter) {
+                final Properties answer = new Properties();
+                final Config config = 
ConfigProviderResolver.instance().getConfig();
+
+                for (String name : config.getPropertyNames()) {
+                    if (filter.test(name)) {
+                        answer.put(name, config.getValue(name, String.class));
+                    }
+                }
+
+                return answer;
+            }
+        });
 
         return pc;
+
     }
 
     @Override
diff --git a/integration-tests/core-main/test/pom.xml 
b/integration-tests/core-main/test/pom.xml
index 63162ca..c30021a 100644
--- a/integration-tests/core-main/test/pom.xml
+++ b/integration-tests/core-main/test/pom.xml
@@ -92,6 +92,15 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <systemPropertyVariables>
+                        <quarkus.test.profile>staging</quarkus.test.profile>
+                    </systemPropertyVariables>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 
diff --git 
a/integration-tests/core-main/test/src/main/resources/application.properties 
b/integration-tests/core-main/test/src/main/resources/application.properties
index be04943..23a94b0 100644
--- a/integration-tests/core-main/test/src/main/resources/application.properties
+++ b/integration-tests/core-main/test/src/main/resources/application.properties
@@ -28,7 +28,7 @@ quarkus.camel.main.routes-discovery.exclude-patterns = 
org/**/*Filtered
 # Camel
 #
 camel.context.name=quarkus-camel-example
-camel.main.xml-routes = file:src/test/resources/my-routes.xml
+
 #
 # Timer
 #
@@ -37,4 +37,12 @@ camel.component.timer.basic-property-binding = true
 #
 # Main
 #
-camel.main.auto-configuration-log-summary = false
\ No newline at end of file
+camel.main.auto-configuration-log-summary = false
+camel.main.xml-routes = file:src/test/resources/my-routes.xml
+
+
+#
+# Other
+#
+the.message = default
+%staging.the.message = test
\ No newline at end of file
diff --git 
a/integration-tests/core-main/test/src/test/java/org/apache/camel/quarkus/core/CamelTest.java
 
b/integration-tests/core-main/test/src/test/java/org/apache/camel/quarkus/core/CamelTest.java
index 7e3d5b9..0074eab 100644
--- 
a/integration-tests/core-main/test/src/test/java/org/apache/camel/quarkus/core/CamelTest.java
+++ 
b/integration-tests/core-main/test/src/test/java/org/apache/camel/quarkus/core/CamelTest.java
@@ -17,8 +17,10 @@
 package org.apache.camel.quarkus.core;
 
 import java.net.HttpURLConnection;
+import java.util.Objects;
 import javax.ws.rs.core.MediaType;
 
+import io.quarkus.runtime.configuration.ProfileManager;
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
 import io.restassured.http.ContentType;
@@ -40,6 +42,18 @@ public class CamelTest {
     public void testProperties() {
         
RestAssured.when().get("/test/property/camel.context.name").then().body(is("quarkus-camel-example"));
         
RestAssured.when().get("/test/property/camel.component.timer.basic-property-binding").then().body(is("true"));
+
+        //
+        // It is not possible to use a custom test configuration profile in 
native mode for now.
+        // Native tests are always run using the prod profile, see:
+        //
+        //     
https://quarkus.io/guides/maven-tooling#custom-test-configuration-profile
+        //
+        if (Objects.equals("staging", ProfileManager.getActiveProfile())) {
+            
RestAssured.when().get("/test/property/the.message").then().body(is("test"));
+        } else {
+            
RestAssured.when().get("/test/property/the.message").then().body(is("default"));
+        }
     }
 
     @Test

Reply via email to