Handle asynchronous deletion of instances

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1478021 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
index a39d105..22c0ddf 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -181,9 +181,9 @@
         // Wait for bundle initialization.
         boolean bundleStability = getBundleStability(context);
         int count = 0;
-        while (!bundleStability && count < 500) {
+        while (!bundleStability && count < 1000) {
             try {
-                Thread.sleep(5);
+                Thread.sleep(100);
             } catch (InterruptedException e) {
                 // Interrupted
             }
@@ -191,11 +191,11 @@
             bundleStability = getBundleStability(context);
         }
 
-        if (count == 500) {
+        if (count == 1000) {
             for (Bundle bundle : bc.getBundles()) {
                 System.out.println("Bundle " + bundle.getSymbolicName() + " - " + bundle.getState());
             }
-            System.err.println("Bundle stability isn't reached after 500 tries");
+            System.err.println("Bundle stability isn't reached after 1000 tries");
             throw new IllegalStateException("Cannot reach the bundle stability");
         }
 
@@ -203,11 +203,11 @@
         count = 0;
         int count1 = 0;
         int count2 = 0;
-        while (! serviceStability && count < 500) {
+        while (! serviceStability && count < 1000) {
             try {
                 ServiceReference[] refs = context.getServiceReferences((String) null, null);
                 count1 = refs.length;
-                Thread.sleep(500);
+                Thread.sleep(1000);
                 refs = context.getServiceReferences((String) null, null);
                 count2 = refs.length;
                 serviceStability = count1 == count2;
@@ -219,8 +219,8 @@
             count++;
         }
 
-        if (count == 500) {
-            System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
+        if (count == 1000) {
+            System.err.println("Service stability isn't reached after 1000 tries (" + count1 + " != " + count2);
             throw new IllegalStateException("Cannot reach the service stability");
         }
     }
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java
index 7b9b8d1..9c04b4a 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java
@@ -24,7 +24,8 @@
 import org.junit.Before;

 import org.junit.Test;

 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;

-import org.ops4j.pax.exam.spi.reactors.PerMethod;

+import org.ops4j.pax.exam.spi.reactors.PerClass;

+import org.osgi.framework.InvalidSyntaxException;

 import org.osgi.framework.ServiceReference;

 import org.osgi.service.cm.Configuration;

 import org.osgi.service.cm.ConfigurationAdmin;

@@ -41,17 +42,19 @@
  * iPOJO does not expose the ManagedServiceFactory anymore, we must use the configuration admin.

  * To avoid conflicts with persisted configuration, we run one framework per tests

  */

-@ExamReactorStrategy(PerMethod.class)

+@ExamReactorStrategy(PerClass.class)

 public class TestDynamicallyConfigurablePropertiesUsingConfigAdmin extends Common {

 

     ComponentInstance instance, instance2;

 

     @Before

     public void setUp() {

+        cleanupConfigurationAdmin();

+

         String type = "CONFIG-FooProviderType-3";

 

         Hashtable<String, String> p1 = new Hashtable<String, String>();

-        p1.put("instance.name", "instance");

+        p1.put("instance.name", "instance-r");

         p1.put("foo", "foo");

         p1.put("bar", "2");

         p1.put("baz", "baz");

@@ -63,6 +66,31 @@
         instance2 = ipojoHelper.createComponentInstance(type, p2);

     }

 

+    private void cleanupConfigurationAdmin() {

+        ConfigurationAdmin admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName

+                (), null);

+        assertNotNull("Check configuration admin availability", admin);

+        try {

+            int found = 0;

+            Configuration[] configurations = admin.listConfigurations(null);

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

+                System.out.println("Deleting configuration " + configurations[i].getPid());

+                configurations[i].delete();

+                found++;

+            }

+

+            // Wait the dispatching.

+            Thread.sleep(found * 500);

+

+        } catch (IOException e) {

+            e.printStackTrace();

+        } catch (InvalidSyntaxException e) {

+            e.printStackTrace();

+        } catch (InterruptedException e) {

+            e.printStackTrace();

+        }

+    }

+

     @After

     public void tearDown() {

         instance.dispose();

@@ -91,14 +119,14 @@
         // Configuration of baz

         Properties conf = new Properties();

         conf.put("baz", "zab");

-        conf.put("bar", new Integer(2));

+        conf.put("bar", 2);

         conf.put("foo", "foo");

         conf.put("instance.name", instance.getInstanceName());

 

         configuration.update(conf);

 

         // Asynchronous dispatching of the configuration

-        Thread.sleep(200);

+        Thread.sleep(1000);

 

         // Recheck props

         fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());

@@ -131,7 +159,7 @@
         // Configuration of baz

         Properties conf = new Properties();

         conf.put("baz", "zab");

-        conf.put("bar", new Integer(2));

+        conf.put("bar", 2);

         conf.put("foo", "foo");

 

         // Asynchronous dispatching of the configuration

@@ -144,7 +172,7 @@
         barP = (Integer) fooRef.getProperty("bar");

         bazP = (String) fooRef.getProperty("baz");

         assertEquals("Check foo equality -2", fooP, "foo");

-        assertEquals("Check bar equality -2", barP, new Integer(2));

+        assertEquals("Check bar equality -2", barP, 2);

         assertEquals("Check baz equality -2", bazP, "zab");

     }

 

@@ -171,7 +199,7 @@
         Properties conf = new Properties();

         conf.put("baz", "zab");

         conf.put("foo", "oof");

-        conf.put("bar", new Integer(0));

+        conf.put("bar", 0);

 

         // Asynchronous dispatching of the configuration

         configuration.update(conf);

@@ -221,11 +249,11 @@
         Properties conf = new Properties();

         conf.put("baz", "zab");

         conf.put("foo", "oof");

-        conf.put("bar", new Integer(0));

+        conf.put("bar", 0);

 

         // Asynchronous dispatching of the configuration

         configuration.update(conf);

-        Thread.sleep(200);

+        Thread.sleep(1000);

 

         // Recheck props

         fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());

@@ -234,7 +262,7 @@
         bazP = (String) fooRef.getProperty("baz");

 

         assertEquals("Check foo equality", fooP, "oof");

-        assertEquals("Check bar equality", barP, new Integer(0));

+        assertEquals("Check bar equality", barP, 0);

         assertEquals("Check baz equality", bazP, "zab");

 

         // Check field value

@@ -244,7 +272,7 @@
         barP = (Integer) p.get("bar");

 

         assertEquals("Check foo field equality", fooP, "oof");

-        assertEquals("Check bar field equality", barP, new Integer(0));

+        assertEquals("Check bar field equality", barP, 0);

 

         osgiHelper.getContext().ungetService(fooRef);

     }

@@ -324,14 +352,16 @@
         Properties conf = new Properties();

         conf.put("baz", "zab");

         conf.put("foo", "foo");

-        conf.put("bar", new Integer(2));

+        conf.put("bar", 2);

         conf.put("propagated1", "propagated");

-        conf.put("propagated2", new Integer(1));

+        conf.put("propagated2", 1);

         conf.put(".notpropagated", "xxx");

 

         // Asynchronous dispatching of the configuration

         configuration.update(conf);

-        Thread.sleep(200);

+        Thread.sleep(1000);

+

+        System.out.println(instance.getInstanceDescription().getDescription());

 

         // Recheck props

         fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());

@@ -379,7 +409,7 @@
 

         // Asynchronous dispatching of the configuration

         configuration.update(conf);

-        Thread.sleep(200);

+        Thread.sleep(1000);

 

         // Recheck props

         fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());

diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceConfigurableProperties.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceConfigurableProperties.java
index 961a0de..7bb4b7f 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceConfigurableProperties.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceConfigurableProperties.java
@@ -24,12 +24,16 @@
 import org.junit.After;

 import org.junit.Before;

 import org.junit.Test;

+import org.osgi.framework.InvalidSyntaxException;

 import org.osgi.framework.ServiceReference;

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

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

 import org.osgi.service.cm.ConfigurationException;

 import org.osgi.service.cm.ManagedService;

 import org.ow2.chameleon.testing.helpers.IPOJOHelper;

 import org.ow2.chameleon.testing.helpers.OSGiHelper;

 

+import java.io.IOException;

 import java.util.Hashtable;

 import java.util.Properties;

 

@@ -61,6 +65,8 @@
         osgiHelper = new OSGiHelper(bc);

         ipojoHelper = new IPOJOHelper(bc);

 

+        cleanupConfigurationAdmin();

+

         String type = "CONFIG-FooProviderType-4";

         Hashtable<String, String> p = new Hashtable<String, String>();

         p.put("instance.name", "instance");

@@ -96,6 +102,22 @@
         instance3 = null;

     }

 

+    private void cleanupConfigurationAdmin() {

+        ConfigurationAdmin admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName

+                (), null);

+        assertNotNull("Check configuration admin availability", admin);

+        try {

+            Configuration[] configurations = admin.listConfigurations(null);

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

+                configurations[i].delete();

+            }

+        } catch (IOException e) {

+            e.printStackTrace();

+        } catch (InvalidSyntaxException e) {

+            e.printStackTrace();

+        }

+    }

+

     @Test

     public void testStaticInstance1() {

         ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance1.getInstanceName());

diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndConfigAdmin.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndConfigAdmin.java
index b0e3d0e..fcee2a7 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndConfigAdmin.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndConfigAdmin.java
@@ -26,6 +26,7 @@
 import org.junit.Test;

 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;

 import org.ops4j.pax.exam.spi.reactors.PerMethod;

+import org.osgi.framework.InvalidSyntaxException;

 import org.osgi.framework.ServiceReference;

 import org.osgi.service.cm.Configuration;

 import org.osgi.service.cm.ConfigurationAdmin;

@@ -40,6 +41,7 @@
 import java.util.Properties;

 

 import static junit.framework.Assert.*;

+import static org.junit.Assert.assertNotNull;

 

 

 @ExamReactorStrategy(PerMethod.class)

@@ -51,6 +53,9 @@
     public void setUp() {

         osgiHelper = new OSGiHelper(bc);

         ipojoHelper = new IPOJOHelper(bc);

+

+        cleanupConfigurationAdmin();

+

         String type = "CONFIG-FooProviderType-3Updated";

 

         Hashtable<String, String> p1 = new Hashtable<String, String>();

@@ -75,6 +80,22 @@
         instance = null;

     }

 

+    private void cleanupConfigurationAdmin() {

+        ConfigurationAdmin admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName

+                (), null);

+        assertNotNull("Check configuration admin availability", admin);

+        try {

+            Configuration[] configurations = admin.listConfigurations(null);

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

+                configurations[i].delete();

+            }

+        } catch (IOException e) {

+            e.printStackTrace();

+        } catch (InvalidSyntaxException e) {

+            e.printStackTrace();

+        }

+    }

+

     @Test

     public void testStatic() throws IOException, InterruptedException {

 

diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndManagedService.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndManagedService.java
index 617d053..17bfdc9 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndManagedService.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndManagedService.java
@@ -20,23 +20,41 @@
 package org.apache.felix.ipojo.runtime.core;

 

 import org.apache.felix.ipojo.ComponentInstance;

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

+import org.apache.felix.ipojo.architecture.Architecture;

+import org.apache.felix.ipojo.extender.InstanceDeclaration;

 import org.apache.felix.ipojo.runtime.core.services.FooService;

 import org.junit.After;

 import org.junit.Before;

 import org.junit.Test;

+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;

+import org.ops4j.pax.exam.spi.reactors.PerClass;

+import org.ops4j.pax.exam.spi.reactors.PerMethod;

+import org.osgi.framework.Bundle;

+import org.osgi.framework.BundleContext;

+import org.osgi.framework.InvalidSyntaxException;

 import org.osgi.framework.ServiceReference;

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

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

 import org.osgi.service.cm.ConfigurationException;

 import org.osgi.service.cm.ManagedService;

 import org.ow2.chameleon.testing.helpers.IPOJOHelper;

 import org.ow2.chameleon.testing.helpers.OSGiHelper;

 

+import java.io.File;

+import java.io.FileOutputStream;

+import java.io.IOException;

+import java.io.InputStream;

+import java.net.URL;

 import java.util.Dictionary;

 import java.util.Hashtable;

 import java.util.Properties;

 

 import static junit.framework.Assert.*;

+import static org.junit.Assert.assertNotNull;

 

 

+@ExamReactorStrategy(PerMethod.class)

 public class TestUpdatedMethodAndManagedService extends Common {

 

 

@@ -55,12 +73,43 @@
      */

     ComponentInstance instance3;

 

+    private void cleanupConfigurationAdmin() {

+        ConfigurationAdmin admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName

+                (), null);

+        assertNotNull("Check configuration admin availability", admin);

+        try {

+            int found = 0;

+            Configuration[] configurations = admin.listConfigurations(null);

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

+                System.out.println("Deleting configuration " + configurations[i].getPid());

+                configurations[i].delete();

+                found++;

+            }

 

+            // Wait the dispatching.

+            Thread.sleep(found * 500);

+

+        } catch (IOException e) {

+            e.printStackTrace();

+        } catch (InvalidSyntaxException e) {

+            e.printStackTrace();

+        } catch (InterruptedException e) {

+            e.printStackTrace();

+        }

+    }

 

     @Before

-    public void setUp() {

+    public void setUp() throws IOException {

         osgiHelper = new OSGiHelper(bc);

         ipojoHelper = new IPOJOHelper(bc);

+

+        for (HandlerFactory handler : osgiHelper.getServiceObjects(HandlerFactory.class)) {

+            System.out.println("handler : " + handler.getHandlerName() + " - " + handler.getState() + " - " + handler

+                    .getMissingHandlers());

+        }

+

+        cleanupConfigurationAdmin();

+

         String type = "CONFIG-FooProviderType-4Updated";

         Hashtable<String, String> p = new Hashtable<String, String>();

         p.put("instance.name", "instance");

@@ -68,8 +117,12 @@
         p.put("bar", "2");

         p.put("baz", "baz");

         instance1 = ipojoHelper.createComponentInstance(type, p);

+        System.out.println(instance1.getInstanceDescription().getDescription());

+

         assertEquals("instance1 created", ComponentInstance.VALID, instance1.getState());

 

+        System.out.println(instance1.getInstanceDescription().getDescription());

+

         type = "CONFIG-FooProviderType-3Updated";

         Hashtable<String, String> p1 = new Hashtable<String, String>();

         p1.put("instance.name", "instance-2");

@@ -89,7 +142,6 @@
 

     @After

     public void tearDown() {

-

         instance1.dispose();

         instance2.dispose();

         instance3.dispose();

@@ -98,8 +150,14 @@
         instance3 = null;

     }

 

+

+

     @Test

-    public void testStaticInstance1() {

+    public void testStaticInstance1() throws IOException {

+        for (Architecture architecture : osgiHelper.getServiceObjects(Architecture.class)) {

+            System.out.println(architecture.getInstanceDescription().getName() + " " + architecture

+                    .getInstanceDescription().getState());

+        }

         ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance1.getInstanceName());

         assertNotNull("Check FS availability", fooRef);

         String fooP = (String) fooRef.getProperty("foo");

@@ -347,4 +405,38 @@
         assertEquals("Check last updated", 3, dict.size());

 

     }

+

+    public static void dump(BundleContext bc, File output) throws IOException {

+        if (!output.exists()) {

+            output.mkdirs();

+        }

+

+        for (Bundle bundle : bc.getBundles()) {

+            if (bundle.getBundleId() == 0) {

+                continue;

+            }

+            System.out.println("Location : " + bundle.getLocation());

+            if ("local".equals(bundle.getLocation())) {

+                continue; // Pax Exam, when you hug me, I feel so...

+            }

+            URL location = new URL(bundle.getLocation());

+            FileOutputStream outputStream = null;

+            if (bundle.getVersion() != null) {

+                outputStream = new FileOutputStream(new File(output,

+                        bundle.getSymbolicName() + "-" + bundle.getVersion().toString() + ".jar"));

+            } else {

+                outputStream = new FileOutputStream(new File(output, bundle.getSymbolicName() + ".jar"));

+            }

+

+            int read = 0;

+            byte[] bytes = new byte[1024];

+

+            InputStream inputStream = location.openStream();

+            while ((read = inputStream.read(bytes)) != -1) {

+                outputStream.write(bytes, 0, read);

+            }

+            inputStream.close();

+            outputStream.close();

+        }

+    }

 }

diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndConfigAdmin.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndConfigAdmin.java
index dcb4d12..9b4bd8f 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndConfigAdmin.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndConfigAdmin.java
@@ -22,10 +22,12 @@
 import org.apache.felix.ipojo.ComponentInstance;

 import org.apache.felix.ipojo.runtime.core.services.FooService;

 import org.junit.After;

+import org.junit.Assert;

 import org.junit.Before;

 import org.junit.Test;

 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;

 import org.ops4j.pax.exam.spi.reactors.PerMethod;

+import org.osgi.framework.InvalidSyntaxException;

 import org.osgi.framework.ServiceReference;

 import org.osgi.service.cm.Configuration;

 import org.osgi.service.cm.ConfigurationAdmin;

@@ -53,6 +55,7 @@
     public void setUp() {

         osgiHelper = new OSGiHelper(bc);

         ipojoHelper = new IPOJOHelper(bc);

+        cleanupConfigurationAdmin();

         String type = "CONFIG-FooProviderType-3Updated2";

 

         Hashtable<String, String> p1 = new Hashtable<String, String>();

@@ -76,6 +79,22 @@
         instance = null;

     }

 

+    private void cleanupConfigurationAdmin() {

+        ConfigurationAdmin admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName

+                (), null);

+        Assert.assertNotNull("Check configuration admin availability", admin);

+        try {

+            Configuration[] configurations = admin.listConfigurations(null);

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

+                configurations[i].delete();

+            }

+        } catch (IOException e) {

+            e.printStackTrace();

+        } catch (InvalidSyntaxException e) {

+            e.printStackTrace();

+        }

+    }

+

     @Test

     public void testStatic() throws IOException, InterruptedException {

 

diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndManagedService.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndManagedService.java
index 70cf4af..2bb65e5 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndManagedService.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndManagedService.java
@@ -24,22 +24,25 @@
 import org.junit.After;

 import org.junit.Before;

 import org.junit.Test;

+import org.osgi.framework.InvalidSyntaxException;

 import org.osgi.framework.ServiceReference;

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

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

 import org.osgi.service.cm.ConfigurationException;

 import org.osgi.service.cm.ManagedService;

 import org.ow2.chameleon.testing.helpers.IPOJOHelper;

 import org.ow2.chameleon.testing.helpers.OSGiHelper;

 

+import java.io.IOException;

 import java.util.Hashtable;

 import java.util.Properties;

 

 import static junit.framework.Assert.*;

+import static org.junit.Assert.assertNotNull;

 

 

 public class TestUpdatedNoArgMethodAndManagedService extends Common {

 

-

-

     /**

      * Instance where the ManagedServicePID is provided by the component type.

      */

@@ -60,9 +63,12 @@
     public void setUp() {

         osgiHelper = new OSGiHelper(bc);

         ipojoHelper = new IPOJOHelper(bc);

+

+        cleanupConfigurationAdmin();

+

         String type = "CONFIG-FooProviderType-4Updated2";

         Hashtable<String, String> p = new Hashtable<String, String>();

-        p.put("instance.name", "instance");

+        p.put("instance.name", "any-instance");

         p.put("foo", "foo");

         p.put("bar", "2");

         p.put("baz", "baz");

@@ -75,7 +81,7 @@
         p1.put("foo", "foo");

         p1.put("bar", "2");

         p1.put("baz", "baz");

-        p1.put("managed.service.pid", "instance");

+        p1.put("managed.service.pid", "instanceMSP");

         instance2 = ipojoHelper.createComponentInstance(type, p1);

 

         type = "CONFIG-FooProviderType-3Updated2";

@@ -95,9 +101,27 @@
         instance3 = null;

     }

 

+    private void cleanupConfigurationAdmin() {

+        ConfigurationAdmin admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName

+                (), null);

+        assertNotNull("Check configuration admin availability", admin);

+        try {

+            Configuration[] configurations = admin.listConfigurations(null);

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

+                configurations[i].delete();

+            }

+        } catch (IOException e) {

+            e.printStackTrace();

+        } catch (InvalidSyntaxException e) {

+            e.printStackTrace();

+        }

+    }

+

     @Test

     public void testStaticInstance1() {

-        ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance1.getInstanceName());

+        ServiceReference fooRef = osgiHelper.waitForService(FooService.class.getName(),

+                "(instance.name=" + instance1.getInstanceName() + ")",

+                5000);

         assertNotNull("Check FS availability", fooRef);

         String fooP = (String) fooRef.getProperty("foo");

         Integer barP = (Integer) fooRef.getProperty("bar");

@@ -147,7 +171,7 @@
         assertEquals("Check bar equality -1", barP, new Integer(2));

         assertEquals("Check baz equality -1", bazP, "baz");

 

-        ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "instance");

+        ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "instanceMSP");

         assertNotNull("Check ManagedService availability", msRef);

 

 

@@ -273,7 +297,7 @@
         assertEquals("Check bar equality", barP, new Integer(2));

         assertEquals("Check baz equality", bazP, "baz");

 

-        ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "instance");

+        ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "instanceMSP");

         assertNotNull("Check ManagedServiceFactory availability", msRef);

 

         // Configuration of baz