Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 49D3618D8B for ; Sun, 22 Nov 2015 18:42:25 +0000 (UTC) Received: (qmail 36195 invoked by uid 500); 22 Nov 2015 18:42:25 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 36158 invoked by uid 500); 22 Nov 2015 18:42:25 -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 36149 invoked by uid 99); 22 Nov 2015 18:42:25 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 Nov 2015 18:42:25 +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 BAB0A180A17 for ; Sun, 22 Nov 2015 18:42:24 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.446 X-Spam-Level: X-Spam-Status: No, score=0.446 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.554] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id SzVFsVh1OBdQ for ; Sun, 22 Nov 2015 18:42:23 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id 581CB2306D for ; Sun, 22 Nov 2015 18:42:23 +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 EF9A9E00B6 for ; Sun, 22 Nov 2015 18:42:22 +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 ECA4F3A027A for ; Sun, 22 Nov 2015 18:42:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1715673 - /felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FactoryInjectedWithConfigurationBeforeTheCreateMethod.java Date: Sun, 22 Nov 2015 18:42:22 -0000 To: commits@felix.apache.org From: pderop@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151122184222.ECA4F3A027A@svn01-us-west.apache.org> Author: pderop Date: Sun Nov 22 18:42:22 2015 New Revision: 1715673 URL: http://svn.apache.org/viewvc?rev=1715673&view=rev Log: Added a missing test that is verifying that a ConfigurationDependency callback instance is always called on a Factory object before the Factory.create method is called. Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FactoryInjectedWithConfigurationBeforeTheCreateMethod.java Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FactoryInjectedWithConfigurationBeforeTheCreateMethod.java URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FactoryInjectedWithConfigurationBeforeTheCreateMethod.java?rev=1715673&view=auto ============================================================================== --- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FactoryInjectedWithConfigurationBeforeTheCreateMethod.java (added) +++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FactoryInjectedWithConfigurationBeforeTheCreateMethod.java Sun Nov 22 18:42:22 2015 @@ -0,0 +1,107 @@ +/* + * 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.io.IOException; +import java.util.Dictionary; +import java.util.Properties; + +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.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; + +/** + * Use case: one component is instantiated using another factory object, and the + * factory object needs the configuration before the factory.create method is called. + */ +public class FactoryInjectedWithConfigurationBeforeTheCreateMethod extends TestBase { + Ensure m_e; + + public void testServiceInjection() { + DependencyManager m = getDM(); + m_e = new Ensure(); + + // Create the component that creates a configuration. + Component configurator = m.createComponent().setImplementation(new Configurator("foobar")).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true)); + + // Create the object that has to be injected with the configuration before its create method is called. + MyFactory factory = new MyFactory(); + + // Create the Component for the MyComponent class that is created using the factory above. + Component myComponent = m.createComponent().setFactory(factory, "create").add(m.createConfigurationDependency().setPid("foobar").setCallback(factory, "updated")); + + // provide the configuration + m.add(configurator); + + m.add(myComponent); + m_e.waitForStep(4, 300000000); + m.remove(myComponent); + m.remove(configurator); + } + + class Configurator { + private volatile ConfigurationAdmin m_ca; + Configuration m_conf; + final String m_pid; + + public Configurator(String pid) { + m_pid = pid; + } + + public void init() { + try { + Assert.assertNotNull(m_ca); + m_e.step(1); + m_conf = m_ca.getConfiguration(m_pid, null); + Properties props = new Properties(); + props.setProperty("testkey", "testvalue"); + m_conf.update(props); + } + catch (IOException e) { + Assert.fail("Could not create configuration: " + e.getMessage()); + } + } + + public void destroy() throws IOException { + m_conf.delete(); + } + } + + public class MyFactory { + public void updated(Dictionary conf) { + Assert.assertNotNull("configuration is null", conf); + m_e.step(2); + } + + public MyComponent create() { + m_e.step(3); + return new MyComponent(); + } + } + + public class MyComponent { + void start() { + m_e.step(4); + } + } +}