felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1615520 - in /felix/sandbox/pderop/dependencymanager-prototype: org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/ org.apache.felix.dm/src/org/apache/felix/dm/impl/ org.apache.felix.dm/src/org/apache/felix/dm/impl/metatype/
Date Mon, 04 Aug 2014 09:22:24 GMT
Author: pderop
Date: Mon Aug  4 09:22:24 2014
New Revision: 1615520

URL: http://svn.apache.org/r1615520
Log:
[FELIX-4588] createCopy method ConfigurationDependency produces a malfunctioning clone.

Added:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithConfigurationAndMetaType.java
Modified:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm/src/org/apache/felix/dm/impl/metatype/MetaTypeProviderImpl.java

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithConfigurationAndMetaType.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithConfigurationAndMetaType.java?rev=1615520&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithConfigurationAndMetaType.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm.itest/src/org/apache/felix/dm/itest/AdapterWithConfigurationAndMetaType.java
Mon Aug  4 09:22:24 2014
@@ -0,0 +1,160 @@
+package org.apache.felix.dm.itest;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.metatype.AttributeDefinition;
+import org.osgi.service.metatype.MetaTypeInformation;
+import org.osgi.service.metatype.MetaTypeService;
+import org.osgi.service.metatype.ObjectClassDefinition;
+
+/**
+ * Tests an Adapter which adapts A To B interface.
+ * And the Adapter also depends on a Configuration Dependency with MetaType support.
+ */
+public class AdapterWithConfigurationAndMetaType extends TestBase {
+    final static String PID = "AdapterWithConfigurationAndMetaType";
+    final static String PID_HEADING = "English Dictionary";
+    final static String PID_DESC = "Configuration for the EnglishDictionary Service";
+    final static String WORDS_HEADING = "English words";
+    final static String WORDS_DESC = "Declare here some valid English words";
+    final static String WORDS_PROPERTY = "words";
+    
+    public void testAdapterWithConfigurationDependencyAndMetaType() {
+        DependencyManager m = new DependencyManager(context);
+        Ensure e = new Ensure();
+        
+        m.add(m.createAdapterService(A.class, null)
+            .setInterface(B.class.getName(), null)
+            .setImplementation(new BImpl(e))
+            .add(m.createConfigurationDependency()
+                .setPid(PID)
+                .setHeading(PID_HEADING)
+                .setDescription(PID_DESC)
+                .add(m.createPropertyMetaData()
+                    .setCardinality(Integer.MAX_VALUE)
+                    .setType(String.class)
+                    .setHeading(WORDS_HEADING)
+                    .setDescription(WORDS_DESC)
+                    .setDefaults(new String[] {"hello", "world"})
+                    .setId(WORDS_PROPERTY))));
+  
+        m.add(m.createComponent()
+            .setInterface(A.class.getName(), null)
+            .setImplementation(new AImpl()));
+      
+        Component configurator = m.createComponent()
+            .setImplementation(new Configurator(e))
+            .add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true))
+            .add(m.createServiceDependency().setService(MetaTypeService.class).setRequired(true));
+        m.add(configurator);
+        
+        // Ensures that all components are started
+        e.waitForStep(4, 5000);
+        
+        // now stop configurator, and ensure that all components have been stopped
+        m.remove(configurator);
+        e.waitForStep(7, 5000);
+    }
+    
+    public interface A {
+    }
+
+    public interface B {
+    }
+
+    public class AImpl implements A {
+    }
+    
+    public class Configurator {
+        volatile MetaTypeService m_metaType;
+        volatile ConfigurationAdmin m_cm;
+        volatile BundleContext m_ctx;
+        final Ensure m_ensure;
+        Configuration m_conf;
+
+        Configurator(Ensure ensure) {
+            m_ensure = ensure;
+        }
+
+        void start() {
+            m_ensure.step(1);
+            checkMetaTypeAndConfigure();
+        }        
+
+        void stop() {
+            m_ensure.step(5);
+            if (m_conf != null) {
+                try {
+                    m_ensure.step(6);
+                    m_conf.delete();
+                }
+                catch (IOException e) {
+                    m_ensure.throwable(e);
+                }
+            }
+        }
+        
+        void checkMetaTypeAndConfigure() {
+            MetaTypeInformation info = m_metaType.getMetaTypeInformation(m_ctx.getBundle());
+            Assert.assertNotNull(info);
+            Assert.assertEquals(PID, info.getPids()[0]);
+            ObjectClassDefinition ocd = info.getObjectClassDefinition(PID, null);
+            Assert.assertNotNull(ocd);
+            Assert.assertEquals(PID_HEADING, ocd.getName());
+            Assert.assertEquals(PID_DESC, ocd.getDescription());
+            AttributeDefinition[] defs = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
+            Assert.assertNotNull(defs);
+            Assert.assertEquals(1, defs.length);
+            Assert.assertEquals(WORDS_HEADING, defs[0].getName());
+            Assert.assertEquals(WORDS_DESC, defs[0].getDescription());
+            Assert.assertEquals(WORDS_PROPERTY, defs[0].getID());
+            m_ensure.step(2);
+            
+            try {
+                m_conf = m_cm.getConfiguration(PID, null);
+                Hashtable<String, String> props = new Hashtable<>();
+                props.put("foo", "bar");
+                m_conf.update(props);                
+            } catch (Throwable t) {
+                m_ensure.throwable(t);
+            }
+        }
+    }
+
+    public class BImpl implements B, A {
+        final Ensure m_ensure;
+        volatile A m_a;
+        Dictionary<String, String> m_conf;
+
+        public BImpl(Ensure e) {
+            m_ensure = e;
+        }
+
+        public void updated(Dictionary<String, String> conf) {
+            if (conf != null) {
+                m_ensure.step(3);
+                m_conf = conf;
+            }
+        }
+
+        public void start() {
+            Assert.assertNotNull(m_a);
+            Assert.assertNotNull(m_conf);
+            Assert.assertEquals("bar", m_conf.get("foo"));
+            m_ensure.step(4);
+        }
+        
+        public void stop() {
+            m_ensure.step(7);
+        }
+    }
+}

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java?rev=1615520&r1=1615519&r2=1615520&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm/src/org/apache/felix/dm/impl/ConfigurationDependencyImpl.java
Mon Aug  4 09:22:24 2014
@@ -58,6 +58,7 @@ public class ConfigurationDependencyImpl
 	    m_pid = prototype.m_pid;
 	    m_callback = prototype.m_callback;
 	    m_logger = prototype.m_logger;
+        m_metaType = prototype.m_metaType != null ? new MetaTypeProviderImpl(prototype.m_metaType,
this, null) : null;
 	}
 	
 	@Override

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm/src/org/apache/felix/dm/impl/metatype/MetaTypeProviderImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm/src/org/apache/felix/dm/impl/metatype/MetaTypeProviderImpl.java?rev=1615520&r1=1615519&r2=1615520&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm/src/org/apache/felix/dm/impl/metatype/MetaTypeProviderImpl.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dm/src/org/apache/felix/dm/impl/metatype/MetaTypeProviderImpl.java
Mon Aug  4 09:22:24 2014
@@ -25,9 +25,7 @@ import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Locale;
-import java.util.Map;
 import java.util.Properties;
 import java.util.StringTokenizer;
 import java.util.TreeSet;
@@ -53,11 +51,11 @@ import org.osgi.service.metatype.ObjectC
 public class MetaTypeProviderImpl implements MetaTypeProvider, ManagedService, ManagedServiceFactory
{
     private ManagedService m_managedServiceDelegate;
     private ManagedServiceFactory m_managedServiceFactoryDelegate;
-    private List m_propertiesMetaData = new ArrayList();
+    private ArrayList m_propertiesMetaData = new ArrayList();
     private String m_description;
     private String m_heading;
     private String m_localization;
-    private Map m_localesProperties = new HashMap();
+    private HashMap m_localesProperties = new HashMap();
     private Logger m_logger;
     private BundleContext m_bctx;
     private String m_pid;
@@ -77,6 +75,21 @@ public class MetaTypeProviderImpl implem
             m_localization = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
         }
     }
+    
+    public MetaTypeProviderImpl(MetaTypeProviderImpl prototype, ManagedService msDelegate,
ManagedServiceFactory msfDelegate) {
+        m_pid = prototype.m_pid;
+        m_bctx = prototype.m_bctx;
+        m_logger = prototype.m_logger;
+        m_localization = prototype.m_localization;
+        m_propertiesMetaData = prototype.m_propertiesMetaData != null ? (ArrayList) prototype.m_propertiesMetaData.clone()
: null;
+        m_description = prototype.m_description;
+        m_heading = prototype.m_heading;
+        m_localization = prototype.m_localization;
+        m_localesProperties = prototype.m_localesProperties != null ? (HashMap) prototype.m_localesProperties.clone()
: null;
+        m_managedServiceDelegate = msDelegate;
+        m_managedServiceFactoryDelegate = msfDelegate;
+    }
+
 
     /**
      * Registers the metatype information of a given configuration property



Mime
View raw message