TAMAYA-160: Fixed bugs:
 - throwing exception on non resolvable values.
 - Now also evaluating key combination class_simpleValue.fieldName


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/2d51d67d
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/2d51d67d
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/2d51d67d

Branch: refs/heads/master
Commit: 2d51d67dcdcaeded307345c572afa0f84ce0bfdd
Parents: 66d21d5
Author: anatole <anat...@apache.org>
Authored: Wed May 11 04:15:53 2016 +0200
Committer: anatole <anat...@apache.org>
Committed: Wed May 11 04:15:53 2016 +0200

----------------------------------------------------------------------
 .../inject/internal/ConfiguredFieldImpl.java      |  5 ++++-
 .../tamaya/inject/internal/InjectionHelper.java   |  2 +-
 .../apache/tamaya/inject/TamayaInjectionTest.java | 18 ++++++++++++++++++
 .../apache/tamaya/inject/TestPropertySource.java  |  3 +++
 4 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d51d67d/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
----------------------------------------------------------------------
diff --git 
a/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
 
b/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
index bc1c5ba..64b0c95 100644
--- 
a/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
+++ 
b/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
@@ -97,6 +97,7 @@ public class ConfiguredFieldImpl implements ConfiguredField{
      * This method applies a configuration to the field.
      *
      * @param target      the target instance, not null.
+     * @param config The configuration to be used.
      * @param resolve     set to true, if expression resolution should be 
applied on the keys passed.
      * @throws ConfigException if the configuration required could not be 
resolved or converted.
      */
@@ -120,7 +121,9 @@ public class ConfiguredFieldImpl implements ConfiguredField{
                     return annotatedField;
                 }
             });
-            annotatedField.set(target, value);
+            if(value!=null) {
+                annotatedField.set(target, value);
+            }
         } catch (Exception e) {
             throw new ConfigException("Failed to evaluate annotated field: " + 
this.annotatedField.getDeclaringClass()
                     .getName() + '.' + annotatedField.getName(), e);

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d51d67d/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
----------------------------------------------------------------------
diff --git 
a/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
 
b/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
index 19d2166..305a660 100644
--- 
a/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
+++ 
b/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
@@ -134,7 +134,7 @@ final class InjectionHelper {
         }
         String configValue = evaluteConfigValue(keys, retKey, config);
         if (configValue == null) {
-            if(prop.defaultValue().isEmpty()){
+            if(prop==null || prop.defaultValue().isEmpty()){
                 return null;
             }
             return prop.defaultValue();

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d51d67d/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
----------------------------------------------------------------------
diff --git 
a/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java 
b/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
index ebcd04f..d5a26c1 100644
--- a/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
+++ b/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.inject;
 
 import annottext.AnnotatedConfigBean;
 import annottext.AnnotatedConfigTemplate;
+import annottext.NonAnnotatedConfigBean;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -32,6 +33,23 @@ import static org.junit.Assert.assertTrue;
 public class TamayaInjectionTest {
 
     @Test
+    public void testInjectionNonAnnotatedClass(){
+        assertNotNull(ConfigurationInjection.getConfigurationInjector());
+        NonAnnotatedConfigBean testInstance = new NonAnnotatedConfigBean();
+        assertEquals(testInstance.simple_value, "Should be overridden!");
+        assertEquals(testInstance.classFieldKey, "Foo");
+        assertEquals(testInstance.fieldKey, null);
+        assertEquals(testInstance.fullKey, null);
+        assertEquals(testInstance.test2, "This is not set.");
+        
ConfigurationInjection.getConfigurationInjector().configure(testInstance);
+        assertEquals(testInstance.simple_value, "aSimpleValue");
+        assertEquals(testInstance.classFieldKey, "Class-Field-Value");
+        assertEquals(testInstance.fieldKey, "Field-Value");
+        assertEquals(testInstance.fullKey, "Fullkey-Value");
+        assertEquals(testInstance.test2, "This is not set.");
+    }
+
+    @Test
     public void testInjectionClass(){
         assertNotNull(ConfigurationInjection.getConfigurationInjector());
         AnnotatedConfigBean testInstance = new AnnotatedConfigBean();

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d51d67d/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
----------------------------------------------------------------------
diff --git 
a/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java 
b/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
index ff5d0fd..0853fd1 100644
--- a/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
+++ b/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
@@ -36,6 +36,9 @@ public class TestPropertySource implements PropertySource {
         properties.put("simple_value", "aSimpleValue");
         properties.put("host.name", "tamaya01.incubator.apache.org");
         properties.put("anotherValue", "HALLO!");
+        properties.put("NonAnnotatedConfigBean.classFieldKey", 
"Class-Field-Value");
+        properties.put("NonAnnotatedConfigBean.fieldKey", "Field-Value");
+        properties.put("annottext.NonAnnotatedConfigBean.fullKey", 
"Fullkey-Value");
     }
 
     @Override

Reply via email to