This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6f52501acbbfc36229d85a2005d5b9f40a31b4d3 Author: Claus Ibsen <[email protected]> AuthorDate: Fri Jan 6 13:56:03 2023 +0100 CAMEL-18865: camel-main - Configuring options on beans dot vs square style. Dot style should use getter/setter and square should use map/list style first. --- .../org/apache/camel/main/BaseMainSupport.java | 2 +- .../java/org/apache/camel/main/MainBeansTest.java | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java index c6c39c3c566..78f6f55ab6e 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java @@ -1445,7 +1445,7 @@ public abstract class BaseMainSupport extends BaseService { "Cannot resolve bean with name " + name); } // configure all the properties on the bean at once (to ensure they are configured in right order) - OrderedLocationProperties config = MainHelper.extractProperties(properties, name + "[", "]", true, (key) -> { + OrderedLocationProperties config = MainHelper.extractProperties(properties, name + "[", "]", true, key -> { // when configuring map/list we want the keys to include the square brackets // (so we know it is a map/list style and not dot style syntax) // and therefore only remove the option prefix name diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainBeansTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainBeansTest.java index cb649abfccd..e734773bb81 100644 --- a/core/camel-main/src/test/java/org/apache/camel/main/MainBeansTest.java +++ b/core/camel-main/src/test/java/org/apache/camel/main/MainBeansTest.java @@ -246,6 +246,32 @@ public class MainBeansTest { main.stop(); } + @Test + public void testBindBeansDottedAndSquareHybridMap() { + Main main = new Main(); + main.configure().addRoutesBuilder(new MyRouteBuilder()); + + // defining a factory bean + main.addProperty("camel.beans.myfactory", "#class:org.apache.camel.main.MyFooFactory"); + main.addProperty("camel.beans.myfactory.hostName", "localhost"); + main.addProperty("camel.beans.myfactory[region]", "emea"); + main.start(); + + CamelContext camelContext = main.getCamelContext(); + assertNotNull(camelContext); + + Object bean = camelContext.getRegistry().lookupByName("myfactory"); + assertNotNull(bean); + assertInstanceOf(MyFooFactory.class, bean); + + MyFooFactory factory = (MyFooFactory) bean; + assertNull(factory.get("hostName")); + assertEquals("localhost", factory.getHostName()); + assertEquals("emea", factory.get("region")); + + main.stop(); + } + public static class MyRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception {
