tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [16/45] incubator-tamaya-sandbox git commit: TAMAYA-260: Fixed CDI tests/impl for all non Provider-related test cases.
Date Thu, 28 Sep 2017 20:12:30 GMT
TAMAYA-260: Fixed CDI tests/impl for all non Provider-related test cases.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/4a63a4a4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/4a63a4a4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/4a63a4a4

Branch: refs/heads/master
Commit: 4a63a4a4f30492535bd3b98881b442f681d69f78
Parents: 50927f4
Author: anatole <anatole@apache.org>
Authored: Mon Aug 14 01:13:13 2017 +0200
Committer: anatole <anatole@apache.org>
Committed: Mon Aug 14 01:13:13 2017 +0200

----------------------------------------------------------------------
 .../microprofile/cdi/BridgingConfigBean.java    |  3 ++-
 .../cdi/MicroprofileCDIExtension.java           |  2 +-
 .../cdi/MicroprofileConfigurationProducer.java  | 28 +++++++++++++++-----
 .../imported/CDIPlainInjectionTest.java         | 16 ++++++-----
 4 files changed, 34 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/4a63a4a4/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java
b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java
index 763f6ed..deb2496 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/BridgingConfigBean.java
@@ -79,7 +79,8 @@ final class BridgingConfigBean implements Bean<Object> {
 
     @Override
     public boolean isNullable() {
-        return delegate.isNullable();
+        return false;
+        // delegate.isNullable();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/4a63a4a4/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
index 9260d3d..7a819fc 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
@@ -63,7 +63,7 @@ public class MicroprofileCDIExtension implements Extension {
             if (injectionPoint.getAnnotated().isAnnotationPresent(ConfigProperty.class))
{
                 System.err.println("Configured: " + injectionPoint);
                 final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
-                String key = !annotation.name().isEmpty()?annotation.name():injectionPoint.getMember().getName();
+                String key = !annotation.name().isEmpty()?annotation.name():MicroprofileConfigurationProducer.getDefaultKey(injectionPoint);
                 Member member = injectionPoint.getMember();
                 if(member instanceof Field) {
                     types.add(((Field) member).getType());

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/4a63a4a4/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
index 7a7799f..e6c1174 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
@@ -16,6 +16,7 @@
  */
 package org.apache.tamaya.microprofile.cdi;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.tamaya.*;
 import org.apache.tamaya.spi.ConversionContext;
 import org.apache.tamaya.spi.PropertyConverter;
@@ -34,6 +35,8 @@ import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import static org.apache.commons.lang.WordUtils.uncapitalize;
+
 /**
  * Producer bean for configuration properties.
  */
@@ -45,9 +48,12 @@ public class MicroprofileConfigurationProducer {
     @Produces
     @ConfigProperty
     public Object resolveAndConvert(final InjectionPoint injectionPoint) {
-        System.err.println("Inject: " + injectionPoint);
+        LOGGER.finest( () -> "Inject: " + injectionPoint);
         final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
         String key = annotation.name();
+        if(key.isEmpty()){
+            key = getDefaultKey(injectionPoint);
+        }
 
         // unless the extension is not installed, this should never happen because the extension
         // enforces the resolvability of the config
@@ -64,6 +70,16 @@ public class MicroprofileConfigurationProducer {
         return value;
     }
 
+    static String getDefaultKey(InjectionPoint injectionPoint) {
+        String memberName = injectionPoint.getMember().getName();
+        String beanClassNames[] = injectionPoint.getBean().getBeanClass().getName().split("\\$");
+        if(beanClassNames.length==1) {
+            return beanClassNames[0] + "." + uncapitalize(memberName);
+        }else{
+            return beanClassNames[0] + "." + uncapitalize(beanClassNames[1]) + "." + uncapitalize(memberName);
+        }
+    }
+
     static ConversionContext createConversionContext(String key, InjectionPoint injectionPoint)
{
         final Type targetType = injectionPoint.getAnnotated().getBaseType();
         Configuration config = ConfigurationProvider.getConfiguration();
@@ -76,12 +92,12 @@ public class MicroprofileConfigurationProducer {
     }
 
     static Object resolveValue(String defaultTextValue, ConversionContext context, InjectionPoint
injectionPoint) {
-        Configuration config = ConfigurationProvider.getConfiguration();
-        String textValue = config.get(context.getKey());
-        if (textValue == null) {
-            textValue = defaultTextValue;
-        }
+        Config config = ConfigProviderResolver.instance().getConfig();
+        String textValue = config.getOptionalValue(context.getKey(), String.class).orElse(defaultTextValue);
         Object value = null;
+        if(String.class.equals(context.getTargetType().getRawType())){
+            value = textValue;
+        }
         if (textValue != null) {
             List<PropertyConverter> converters = ConfigurationProvider.getConfiguration().getContext()
                     .getPropertyConverters((TypeLiteral)context.getTargetType());

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/4a63a4a4/microprofile/src/test/java/org/apache/tamaya/microprofile/imported/CDIPlainInjectionTest.java
----------------------------------------------------------------------
diff --git a/microprofile/src/test/java/org/apache/tamaya/microprofile/imported/CDIPlainInjectionTest.java
b/microprofile/src/test/java/org/apache/tamaya/microprofile/imported/CDIPlainInjectionTest.java
index e27ff4a..443e8d8 100644
--- a/microprofile/src/test/java/org/apache/tamaya/microprofile/imported/CDIPlainInjectionTest.java
+++ b/microprofile/src/test/java/org/apache/tamaya/microprofile/imported/CDIPlainInjectionTest.java
@@ -27,13 +27,12 @@ import org.apache.tamaya.microprofile.cdi.*;
 import org.eclipse.microprofile.config.inject.ConfigProperty;
 import org.eclipse.microprofile.config.spi.ConfigSource;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import javax.enterprise.context.Dependent;
-import javax.enterprise.inject.spi.CDI;
+import javax.enterprise.inject.Instance;
 import javax.inject.Inject;
 import javax.inject.Provider;
 import java.util.HashMap;
@@ -48,12 +47,11 @@ import static org.junit.Assert.assertEquals;
  * The tests depend only on CDI 1.2.
  * @author Ondrej Mihalyi
  */
-@Ignore
 @RunWith(ApplicationComposer.class)
 public class CDIPlainInjectionTest{
 
     private static final String DEFAULT_PROPERTY_BEAN_KEY =
-            "org.eclipse.microprofile.config.tck.CDIPlainInjectionTest.defaultPropertyBean.configProperty";
+            "org.apache.tamaya.microprofile.imported.CDIPlainInjectionTest.defaultPropertyBean.configProperty";
 
     static{
         System.setProperty("my.string.property", "text");
@@ -65,9 +63,12 @@ public class CDIPlainInjectionTest{
         System.setProperty(DEFAULT_PROPERTY_BEAN_KEY, "pathConfigValue");
     }
 
+    @Inject
+    private Instance<Object> instance;
+
     @Module
     @Classes(cdi = true, value = {
-            SimpleValuesBean.class,  DynamicValuesBean.class, DefaultPropertyBean.class,
+            SimpleValuesBean.class,  /*DynamicValuesBean.class, */ DefaultPropertyBean.class,
             MicroprofileCDIExtension.class,
             MicroprofileConfigurationProducer.class,
             ConfiguredType.class, ConfiguredMethod.class, ConfiguredField.class,
@@ -101,6 +102,7 @@ public class CDIPlainInjectionTest{
     }
 
     @Test
+    @Ignore
     public void can_inject_dynamic_values_via_CDI_provider() {
         clear_all_property_values();
 
@@ -146,7 +148,7 @@ public class CDIPlainInjectionTest{
     }
 
     private <T> T getBeanOfType(Class<T> beanClass) {
-        return CDI.current().select(beanClass).get();
+        return instance.select(beanClass).get();
     }
 
     @Dependent
@@ -204,7 +206,7 @@ public class CDIPlainInjectionTest{
 
     }
 
-    @Dependent
+//    @Dependent
     public static class DynamicValuesBean {
 
         @Inject


Mime
View raw message