You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/05/24 10:13:04 UTC

[camel] 24/27: CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.

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

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

commit 23398845e03725a98d1108bcaffdf0027f45284d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri May 24 11:02:07 2019 +0200

    CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
 .../java/org/apache/camel/impl/RegistryTest.java   | 56 ----------------------
 .../camel/support/IntrospectionSupportTest.java    |  6 +--
 .../org/apache/camel/support/jndi/JndiTest.java    | 11 +----
 .../apache/camel/support/IntrospectionSupport.java |  6 ++-
 .../org/apache/camel/support/jndi/JndiContext.java |  2 +-
 5 files changed, 9 insertions(+), 72 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/RegistryTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/RegistryTest.java
deleted file mode 100644
index ad5da1d..0000000
--- a/core/camel-core/src/test/java/org/apache/camel/impl/RegistryTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.impl;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.camel.support.jndi.JndiTest;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class RegistryTest extends Assert {
-    protected JndiRegistry registry;
-
-    @Test
-    public void testBind() throws Exception {
-        List<?> foo = Arrays.asList("a", "b", "c");
-
-        registry.bind("foo", foo);
-
-        List<?> list = registry.lookupByNameAndType("foo", List.class);
-        assertEquals("Should be same!", foo, list);
-    }
-
-    @Test
-    public void testDefaultProviderAllowsValuesToBeCreatedInThePropertiesFile() throws Exception {
-        Object value = registry.lookupByName("foo");
-        assertEquals("lookup of foo", "bar", value);
-    }
-
-    @Test
-    public void testLookupOfUnknownName() throws Exception {
-        Object value = registry.lookupByName("No such entry!");
-        assertNull("Should not find anything!", value);
-    }
-
-    @Before
-    public void setUp() throws Exception {
-
-        registry = new JndiRegistry(JndiTest.createInitialContext());
-    }
-}
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/IntrospectionSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/IntrospectionSupportTest.java
index 874fe41..0088941 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/IntrospectionSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/IntrospectionSupportTest.java
@@ -357,7 +357,7 @@ public class IntrospectionSupportTest extends ContextTestSupport {
         bean.setName("Claus");
         bean.setPrice(10.0);
 
-        IntrospectionSupport.setProperty(bean, "name", "James");
+        IntrospectionSupport.setProperty(context, bean, "name", "James");
         assertEquals("James", bean.getName());
     }
 
@@ -371,8 +371,8 @@ public class IntrospectionSupportTest extends ContextTestSupport {
         bean.setGoldCustomer(true);
         bean.setLittle(true);
 
-        IntrospectionSupport.setProperty(bean, "name", "James");
-        IntrospectionSupport.setProperty(bean, "gold-customer", "false");
+        IntrospectionSupport.setProperty(context, bean, "name", "James");
+        IntrospectionSupport.setProperty(context, bean, "gold-customer", "false");
         assertEquals("James", bean.getName());
         assertEquals(false, bean.isGoldCustomer());
     }
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/jndi/JndiTest.java b/core/camel-core/src/test/java/org/apache/camel/support/jndi/JndiTest.java
index 015ea1b..c8ce1ef 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/jndi/JndiTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/jndi/JndiTest.java
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 package org.apache.camel.support.jndi;
+
 import java.io.InputStream;
 import java.util.Hashtable;
 import java.util.Properties;
@@ -49,16 +50,6 @@ public class JndiTest extends TestSupport {
         assertEquals("foo", "bar", value);
     }
 
-    @Test
-    public void testLookupOfTypedObject() throws Exception {
-        Object value = assertLookup("example");
-        ExampleBean bean = assertIsInstanceOf(ExampleBean.class, value);
-        assertEquals("Bean.name", "James", bean.getName());
-        assertEquals("Bean.price", 2.34d, bean.getPrice(), 1e-5d);
-
-        log.info("Found bean: " + bean);
-    }
-
     protected Object assertLookup(String name) throws NamingException {
         Object value = context.lookup(name);
         assertNotNull("Should have found JNDI entry: " + name + " in context: " + context, value);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
index c238b85..fc62a37 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
@@ -602,7 +602,7 @@ public final class IntrospectionSupport {
                         return true;
                     } else {
                         // We need to convert it
-                        Object convertedValue = typeConverter != null ? typeConverter.convertTo(parameterType, ref) : ref;
+                        Object convertedValue = typeConverter != null ? typeConverter.mandatoryConvertTo(parameterType, ref) : ref;
                         // we may want to set options on classes that has package view visibility, so override the accessible
                         setter.setAccessible(true);
                         setter.invoke(target, convertedValue);
@@ -677,11 +677,13 @@ public final class IntrospectionSupport {
         // allow build pattern as a setter as well
         return setProperty(null, typeConverter, target, name, value, null, true);
     }
-    
+
+    @Deprecated
     public static boolean setProperty(Object target, String name, Object value, boolean allowBuilderPattern) throws Exception {
         return setProperty(null, null, target, name, value, null, allowBuilderPattern);
     }
 
+    @Deprecated
     public static boolean setProperty(Object target, String name, Object value) throws Exception {
         // allow build pattern as a setter as well
         return setProperty(target, name, value, true);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/jndi/JndiContext.java b/core/camel-support/src/main/java/org/apache/camel/support/jndi/JndiContext.java
index caca560..80b521b 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/jndi/JndiContext.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/jndi/JndiContext.java
@@ -96,7 +96,7 @@ public class JndiContext implements Context, Serializable {
      * properties set on the injected bean
      */
     public static Map<String, Object> createBindingsMapFromEnvironment(Hashtable<String, Object> env) throws Exception {
-        return new HashMap<>();
+        return new HashMap<>(env);
     }
 
     public void freeze() {