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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git

commit e28a921e7db2c86f702624b2678cc2f8f52746b9
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jun 10 13:30:36 2021 +0200

    CAMEL-16700: main: allow to configure global options through properties
---
 .../src/main/docs/spring-boot.adoc                 |  2 +-
 .../spring/boot/CamelConfigurationProperties.java  |  2 +-
 .../camel/spring/boot/GlobalOptionsTest.java       | 81 ++++++++++++++++++++++
 3 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/core/camel-spring-boot/src/main/docs/spring-boot.adoc 
b/core/camel-spring-boot/src/main/docs/spring-boot.adoc
index dbf7d70..6252432 100644
--- a/core/camel-spring-boot/src/main/docs/spring-boot.adoc
+++ b/core/camel-spring-boot/src/main/docs/spring-boot.adoc
@@ -169,7 +169,7 @@ The component supports 173 options, which are listed below.
 | *camel.springboot.exchange-factory-capacity* | The capacity the pool (for 
each consumer) uses for storing exchanges. The default capacity is 100. | 100 | 
Integer
 | *camel.springboot.exchange-factory-statistics-enabled* | Configures whether 
statistics is enabled on exchange factory. | false | Boolean
 | *camel.springboot.file-configurations* | Directory to load additional 
configuration files that contains configuration values that takes precedence 
over any other configuration. This can be used to refer to files that may have 
secret configuration that has been mounted on the file system for containers. 
You must use either file: or classpath: as prefix to load from file system or 
classpath. Then you can specify a pattern to load from sub directories and a 
name pattern such as file:/var/ [...]
-| *camel.springboot.global-options* | Sets global options that can be 
referenced in the camel context  Important: This has nothing to do with 
property placeholders, and is just a plain set of key/value pairs which are 
used to configure global options on CamelContext, such as a maximum debug 
logging length etc. |  | Map
+| *camel.springboot.global-options* | Sets global options that can be 
referenced in the camel context Important: This has nothing to do with property 
placeholders, and is just a plain set of key/value pairs which are used to 
configure global options on CamelContext, such as a maximum debug logging 
length etc. |  | Map
 | *camel.springboot.include-non-singletons* | Whether to include non-singleton 
beans (prototypes) when scanning for RouteBuilder instances. By default only 
singleton beans is included in the context scan. | false | Boolean
 | *camel.springboot.inflight-repository-browse-enabled* | Sets whether the 
inflight repository should allow browsing each inflight exchange. This is by 
default disabled as there is a very slight performance overhead when enabled. | 
false | Boolean
 | *camel.springboot.java-routes-exclude-pattern* | Used for exclusive 
filtering RouteBuilder classes which are collected from the registry or via 
classpath scanning. The exclusive filtering takes precedence over inclusive 
filtering. The pattern is using Ant-path style pattern. Multiple patterns can 
be specified separated by comma. For example to exclude all classes starting 
with Bar use: &#42;&#42;/Bar&#42; To exclude all routes form a specific package 
use: com/mycompany/bar/&#42; To exc [...]
diff --git 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
index f3fa553..b9cc9b6 100644
--- 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
+++ 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
@@ -468,7 +468,7 @@ public class CamelConfigurationProperties extends 
DefaultConfigurationProperties
 
     /**
      * Sets global options that can be referenced in the camel context
-     * 
+     *
      * Important: This has nothing to do with property placeholders, and is 
just a plain set of key/value pairs
      * which are used to configure global options on CamelContext, such as a 
maximum debug logging length etc.
      */
diff --git 
a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/GlobalOptionsTest.java
 
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/GlobalOptionsTest.java
new file mode 100644
index 0000000..cdb656d
--- /dev/null
+++ 
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/GlobalOptionsTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.spring.boot;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@SpringBootTest(
+    classes = {
+        CamelAutoConfiguration.class,
+        GlobalOptionsTest.TestConfiguration.class
+    },
+    properties = {
+        "camel.springboot.global-options[foo] = 123",
+        "camel.springboot.global-options[bar] = true",
+        "camel.springboot.globalOptions[baz] = 999",
+        "camel.springboot.globalOptions[cheese] = Gauda",
+        "camel.springboot.global-options[drink] = Wine",
+    }
+)
+public class GlobalOptionsTest {
+    @Autowired
+    private CamelContext context;
+
+    @Test
+    public void testGlobalOptions() throws Exception {
+        assertNotNull(context);
+
+        assertEquals(5, context.getGlobalOptions().size());
+        assertEquals("123", context.getGlobalOptions().get("foo"));
+        assertEquals("true", context.getGlobalOptions().get("bar"));
+        assertEquals("Gauda", context.getGlobalOptions().get("cheese"));
+        assertEquals("Wine", context.getGlobalOptions().get("drink"));
+        assertEquals("999", context.getGlobalOptions().get("baz"));
+    }
+
+    // *************************************
+    // Config
+    // *************************************
+
+    @Configuration
+    public static class TestConfiguration {
+        @Bean
+        public RouteBuilder routeBuilder() {
+            return new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:start")
+                        .to("mock:result");
+                }
+            };
+        }
+    }
+}

Reply via email to