Improve javadoc of the instance creator
Fix several concurrency issues with the configuration admin (such as Felix-732)
Commit a test suite testing configuration admin support
Improve the documentation of XSD Schemas (external handlers)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@698589 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/core/configadmin/pom.xml b/ipojo/tests/core/configadmin/pom.xml
new file mode 100644
index 0000000..5acb536
--- /dev/null
+++ b/ipojo/tests/core/configadmin/pom.xml
@@ -0,0 +1,101 @@
+<!--

+	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.

+-->

+<project>

+	<modelVersion>4.0.0</modelVersion>

+	<packaging>bundle</packaging>

+	<name>iPOJO Configuration Admin Management Test Suite</name>

+	<artifactId>tests.core.configadmin</artifactId>

+	<groupId>ipojo.tests</groupId>

+	<version>0.9.0-SNAPSHOT</version>

+	<dependencies>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.apache.felix.ipojo</artifactId>

+			<version>0.9.0-SNAPSHOT</version>

+		</dependency>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.apache.felix.ipojo.metadata</artifactId>

+			<version>0.9.0-SNAPSHOT</version>

+		</dependency>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.osgi.core</artifactId>

+			<version>1.0.0</version>

+		</dependency>

+		<dependency>

+			<groupId>junit</groupId>

+			<artifactId>junit</artifactId>

+			<version>3.8.1</version>

+		</dependency>

+		<dependency>

+			<groupId>ipojo.examples</groupId>

+			<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>

+			<version>0.9.0-SNAPSHOT</version>

+		</dependency>

+	</dependencies>

+	<build>

+		<plugins>

+			<plugin>

+				<groupId>org.apache.felix</groupId>

+				<artifactId>maven-bundle-plugin</artifactId>

+				<version>1.4.2</version>

+				<extensions>true</extensions>

+				<configuration>

+					<instructions>

+						<Export-Package>

+							org.apache.felix.ipojo.test.scenarios.configadmin.service

+						</Export-Package>

+						<Bundle-SymbolicName>

+							${pom.artifactId}

+						</Bundle-SymbolicName>

+						<Private-Package>

+							org.apache.felix.ipojo.test*

+						</Private-Package>

+						<Test-Suite>

+							org.apache.felix.ipojo.test.scenarios.configadmin.ConfigurationTestSuite						</Test-Suite>

+					</instructions>

+				</configuration>

+			</plugin>

+			<plugin>

+				<groupId>org.apache.felix</groupId>

+				<artifactId>maven-ipojo-plugin</artifactId>

+				<version>0.9.0-SNAPSHOT</version>

+				<executions>

+					<execution>

+						<goals>

+							<goal>ipojo-bundle</goal>

+						</goals>

+						<configuration>

+							<ignoreAnnotations>true</ignoreAnnotations>

+						</configuration>

+					</execution>

+				</executions>

+			</plugin>

+			<plugin>

+				<groupId>org.apache.maven.plugins</groupId>

+				<artifactId>maven-compiler-plugin</artifactId>

+				<configuration>

+					<source>1.4</source>

+					<target>1.4</target>

+				</configuration>

+			</plugin>

+		</plugins>

+	</build>

+</project>

diff --git a/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ConfigurableFooProvider.java b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ConfigurableFooProvider.java
new file mode 100644
index 0000000..e4bfcb4
--- /dev/null
+++ b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ConfigurableFooProvider.java
@@ -0,0 +1,53 @@
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.configadmin.service.FooService;
+
+public class ConfigurableFooProvider implements FooService {
+    
+    private String message; // Configurable property
+    private int invokeCount = 0;
+    
+    public void setMessage(String message) {
+        System.out.println("Set message to " + message);
+        this.message = message;
+        invokeCount++;
+    }
+
+    public boolean foo() {
+        return true;
+    }
+
+    public Properties fooProps() {
+        Properties props = new Properties();
+        if (message == null) {
+            props.put("message", "NULL");
+        } else {
+            props.put("message", message);
+        }
+        props.put("count", new Integer(invokeCount));
+        return props;
+    }
+
+    public boolean getBoolean() {
+        return false;
+    }
+
+    public double getDouble() {
+        return invokeCount;
+    }
+
+    public int getInt() {
+        return invokeCount;
+    }
+
+    public long getLong() {
+        return invokeCount;
+    }
+
+    public Boolean getObject() {
+        return null;
+    }
+
+}
diff --git a/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ConfigurationTestSuite.java b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ConfigurationTestSuite.java
new file mode 100644
index 0000000..20850e3
--- /dev/null
+++ b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ConfigurationTestSuite.java
@@ -0,0 +1,37 @@
+/* 

+ * 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.ipojo.test.scenarios.configadmin;

+

+import junit.framework.Test;

+

+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;

+import org.osgi.framework.BundleContext;

+

+public class ConfigurationTestSuite {

+

+	public static Test suite(BundleContext bc) {

+		OSGiTestSuite ots = new OSGiTestSuite("Configuration Admin Test Suite", bc);

+		ots.addTestSuite(ManagedServiceFactoryTestForServices.class);

+	      ots.addTestSuite(ManagedServiceFactoryTestForImmediate.class);

+	      ots.addTestSuite(ManagedServiceTestForImmediate.class);

+	      ots.addTestSuite(ManagedServiceTestForService.class);

+		return ots;

+	}

+

+}

diff --git a/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceFactoryTestForImmediate.java b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceFactoryTestForImmediate.java
new file mode 100644
index 0000000..62518fb
--- /dev/null
+++ b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceFactoryTestForImmediate.java
@@ -0,0 +1,337 @@
+package org.apache.felix.ipojo.test.scenarios.configadmin;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.configadmin.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public class ManagedServiceFactoryTestForImmediate extends OSGiTestCase {
+    
+    private ComponentFactory factory;
+    private ConfigurationAdmin admin;
+    
+    public void setUp() {
+        factory = (ComponentFactory) Utils.getFactoryByName(context, "CA-ImmConfigurableProvider");
+        admin = (ConfigurationAdmin) Utils.getServiceObject(context, ConfigurationAdmin.class.getName(), null);
+        assertNotNull("Check configuration admin availability", admin);
+        try {
+            Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ImmConfigurableProvider)");
+            for (int i = 0; configurations != null && i < configurations.length; i++) {
+                configurations[i].delete();
+            }
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (InvalidSyntaxException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+    
+    public void tearDown() {
+        try {
+            Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ImmConfigurableProvider)");
+            for (int i = 0; configurations != null && i < configurations.length; i++) {
+                configurations[i].delete();
+            }
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (InvalidSyntaxException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        admin = null;
+
+        
+    }
+    
+    public void testCreationAndReconfiguration() {
+        Configuration configuration = null;
+        try {
+            configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", null);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        Dictionary props = configuration.getProperties();
+        if(props == null) {
+            props = new Properties();
+        }
+        props.put("message", "message");
+        
+        try {
+            configuration.update(props);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        
+        String pid = configuration.getPid();
+        System.out.println("PID : " + pid);
+        
+        //  The instance should be created, wait for the architecture service
+        Utils.waitForService(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        Architecture architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        FooService fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message", mes);
+        assertEquals("Assert count", 1, count);
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        props.put("message", "message2");
+        try {
+            configuration.update(props);
+            // Update the configuration ...
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message2", mes);
+        assertEquals("Assert count", 2, count);
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        try {
+            configuration.delete();
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReference(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        assertNull("Check unavailability", ref);
+    }
+    
+    public void testCreationAndReconfiguration2() {
+        //The reconfiguration happens before the service invocation
+        Configuration configuration = null;
+        try {
+            configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", null);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        Dictionary props = configuration.getProperties();
+        if(props == null) {
+            props = new Properties();
+        }
+        props.put("message", "message");
+        
+        try {
+            configuration.update(props);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        
+        String pid = configuration.getPid();
+        System.out.println("PID : " + pid);
+        
+        //  The instance should be created, wait for the architecture service
+        Utils.waitForService(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        Architecture architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        props.put("message", "message2");
+        try {
+            configuration.update(props);
+            // Update the configuration ...
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check object -2", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        //Invoke
+        FooService fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message2", mes);
+        assertEquals("Assert count", 2, count);
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+                
+        try {
+            configuration.delete();
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReference(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        assertNull("Check unavailability", ref);
+    }
+    
+    public void testDelayedCreationAndReconfiguration() {
+        factory.stop();
+        Configuration configuration = null;
+        try {
+            configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", null);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        Dictionary props = configuration.getProperties();
+        if(props == null) {
+            props = new Properties();
+        }
+        props.put("message", "message");
+        
+        try {
+            configuration.update(props);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        
+        String pid = configuration.getPid();
+        System.out.println("PID : " + pid);
+        
+        assertNull("check no instance", Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")"));
+        
+        factory.start();
+        
+        
+        //  The instance should be created, wait for the architecture service
+        Utils.waitForService(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        Architecture architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        FooService fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message", mes);
+        assertEquals("Assert count", 1, count);
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        props.put("message", "message2");
+        try {
+            configuration.update(props);
+            // Update the configuration ...
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message2", mes);
+        //assertEquals("Assert count", 2, count);
+        // This test was removed as the result can be 3. 
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        try {
+            configuration.delete();
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReference(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        assertNull("Check unavailability", ref);
+    }
+    
+    public void testDelayedCreationAndReconfiguration2() {
+        factory.stop();
+        //The reconfiguration happens before the service invocation
+        Configuration configuration = null;
+        try {
+            configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", null);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        Dictionary props = configuration.getProperties();
+        if(props == null) {
+            props = new Properties();
+        }
+        props.put("message", "message");
+        
+        try {
+            configuration.update(props);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        
+        String pid = configuration.getPid();
+        System.out.println("PID : " + pid);
+        
+        assertNull("check no instance", Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")"));
+        
+        factory.start();
+        
+        
+        //  The instance should be created, wait for the architecture service
+        Utils.waitForService(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        Architecture architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        props.put("message", "message2");
+        try {
+            configuration.update(props);
+            // Update the configuration ...
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check object -1", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        //Invoke
+        FooService fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message2", mes);
+        //assertEquals("Assert count", 2, count);
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+                
+        try {
+            configuration.delete();
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReference(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        assertNull("Check unavailability", ref);
+    }
+    
+    
+
+}
diff --git a/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceFactoryTestForServices.java b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceFactoryTestForServices.java
new file mode 100644
index 0000000..9567492
--- /dev/null
+++ b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceFactoryTestForServices.java
@@ -0,0 +1,340 @@
+package org.apache.felix.ipojo.test.scenarios.configadmin;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.configadmin.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public class ManagedServiceFactoryTestForServices extends OSGiTestCase {
+    
+    private ComponentFactory factory;
+    private ConfigurationAdmin admin;
+    
+    public void setUp() {
+        factory = (ComponentFactory) Utils.getFactoryByName(context, "CA-ConfigurableProvider");
+        admin = (ConfigurationAdmin) Utils.getServiceObject(context, ConfigurationAdmin.class.getName(), null);
+        assertNotNull("Check configuration admin availability", admin);
+        try {
+            Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ConfigurableProvider)");
+            for (int i = 0; configurations != null && i < configurations.length; i++) {
+                configurations[i].delete();
+            }
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (InvalidSyntaxException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+    
+    public void tearDown() {
+        try {
+            Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ConfigurableProvider)");
+            for (int i = 0; configurations != null && i < configurations.length; i++) {
+                configurations[i].delete();
+            }
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (InvalidSyntaxException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        admin = null;
+
+        
+    }
+    
+    public void testCreationAndReconfiguration() {
+        Configuration configuration = null;
+        try {
+            configuration = admin.createFactoryConfiguration("CA-ConfigurableProvider", null);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        Dictionary props = configuration.getProperties();
+        if(props == null) {
+            props = new Properties();
+        }
+        props.put("message", "message");
+        
+        try {
+            configuration.update(props);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        
+        String pid = configuration.getPid();
+        System.out.println("PID : " + pid);
+        
+        //  The instance should be created, wait for the architecture service
+        Utils.waitForService(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        Architecture architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check no object", 0, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        FooService fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message", mes);
+        assertEquals("Assert count", 1, count);
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        props.put("message", "message2");
+        try {
+            configuration.update(props);
+            // Update the configuration ...
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message2", mes);
+        assertEquals("Assert count", 2, count);
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        try {
+            configuration.delete();
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReference(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        assertNull("Check unavailability", ref);
+    }
+    
+    public void testCreationAndReconfiguration2() {
+        //The reconfiguration happens before the service invocation
+        Configuration configuration = null;
+        try {
+            configuration = admin.createFactoryConfiguration("CA-ConfigurableProvider", null);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        Dictionary props = configuration.getProperties();
+        if(props == null) {
+            props = new Properties();
+        }
+        props.put("message", "message");
+        
+        try {
+            configuration.update(props);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        
+        String pid = configuration.getPid();
+        System.out.println("PID : " + pid);
+        
+        //  The instance should be created, wait for the architecture service
+        Utils.waitForService(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        Architecture architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check no object", 0, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        props.put("message", "message2");
+        try {
+            configuration.update(props);
+            // Update the configuration ...
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check no object -2", 0, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        //Invoke
+        FooService fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message2", mes);
+        assertEquals("Assert count", 1, count);
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+                
+        try {
+            configuration.delete();
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReference(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        assertNull("Check unavailability", ref);
+    }
+    
+    public void testDelayedCreationAndReconfiguration() {
+        factory.stop();
+        Configuration configuration = null;
+        try {
+            configuration = admin.createFactoryConfiguration("CA-ConfigurableProvider", null);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        Dictionary props = configuration.getProperties();
+        if(props == null) {
+            props = new Properties();
+        }
+        props.put("message", "message");
+        
+        try {
+            configuration.update(props);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        
+        String pid = configuration.getPid();
+        System.out.println("PID : " + pid);
+        
+        assertNull("check no instance", Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")"));
+        
+        factory.start();
+        
+        
+        //  The instance should be created, wait for the architecture service
+        Utils.waitForService(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        Architecture architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check no object", 0, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        FooService fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message", mes);
+        assertEquals("Assert count", 1, count);
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        System.out.println("===");
+        
+        props.put("message", "message2");
+        try {
+            configuration.update(props);
+            // Update the configuration ...
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        System.out.println("===");
+        
+        fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message2", mes);
+       // assertEquals("Assert count", 2, count);
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        try {
+            configuration.delete();
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReference(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        assertNull("Check unavailability", ref);
+    }
+    
+    public void testDelayedCreationAndReconfiguration2() {
+        factory.stop();
+        //The reconfiguration happens before the service invocation
+        Configuration configuration = null;
+        try {
+            configuration = admin.createFactoryConfiguration("CA-ConfigurableProvider", null);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        Dictionary props = configuration.getProperties();
+        if(props == null) {
+            props = new Properties();
+        }
+        props.put("message", "message");
+        
+        try {
+            configuration.update(props);
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        
+        String pid = configuration.getPid();
+        System.out.println("PID : " + pid);
+        
+        assertNull("check no instance", Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")"));
+        
+        factory.start();
+        
+        
+        //  The instance should be created, wait for the architecture service
+        Utils.waitForService(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        Architecture architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check no object", 0, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        props.put("message", "message2");
+        try {
+            configuration.update(props);
+            // Update the configuration ...
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Check no object -2", 0, architecture.getInstanceDescription().getCreatedObjects().length);
+        
+        //Invoke
+        FooService fs = (FooService) Utils.getServiceObject(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        architecture = (Architecture) Utils.getServiceObject(context, Architecture.class.getName(), "(architecture.instance="+pid+")");
+        
+        assertEquals("Assert Message", "message2", mes);
+        assertEquals("Assert count", 1, count);
+        assertEquals("Check 1 object", 1, architecture.getInstanceDescription().getCreatedObjects().length);
+                
+        try {
+            configuration.delete();
+            Thread.sleep(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReference(context, FooService.class.getName(), "(instance.name=" + pid + ")");
+        assertNull("Check unavailability", ref);
+    }
+    
+    
+
+}
diff --git a/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForImmediate.java b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForImmediate.java
new file mode 100644
index 0000000..c906f7b
--- /dev/null
+++ b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForImmediate.java
@@ -0,0 +1,349 @@
+package org.apache.felix.ipojo.test.scenarios.configadmin;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.configadmin.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public class ManagedServiceTestForImmediate extends OSGiTestCase {
+    
+    private String factNameImm = "CA-ImmConfigurableProvider";
+    private String msp = "foo";
+
+    private ComponentFactory factImm;
+    
+    private ConfigurationAdmin admin;
+    
+    
+    public void setUp() {
+        factImm = (ComponentFactory) Utils.getFactoryByName(context, factNameImm);
+        admin = (ConfigurationAdmin) Utils.getServiceObject(context, ConfigurationAdmin.class.getName(), null);
+        assertNotNull("Check configuration admin availability", admin);
+        cleanConfigurationAdmin();
+    }
+    
+    public void tearDown() {
+        cleanConfigurationAdmin();
+        admin = null;
+    }
+    
+    private void cleanConfigurationAdmin() {
+        try {
+            Configuration[] configurations = admin.listConfigurations("(service.pid=" + msp + ")");
+            for (int i = 0; configurations != null && i < configurations.length; i++) {
+                configurations[i].delete();
+            }
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (InvalidSyntaxException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+    
+    public void testFactoryCreationAndReconfiguration() {
+        Properties props = new Properties();
+        props.put("managed.service.pid", msp);
+        props.put("message", "message");
+        ComponentInstance instance  = null;
+        try {
+            instance =  factImm.createComponentInstance(props);
+        } catch (Exception e) {
+           fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        FooService fs = (FooService) context.getService(ref);
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message", mes);
+        assertEquals("Check count", 1, count);
+        
+        //Update
+        Configuration configuration;
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message2");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        fs = (FooService) context.getService(ref);
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message2", mes);
+        assertEquals("Check count", 2, count);
+        
+        instance.dispose();
+        
+    }
+    
+    public void testMSFCreationAndReconfiguration() {
+        Configuration conf = null;
+        try {
+            conf = admin.createFactoryConfiguration(factNameImm);
+            Dictionary props = conf.getProperties();
+            if (props == null) {
+                props = new Properties();
+            }
+            props.put("managed.service.pid", msp);
+            props.put("message", "message");
+            conf.update(props);
+            Thread.sleep(100); // Wait for the creation.
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        
+        Architecture arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+        
+        ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), conf.getPid());
+        assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+        FooService fs = (FooService) context.getService(ref);
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message", mes);
+        assertEquals("Check count", 1, count);
+        
+        //Update
+        Configuration configuration;
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message2");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+        ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), conf.getPid());
+        assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+
+        arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+        fs = (FooService) context.getService(ref);
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message2", mes);
+        assertEquals("Check count", 2, count);
+        
+        try {
+            conf.delete();
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        
+    }
+    
+    public void testCreationAndReconfiguration2() {
+        // The configuration exists before the instance creation.
+        
+      //Update
+        Configuration configuration;
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message2");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        Properties props = new Properties();
+        props.put("managed.service.pid", msp);
+        props.put("message", "message");
+        ComponentInstance instance  = null;
+        try {
+            instance =  factImm.createComponentInstance(props);
+        } catch (Exception e) {
+           fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        FooService fs = (FooService) context.getService(ref);
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message2", mes); // Already reconfigured.
+        assertEquals("Check count", 1, count);
+        
+        instance.dispose();
+        
+        //Reconfiguration
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message3");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        // Recreation of the instance.
+        props = new Properties();
+        props.put("managed.service.pid", msp);
+        props.put("message", "message");
+        instance  = null;
+        try {
+            instance =  factImm.createComponentInstance(props);
+        } catch (Exception e) {
+           fail(e.getMessage());
+        }
+        
+        ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        fs = (FooService) context.getService(ref);
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message3", mes); // Already reconfigured.
+        assertEquals("Check count", 1, count);
+        
+        instance.dispose();
+        
+        
+    }
+
+    public void testCreationAndReconfiguration3() {
+        // The configuration exists before the instance creation.
+        
+      //Update
+        Configuration configuration;
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message2");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        Properties props = new Properties();
+        props.put("managed.service.pid", msp);
+        props.put("message", "message");
+        ComponentInstance instance  = null;
+        try {
+            instance =  factImm.createComponentInstance(props);
+        } catch (Exception e) {
+           fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        FooService fs = (FooService) context.getService(ref);
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message2", mes); // Already reconfigured.
+        assertEquals("Check count", 1, count);
+        
+        //Reconfiguration
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message3");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        instance.dispose();
+        
+        // Recreation of the instance.
+        props = new Properties();
+        props.put("managed.service.pid", msp);
+        props.put("message", "message");
+        instance  = null;
+        try {
+            instance =  factImm.createComponentInstance(props);
+        } catch (Exception e) {
+           fail(e.getMessage());
+        }
+        
+        ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        fs = (FooService) context.getService(ref);
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message3", mes); // Already reconfigured.
+        assertEquals("Check count", 1, count);
+        
+        instance.dispose();
+        
+        
+    }
+   
+    
+    
+
+}
diff --git a/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForService.java b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForService.java
new file mode 100644
index 0000000..81d57ce
--- /dev/null
+++ b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForService.java
@@ -0,0 +1,349 @@
+package org.apache.felix.ipojo.test.scenarios.configadmin;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.configadmin.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public class ManagedServiceTestForService extends OSGiTestCase {
+    
+    private String factNameSvc = "CA-ConfigurableProvider";
+    private String msp = "foo";
+
+    private ComponentFactory factSvc;
+    
+    private ConfigurationAdmin admin;
+    
+    
+    public void setUp() {
+        factSvc = (ComponentFactory) Utils.getFactoryByName(context, factNameSvc);
+        admin = (ConfigurationAdmin) Utils.getServiceObject(context, ConfigurationAdmin.class.getName(), null);
+        assertNotNull("Check configuration admin availability", admin);
+        cleanConfigurationAdmin();
+    }
+    
+    public void tearDown() {
+        cleanConfigurationAdmin();
+        admin = null;
+    }
+    
+    private void cleanConfigurationAdmin() {
+        try {
+            Configuration[] configurations = admin.listConfigurations("(service.pid=" + msp + ")");
+            for (int i = 0; configurations != null && i < configurations.length; i++) {
+                configurations[i].delete();
+            }
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (InvalidSyntaxException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+    
+    public void testFactoryCreationAndReconfiguration() {
+        Properties props = new Properties();
+        props.put("managed.service.pid", msp);
+        props.put("message", "message");
+        ComponentInstance instance  = null;
+        try {
+            instance =  factSvc.createComponentInstance(props);
+        } catch (Exception e) {
+           fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check no object", 0, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        FooService fs = (FooService) context.getService(ref);
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message", mes);
+        assertEquals("Check count", 1, count);
+        
+        //Update
+        Configuration configuration;
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message2");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        fs = (FooService) context.getService(ref);
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message2", mes);
+        assertEquals("Check count", 2, count);
+        
+        instance.dispose();
+        
+    }
+    
+    public void testMSFCreationAndReconfiguration() {
+        Configuration conf = null;
+        try {
+            conf = admin.createFactoryConfiguration(factNameSvc);
+            Dictionary props = conf.getProperties();
+            if (props == null) {
+                props = new Properties();
+            }
+            props.put("managed.service.pid", msp);
+            props.put("message", "message");
+            conf.update(props);
+            Thread.sleep(100); // Wait for the creation.
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        
+        Architecture arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+        
+        ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), conf.getPid());
+        assertEquals("Check no object", 0, arch.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+        FooService fs = (FooService) context.getService(ref);
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message", mes);
+        assertEquals("Check count", 1, count);
+        
+        //Update
+        Configuration configuration;
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message2");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+        ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), conf.getPid());
+        assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+
+        arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+        fs = (FooService) context.getService(ref);
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message2", mes);
+        assertEquals("Check count", 2, count);
+        
+        try {
+            conf.delete();
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+        
+    }
+    
+    public void testCreationAndReconfiguration2() {
+        // The configuration exists before the instance creation.
+        
+      //Update
+        Configuration configuration;
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message2");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        Properties props = new Properties();
+        props.put("managed.service.pid", msp);
+        props.put("message", "message");
+        ComponentInstance instance  = null;
+        try {
+            instance =  factSvc.createComponentInstance(props);
+        } catch (Exception e) {
+           fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check no object", 0, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        FooService fs = (FooService) context.getService(ref);
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message2", mes); // Already reconfigured.
+        assertEquals("Check count", 1, count);
+        
+        instance.dispose();
+        
+        //Reconfiguration
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message3");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        // Recreation of the instance.
+        props = new Properties();
+        props.put("managed.service.pid", msp);
+        props.put("message", "message");
+        instance  = null;
+        try {
+            instance =  factSvc.createComponentInstance(props);
+        } catch (Exception e) {
+           fail(e.getMessage());
+        }
+        
+        ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check no object", 0, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        fs = (FooService) context.getService(ref);
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message3", mes); // Already reconfigured.
+        assertEquals("Check count", 1, count);
+        
+        instance.dispose();
+        
+        
+    }
+
+    public void testCreationAndReconfiguration3() {
+        // The configuration exists before the instance creation.
+        
+      //Update
+        Configuration configuration;
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message2");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        Properties props = new Properties();
+        props.put("managed.service.pid", msp);
+        props.put("message", "message");
+        ComponentInstance instance  = null;
+        try {
+            instance =  factSvc.createComponentInstance(props);
+        } catch (Exception e) {
+           fail(e.getMessage());
+        }
+        
+        ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check no object", 0, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        FooService fs = (FooService) context.getService(ref);
+        Properties p = fs.fooProps();
+        String mes = p.getProperty("message");
+        int count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message2", mes); // Already reconfigured.
+        assertEquals("Check count", 1, count);
+        
+        //Reconfiguration
+        try {
+            configuration = admin.getConfiguration(msp);
+            Dictionary prc = configuration.getProperties();
+            if (prc == null) {
+                prc = new Properties();
+            }
+            prc.put("message", "message3");
+            configuration.update(prc);
+            Thread.sleep(5);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        
+        instance.dispose();
+        
+        // Recreation of the instance.
+        props = new Properties();
+        props.put("managed.service.pid", msp);
+        props.put("message", "message");
+        instance  = null;
+        try {
+            instance =  factSvc.createComponentInstance(props);
+        } catch (Exception e) {
+           fail(e.getMessage());
+        }
+        
+        ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+        assertEquals("Check no object", 0, instance.getInstanceDescription().getCreatedObjects().length);
+        assertNotNull("FS availability", ref);
+        
+        fs = (FooService) context.getService(ref);
+        p = fs.fooProps();
+        mes = p.getProperty("message");
+        count = ((Integer) p.get("count")).intValue();
+        assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+        assertEquals("Check message", "message3", mes); // Already reconfigured.
+        assertEquals("Check count", 1, count);
+        
+        instance.dispose();
+        
+        
+    }
+   
+    
+    
+
+}
diff --git a/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/CheckService.java b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/CheckService.java
new file mode 100644
index 0000000..6b9cfa0
--- /dev/null
+++ b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/CheckService.java
@@ -0,0 +1,31 @@
+/* 

+ * 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.ipojo.test.scenarios.configadmin.service;

+

+import java.util.Properties;

+

+public interface CheckService {

+    

+    public static final String foo = "foo";

+	

+	public boolean check();

+	

+	public Properties getProps();

+

+}

diff --git a/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/FooService.java b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/FooService.java
new file mode 100644
index 0000000..94abc61
--- /dev/null
+++ b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/FooService.java
@@ -0,0 +1,39 @@
+/* 

+ * 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.ipojo.test.scenarios.configadmin.service;

+

+import java.util.Properties;

+

+public interface FooService {

+

+	boolean foo();

+	

+	Properties fooProps();

+	

+	Boolean getObject();

+	

+	boolean getBoolean();

+	

+	int getInt();

+	

+	long getLong();

+	

+	double getDouble();

+	

+}

diff --git a/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
new file mode 100644
index 0000000..df20679
--- /dev/null
+++ b/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
@@ -0,0 +1,346 @@
+/* 

+ * 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.ipojo.test.scenarios.util;

+

+import java.util.Dictionary;

+import java.util.Properties;

+

+import junit.framework.Assert;

+

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.Factory;

+import org.apache.felix.ipojo.Handler;

+import org.apache.felix.ipojo.HandlerManagerFactory;

+import org.apache.felix.ipojo.ServiceContext;

+import org.osgi.framework.BundleContext;

+import org.osgi.framework.InvalidSyntaxException;

+import org.osgi.framework.ServiceReference;

+import org.osgi.service.cm.ManagedServiceFactory;

+

+public class Utils {

+

+    public static Factory getFactoryByName(BundleContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");

+            if (refs == null) {

+                System.err.println("Cannot get the factory " + factoryName);

+                return null;

+            }

+            return ((Factory) bc.getService(refs[0]));

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static HandlerManagerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");

+            if (refs == null) {

+                System.err.println("Cannot get the factory " + factoryName);

+                return null;

+            }

+            return (HandlerManagerFactory) bc.getService(refs[0]);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) {

+            System.err.println("Factory " + factoryName + " not found");

+            return null;

+        }

+

+        // if(fact.isAcceptable(configuration)) {

+        try {

+            return fact.createComponentInstance(configuration);

+        } catch (Exception e) {

+            e.printStackTrace();

+            Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+        // }

+        // else {

+        // System.err.println("Configuration not accepted by : " + factoryName);

+        // return null;

+        // }

+    }

+

+    public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) {

+            System.err.println("Factory " + factoryName + " not found");

+            return null;

+        }

+

+        try {

+            Properties props = new Properties();

+            props.put("instance.name",name);

+            return fact.createComponentInstance(props);

+        } catch (Exception e) {

+            System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());

+            e.printStackTrace();

+            return null;

+        }

+    }

+

+    public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return new ServiceReference[0];

+        } else {

+            return refs;

+        }

+    }

+

+    public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {

+        ServiceReference[] refs = null;

+        String filter = null;

+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {

+            filter = "(" + "factory.name" + "=" + name + ")";

+        } else {

+            filter = "(" + "instance.name" + "=" + name + ")";

+        }

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+    

+    public static ServiceReference getServiceReferenceByPID(BundleContext bc, String itf, String pid) {

+        ServiceReference[] refs = null;

+        String filter = "(" + "service.pid" + "=" + pid + ")";

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else if (refs.length == 1) {

+            return refs[0];

+        } else {

+            Assert.fail("A service lookup by PID returned several providers (" + refs.length + ")" + " for " + itf + " with " + pid);

+            return null;

+        }

+    }

+

+    public static Object getServiceObject(BundleContext bc, String itf, String filter) {

+        ServiceReference ref = getServiceReference(bc, itf, filter);

+        if (ref != null) {

+            return bc.getService(ref);

+        } else {

+            return null;

+        }

+    }

+

+    public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);

+        if (refs != null) {

+            Object[] list = new Object[refs.length];

+            for (int i = 0; i < refs.length; i++) {

+                list[i] = bc.getService(refs[i]);

+            }

+            return list;

+        } else {

+            return new Object[0];

+        }

+    }

+

+//    public static ServiceContext getServiceContext(ComponentInstance ci) {

+//        if (ci instanceof CompositeManager) {

+//            return ((CompositeManager) ci).getServiceContext();

+//        } else {

+//            throw new RuntimeException("Cannot get the service context form an non composite instance");

+//        }

+//    }

+

+    public static Factory getFactoryByName(ServiceContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");

+            if (refs == null) { return null; }

+            return ((Factory) bc.getService(refs[0]));

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) { return null; }

+

+        if (fact.isAcceptable(configuration)) {

+            try {

+                return fact.createComponentInstance(configuration);

+            } catch (Exception e) {

+                System.err.println(e.getMessage());

+                e.printStackTrace();

+                return null;

+            }

+        } else {

+            System.err.println("Configuration not accepted by : " + factoryName);

+            return null;

+        }

+    }

+

+    public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return new ServiceReference[0];

+        } else {

+            return refs;

+        }

+    }

+

+    public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {

+        ServiceReference[] refs = null;

+        String filter = null;

+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {

+            filter = "(" + "factory.name" + "=" + name + ")";

+        } else {

+            filter = "(" + "instance.name" + "=" + name + ")";

+        }

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static Object getServiceObject(ServiceContext bc, String itf, String filter) {

+        ServiceReference ref = getServiceReference(bc, itf, filter);

+        if (ref != null) {

+            return bc.getService(ref);

+        } else {

+            return null;

+        }

+    }

+

+    public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);

+        if (refs != null) {

+            Object[] list = new Object[refs.length];

+            for (int i = 0; i < refs.length; i++) {

+                list[i] = bc.getService(refs[i]);

+            }

+            return list;

+        } else {

+            return new Object[0];

+        }

+    }

+    

+    public static boolean contains(String string, String[] array) {

+        for (int i = 0; array != null && i < array.length; i++) {

+            if (array[i] != null  && array[i].equals(string)) {

+                return true;

+            }

+        }

+        return false;

+    }

+    

+    public static boolean contains(int value, int[] array) {

+        for (int i = 0; array != null && i < array.length; i++) {

+            if (array[i] == value) {

+                return true;

+            }

+        }

+        return false;

+    }

+    

+    public static void waitForService(BundleContext context, String itf, String filter) {

+        ServiceReference[] refs = getServiceReferences(context, itf, filter);

+        int count = 0;

+        if (refs.length != 0) {

+            return;

+        } else {

+            while(refs.length == 0) {

+                try {

+                    Thread.sleep(5);

+                } catch (InterruptedException e) {

+                    // Interrupted

+                }

+                count++;

+                if (count == 10) {

+                    throw new RuntimeException("Timeout ... no services match with " + filter);

+                }

+                refs = getServiceReferences(context, itf, filter);

+            }

+        }

+    }

+

+}

diff --git a/ipojo/tests/core/configadmin/src/main/resources/metadata.xml b/ipojo/tests/core/configadmin/src/main/resources/metadata.xml
new file mode 100644
index 0000000..98a5e78
--- /dev/null
+++ b/ipojo/tests/core/configadmin/src/main/resources/metadata.xml
@@ -0,0 +1,21 @@
+<ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

+	xsi:schemaLocation="org.apache.felix.ipojo http://people.apache.org/~clement/ipojo/schemas/core.xsd" xmlns="org.apache.felix.ipojo">

+		<component classname="org.apache.felix.ipojo.test.scenarios.component.ConfigurableFooProvider" 

+			name="CA-ConfigurableProvider">

+			<provides></provides>

+			<properties>

+				<property name="message" method="setMessage"/>

+			</properties>

+		</component>

+		<component classname="org.apache.felix.ipojo.test.scenarios.component.ConfigurableFooProvider" 

+			immediate="true"

+			name="CA-ImmConfigurableProvider">

+			<provides></provides>

+			<properties>

+				<property name="message" method="setMessage"/>

+			</properties>

+		</component>

+		

+		

+			

+</ipojo>