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 01301200BB5 for ; Sun, 6 Nov 2016 23:53:24 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id F3CF0160B0D; Sun, 6 Nov 2016 22:53:23 +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 1DF98160AFC for ; Sun, 6 Nov 2016 23:53:22 +0100 (CET) Received: (qmail 66570 invoked by uid 500); 6 Nov 2016 22:53:22 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 66561 invoked by uid 99); 6 Nov 2016 22:53:22 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 Nov 2016 22:53:22 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id C7D1D1A94F7 for ; Sun, 6 Nov 2016 22:53:21 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.199 X-Spam-Level: X-Spam-Status: No, score=-1.199 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 0glvm3Pn2D2q for ; Sun, 6 Nov 2016 22:53:19 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 680615FC2B for ; Sun, 6 Nov 2016 22:53:19 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 7BEACE0057 for ; Sun, 6 Nov 2016 22:53:14 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id A39293A0222 for ; Sun, 6 Nov 2016 22:53:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1768398 - in /felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api: FELIX5400_OverrideDefaultListConfigTypeWithEmptyMap.java FELIX5400_OverrideDefaultMapConfigTypeWithEmptyList.java Date: Sun, 06 Nov 2016 22:53:13 -0000 To: commits@felix.apache.org From: pderop@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20161106225313.A39293A0222@svn01-us-west.apache.org> archived-at: Sun, 06 Nov 2016 22:53:24 -0000 Author: pderop Date: Sun Nov 6 22:53:12 2016 New Revision: 1768398 URL: http://svn.apache.org/viewvc?rev=1768398&view=rev Log: FELIX-5400: added test case for 5400 issue. Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5400_OverrideDefaultListConfigTypeWithEmptyMap.java felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5400_OverrideDefaultMapConfigTypeWithEmptyList.java Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5400_OverrideDefaultListConfigTypeWithEmptyMap.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5400_OverrideDefaultListConfigTypeWithEmptyMap.java?rev=1768398&view=auto ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5400_OverrideDefaultListConfigTypeWithEmptyMap.java (added) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5400_OverrideDefaultListConfigTypeWithEmptyMap.java Sun Nov 6 22:53:12 2016 @@ -0,0 +1,83 @@ +/* + * 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.felix.dm.itest.api; + +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.felix.dm.Component; +import org.apache.felix.dm.DependencyManager; +import org.apache.felix.dm.itest.util.Ensure; +import org.apache.felix.dm.itest.util.TestBase; +import org.junit.Assert; +import org.osgi.service.cm.ConfigurationAdmin; + +/** + * This test validates that we can register in the actual configuration an empty map for overriding a non empty default + * map that the configuration type has defined by default. + * + * Example: if the configuration type provides a default map value {foo=bar} for property "map", and if + * there is a "map={}" entry in the actual configuration, then the empty map should be returned instead of {foo=bar}. + */ +public class FELIX5400_OverrideDefaultListConfigTypeWithEmptyMap extends TestBase { + Ensure m_ensure = new Ensure(); + + public void testDefaulValues() { + DependencyManager m = getDM(); + + ConfigurationCreator configurator = new ConfigurationCreator(m_ensure, MyConfig.class.getName(), 1, + "map={}"); + + Component confCreator = m.createComponent() + .setImplementation(configurator) + .add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true)); + + Component myComponent = m.createComponent() + .setImplementation(new MyComponent()) + .add(m.createConfigurationDependency().setCallback("updated", MyConfig.class).setRequired(true)); + + + // register an empty configuration. + m.add(confCreator); + m_ensure.waitForStep(1, 5000); + + // create the component: since there is no value for the map in the actual configuration, then default map + // provided by the configuration type default method should be returned. + m.add(myComponent); + m_ensure.waitForStep(2, 5000); + + } + + public interface MyConfig { + public default SortedMap getMap() { + SortedMap defaultMap = new TreeMap<>(); + defaultMap.put("foo", "bar"); + return defaultMap; + } + } + + public class MyComponent { + void updated(MyConfig cnf) { + Map map = cnf.getMap(); + Assert.assertEquals(0, map.size()); // the actual configuration contains "map={}" and default "map={foo=bar}" must not be returned + m_ensure.step(2); + } + } +} Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5400_OverrideDefaultMapConfigTypeWithEmptyList.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5400_OverrideDefaultMapConfigTypeWithEmptyList.java?rev=1768398&view=auto ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5400_OverrideDefaultMapConfigTypeWithEmptyList.java (added) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5400_OverrideDefaultMapConfigTypeWithEmptyList.java Sun Nov 6 22:53:12 2016 @@ -0,0 +1,78 @@ +/* + * 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.felix.dm.itest.api; + +import java.util.Arrays; +import java.util.List; + +import org.apache.felix.dm.Component; +import org.apache.felix.dm.DependencyManager; +import org.apache.felix.dm.itest.util.Ensure; +import org.apache.felix.dm.itest.util.TestBase; +import org.junit.Assert; +import org.osgi.service.cm.ConfigurationAdmin; + +/** + * This test validates that we can register in the actual configuration an empty list for overriding a non empty default + * list that the configuration type has defined by default. + * + * Example: if the configuration type provides a default list value [a, b] for property "list", and if + * there is a "list=[]" entry in the actual configuration, then the empty list should be returned instead of default [a,b]. + */ +public class FELIX5400_OverrideDefaultMapConfigTypeWithEmptyList extends TestBase { + Ensure m_ensure = new Ensure(); + + public void testDefaulValues() { + DependencyManager m = getDM(); + + ConfigurationCreator configurator = new ConfigurationCreator(m_ensure, MyConfig.class.getName(), 1, "list=[]"); + + Component confCreator = m.createComponent() + .setImplementation(configurator) + .add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true)); + + Component myComponent = m.createComponent() + .setImplementation(new MyComponent()) + .add(m.createConfigurationDependency().setCallback("updated", MyConfig.class).setRequired(true)); + + + // register an empty configuration. + m.add(confCreator); + m_ensure.waitForStep(1, 5000); + + // create the component: since there is no value for the map in the actual configuration, then default map + // provided by the configuration type default method should be returned. + m.add(myComponent); + m_ensure.waitForStep(2, 5000); + } + + public interface MyConfig { + public default List getList() { + return Arrays.asList("a", "b"); + } + } + + public class MyComponent { + void updated(MyConfig cnf) { + List list = cnf.getList(); + Assert.assertEquals(0, list.size()); // the actual configuration contains "list=[]" and default "list=[a,b]" must not be returned. + m_ensure.step(2); + } + } +}