Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9380D200D1F for ; Thu, 28 Sep 2017 22:12:24 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 91E591609EF; Thu, 28 Sep 2017 20:12:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B6BD11609ED for ; Thu, 28 Sep 2017 22:12:23 +0200 (CEST) Received: (qmail 62310 invoked by uid 500); 28 Sep 2017 20:12:22 -0000 Mailing-List: contact commits-help@tamaya.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tamaya.incubator.apache.org Delivered-To: mailing list commits@tamaya.incubator.apache.org Received: (qmail 62301 invoked by uid 99); 28 Sep 2017 20:12:22 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Sep 2017 20:12:22 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 6561E1810E1 for ; Thu, 28 Sep 2017 20:12:22 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.222 X-Spam-Level: X-Spam-Status: No, score=-4.222 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id tCGTQe9_c637 for ; Thu, 28 Sep 2017 20:12:20 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 86F4F6105E for ; Thu, 28 Sep 2017 20:12:18 +0000 (UTC) Received: (qmail 61940 invoked by uid 99); 28 Sep 2017 20:12:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Sep 2017 20:12:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2D687F5C01; Thu, 28 Sep 2017 20:12:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anatole@apache.org To: commits@tamaya.incubator.apache.org Date: Thu, 28 Sep 2017 20:12:30 -0000 Message-Id: <103437d5c23141379d2637b34b996ee3@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [16/45] incubator-tamaya-sandbox git commit: TAMAYA-260: Fixed CDI tests/impl for all non Provider-related test cases. archived-at: Thu, 28 Sep 2017 20:12:24 -0000 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 Authored: Mon Aug 14 01:13:13 2017 +0200 Committer: anatole 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 { @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 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 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 getBeanOfType(Class 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