Split the composite test suite
Add the annotation test suite (checking annotations processing)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@652169 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instance/SimpleInstance.java b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instance/SimpleInstance.java
new file mode 100644
index 0000000..179c296
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instance/SimpleInstance.java
@@ -0,0 +1,268 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.composite.instance;

+

+import java.util.Properties;

+

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

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

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

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

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

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

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

+import org.apache.felix.ipojo.test.composite.service.FooService;

+import org.apache.felix.ipojo.test.composite.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class SimpleInstance extends OSGiTestCase {

+

+	private ComponentFactory fooFactory1, fooFactory2;

+    private ComponentFactory compoFactory;

+	private ComponentInstance empty;

+	

+	

+	public void setUp() {

+        fooFactory1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooProviderType-1");

+        fooFactory2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooProviderType-Dyn2");

+        compoFactory = (ComponentFactory) Utils.getFactoryByName(context, "composite.inst.1");

+		Factory fact = Utils.getFactoryByName(context, "composite.empty");

+		Properties props = new Properties();

+		props.put("name", "empty-X");

+		try {

+			empty = fact.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot create the empty composite : " + e.getMessage());

+		}

+	}

+	

+	public void tearDown() {

+		empty.dispose();

+		empty = null;

+	}

+	

+	public void testCreation() {

+		Properties props = new Properties();

+		props.put("name", "under-A");

+		ComponentInstance under = null;

+		try {

+			under = compoFactory.createComponentInstance(props);

+		} catch(Exception e) {

+		    e.printStackTrace();

+			fail("Cannot instantiate under from " + compoFactory.getName() + " -> " + e.getMessage());

+		}      

+		

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		under.dispose();

+	}

+	

+	public void testServiceAvailability() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = compoFactory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}	

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc = Utils.getServiceContext(under);

+       

+		assertNotNull("Check service availability", sc.getServiceReference(FooService.class.getName()));

+        assertEquals("Check service provider", Utils.getServiceReferences(sc, FooService.class.getName(), null).length, 2);

+		

+		under.dispose();

+	}

+	

+	public void testCreationLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = compoFactory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+		    e.printStackTrace();

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		under.dispose();

+	}

+	

+	public void testServiceAvailabilityLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

+		props.put("name", "under-X");

+		ComponentInstance under = null;

+		try {

+			under = compoFactory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}	

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc2 = Utils.getServiceContext(under);

+        

+        assertNotNull("Check service availability", sc2.getServiceReference(FooService.class.getName()));

+        assertEquals("Check service providers", Utils.getServiceReferences(sc2, FooService.class.getName(), null).length, 2);

+		

+		under.dispose();

+	}

+	

+	public void testFactoryManagement() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = compoFactory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+		

+		fooFactory1.stop();

+		assertTrue("Check instance invalidity - 2", under.getState() == ComponentInstance.INVALID);

+        

+        fooFactory1.start();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+        

+		fooFactory2.stop();

+        assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);

+		

+		fooFactory2.start();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		

+		under.dispose();

+		fooFactory1.start();

+		fooFactory2.start();

+	}

+	

+	public void testFactoryManagementLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = compoFactory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+		

+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+        

+        fooFactory1.stop();

+        assertTrue("Check instance invalidity - 2", under.getState() == ComponentInstance.INVALID);

+        

+        fooFactory1.start();

+        assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+        

+        fooFactory2.stop();

+        assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);

+        

+        fooFactory2.start();

+        assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+        

+        under.dispose();

+        fooFactory1.start();

+        fooFactory2.start();

+	}

+	

+	public void atestArchitecture() { //TODO : to reactive

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = compoFactory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		ServiceReference ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		Architecture arch = (Architecture) context.getService(ref);

+		InstanceDescription id = arch.getInstanceDescription();

+		

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		InstanceDescription[] contained = id.getContainedInstances();

+		assertEquals("Check contained instances count (" + contained.length + ")", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");

+

+		fact3.stop();

+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.INVALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 0);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");

+

+		fact1.start();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");

+

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+

+}

diff --git a/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/ConfigurableInstantiation.java b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/ConfigurableInstantiation.java
new file mode 100644
index 0000000..2c851ea
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/ConfigurableInstantiation.java
@@ -0,0 +1,103 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.composite.instantiator;

+

+import java.util.Properties;

+

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

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

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

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

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

+import org.apache.felix.ipojo.test.composite.service.FooService;

+import org.apache.felix.ipojo.test.composite.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class ConfigurableInstantiation extends OSGiTestCase {

+

+	private ComponentFactory acceptF;

+	private ComponentFactory refuse1F;

+	private ComponentFactory refuse2F;

+	

+	public void setUp() {

+		acceptF = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.5-accept");

+		refuse1F = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.5-refuse1");

+		refuse2F = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.5-refuse2");

+		

+	}

+	

+	public void tearDown() { }

+	

+	public void testAccept() {

+		Properties props = new Properties();

+		props.put("name", "under-A");

+		ComponentInstance under = null;

+		try {

+			under = acceptF.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc = Utils.getServiceContext(under);

+		ServiceReference ref = sc.getServiceReference(FooService.class.getName());

+		assertNotNull("Check refs not null", ref);

+		FooService foo = (FooService) sc.getService(ref);

+		Properties p = foo.fooProps();

+		boolean b = ((Boolean) p.get("boolProp")).booleanValue();

+		String s = (String) p.get("strProp");

+		int i = ( (Integer) p.get("intProp")).intValue();

+		assertTrue("Test boolean", b);

+		assertEquals("Test string", s, "foo");

+		

+		assertEquals("Test int", i, 5); // The code fix to 5.

+		under.dispose();

+	}

+	

+	public void testRefuse1() {

+		Properties props = new Properties();

+		props.put("name", "under-ref1");

+		ComponentInstance under = null;

+		try {

+			under = refuse1F.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		

+		assertTrue("Check that under is not valid", under.getState() == ComponentInstance.INVALID);

+        

+        under.dispose();

+	}

+	

+	public void testRefuse2() {

+		Properties props = new Properties();

+		props.put("name", "under-ref2");

+		ComponentInstance under = null;

+		try {

+			under = refuse2F.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		

+		assertTrue("Check that under is not valid", under.getState() == ComponentInstance.INVALID);

+        

+        under.dispose();

+	}

+	

+}

diff --git a/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/InstantiatorTestSuite.java b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/InstantiatorTestSuite.java
new file mode 100644
index 0000000..796bb62
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/InstantiatorTestSuite.java
@@ -0,0 +1,40 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.composite.instantiator;

+

+import junit.framework.Test;

+

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

+import org.apache.felix.ipojo.test.composite.instance.SimpleInstance;

+import org.osgi.framework.BundleContext;

+

+public class InstantiatorTestSuite {

+

+	public static Test suite(BundleContext bc) {

+		OSGiTestSuite ots = new OSGiTestSuite("Composite Service Instantiation Test Suite", bc);

+		ots.addTestSuite(SimpleInstantiation.class);

+		ots.addTestSuite(OptionalInstantiation.class);

+		ots.addTestSuite(MultipleInstantiation.class);

+		ots.addTestSuite(OptionalMultipleInstantiation.class);

+		ots.addTestSuite(ConfigurableInstantiation.class);

+		ots.addTestSuite(SimpleInstance.class);

+		return ots;

+	}

+

+}

diff --git a/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/MultipleInstantiation.java b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/MultipleInstantiation.java
new file mode 100644
index 0000000..f155add
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/MultipleInstantiation.java
@@ -0,0 +1,288 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.composite.instantiator;

+

+import java.util.Properties;

+

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

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

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

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

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

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

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

+import org.apache.felix.ipojo.test.composite.service.BarService;

+import org.apache.felix.ipojo.test.composite.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class MultipleInstantiation extends OSGiTestCase {

+

+	private ComponentFactory bar2Factory;

+	private ComponentInstance empty;

+	

+	public void setUp() {

+		bar2Factory = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.2");

+		Factory fact = Utils.getFactoryByName(context, "composite.empty");

+		Properties props = new Properties();

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

+		try {

+			empty = fact.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot create the empty composite : " + e.getMessage());

+		}

+	}

+	

+	public void tearDown() {

+		empty.dispose();

+		empty = null;

+	}

+	

+	public void testCreation() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		under.dispose();

+	}

+	

+	public void testServiceAvailability() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}	

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc = Utils.getServiceContext(under);

+		assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));

+		int count = Utils.getServiceReferences(sc, BarService.class.getName(), null).length;

+		assertEquals("Check service provider number : " + count, count, 3);

+		

+		under.dispose();

+	}

+	

+	public void testCreationLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		under.dispose();

+	}

+	

+	public void testServiceAvailabilityLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}	

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc2 = Utils.getServiceContext(under);

+		assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 3);

+		

+		under.dispose();

+	}

+	

+	public void testFactoryManagement() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		ServiceContext sc = Utils.getServiceContext(under);

+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 2);

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 1);

+		

+		fact3.stop();

+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 0);

+		

+		fact1.start();

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 1);

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+	

+	public void testFactoryManagementLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc2 = Utils.getServiceContext(under);

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 2);

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);

+		

+		fact3.stop();

+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 0);

+		

+		fact1.start();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);

+		

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+	public void testArchitecture() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		ServiceReference ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		Architecture arch = (Architecture) context.getService(ref);

+		InstanceDescription id = arch.getInstanceDescription();

+		

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		InstanceDescription[] contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 3);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.2");

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 2);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.2");

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.2");

+

+		fact3.stop();

+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.INVALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 0);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.2");

+

+		fact1.start();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.2");

+

+		context.ungetService(ref);

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+	

+	

+	

+	

+	

+	

+	

+	

+	

+	

+	

+	

+

+}

diff --git a/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalInstantiation.java b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalInstantiation.java
new file mode 100644
index 0000000..e617d64
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalInstantiation.java
@@ -0,0 +1,279 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.composite.instantiator;

+

+import java.util.Properties;

+

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

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

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

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

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

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

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

+import org.apache.felix.ipojo.test.composite.service.BarService;

+import org.apache.felix.ipojo.test.composite.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class OptionalInstantiation extends OSGiTestCase {

+

+	private ComponentFactory bar1Factory;

+	private ComponentInstance empty;

+	

+	public void setUp() {

+		bar1Factory = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.3");

+		Factory fact = Utils.getFactoryByName(context, "composite.empty");

+		Properties props = new Properties();

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

+		try {

+			empty = fact.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot create the empty composite : " + e.getMessage());

+		}

+	}

+	

+	public void tearDown() {

+		empty.dispose();

+		empty = null;

+	}

+	

+	public void testCreation() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		under.dispose();

+	}

+	

+	public void testServiceAvailability() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}	

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc = Utils.getServiceContext(under);

+		assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));

+		

+		under.dispose();

+	}

+	

+	public void testCreationLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		under.dispose();

+	}

+	

+	public void testServiceAvailabilityLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}	

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc2 = Utils.getServiceContext(under);

+		assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));

+		

+		under.dispose();

+	}

+	

+	public void testFactoryManagement() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		

+		fact3.stop();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc = Utils.getServiceContext(under);

+		assertNull("Check that no Bar Service is available", sc.getServiceReference(BarService.class.getName()));

+		

+		fact1.start();

+		assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);

+		

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+	

+	public void testFactoryManagementLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		

+		fact3.stop();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		

+		fact1.start();

+		assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);

+		

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+	

+	public void testArchitecture() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		

+		ServiceReference ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		Architecture arch = (Architecture) context.getService(ref);

+		assertNotNull("Check architecture", arch);

+		InstanceDescription id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		InstanceDescription[] contained = id.getContainedInstances();

+		assertNotNull("Check contained not null", contained);

+		assertEquals("Check contained instances count ("+contained.length+") - 1", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");

+

+		fact3.stop();

+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 0);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");

+

+		fact1.start();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");

+

+		context.ungetService(ref);

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+	

+	

+	

+	

+	

+	

+	

+	

+	

+	

+

+}

diff --git a/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalMultipleInstantiation.java b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalMultipleInstantiation.java
new file mode 100644
index 0000000..a3d9351
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalMultipleInstantiation.java
@@ -0,0 +1,203 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.composite.instantiator;

+

+import java.util.Properties;

+

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

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

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

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

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

+import org.apache.felix.ipojo.test.composite.service.BarService;

+import org.apache.felix.ipojo.test.composite.util.Utils;

+

+public class OptionalMultipleInstantiation extends OSGiTestCase {

+

+	private ComponentFactory bar2Factory;

+	private ComponentInstance empty;

+	

+	public void setUp() {

+		bar2Factory = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.4");

+		assertNotNull("Check bar2factory availability", bar2Factory);

+		

+		Factory fact = Utils.getFactoryByName(context, "composite.empty");

+		Properties props = new Properties();

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

+		try {

+			empty = fact.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot create the empty composite : " + e.getMessage());

+		}

+	}

+	

+	public void tearDown() {

+		empty.dispose();

+		empty = null;

+	}

+	

+	public void testCreation() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		under.dispose();

+	}

+	

+	public void testServiceAvailability() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}	

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc = Utils.getServiceContext(under);

+		assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));

+		int count = Utils.getServiceReferences(sc, BarService.class.getName(), null).length;

+		assertEquals("Check service provider number : " + count, count, 3);

+		

+		under.dispose();

+	}

+	

+	public void testCreationLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		under.dispose();

+	}

+	

+	public void testServiceAvailabilityLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}	

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc2 = Utils.getServiceContext(under);

+		assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 3);

+		

+		under.dispose();

+	}

+	

+	public void testFactoryManagement() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		ServiceContext sc = Utils.getServiceContext(under);

+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 2);

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 1);

+		

+		fact3.stop();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 0);

+		

+		fact1.start();

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 1);

+		assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);

+		

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+	

+	public void testFactoryManagementLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar2Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc2 = Utils.getServiceContext(under);

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 2);

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);

+		

+		fact3.stop();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 0);

+		

+		fact1.start();

+		assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);

+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);

+		

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+	

+	

+	

+	

+	

+	

+	

+	

+	

+	

+

+}

diff --git a/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/SimpleInstantiation.java b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/SimpleInstantiation.java
new file mode 100644
index 0000000..4430c19
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/SimpleInstantiation.java
@@ -0,0 +1,265 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.composite.instantiator;

+

+import java.util.Properties;

+

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

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

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

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

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

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

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

+import org.apache.felix.ipojo.test.composite.service.BarService;

+import org.apache.felix.ipojo.test.composite.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class SimpleInstantiation extends OSGiTestCase {

+

+	private ComponentFactory bar1Factory;

+	private ComponentInstance empty;

+	

+	public void setUp() {

+		bar1Factory = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.1");

+		Factory fact = Utils.getFactoryByName(context, "composite.empty");

+		Properties props = new Properties();

+		props.put("name", "empty-X");

+		try {

+			empty = fact.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot create the empty composite : " + e.getMessage());

+		}

+	}

+	

+	public void tearDown() {

+		empty.dispose();

+		empty = null;

+	}

+	

+	public void testCreation() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props);

+		} catch(Exception e) {

+		    e.printStackTrace();

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		under.dispose();

+	}

+	

+	public void testServiceAvailability() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}	

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc = Utils.getServiceContext(under);

+		assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));

+		

+		under.dispose();

+	}

+	

+	public void testCreationLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		under.dispose();

+	}

+	

+	public void testServiceAvailabilityLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

+		props.put("name", "under-X");

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}	

+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+		ServiceContext sc2 = Utils.getServiceContext(under);

+		assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));

+		

+		under.dispose();

+	}

+	

+	public void testFactoryManagement() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		

+		fact3.stop();

+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);

+		

+		fact1.start();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+	

+	public void testFactoryManagementLevel2() {

+		ServiceContext sc = Utils.getServiceContext(empty);

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props, sc);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		

+		fact3.stop();

+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);

+		

+		fact1.start();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+	

+	public void testArchitecture() {

+		Properties props = new Properties();

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

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		ServiceReference ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		Architecture arch = (Architecture) context.getService(ref);

+		InstanceDescription id = arch.getInstanceDescription();

+		

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		InstanceDescription[] contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");

+		

+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");

+		

+		fact2.stop();

+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");

+

+		fact3.stop();

+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.INVALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 0);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");

+

+		fact1.start();

+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) context.getService(ref);

+		id = arch.getInstanceDescription();

+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);

+		contained = id.getContainedInstances();

+		assertEquals("Check contained instances count", contained.length, 1);

+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);

+		assertEquals("Check instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");

+

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+

+}

diff --git a/ipojo/tests/tests.composite.service.instance/src/main/resources/metadata.xml b/ipojo/tests/tests.composite.service.instance/src/main/resources/metadata.xml
new file mode 100644
index 0000000..dc1c764
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.instance/src/main/resources/metadata.xml
@@ -0,0 +1,54 @@
+<ipojo xmlns:cs="org.apache.felix.ipojo.test.composite.handler.CheckServiceHandler">	

+	<composite name="composite.bar.1" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService"/>

+	</composite>

+	

+	<composite name="composite.bar.2" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService" aggregate="true"/>

+	</composite>

+	

+	<composite name="composite.bar.3" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService" optional="true"/>

+	</composite>

+	

+	<composite name="composite.bar.4" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.FooService" aggregate="true" optional="true"/>

+	</composite>

+	

+	<composite name="composite.bar.5-accept" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.FooService">

+			<property name="boolean" value="true"/>

+			<property name="string" value="foo"/>

+			<property name="strAprop" value="{foo, bar, baz}"/>

+			<property name="int" value="5"/>

+		</subservice>

+	</composite>

+	

+	<composite name="composite.bar.5-refuse1" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService">

+			<property name="foo" value="bar"/>

+			<property name="boolean" value="true"/>

+			<property name="string" value="foo"/>

+			<property name="strAprop" value="{foo, bar, baz}"/>

+			<property name="int" value="5"/>

+		</subservice>

+	</composite>

+	

+	<composite name="composite.bar.5-refuse2" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService">

+			<property name="string" value="foo"/>

+			<property name="strAprop" value="{foo, bar, baz}"/>

+		</subservice>

+	</composite>

+

+    <!-- Instance of a specified component -->

+	<composite name="composite.inst.1" factory="true" architecture="true">

+		<instance component="COMPO-FooProviderType-1" /> <!-- name="FooProv"  -->

+		<instance component="COMPO-FooProviderType-Dyn2">

+			<property name="boolean" value="true"/>

+			<property name="string" value="foo"/>

+			<property name="strAProp" value="{a,b,c}"/>

+		</instance>

+	</composite>

+

+</ipojo>