Further integration tests and split up of tests into
multiple classes.
Note: These tests are expected to cause build failure
in the configadmin project at the current Rev. (805665)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@805666 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBaseTest.java b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBaseTest.java
index 13bff15..1a4257f 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBaseTest.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBaseTest.java
@@ -21,7 +21,7 @@
 
 import junit.framework.TestCase;
 
-import org.apache.felix.cm.integration.helper.TestActivator;
+import org.apache.felix.cm.integration.helper.ManagedServiceTestActivator;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
@@ -40,7 +40,7 @@
         // start the bundle and assert this
         bundle = installBundle( pid );
         bundle.start();
-        final TestActivator tester = TestActivator.INSTANCE;
+        final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
         TestCase.assertNotNull( "Activator not started !!", tester );
 
         // give cm time for distribution
@@ -48,7 +48,7 @@
 
         // assert activater has no configuration
         TestCase.assertNull( "Expect no Properties after Service Registration", tester.props );
-        TestCase.assertEquals( "Expect no update call", 1, tester.numUpdatedCalls );
+        TestCase.assertEquals( "Expect no update call", 1, tester.numManagedServiceUpdatedCalls );
 
         // configure after ManagedServiceRegistration --> configure via update
         configure( pid );
@@ -56,19 +56,19 @@
 
         // assert activater has configuration
         TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
-        TestCase.assertEquals( "Expect a single update call", 2, tester.numUpdatedCalls );
+        TestCase.assertEquals( "Expect a single update call", 2, tester.numManagedServiceUpdatedCalls );
 
         // stop the bundle now
         bundle.stop();
 
         // assert INSTANCE is null
-        TestCase.assertNull( TestActivator.INSTANCE );
+        TestCase.assertNull( ManagedServiceTestActivator.INSTANCE );
 
         delay();
 
         // start the bundle again (and check)
         bundle.start();
-        final TestActivator tester2 = TestActivator.INSTANCE;
+        final ManagedServiceTestActivator tester2 = ManagedServiceTestActivator.INSTANCE;
         TestCase.assertNotNull( "Activator not started the second time!!", tester2 );
         TestCase.assertNotSame( "Instances must not be the same", tester, tester2 );
 
@@ -77,7 +77,7 @@
 
         // assert activater has configuration
         TestCase.assertNotNull( "Expect Properties after Service Registration", tester2.props );
-        TestCase.assertEquals( "Expect a second update call", 1, tester2.numUpdatedCalls );
+        TestCase.assertEquals( "Expect a second update call", 1, tester2.numManagedServiceUpdatedCalls );
 
         // cleanup
         bundle.uninstall();
@@ -97,7 +97,7 @@
         // start the bundle and assert this
         bundle = installBundle( pid );
         bundle.start();
-        final TestActivator tester = TestActivator.INSTANCE;
+        final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
         TestCase.assertNotNull( "Activator not started !!", tester );
 
         // give cm time for distribution
@@ -105,19 +105,19 @@
 
         // assert activater has configuration
         TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
-        TestCase.assertEquals( "Expect no update call", 1, tester.numUpdatedCalls );
+        TestCase.assertEquals( "Expect no update call", 1, tester.numManagedServiceUpdatedCalls );
 
         // stop the bundle now
         bundle.stop();
 
         // assert INSTANCE is null
-        TestCase.assertNull( TestActivator.INSTANCE );
+        TestCase.assertNull( ManagedServiceTestActivator.INSTANCE );
 
         delay();
 
         // start the bundle again (and check)
         bundle.start();
-        final TestActivator tester2 = TestActivator.INSTANCE;
+        final ManagedServiceTestActivator tester2 = ManagedServiceTestActivator.INSTANCE;
         TestCase.assertNotNull( "Activator not started the second time!!", tester2 );
         TestCase.assertNotSame( "Instances must not be the same", tester, tester2 );
 
@@ -126,7 +126,7 @@
 
         // assert activater has configuration
         TestCase.assertNotNull( "Expect Properties after Service Registration", tester2.props );
-        TestCase.assertEquals( "Expect a second update call", 1, tester2.numUpdatedCalls );
+        TestCase.assertEquals( "Expect a second update call", 1, tester2.numManagedServiceUpdatedCalls );
 
         // cleanup
         bundle.uninstall();
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java
index 36203cd..981c1a4 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java
@@ -23,14 +23,13 @@
 import java.util.Hashtable;
 import junit.framework.TestCase;
 
-import org.apache.felix.cm.integration.helper.TestActivator;
+import org.apache.felix.cm.integration.helper.ManagedServiceTestActivator;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
 
 
 @RunWith(JUnit4TestRunner.class)
@@ -55,7 +54,7 @@
         TestCase.assertNull( beforeStart.getBundleLocation() );
 
         bundle.start();
-        final TestActivator tester = TestActivator.INSTANCE;
+        final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
         TestCase.assertNotNull( "Activator not started !!", tester );
 
         // give cm time for distribution
@@ -63,7 +62,7 @@
 
         // assert activater has configuration
         TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
-        TestCase.assertEquals( "Expect a single update call", 1, tester.numUpdatedCalls );
+        TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );
 
         // ensure a freshly retrieved object also has the location
         final Configuration beforeStop = getConfiguration( pid );
@@ -125,7 +124,7 @@
         TestCase.assertNull( beforeStart.getBundleLocation() );
 
         bundle.start();
-        final TestActivator tester = TestActivator.INSTANCE;
+        final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
         TestCase.assertNotNull( "IOActivator not started !!", tester );
 
         // give cm time for distribution
@@ -133,7 +132,7 @@
 
         // assert activater has configuration
         TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
-        TestCase.assertEquals( "Expect a single update call", 1, tester.numUpdatedCalls );
+        TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );
 
         // ensure a freshly retrieved object also has the location
         final Configuration beforeStop = getConfiguration( pid );
@@ -187,8 +186,7 @@
         final String pid = "test_not_updated_new_configuration_not_bound_after_bundle_uninstall";
 
         // create a configuration but do not update with properties
-        final ConfigurationAdmin ca = getConfigurationAdmin();
-        final Configuration newConfig = ca.getConfiguration( pid, null );
+        final Configuration newConfig = configure( pid, null, false );
         TestCase.assertNull( newConfig.getProperties() );
         TestCase.assertNull( newConfig.getBundleLocation() );
 
@@ -198,10 +196,10 @@
         delay();
 
         // ensure no properties provided to bundle
-        final TestActivator tester = TestActivator.INSTANCE;
+        final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
         TestCase.assertNotNull( "Activator not started !!", tester );
         TestCase.assertNull( "Expect no properties after Service Registration", tester.props );
-        TestCase.assertEquals( "Expect a single update call", 1, tester.numUpdatedCalls );
+        TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );
 
         // assert configuration is still unset but bound
         TestCase.assertNull( newConfig.getProperties() );
@@ -226,19 +224,11 @@
     public void test_create_with_location_unbind_before_service_supply() throws BundleException, IOException
     {
 
-        /*
-         * 1. create Configuration with pid and non-null location. 2. update the
-         * configuration with non-null props. 3. set location of the
-         * configuration to null. 4. bundleA registers a ManagedService service
-         * with the pid.
-         */
-
         final String pid = "test_create_with_location_unbind_before_service_supply";
         final String dummyLocation = "http://some/dummy/location";
 
         // 1. create and statically bind the configuration
-        final ConfigurationAdmin ca = getConfigurationAdmin();
-        final Configuration config = ca.getConfiguration( pid, dummyLocation );
+        final Configuration config = configure( pid, dummyLocation, false );
         TestCase.assertEquals( pid, config.getPid() );
         TestCase.assertEquals( dummyLocation, config.getBundleLocation() );
 
@@ -259,12 +249,12 @@
         bundle.start();
         delay();
 
-        final TestActivator tester = TestActivator.INSTANCE;
+        final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
         TestCase.assertNotNull( "Activator not started !!", tester );
 
         // assert activater has configuration (two calls, one per pid)
         TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
-        TestCase.assertEquals( "Expect a single update call", 1, tester.numUpdatedCalls );
+        TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );
 
         TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );
 
@@ -304,12 +294,12 @@
         // give cm time for distribution
         delay();
 
-        final TestActivator tester = TestActivator.INSTANCE;
+        final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
         TestCase.assertNotNull( "Activator not started !!", tester );
 
         // assert activater has configuration (two calls, one per pid)
         TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
-        TestCase.assertEquals( "Expect a single update call", 1, tester.numUpdatedCalls );
+        TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );
 
         TestCase.assertEquals( location, config.getBundleLocation() );
 
@@ -415,10 +405,132 @@
         TestCase.assertEquals( location, configBoundAfterRestart.getBundleLocation() );
     }
 
-    /*
-     * @Test public void test_() throws BundleException { final int count = 2;
-     * for (int i=0; i < count; i++) { final Bundle bundle = installBundle(
-     * "dummy", FailureActivator.class ); bundle.start(); delay();
-     * bundle.uninstall(); delay(); } }
-     */
+
+    @Test
+    public void test_static_binding() throws BundleException
+    {
+        final String pid = "test_static_binding";
+
+        // install a bundle to get a location for binding
+        bundle = installBundle( pid );
+        final String location = bundle.getLocation();
+
+        // create and statically bind the configuration
+        configure( pid );
+        final Configuration config = getConfiguration( pid );
+        TestCase.assertEquals( pid, config.getPid() );
+        TestCase.assertNull( config.getBundleLocation() );
+        config.setBundleLocation( location );
+        TestCase.assertEquals( location, config.getBundleLocation() );
+
+        // start the bundle
+        bundle.start();
+        delay();
+        TestCase.assertEquals( location, config.getBundleLocation() );
+
+        // assert the configuration is supplied
+        final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
+        TestCase.assertNotNull( "Activator not started !!", tester );
+        TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
+        TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );
+
+        // remove the static binding and assert still bound
+        config.setBundleLocation( null );
+        TestCase.assertEquals( location, config.getBundleLocation() );
+
+        // uninstall bundle and assert configuration unbound
+        bundle.uninstall();
+        bundle = null;
+        delay();
+        TestCase.assertNull( config.getBundleLocation() );
+    }
+
+
+    @Test
+    public void test_two_bundles_one_pid() throws BundleException, IOException
+    {
+        // 1. Bundle registers service with pid1
+        final String pid = "test_two_bundles_one_pid";
+        final Bundle bundleA = installBundle( pid, ManagedServiceTestActivator.class );
+        final String locationA = bundleA.getLocation();
+        bundleA.start();
+        delay();
+
+        // call back with null
+        final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
+        TestCase.assertNull( tester.props );
+        TestCase.assertEquals( 1, tester.numManagedServiceUpdatedCalls );
+
+        // 2. create new Conf with pid1 and locationA.
+        final Configuration config = configure( pid, locationA, false );
+        delay();
+
+        // ==> No call back.
+        TestCase.assertNull( tester.props );
+        TestCase.assertEquals( 1, tester.numManagedServiceUpdatedCalls );
+
+        // 3. Configuration#update(prop) is called.
+        config.update( theConfig );
+        delay();
+
+        // ==> call back with the prop.
+        TestCase.assertNotNull( tester.props );
+        TestCase.assertEquals( 2, tester.numManagedServiceUpdatedCalls );
+
+        // 4. Stop BundleA
+        bundleA.stop();
+        delay();
+
+        // 5. Start BundleA
+        bundleA.start();
+        delay();
+
+        // ==> call back with the prop.
+        final ManagedServiceTestActivator tester2 = ManagedServiceTestActivator.INSTANCE;
+        TestCase.assertNotNull( tester2.props );
+        TestCase.assertEquals( 1, tester2.numManagedServiceUpdatedCalls );
+
+        // 6. Configuration#deleted() is called.
+        config.delete();
+        delay();
+
+        // ==> call back with null.
+        TestCase.assertNull( tester2.props );
+        TestCase.assertEquals( 2, tester2.numManagedServiceUpdatedCalls );
+
+        // 7. uninstall Bundle A for cleanup.
+        bundleA.uninstall();
+        delay();
+
+        // Test 2
+
+        // 8. BundleA registers ManagedService with pid1.
+        final Bundle bundleA2 = installBundle( pid, ManagedServiceTestActivator.class );
+        final String locationA2 = bundleA.getLocation();
+        bundleA2.start();
+        delay();
+
+        // call back with null
+        final ManagedServiceTestActivator tester21 = ManagedServiceTestActivator.INSTANCE;
+        TestCase.assertNull( tester21.props );
+        TestCase.assertEquals( 1, tester21.numManagedServiceUpdatedCalls );
+
+        // 9. create new Conf with pid1 and locationB.
+        final String locationB = "test:locationB/" + pid;
+        final Configuration configB = configure( pid, locationB, false );
+        delay();
+
+        // ==> No call back.
+        TestCase.assertNull( tester21.props );
+        TestCase.assertEquals( 1, tester21.numManagedServiceUpdatedCalls );
+
+        // 10. Configuration#update(prop) is called.
+        configB.update( theConfig );
+        delay();
+
+        // ==> No call back because the Conf is not bound to locationA.
+        TestCase.assertNull( tester21.props );
+        TestCase.assertEquals( 1, tester21.numManagedServiceUpdatedCalls );
+    }
+
 }
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java
index 0e4b3a6..f1002f9 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java
@@ -31,8 +31,9 @@
 import java.util.Hashtable;
 import junit.framework.TestCase;
 
+import org.apache.felix.cm.integration.helper.ManagedServiceTestActivator;
 import org.apache.felix.cm.integration.helper.MyTinyBundle;
-import org.apache.felix.cm.integration.helper.TestActivator;
+import org.apache.felix.cm.integration.helper.BaseTestActivator;
 import org.junit.After;
 import org.junit.Before;
 import org.ops4j.pax.exam.Inject;
@@ -72,12 +73,10 @@
     @org.ops4j.pax.exam.junit.Configuration
     public static Option[] configuration()
     {
-        return options(
-            provision(
-                scanDir( "target" ).filter( "*.jar" ),
-                mavenBundle( "org.ops4j.pax.swissbox", "pax-swissbox-tinybundles", "1.0.0" )
-            )
-//          , PaxRunnerOptions.vmOption( "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=30303" )
+        return options( provision( scanDir( "target" ).filter( "*.jar" ), mavenBundle( "org.ops4j.pax.swissbox",
+            "pax-swissbox-tinybundles", "1.0.0" ) )
+//         , PaxRunnerOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=30303" )
+        // , PaxRunnerOptions.logProfile()
         );
     }
 
@@ -105,21 +104,22 @@
 
     protected Bundle installBundle( final String pid ) throws BundleException
     {
-        return installBundle( pid, TestActivator.class );
+        return installBundle( pid, ManagedServiceTestActivator.class );
     }
 
 
     protected Bundle installBundle( final String pid, final Class<?> activatorClass ) throws BundleException
     {
+        final String activatorClassName = activatorClass.getName();
         final InputStream bundleStream = new MyTinyBundle().prepare(
-            withBnd().set( Constants.BUNDLE_SYMBOLICNAME, "simpleconfiguration" ).set( Constants.BUNDLE_VERSION,
-                "0.0.11" ).set( Constants.IMPORT_PACKAGE, "org.apache.felix.cm.integration.helper" ).set(
-                Constants.BUNDLE_ACTIVATOR, activatorClass.getName() ).set( TestActivator.HEADER_PID, pid ) ).build(
+            withBnd().set( Constants.BUNDLE_SYMBOLICNAME, activatorClassName ).set( Constants.BUNDLE_VERSION, "0.0.11" )
+                .set( Constants.IMPORT_PACKAGE, "org.apache.felix.cm.integration.helper" ).set(
+                    Constants.BUNDLE_ACTIVATOR, activatorClassName ).set( BaseTestActivator.HEADER_PID, pid ) ).build(
             TinyBundles.asStream() );
 
         try
         {
-            return bundleContext.installBundle( "test:SimpleComponent", bundleStream );
+            return bundleContext.installBundle( "test:" + activatorClassName, bundleStream );
         }
         finally
         {
@@ -165,28 +165,66 @@
     }
 
 
-    protected void configure( String pid )
+    protected Configuration configure( final String pid )
     {
-        ConfigurationAdmin ca = getConfigurationAdmin();
+        return configure( pid, null, true );
+    }
+
+
+    protected Configuration configure( final String pid, final String location, final boolean withProps )
+    {
+        final ConfigurationAdmin ca = getConfigurationAdmin();
         try
         {
-            org.osgi.service.cm.Configuration config = ca.getConfiguration( pid, null );
-            config.update( theConfig );
+            final Configuration config = ca.getConfiguration( pid, location );
+            if ( withProps )
+            {
+                config.update( theConfig );
+            }
+            return config;
         }
         catch ( IOException ioe )
         {
             TestCase.fail( "Failed updating configuration " + pid + ": " + ioe.toString() );
+            return null; // keep the compiler quiet
+        }
+    }
+
+
+    protected Configuration createFactoryConfiguration( final String factoryPid )
+    {
+        return createFactoryConfiguration( factoryPid, null, true );
+    }
+
+
+    protected Configuration createFactoryConfiguration( final String factoryPid, final String location,
+        final boolean withProps )
+    {
+        final ConfigurationAdmin ca = getConfigurationAdmin();
+        try
+        {
+            final Configuration config = ca.createFactoryConfiguration( factoryPid, null );
+            if ( withProps )
+            {
+                config.update( theConfig );
+            }
+            return config;
+        }
+        catch ( IOException ioe )
+        {
+            TestCase.fail( "Failed updating factory configuration " + factoryPid + ": " + ioe.toString() );
+            return null; // keep the compiler quiet
         }
     }
 
 
     protected Configuration getConfiguration( final String pid )
     {
-        ConfigurationAdmin ca = getConfigurationAdmin();
+        final ConfigurationAdmin ca = getConfigurationAdmin();
         try
         {
             final String filter = "(" + Constants.SERVICE_PID + "=" + pid + ")";
-            org.osgi.service.cm.Configuration[] configs = ca.listConfigurations( filter );
+            final Configuration[] configs = ca.listConfigurations( filter );
             if ( configs != null && configs.length > 0 )
             {
                 return configs[0];
@@ -206,12 +244,12 @@
     }
 
 
-    protected void deleteConfig( String pid )
+    protected void deleteConfig( final String pid )
     {
-        ConfigurationAdmin ca = getConfigurationAdmin();
+        final ConfigurationAdmin ca = getConfigurationAdmin();
         try
         {
-            org.osgi.service.cm.Configuration config = ca.getConfiguration( pid );
+            final Configuration config = ca.getConfiguration( pid );
             config.delete();
         }
         catch ( IOException ioe )
@@ -221,33 +259,16 @@
     }
 
 
-    protected String createFactoryConfiguration( String factoryPid )
-    {
-        ConfigurationAdmin ca = getConfigurationAdmin();
-        try
-        {
-            org.osgi.service.cm.Configuration config = ca.createFactoryConfiguration( factoryPid, null );
-            config.update( theConfig );
-            return config.getPid();
-        }
-        catch ( IOException ioe )
-        {
-            TestCase.fail( "Failed updating factory configuration " + factoryPid + ": " + ioe.toString() );
-            return null;
-        }
-    }
-
-
     protected void deleteFactoryConfigurations( String factoryPid )
     {
         ConfigurationAdmin ca = getConfigurationAdmin();
         try
         {
             final String filter = "(service.factoryPid=" + factoryPid + ")";
-            org.osgi.service.cm.Configuration[] configs = ca.listConfigurations( filter );
+            Configuration[] configs = ca.listConfigurations( filter );
             if ( configs != null )
             {
-                for ( org.osgi.service.cm.Configuration configuration : configs )
+                for ( Configuration configuration : configs )
                 {
                     configuration.delete();
                 }
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/MultiServiceFactoryPIDTest.java b/configadmin/src/test/java/org/apache/felix/cm/integration/MultiServiceFactoryPIDTest.java
new file mode 100644
index 0000000..2d09b54
--- /dev/null
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/MultiServiceFactoryPIDTest.java
@@ -0,0 +1,271 @@
+/*
+ * 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.cm.integration;
+
+
+import junit.framework.TestCase;
+
+import org.apache.felix.cm.integration.helper.ManagedServiceFactoryTestActivator;
+import org.apache.felix.cm.integration.helper.ManagedServiceFactoryTestActivator2;
+import org.apache.felix.cm.integration.helper.MultiManagedServiceFactoryTestActivator;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.service.cm.Configuration;
+
+
+/**
+ * The <code>MultiServicePIDTest</code> tests the case of multiple services
+ * bound with the same PID
+ */
+@RunWith(JUnit4TestRunner.class)
+public class MultiServiceFactoryPIDTest extends ConfigurationTestBase
+{
+
+    @Test
+    public void test_two_services_same_pid_in_same_bundle_configure_before_registration() throws BundleException
+    {
+        final String factoryPid = "test.pid";
+
+        final Configuration config = createFactoryConfiguration( factoryPid );
+        final String pid = config.getPid();
+        TestCase.assertEquals( factoryPid, config.getFactoryPid() );
+        TestCase.assertNull( config.getBundleLocation() );
+
+        bundle = installBundle( factoryPid, MultiManagedServiceFactoryTestActivator.class );
+        bundle.start();
+
+        // give cm time for distribution
+        delay();
+
+        final MultiManagedServiceFactoryTestActivator tester = MultiManagedServiceFactoryTestActivator.INSTANCE;
+        TestCase.assertNotNull( "Activator not started !!", tester );
+
+        // assert activater has configuration (two calls, one per pid)
+        TestCase.assertNotNull( "Expect Properties after Service Registration", tester.configs.get( pid ) );
+        TestCase.assertEquals( "Expect a single update call", 2, tester.numManagedServiceFactoryUpdatedCalls );
+
+        TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );
+
+        bundle.uninstall();
+        bundle = null;
+
+        delay();
+
+        TestCase.assertNull( config.getBundleLocation() );
+
+        // remove the configuration for good
+        deleteConfig( pid );
+    }
+
+
+    @Test
+    public void test_two_services_same_pid_in_same_bundle_configure_after_registration() throws BundleException
+    {
+        final String factoryPid = "test.pid";
+
+        bundle = installBundle( factoryPid, MultiManagedServiceFactoryTestActivator.class );
+        bundle.start();
+
+        // give cm time for distribution
+        delay();
+
+        final MultiManagedServiceFactoryTestActivator tester = MultiManagedServiceFactoryTestActivator.INSTANCE;
+        TestCase.assertNotNull( "Activator not started !!", tester );
+
+        // no configuration yet
+        TestCase.assertTrue( "Expect Properties after Service Registration", tester.configs.isEmpty() );
+        TestCase.assertEquals( "Expect two update calls", 0, tester.numManagedServiceFactoryUpdatedCalls );
+
+        final Configuration config = createFactoryConfiguration( factoryPid );
+        final String pid = config.getPid();
+
+        delay();
+
+        TestCase.assertEquals( factoryPid, config.getFactoryPid() );
+        TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );
+
+        // assert activater has configuration (two calls, one per pid)
+        TestCase.assertNotNull( "Expect Properties after Service Registration", tester.configs.get( pid ) );
+        TestCase.assertEquals( "Expect another two single update call", 2, tester.numManagedServiceFactoryUpdatedCalls );
+
+        bundle.uninstall();
+        bundle = null;
+
+        delay();
+
+        TestCase.assertNull( config.getBundleLocation() );
+
+        // remove the configuration for good
+        deleteConfig( pid );
+    }
+
+
+    @Test
+    public void test_two_services_same_pid_in_two_bundle_configure_before_registration() throws BundleException
+    {
+        Bundle bundle2 = null;
+        try
+        {
+            final String factoryPid = "test.pid";
+            final Configuration config = createFactoryConfiguration( factoryPid );
+            final String pid = config.getPid();
+
+            TestCase.assertEquals( factoryPid, config.getFactoryPid() );
+            TestCase.assertNull( config.getBundleLocation() );
+
+            bundle = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class );
+            bundle.start();
+
+            bundle2 = installBundle( factoryPid, ManagedServiceFactoryTestActivator2.class );
+            bundle2.start();
+
+            // give cm time for distribution
+            delay();
+
+            final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
+            TestCase.assertNotNull( "Activator not started !!", tester );
+
+            final ManagedServiceFactoryTestActivator2 tester2 = ManagedServiceFactoryTestActivator2.INSTANCE;
+            TestCase.assertNotNull( "Activator 2 not started !!", tester2 );
+
+            // expect first activator to have received properties
+
+            // assert first bundle has configuration (two calls, one per srv)
+            TestCase.assertNotNull( "Expect Properties after Service Registration", tester.configs.get( pid ) );
+            TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceFactoryUpdatedCalls );
+
+            // assert second bundle has no configuration
+            TestCase.assertTrue( tester2.configs.isEmpty() );
+            TestCase.assertEquals( 0, tester2.numManagedServiceFactoryUpdatedCalls );
+
+            // expect configuration bound to first bundle
+            TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );
+
+            bundle.uninstall();
+            bundle = null;
+
+            delay();
+
+            TestCase.assertNull( config.getBundleLocation() );
+
+            // remove the configuration for good
+            deleteConfig( pid );
+        }
+        finally
+        {
+            if ( bundle2 != null )
+            {
+                bundle2.uninstall();
+            }
+        }
+    }
+
+
+    @Test
+    public void test_two_services_same_pid_in_two_bundle_configure_after_registration() throws BundleException
+    {
+        Bundle bundle2 = null;
+        try
+        {
+            final String factoryPid = "test.pid";
+
+            bundle = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class );
+            bundle.start();
+
+            bundle2 = installBundle( factoryPid, ManagedServiceFactoryTestActivator2.class );
+            bundle2.start();
+
+            final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
+            TestCase.assertNotNull( "Activator not started !!", tester );
+
+            final ManagedServiceFactoryTestActivator2 tester2 = ManagedServiceFactoryTestActivator2.INSTANCE;
+            TestCase.assertNotNull( "Activator not started !!", tester2 );
+
+            delay();
+
+            // expect no configuration but a call in each service
+            TestCase.assertTrue( "Expect Properties after Service Registration", tester.configs.isEmpty() );
+            TestCase.assertEquals( "Expect a single update call", 0, tester.numManagedServiceFactoryUpdatedCalls );
+            TestCase.assertTrue( "Expect Properties after Service Registration", tester2.configs.isEmpty() );
+            TestCase.assertEquals( "Expect a single update call", 0, tester2.numManagedServiceFactoryUpdatedCalls );
+
+            final Configuration config = createFactoryConfiguration( factoryPid );
+            final String pid = config.getPid();
+
+            delay();
+
+            TestCase.assertEquals( factoryPid, config.getFactoryPid() );
+            TestCase.assertNotNull( config.getBundleLocation() );
+
+            if ( bundle.getLocation().equals( config.getBundleLocation() ) )
+            {
+                // configuration assigned to the first bundle
+                TestCase.assertNotNull( "Expect Properties after Service Registration", tester.configs.get( pid ) );
+                TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceFactoryUpdatedCalls );
+
+                TestCase.assertTrue( "Expect Properties after Service Registration", tester2.configs.isEmpty() );
+                TestCase.assertEquals( "Expect a single update call", 0, tester2.numManagedServiceFactoryUpdatedCalls );
+
+                bundle.uninstall();
+                bundle = null;
+
+                delay();
+
+                TestCase.assertNull( config.getBundleLocation() );
+            }
+            else if ( bundle2.getLocation().equals( config.getBundleLocation() ) )
+            {
+                // configuration assigned to the second bundle
+                // assert activater has configuration (two calls, one per pid)
+                TestCase.assertNotNull( "Expect Properties after Service Registration", tester2.configs.get( pid ) );
+                TestCase.assertEquals( "Expect a single update call", 1, tester2.numManagedServiceFactoryUpdatedCalls );
+
+                TestCase.assertTrue( "Expect Properties after Service Registration", tester.configs.isEmpty() );
+                TestCase.assertEquals( "Expect a single update call", 0, tester.numManagedServiceFactoryUpdatedCalls );
+
+                bundle2.uninstall();
+                bundle2 = null;
+
+                delay();
+
+                // really ??
+                TestCase.assertNull( config.getBundleLocation() );
+            }
+            else
+            {
+                // configuration assigned to some other bundle ... fail
+                TestCase.fail( "Configuration assigned to unexpected bundle " + config.getBundleLocation() );
+            }
+
+            // remove the configuration for good
+            deleteConfig( pid );
+        }
+        finally
+        {
+            if ( bundle2 != null )
+            {
+                bundle2.uninstall();
+            }
+        }
+    }
+
+}
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/MultiServicePIDTest.java b/configadmin/src/test/java/org/apache/felix/cm/integration/MultiServicePIDTest.java
new file mode 100644
index 0000000..d69e509
--- /dev/null
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/MultiServicePIDTest.java
@@ -0,0 +1,272 @@
+/*
+ * 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.cm.integration;
+
+
+import junit.framework.TestCase;
+
+import org.apache.felix.cm.integration.helper.ManagedServiceTestActivator;
+import org.apache.felix.cm.integration.helper.ManagedServiceTestActivator2;
+import org.apache.felix.cm.integration.helper.MultiManagedServiceTestActivator;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.service.cm.Configuration;
+
+
+/**
+ * The <code>MultiServicePIDTest</code> tests the case of multiple services
+ * bound with the same PID
+ */
+@RunWith(JUnit4TestRunner.class)
+public class MultiServicePIDTest extends ConfigurationTestBase
+{
+
+    @Test
+    public void test_two_services_same_pid_in_same_bundle_configure_before_registration() throws BundleException
+    {
+        final String pid = "test.pid";
+
+        configure( pid );
+
+        final Configuration config = getConfiguration( pid );
+        TestCase.assertEquals( pid, config.getPid() );
+        TestCase.assertNull( config.getBundleLocation() );
+
+        bundle = installBundle( pid, MultiManagedServiceTestActivator.class );
+        bundle.start();
+
+        // give cm time for distribution
+        delay();
+
+        final MultiManagedServiceTestActivator tester = MultiManagedServiceTestActivator.INSTANCE;
+        TestCase.assertNotNull( "Activator not started !!", tester );
+
+        // assert activater has configuration (two calls, one per pid)
+        TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
+        TestCase.assertEquals( "Expect a single update call", 2, tester.numManagedServiceUpdatedCalls );
+
+        TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );
+
+        bundle.uninstall();
+        bundle = null;
+
+        delay();
+
+        TestCase.assertNull( config.getBundleLocation() );
+
+        // remove the configuration for good
+        deleteConfig( pid );
+    }
+
+
+    @Test
+    public void test_two_services_same_pid_in_same_bundle_configure_after_registration() throws BundleException
+    {
+        final String pid = "test.pid";
+
+        bundle = installBundle( pid, MultiManagedServiceTestActivator.class );
+        bundle.start();
+
+        // give cm time for distribution
+        delay();
+
+        final MultiManagedServiceTestActivator tester = MultiManagedServiceTestActivator.INSTANCE;
+        TestCase.assertNotNull( "Activator not started !!", tester );
+
+        // no configuration yet
+        TestCase.assertNull( "Expect Properties after Service Registration", tester.props );
+        TestCase.assertEquals( "Expect two update calls", 2, tester.numManagedServiceUpdatedCalls );
+
+        configure( pid );
+        delay();
+
+        final Configuration config = getConfiguration( pid );
+        TestCase.assertEquals( pid, config.getPid() );
+        TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );
+
+        // assert activater has configuration (two calls, one per pid)
+        TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
+        TestCase.assertEquals( "Expect another two single update call", 4, tester.numManagedServiceUpdatedCalls );
+
+        bundle.uninstall();
+        bundle = null;
+
+        delay();
+
+        TestCase.assertNull( config.getBundleLocation() );
+
+        // remove the configuration for good
+        deleteConfig( pid );
+    }
+
+
+    @Test
+    public void test_two_services_same_pid_in_two_bundle_configure_before_registration() throws BundleException
+    {
+        Bundle bundle2 = null;
+        try
+        {
+            final String pid = "test.pid";
+
+            configure( pid );
+
+            final Configuration config = getConfiguration( pid );
+            TestCase.assertEquals( pid, config.getPid() );
+            TestCase.assertNull( config.getBundleLocation() );
+
+            bundle = installBundle( pid, ManagedServiceTestActivator.class );
+            bundle.start();
+
+            bundle2 = installBundle( pid, ManagedServiceTestActivator2.class );
+            bundle2.start();
+
+            // give cm time for distribution
+            delay();
+
+            final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
+            TestCase.assertNotNull( "Activator not started !!", tester );
+
+            final ManagedServiceTestActivator2 tester2 = ManagedServiceTestActivator2.INSTANCE;
+            TestCase.assertNotNull( "Activator 2 not started !!", tester2 );
+
+            // expect first activator to have received properties
+
+            // assert first bundle has configuration (two calls, one per srv)
+            TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
+            TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );
+
+            // assert second bundle has no configuration
+            TestCase.assertNull( tester2.props );
+            TestCase.assertEquals( 0, tester2.numManagedServiceUpdatedCalls );
+
+            // expect configuration bound to first bundle
+            TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );
+
+            bundle.uninstall();
+            bundle = null;
+
+            delay();
+
+            TestCase.assertNull( config.getBundleLocation() );
+
+            // remove the configuration for good
+            deleteConfig( pid );
+        }
+        finally
+        {
+            if ( bundle2 != null )
+            {
+                bundle2.uninstall();
+            }
+        }
+    }
+
+
+    @Test
+    public void test_two_services_same_pid_in_two_bundle_configure_after_registration() throws BundleException
+    {
+        Bundle bundle2 = null;
+        try
+        {
+            final String pid = "test.pid";
+
+            bundle = installBundle( pid, ManagedServiceTestActivator.class );
+            bundle.start();
+
+            bundle2 = installBundle( pid, ManagedServiceTestActivator2.class );
+            bundle2.start();
+
+            final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
+            TestCase.assertNotNull( "Activator not started !!", tester );
+
+            final ManagedServiceTestActivator2 tester2 = ManagedServiceTestActivator2.INSTANCE;
+            TestCase.assertNotNull( "Activator not started !!", tester2 );
+
+            delay();
+
+            // expect no configuration but a call in each service
+            TestCase.assertNull( "Expect Properties after Service Registration", tester.props );
+            TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );
+            TestCase.assertNull( "Expect Properties after Service Registration", tester2.props );
+            TestCase.assertEquals( "Expect a single update call", 1, tester2.numManagedServiceUpdatedCalls );
+
+            configure( pid );
+
+            delay();
+
+            final Configuration config = getConfiguration( pid );
+            TestCase.assertEquals( pid, config.getPid() );
+            TestCase.assertNotNull( config.getBundleLocation() );
+
+            if ( bundle.getLocation().equals( config.getBundleLocation() ) )
+            {
+                // configuration assigned to the first bundle
+                TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
+                TestCase.assertEquals( "Expect a single update call", 2, tester.numManagedServiceUpdatedCalls );
+
+                TestCase.assertNull( "Expect Properties after Service Registration", tester2.props );
+                TestCase.assertEquals( "Expect a single update call", 1, tester2.numManagedServiceUpdatedCalls );
+
+                bundle.uninstall();
+                bundle = null;
+
+                delay();
+
+                TestCase.assertNull( config.getBundleLocation() );
+            }
+            else if ( bundle2.getLocation().equals( config.getBundleLocation() ) )
+            {
+                // configuration assigned to the second bundle
+                // assert activater has configuration (two calls, one per pid)
+                TestCase.assertNotNull( "Expect Properties after Service Registration", tester2.props );
+                TestCase.assertEquals( "Expect a single update call", 2, tester2.numManagedServiceUpdatedCalls );
+
+                TestCase.assertNull( "Expect Properties after Service Registration", tester.props );
+                TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );
+
+                bundle2.uninstall();
+                bundle2 = null;
+
+                delay();
+
+                // really ??
+                TestCase.assertNull( config.getBundleLocation() );
+            }
+            else
+            {
+                // configuration assigned to some other bundle ... fail
+                TestCase.fail( "Configuration assigned to unexpected bundle " + config.getBundleLocation() );
+            }
+
+            // remove the configuration for good
+            deleteConfig( pid );
+        }
+        finally
+        {
+            if ( bundle2 != null )
+            {
+                bundle2.uninstall();
+            }
+        }
+    }
+
+}
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/MultiValuePIDTest.java b/configadmin/src/test/java/org/apache/felix/cm/integration/MultiValuePIDTest.java
index 2999011..e0ed8da 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/integration/MultiValuePIDTest.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/MultiValuePIDTest.java
@@ -21,7 +21,7 @@
 
 import junit.framework.TestCase;
 
-import org.apache.felix.cm.integration.helper.TestActivator;
+import org.apache.felix.cm.integration.helper.ManagedServiceTestActivator;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
@@ -57,12 +57,12 @@
         // give cm time for distribution
         delay();
 
-        final TestActivator tester = TestActivator.INSTANCE;
+        final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
         TestCase.assertNotNull( "Activator not started !!", tester );
 
         // assert activater has configuration (two calls, one per pid)
         TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
-        TestCase.assertEquals( "Expect a single update call", 2, tester.numUpdatedCalls );
+        TestCase.assertEquals( "Expect a single update call", 2, tester.numManagedServiceUpdatedCalls );
 
         TestCase.assertEquals( bundle.getLocation(), config1.getBundleLocation() );
         TestCase.assertEquals( bundle.getLocation(), config2.getBundleLocation() );
@@ -105,12 +105,12 @@
         // give cm time for distribution
         delay();
 
-        final TestActivator tester = TestActivator.INSTANCE;
+        final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
         TestCase.assertNotNull( "Activator not started !!", tester );
 
         // assert activater has configuration (two calls, one per pid)
         TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
-        TestCase.assertEquals( "Expect a single update call", 2, tester.numUpdatedCalls );
+        TestCase.assertEquals( "Expect a single update call", 2, tester.numManagedServiceUpdatedCalls );
 
         TestCase.assertEquals( bundle.getLocation(), config1.getBundleLocation() );
         TestCase.assertEquals( bundle.getLocation(), config2.getBundleLocation() );
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/helper/BaseTestActivator.java b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/BaseTestActivator.java
new file mode 100644
index 0000000..8d5dce6
--- /dev/null
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/BaseTestActivator.java
@@ -0,0 +1,112 @@
+/*
+ * 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.cm.integration.helper;
+
+
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+
+public abstract class BaseTestActivator implements BundleActivator, ManagedService, ManagedServiceFactory
+{
+
+    // the bundle manifest header naming a pid of configurations we require
+    public static final String HEADER_PID = "The-Test-PID";
+
+    public int numManagedServiceUpdatedCalls = 0;
+    public int numManagedServiceFactoryUpdatedCalls = 0;
+    public int numManagedServiceFactoryDeleteCalls = 0;
+
+    public Dictionary props = null;
+
+    public Map<String, Dictionary> configs = new HashMap<String, Dictionary>();
+
+
+    // ---------- ManagedService
+
+    public void updated( Dictionary props )
+    {
+        numManagedServiceUpdatedCalls++;
+        this.props = props;
+    }
+
+
+    // ---------- ManagedServiceFactory
+
+    public String getName()
+    {
+        return getClass().getName();
+    }
+
+
+    public void deleted( String pid )
+    {
+        numManagedServiceFactoryDeleteCalls++;
+        this.configs.remove( pid );
+    }
+
+
+    public void updated( String pid, Dictionary props )
+    {
+        numManagedServiceFactoryUpdatedCalls++;
+        this.configs.put( pid, props );
+    }
+
+
+    protected Dictionary getServiceProperties( BundleContext bundleContext ) throws Exception
+    {
+        final Object prop = bundleContext.getBundle().getHeaders().get( HEADER_PID );
+        if ( prop instanceof String )
+        {
+            final Hashtable props = new Hashtable();
+
+            // multi-value PID support
+            final String pid = ( String ) prop;
+            if ( pid.indexOf( ',' ) > 0 )
+            {
+                final String[] pids = pid.split( "," );
+                props.put( Constants.SERVICE_PID, pids );
+            }
+            else if ( pid.indexOf( ';' ) > 0 )
+            {
+                final String[] pids = pid.split( ";" );
+                props.put( Constants.SERVICE_PID, Arrays.asList( pids ) );
+            }
+            else
+            {
+                props.put( Constants.SERVICE_PID, pid );
+            }
+
+            return props;
+        }
+
+        // missing pid, fail
+        throw new Exception( "Missing " + HEADER_PID + " manifest header, cannot start" );
+    }
+
+}
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator.java b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator.java
new file mode 100644
index 0000000..0301447
--- /dev/null
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator.java
@@ -0,0 +1,43 @@
+/*
+ * 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.cm.integration.helper;
+
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+
+public class ManagedServiceFactoryTestActivator extends BaseTestActivator
+{
+
+    public static ManagedServiceFactoryTestActivator INSTANCE;
+
+
+    public void start( BundleContext context ) throws Exception
+    {
+        context.registerService( ManagedServiceFactory.class.getName(), this, getServiceProperties( context ) );
+        INSTANCE = this;
+    }
+
+
+    public void stop( BundleContext arg0 ) throws Exception
+    {
+        INSTANCE = null;
+    }
+}
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator2.java b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator2.java
new file mode 100644
index 0000000..398cbe9
--- /dev/null
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceFactoryTestActivator2.java
@@ -0,0 +1,42 @@
+/*
+ * 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.cm.integration.helper;
+
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+
+public class ManagedServiceFactoryTestActivator2 extends BaseTestActivator
+{
+    public static ManagedServiceFactoryTestActivator2 INSTANCE;
+
+
+    public void start( BundleContext context ) throws Exception
+    {
+        context.registerService( ManagedServiceFactory.class.getName(), this, getServiceProperties( context ) );
+        INSTANCE = this;
+    }
+
+
+    public void stop( BundleContext arg0 ) throws Exception
+    {
+        INSTANCE = null;
+    }
+}
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceTestActivator.java b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceTestActivator.java
new file mode 100644
index 0000000..0ed1261
--- /dev/null
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceTestActivator.java
@@ -0,0 +1,43 @@
+/*
+ * 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.cm.integration.helper;
+
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ManagedService;
+
+
+public class ManagedServiceTestActivator extends BaseTestActivator
+{
+
+    public static ManagedServiceTestActivator INSTANCE;
+
+
+    public void start( BundleContext context ) throws Exception
+    {
+        context.registerService( ManagedService.class.getName(), this, getServiceProperties( context ) );
+        INSTANCE = this;
+    }
+
+
+    public void stop( BundleContext arg0 ) throws Exception
+    {
+        INSTANCE = null;
+    }
+}
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceTestActivator2.java b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceTestActivator2.java
new file mode 100644
index 0000000..1e95d40
--- /dev/null
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/ManagedServiceTestActivator2.java
@@ -0,0 +1,43 @@
+/*
+ * 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.cm.integration.helper;
+
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ManagedService;
+
+
+public class ManagedServiceTestActivator2 extends BaseTestActivator
+{
+
+    public static ManagedServiceTestActivator2 INSTANCE;
+
+
+    public void start( BundleContext context ) throws Exception
+    {
+        context.registerService( ManagedService.class.getName(), this, getServiceProperties( context ) );
+        INSTANCE = this;
+    }
+
+
+    public void stop( BundleContext arg0 ) throws Exception
+    {
+        INSTANCE = null;
+    }
+}
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/helper/MultiManagedServiceFactoryTestActivator.java b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/MultiManagedServiceFactoryTestActivator.java
new file mode 100644
index 0000000..3b2dd3c
--- /dev/null
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/MultiManagedServiceFactoryTestActivator.java
@@ -0,0 +1,46 @@
+/*
+ * 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.cm.integration.helper;
+
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+
+public class MultiManagedServiceFactoryTestActivator extends ManagedServiceFactoryTestActivator
+{
+
+    public static MultiManagedServiceFactoryTestActivator INSTANCE;
+
+
+    public void start( BundleContext context ) throws Exception
+    {
+        super.start( context );
+        context.registerService( ManagedServiceFactory.class.getName(), this, getServiceProperties( context ) );
+        INSTANCE = this;
+    }
+
+
+    @Override
+    public void stop( BundleContext context ) throws Exception
+    {
+        INSTANCE = null;
+        super.stop( context );
+    }
+}
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/helper/MultiManagedServiceTestActivator.java b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/MultiManagedServiceTestActivator.java
new file mode 100644
index 0000000..ff11dca
--- /dev/null
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/MultiManagedServiceTestActivator.java
@@ -0,0 +1,47 @@
+/*
+ * 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.cm.integration.helper;
+
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ManagedService;
+
+
+public class MultiManagedServiceTestActivator extends ManagedServiceTestActivator
+{
+
+    public static MultiManagedServiceTestActivator INSTANCE;
+
+
+    @Override
+    public void start( BundleContext context ) throws Exception
+    {
+        super.start( context );
+        context.registerService( ManagedService.class.getName(), this, getServiceProperties( context ) );
+        INSTANCE = this;
+    }
+
+
+    @Override
+    public void stop( BundleContext context ) throws Exception
+    {
+        INSTANCE = null;
+        super.stop( context );
+    }
+}
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/helper/TestActivator.java b/configadmin/src/test/java/org/apache/felix/cm/integration/helper/TestActivator.java
deleted file mode 100644
index 501949a..0000000
--- a/configadmin/src/test/java/org/apache/felix/cm/integration/helper/TestActivator.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.cm.integration.helper;
-
-
-import java.util.Arrays;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.service.cm.ManagedService;
-
-
-public class TestActivator implements BundleActivator, ManagedService
-{
-
-    // the bundle manifest header naming a pid of configurations we require
-    public static final String HEADER_PID = "The-Test-PID";
-
-    public static TestActivator INSTANCE = null;
-
-    public int numUpdatedCalls = 0;
-
-    public Dictionary props = null;
-
-
-    public void start( BundleContext context ) throws Exception
-    {
-
-        Object prop = context.getBundle().getHeaders().get( HEADER_PID );
-        if ( prop instanceof String )
-        {
-            Hashtable props = new Hashtable();
-
-            // multi-value PID support
-            String pid = ( String ) prop;
-            if ( pid.indexOf( ',' ) > 0 )
-            {
-                String[] pids = pid.split( "," );
-                props.put( Constants.SERVICE_PID, pids );
-            }
-            else if ( pid.indexOf( ';' ) > 0 )
-            {
-                String[] pids = pid.split( ";" );
-                props.put( Constants.SERVICE_PID, Arrays.asList( pids ) );
-            }
-            else
-            {
-                props.put( Constants.SERVICE_PID, pid );
-            }
-
-            context.registerService( ManagedService.class.getName(), this, props );
-        }
-        else
-        {
-            // missing pid, fail
-            throw new Exception( "Missing " + HEADER_PID + " manifest header, cannot start" );
-        }
-
-        INSTANCE = this;
-    }
-
-
-    public void stop( BundleContext context ) throws Exception
-    {
-        INSTANCE = null;
-    }
-
-
-    public void updated( Dictionary props )
-    {
-        numUpdatedCalls++;
-        this.props = props;
-    }
-
-}