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

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

commit 337130bcbc128c57ee98a8e040ec641e33f11634
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Jan 12 15:52:22 2022 +0100

    CAMEL-17479: configuring beans with {{?foo}} supported. Added unit test.
---
 .../OptionalPropertyPlaceholderBeanTest.java       | 79 ++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertyPlaceholderBeanTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertyPlaceholderBeanTest.java
new file mode 100644
index 0000000..f388097
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertyPlaceholderBeanTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.component.properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.pojo.SayService;
+import org.apache.camel.support.PropertyBindingSupport;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class OptionalPropertyPlaceholderBeanTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testQueryOptionalPresent() throws Exception {
+        SayService say = new SayService();
+        assertEquals("Hello", say.getMessage());
+
+        PropertyBindingSupport.build().withTarget(say).withProperty("message", 
"{{?cool.name}}")
+                .withMandatory(false)
+                .withCamelContext(context)
+                .bind();
+        assertEquals("Camel", say.getMessage());
+    }
+
+    @Test
+    @Disabled("TODO: https://issues.apache.org/jira/browse/CAMEL-17479";)
+    public void testQueryOptionalNotPresent() throws Exception {
+        SayService say = new SayService();
+        assertEquals("Hello", say.getMessage());
+
+        PropertyBindingSupport.build().withTarget(say).withProperty("message", 
"{{?unknown}}")
+                .withMandatory(false)
+                .withCamelContext(context)
+                .bind();
+        assertEquals("Hello", say.getMessage());
+    }
+
+    @Test
+    public void testQueryOptionalNotPresentDefaultValue() throws Exception {
+        SayService say = new SayService();
+        assertEquals("Hello", say.getMessage());
+
+        PropertyBindingSupport.build().withTarget(say).withProperty("message", 
"{{?unknown:Bye}}")
+                .withMandatory(false)
+                .withCamelContext(context)
+                .bind();
+        assertEquals("Bye", say.getMessage());
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        
context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties");
+        return context;
+    }
+
+}

Reply via email to