You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2008/04/25 18:50:22 UTC

svn commit: r651646 [12/22] - in /felix/trunk/ipojo/tests: ./ tests.composite/ tests.composite/src/ tests.composite/src/main/ tests.composite/src/main/java/ tests.composite/src/main/java/org/ tests.composite/src/main/java/org/apache/ tests.composite/sr...

Added: felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DelayedSimpleDependencies.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DelayedSimpleDependencies.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DelayedSimpleDependencies.java (added)
+++ felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DelayedSimpleDependencies.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,261 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.dependency;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+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.scenarios.service.dependency.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+public class DelayedSimpleDependencies extends OSGiTestCase {
+	
+	ComponentInstance instance1, instance2, instance3, instance4, instance5;
+	ComponentInstance fooProvider;
+	
+	
+	public void setUp() {
+		try {
+			Properties prov = new Properties();
+			prov.put("name", "FooProvider");
+			fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+		
+			Properties i1 = new Properties();
+			i1.put("name", "Simple");
+			instance1 = Utils.getFactoryByName(context, "SimpleCheckServiceProvider").createComponentInstance(i1);
+			instance1.stop();
+		
+			Properties i2 = new Properties();
+			i2.put("name", "Void");
+			instance2 = Utils.getFactoryByName(context, "VoidCheckServiceProvider").createComponentInstance(i2);
+			instance2.stop();
+		
+			Properties i3 = new Properties();
+			i3.put("name", "Object");
+			instance3 = Utils.getFactoryByName(context, "ObjectCheckServiceProvider").createComponentInstance(i3);
+			instance3.stop();
+		
+			Properties i4 = new Properties();
+			i4.put("name", "Ref");
+			instance4 = Utils.getFactoryByName(context, "RefCheckServiceProvider").createComponentInstance(i4);
+			instance4.stop();
+			
+			Properties i5 = new Properties();
+            i5.put("name", "Both");
+            instance5 = Utils.getFactoryByName(context, "BothCheckServiceProvider").createComponentInstance(i5);
+            instance5.stop();
+		} catch(Exception e) { fail(e.getMessage()); } 
+		
+	}
+	
+	public void tearDown() {
+		instance1.dispose();
+		instance2.dispose();
+		instance3.dispose();
+		instance4.dispose();
+		instance5.dispose();
+		fooProvider.dispose();
+		instance1 = null;
+		instance2 = null;
+		instance3 = null;
+		instance4 = null;
+		instance4 = null;
+		instance5 = null;
+		fooProvider = null;
+	}
+	
+	public void testSimple() {
+		instance1.start();
+		ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ref);
+		InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		CheckService cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		fooProvider.stop();
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+		fooProvider.start();
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+		cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		fooProvider.stop();
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+		id = null;
+		cs = null;
+		context.ungetService(arch_ref);
+		context.ungetService(cs_ref);
+		instance1.stop();
+	}
+	
+	public void testVoid() {
+		instance2.start();
+		ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ref);
+		InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();		
+		assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+		
+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		CheckService cs = (CheckService) context.getService(cs_ref);
+		Properties props = cs.getProps();
+		//Check properties
+		assertTrue("check CheckService invocation -1", ((Boolean)props.get("result")).booleanValue());
+		assertEquals("check void bind invocation -1", ((Integer)props.get("voidB")).intValue(), 1);
+		assertEquals("check void unbind callback invocation -1", ((Integer)props.get("voidU")).intValue(), 0);
+		assertEquals("check object bind callback invocation -1", ((Integer)props.get("objectB")).intValue(), 0);
+		assertEquals("check object unbind callback invocation -1", ((Integer)props.get("objectU")).intValue(), 0);
+		assertEquals("check ref bind callback invocation -1", ((Integer)props.get("refB")).intValue(), 0);
+		assertEquals("check ref unbind callback invocation -1", ((Integer)props.get("refU")).intValue(), 0);
+	    assertEquals("check both bind callback invocation -1", ((Integer)props.get("bothB")).intValue(), 0);
+	    assertEquals("check both unbind callback invocation -1", ((Integer)props.get("bothU")).intValue(), 0);
+	        
+		fooProvider.stop();
+		
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+		
+		id = null;
+		cs = null;
+		context.ungetService(arch_ref);
+		context.ungetService(cs_ref);
+		
+		instance2.stop();
+	}
+	
+	public void testObject() {
+		instance3.start();
+		ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ref);
+		InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();		
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+		
+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		CheckService cs = (CheckService) context.getService(cs_ref);
+		Properties props = cs.getProps();
+		//Check properties
+		assertTrue("check CheckService invocation -1", ((Boolean)props.get("result")).booleanValue());
+		assertEquals("check void bind invocation -1", ((Integer)props.get("voidB")).intValue(), 0);
+		assertEquals("check void unbind callback invocation -1", ((Integer)props.get("voidU")).intValue(), 0);
+		assertEquals("check object bind callback invocation -1", ((Integer)props.get("objectB")).intValue(), 1);
+		assertEquals("check object unbind callback invocation -1", ((Integer)props.get("objectU")).intValue(), 0);
+		assertEquals("check ref bind callback invocation -1", ((Integer)props.get("refB")).intValue(), 0);
+		assertEquals("check ref unbind callback invocation -1", ((Integer)props.get("refU")).intValue(), 0);
+	    assertEquals("check both bind callback invocation -1", ((Integer)props.get("bothB")).intValue(), 0);
+	    assertEquals("check both unbind callback invocation -1", ((Integer)props.get("bothU")).intValue(), 0);
+	        
+		fooProvider.stop();
+		
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+		
+		id = null;
+		cs = null;
+		context.ungetService(arch_ref);
+		context.ungetService(cs_ref);
+		
+		instance3.stop();
+	}
+	
+	public void testRef() {
+		instance4.start();
+		ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ref);
+		InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+		
+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		CheckService cs = (CheckService) context.getService(cs_ref);
+		Properties props = cs.getProps();
+		//Check properties
+		assertTrue("check CheckService invocation -1", ((Boolean)props.get("result")).booleanValue());
+		assertEquals("check void bind invocation -1", ((Integer)props.get("voidB")).intValue(), 0);
+		assertEquals("check void unbind callback invocation -1", ((Integer)props.get("voidU")).intValue(), 0);
+		assertEquals("check object bind callback invocation -1", ((Integer)props.get("objectB")).intValue(), 0);
+		assertEquals("check object unbind callback invocation -1", ((Integer)props.get("objectU")).intValue(), 0);
+		assertEquals("check ref bind callback invocation -1", ((Integer)props.get("refB")).intValue(), 1);
+		assertEquals("check ref unbind callback invocation -1", ((Integer)props.get("refU")).intValue(), 0);
+		assertEquals("check both bind callback invocation -1", ((Integer)props.get("bothB")).intValue(), 0);
+        assertEquals("check both unbind callback invocation -1", ((Integer)props.get("bothU")).intValue(), 0);
+		
+		fooProvider.stop();
+		
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+		
+		id = null;
+		cs = null;
+		context.ungetService(arch_ref);
+		context.ungetService(cs_ref);
+		
+		instance4.stop();
+	}
+	
+	public void testBoth() {
+        instance5.start();
+        ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+        assertNotNull("Check architecture availability", arch_ref);
+        InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        
+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+        
+        ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+        assertNotNull("Check CheckService availability", cs_ref);
+        CheckService cs = (CheckService) context.getService(cs_ref);
+        Properties props = cs.getProps();
+        //Check properties
+        assertTrue("check CheckService invocation -1", ((Boolean)props.get("result")).booleanValue());
+        assertEquals("check void bind invocation -1", ((Integer)props.get("voidB")).intValue(), 0);
+        assertEquals("check void unbind callback invocation -1", ((Integer)props.get("voidU")).intValue(), 0);
+        assertEquals("check object bind callback invocation -1", ((Integer)props.get("objectB")).intValue(), 0);
+        assertEquals("check object unbind callback invocation -1", ((Integer)props.get("objectU")).intValue(), 0);
+        assertEquals("check ref bind callback invocation -1", ((Integer)props.get("refB")).intValue(), 0);
+        assertEquals("check ref unbind callback invocation -1", ((Integer)props.get("refU")).intValue(), 0);
+        assertEquals("check both bind callback invocation -1", ((Integer)props.get("bothB")).intValue(), 1);
+        assertEquals("check both unbind callback invocation -1", ((Integer)props.get("bothU")).intValue(), 0);
+        
+        fooProvider.stop();
+        
+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+        
+        id = null;
+        cs = null;
+        context.ungetService(arch_ref);
+        context.ungetService(cs_ref);
+        
+        instance5.stop();
+    }
+
+}

Added: felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyArchitectureTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyArchitectureTest.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyArchitectureTest.java (added)
+++ felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyArchitectureTest.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,601 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.dependency;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription;
+import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+import org.apache.felix.ipojo.test.scenarios.service.dependency.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.dependency.service.FooService;
+
+public class DependencyArchitectureTest extends OSGiTestCase {
+	
+	ComponentInstance fooProvider1, fooProvider2;
+	
+	ComponentInstance instance1, instance2, instance3, instance4;
+	
+	public void setUp() {
+		try {
+			Properties prov = new Properties();
+			prov.put("name", "FooProvider");
+			fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+			fooProvider1.stop();
+		
+			Properties prov2 = new Properties();
+			prov2.put("name", "FooProvider2");
+			fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+			fooProvider2.stop();
+		
+			Properties i1 = new Properties();
+			i1.put("name", "Simple");
+			instance1 = Utils.getFactoryByName(context, "SimpleCheckServiceProvider").createComponentInstance(i1);
+		
+			Properties i2 = new Properties();
+			i2.put("name", "Optional");
+			instance2 = Utils.getFactoryByName(context, "SimpleOptionalCheckServiceProvider").createComponentInstance(i2);
+		
+			Properties i3 = new Properties();
+			i3.put("name", "Multiple");
+			instance3 = Utils.getFactoryByName(context, "SimpleMultipleCheckServiceProvider").createComponentInstance(i3);
+		
+			Properties i4 = new Properties();
+			i4.put("name", "OptionalMultiple");
+			instance4 = Utils.getFactoryByName(context, "SimpleOptionalMultipleCheckServiceProvider").createComponentInstance(i4);
+		} catch(Exception e) {
+			throw new RuntimeException(e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		instance1.dispose();
+		instance2.dispose();
+		instance3.dispose();
+		instance4.dispose();
+		fooProvider1.dispose();
+		fooProvider2.dispose();
+		instance1 = null;
+		instance2 = null;
+		instance3 = null;
+		instance4 = null;
+		fooProvider1 = null;
+		fooProvider2 = null;
+	}
+	
+	private DependencyHandlerDescription getDependencyDesc(InstanceDescription id) {
+		for(int i = 0; i < id.getHandlers().length; i++) {
+			if(id.getHandlers()[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.dependency.DependencyHandler")) {
+				return (DependencyHandlerDescription) id.getHandlers()[i];
+			}
+		}
+		fail("Dependency Handler not found");
+		return null;
+	}
+	
+	private ProvidedServiceHandlerDescription getPSDesc(InstanceDescription id) {
+		for(int i = 0; i < id.getHandlers().length; i++) {
+			if(id.getHandlers()[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler")) {
+				return (ProvidedServiceHandlerDescription) id.getHandlers()[i];
+			}
+		}
+		fail("Provided Service Handler not found");
+		return null;
+	}
+	
+	public void testSimpleDependency() {
+		ServiceReference arch_dep = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+		assertNotNull("Check architecture availability", arch_dep);
+		InstanceDescription id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
+		
+		// Check dependency handler invalidity
+		DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
+		assertFalse("Check dependency handler invalidity", dhd.isValid());
+		
+		// Check dependency metadata
+		assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
+		assertFalse("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
+		assertFalse("Check dependency optionality", dhd.getDependencies()[0].isOptional());
+		assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
+		
+		fooProvider1.start();
+		
+		ServiceReference arch_ps = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps);
+		InstanceDescription id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);				
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+		
+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		CheckService cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+		ProvidedServiceHandlerDescription psh = getPSDesc(id_ps);
+		assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+		assertEquals("Check POJO creation", id_ps.getCreatedObjects().length, 1);
+		assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+		
+		fooProvider1.stop();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
+		dhd = getDependencyDesc(id_dep);
+		assertFalse("Check dependency handler invalidity", dhd.isValid());
+		
+		fooProvider1.start();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		arch_ps = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps);
+		id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
+		psh = getPSDesc(id_ps);
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		
+		assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+		
+		cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph 
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+		psh = getPSDesc(id_ps);
+		assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+		assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+		
+		fooProvider1.stop();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
+		dhd = getDependencyDesc(id_dep);
+		assertFalse("Check dependency handler invalidity", dhd.isValid());
+		
+		id_dep = null;
+		cs = null;
+		context.ungetService(arch_dep);
+		context.ungetService(cs_ref);
+	}
+	
+	public void testOptionalDependency() {
+		ServiceReference arch_dep = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+		assertNotNull("Check architecture availability", arch_dep);
+		InstanceDescription id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.VALID);
+		
+		// Check dependency handler invalidity
+		DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler invalidity", dhd.isValid());
+		
+		// Check dependency metadata
+		assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
+		assertFalse("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
+		assertTrue("Check dependency optionality", dhd.getDependencies()[0].isOptional());
+		assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
+		
+		fooProvider1.start();
+		
+		ServiceReference arch_ps = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps);
+		InstanceDescription id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);				
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+		
+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		CheckService cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+		ProvidedServiceHandlerDescription psh = getPSDesc(id_ps);
+		assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+		assertEquals("Check POJO creation", id_ps.getCreatedObjects().length, 1);
+		assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+		
+		fooProvider1.stop();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler invalidity", dhd.isValid());
+		
+		fooProvider1.start();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		arch_ps = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps);
+		id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
+		psh = getPSDesc(id_ps);
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		
+		assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+		
+		cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph 
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+		psh = getPSDesc(id_ps);
+		assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+		assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+		
+		fooProvider1.stop();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler invalidity", dhd.isValid());
+		
+		id_dep = null;
+		cs = null;
+		context.ungetService(arch_dep);
+		context.ungetService(cs_ref);
+	}
+	
+	public void testMultipleDependency() {
+		ServiceReference arch_dep = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+		assertNotNull("Check architecture availability", arch_dep);
+		InstanceDescription id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
+		
+		// Check dependency handler invalidity
+		DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
+		assertFalse("Check dependency handler invalidity", dhd.isValid());
+		
+		// Check dependency metadata
+		assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
+		assertTrue("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
+		assertFalse("Check dependency optionality", dhd.getDependencies()[0].isOptional());
+		assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
+		
+		fooProvider1.start();
+		
+		ServiceReference arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps1);
+		InstanceDescription id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		assertTrue("Check instance validity - 1", id_ps1.getState() == ComponentInstance.VALID);				
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+		assertEquals("Check used ref - 1 (" + dhd.getDependencies()[0].getUsedServices().size() + ")", dhd.getDependencies()[0].getUsedServices().size(), 0);
+		
+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		CheckService cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		ProvidedServiceHandlerDescription psh = getPSDesc(id_ps1);
+		assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+		assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+		assertTrue("Check service reference - 2", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+		
+		// Start a second foo service provider
+		fooProvider2.start();
+		
+		arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+		ServiceReference arch_ps2 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider2.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps1);
+		assertNotNull("Check architecture 2 availability", arch_ps2);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		InstanceDescription id_ps2 = ((Architecture) context.getService(arch_ps2)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
+		assertTrue("Check instance 2 invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		assertEquals("Check dependency ref - 3 ", dhd.getDependencies()[0].getServiceReferences().size(), 2);
+		assertEquals("Check used ref - 2 ", dhd.getDependencies()[0].getUsedServices().size(), 1); // provider 2 not already used
+		
+		cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		id_ps2 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		ProvidedServiceHandlerDescription psh1 = getPSDesc(id_ps1);
+		ProvidedServiceHandlerDescription psh2 = getPSDesc(id_ps2);
+		assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+		assertEquals("Check POJO creation", id_ps2.getCreatedObjects().length, 1);
+		assertTrue("Check service reference - 3.1", dhd.getDependencies()[0].getUsedServices().contains(psh1.getProvidedServices()[0].getServiceReference()));
+		assertTrue("Check service reference - 3.2", dhd.getDependencies()[0].getUsedServices().contains(psh2.getProvidedServices()[0].getServiceReference()));
+		assertEquals("Check used ref - 3 ("+dhd.getDependencies()[0].getUsedServices().size()+")", dhd.getDependencies()[0].getUsedServices().size(), 2);
+		
+		fooProvider2.stop();
+		
+		arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps1);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		assertTrue("Check instance validity - 1", id_ps1.getState() == ComponentInstance.VALID);				
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+		assertEquals("Check used ref - 4 ", dhd.getDependencies()[0].getUsedServices().size(), 1);
+		
+		cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		psh = getPSDesc(id_ps1);
+		assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+		assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+		assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+		assertEquals("Check used ref - 5 ", dhd.getDependencies()[0].getUsedServices().size(), 1);
+		
+		fooProvider1.stop();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertFalse("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertFalse("Check dependency handler invalidity", dhd.isValid());
+		
+		fooProvider2.start();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider2.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps1);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
+		psh = getPSDesc(id_ps1);
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		
+		assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+		assertEquals("Check used ref - 6 ", dhd.getDependencies()[0].getUsedServices().size(), 0);
+		
+		cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph 
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		psh = getPSDesc(id_ps1);
+		assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+		assertTrue("Check service reference - 4", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+		assertEquals("Check used ref - 7 ", dhd.getDependencies()[0].getUsedServices().size(), 1);
+		
+		fooProvider2.stop();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertFalse("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertFalse("Check dependency handler invalidity", dhd.isValid());
+		
+		id_dep = null;
+		cs = null;
+		context.ungetService(arch_dep);
+		context.ungetService(cs_ref);
+	}
+	
+	public void testMultipleOptionalDependency() {
+		ServiceReference arch_dep = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+		assertNotNull("Check architecture availability", arch_dep);
+		InstanceDescription id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.VALID);
+		
+		// Check dependency handler invalidity
+		DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler invalidity", dhd.isValid());
+		
+		// Check dependency metadata
+		assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
+		assertTrue("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
+		assertTrue("Check dependency optionality", dhd.getDependencies()[0].isOptional());
+		assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
+		
+		fooProvider1.start();
+		
+		ServiceReference arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps1);
+		InstanceDescription id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);				
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+		
+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		CheckService cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		ProvidedServiceHandlerDescription psh = getPSDesc(id_ps1);
+		assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+		assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+		assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+		
+		// Start a second foo service provider
+		fooProvider2.start();
+		
+		arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+		ServiceReference arch_ps2 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider2.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps1);
+		assertNotNull("Check architecture 2 availability", arch_ps2);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		InstanceDescription id_ps2 = ((Architecture) context.getService(arch_ps2)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
+		assertTrue("Check instance 2 invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		assertEquals("Check dependency ref - 3 ", dhd.getDependencies()[0].getServiceReferences().size(), 2);
+		
+		cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		id_ps2 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		ProvidedServiceHandlerDescription psh1 = getPSDesc(id_ps1);
+		ProvidedServiceHandlerDescription psh2 = getPSDesc(id_ps2);
+		assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+		assertEquals("Check POJO creation", id_ps2.getCreatedObjects().length, 1);
+		assertTrue("Check service reference - 2.1", dhd.getDependencies()[0].getUsedServices().contains(psh1.getProvidedServices()[0].getServiceReference()));
+		assertTrue("Check service reference - 2.2", dhd.getDependencies()[0].getUsedServices().contains(psh2.getProvidedServices()[0].getServiceReference()));
+		
+		fooProvider2.stop();
+		
+		arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps1);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);				
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+		
+		cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		psh = getPSDesc(id_ps1);
+		assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+		assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+		assertTrue("Check service reference - 3", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+
+		fooProvider1.stop();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler invalidity", dhd.isValid());
+		
+		fooProvider2.start();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider2.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ps1);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
+		psh = getPSDesc(id_ps1);
+		assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+		assertTrue("Check dependency handler validity", dhd.isValid());
+		
+		assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+		
+		cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		cs = (CheckService) context.getService(cs_ref);
+		assertTrue("check CheckService invocation", cs.check());
+		
+		// Check object graph 
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		dhd = getDependencyDesc(id_dep);
+		id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+		psh = getPSDesc(id_ps1);
+		assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+		assertTrue("Check service reference - 4", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+
+		fooProvider2.stop();
+		
+		id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+		dhd = getDependencyDesc(id_dep);
+		assertTrue("Check dependency handler invalidity", dhd.isValid());
+		
+		id_dep = null;
+		cs = null;
+		context.ungetService(arch_dep);
+		context.ungetService(cs_ref);
+	}
+	
+	
+	
+}

Added: felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyTestSuite.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyTestSuite.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyTestSuite.java (added)
+++ felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyTestSuite.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,61 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.dependency;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.apache.felix.ipojo.test.scenarios.service.dependency.di.DefaultImplementationTestSuite;
+import org.apache.felix.ipojo.test.scenarios.service.dependency.dynamic.priority.DynamicPriorityDependencyTestSuite;
+import org.apache.felix.ipojo.test.scenarios.service.dependency.statics.StaticDependencyTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class DependencyTestSuite {
+
+	public static Test suite(BundleContext bc) {
+		OSGiTestSuite ots = new OSGiTestSuite("Service Dependencies Test Suite", bc);
+		ots.addTestSuite(SimpleDependencies.class);
+		ots.addTestSuite(OptionalDependencies.class);
+		ots.addTestSuite(OptionalNoNullableDependencies.class);
+		ots.addTestSuite(MultipleDependencies.class);
+		ots.addTestSuite(OptionalMultipleDependencies.class);
+		ots.addTestSuite(DelayedSimpleDependencies.class);
+		ots.addTestSuite(DelayedOptionalDependencies.class);
+		ots.addTestSuite(DelayedMultipleDependencies.class);
+		ots.addTestSuite(DelayedOptionalMultipleDependencies.class);
+        ots.addTestSuite(MethodSimpleDependencies.class);
+        ots.addTestSuite(MethodOptionalDependencies.class);
+        ots.addTestSuite(MethodMultipleDependencies.class);
+        ots.addTestSuite(MethodOptionalMultipleDependencies.class);
+        ots.addTestSuite(MethodDelayedSimpleDependencies.class);
+        ots.addTestSuite(MethodDelayedOptionalDependencies.class);
+        ots.addTestSuite(MethodDelayedMultipleDependencies.class);
+        ots.addTestSuite(MethodDelayedOptionalMultipleDependencies.class);
+        ots.addTestSuite(SimpleFilterDependencies.class);
+        ots.addTestSuite(OptionalSimpleFilterDependencies.class);
+        ots.addTestSuite(MultipleFilterDependencies.class);
+        ots.addTestSuite(OptionalMultipleFilterDependencies.class);
+        ots.addTest(StaticDependencyTestSuite.suite(bc));
+        ots.addTest(DefaultImplementationTestSuite.suite(bc));
+        ots.addTestSuite(DependencyArchitectureTest.class);
+        ots.addTest(DynamicPriorityDependencyTestSuite.suite(bc));
+		return ots;
+	}
+
+}

Added: felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/MethodDelayedMultipleDependencies.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/MethodDelayedMultipleDependencies.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/MethodDelayedMultipleDependencies.java (added)
+++ felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/MethodDelayedMultipleDependencies.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,244 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.dependency;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+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.scenarios.service.dependency.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodDelayedMultipleDependencies extends OSGiTestCase {
+
+	ComponentInstance instance3, instance4, instance5;
+	ComponentInstance fooProvider1, fooProvider2;
+	
+	public void setUp() {
+		try {
+		
+			Properties i3 = new Properties();
+			i3.put("name", "Object");
+			instance3 = Utils.getFactoryByName(context, "MObjectMultipleCheckServiceProvider").createComponentInstance(i3);
+			instance3.stop();
+		
+			Properties i4 = new Properties();
+			i4.put("name", "Ref");
+			instance4 = Utils.getFactoryByName(context, "MRefMultipleCheckServiceProvider").createComponentInstance(i4);
+			instance4.stop();
+			
+			Properties i5 = new Properties();
+            i5.put("name", "Both");
+            instance5 = Utils.getFactoryByName(context, "MBothMultipleCheckServiceProvider").createComponentInstance(i5);
+            instance5.stop();
+		
+			Properties prov = new Properties();
+			prov.put("name", "FooProvider1");
+			fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+		
+			Properties prov2 = new Properties();
+			prov2.put("name", "FooProvider2");
+			fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+		} catch(Exception e) { fail(e.getMessage()); }
+	}
+	
+	public void tearDown() {
+		instance3.dispose();
+		instance4.dispose();
+		instance5.dispose();
+		fooProvider1.dispose();
+		fooProvider2.dispose();
+		instance3 = null;
+		instance4 = null;
+		instance5 = null;
+		fooProvider1 = null;
+		fooProvider2 = null;
+	}
+	
+	public void testObject() {
+		instance3.start();
+		
+		ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ref);
+		InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+		
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+		
+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		CheckService cs = (CheckService) context.getService(cs_ref);
+		Properties props = cs.getProps();
+		//Check properties
+		assertTrue("check CheckService invocation - 1", ((Boolean)props.get("result")).booleanValue()); // True, a provider is here
+		assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);
+		assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);
+		assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 2);
+		assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);
+		assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 0);
+		assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);
+		assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 2);
+		assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 2);
+		assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 2.0);
+		
+		fooProvider1.stop();
+		
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+		
+		cs = (CheckService) context.getService(cs_ref);
+		props = cs.getProps();
+		//Check properties
+		assertTrue("check CheckService invocation - 3", ((Boolean)props.get("result")).booleanValue()); // True, two providers are here
+		assertEquals("check void bind invocation - 3", ((Integer)props.get("voidB")).intValue(), 0);
+		assertEquals("check void unbind callback invocation - 3", ((Integer)props.get("voidU")).intValue(), 0);
+		assertEquals("check object bind callback invocation - 3", ((Integer)props.get("objectB")).intValue(), 2);
+		assertEquals("check object unbind callback invocation - 3", ((Integer)props.get("objectU")).intValue(), 1);
+		assertEquals("check ref bind callback invocation - 3", ((Integer)props.get("refB")).intValue(), 0);
+		assertEquals("check ref unbind callback invocation - 3", ((Integer)props.get("refU")).intValue(), 0);
+		assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 1);
+		assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 1);
+		assertEquals("Check FS invocation (double) - 3", ((Double)props.get("double")).doubleValue(), 1.0);
+		
+		fooProvider2.stop();
+		
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+		
+		id = null;
+		cs = null;
+		context.ungetService(arch_ref);
+		context.ungetService(cs_ref);
+		instance3.stop();
+	}
+	
+	public void testRef() {
+		instance4.start();
+		ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+		assertNotNull("Check architecture availability", arch_ref);
+		InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+		
+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+		assertNotNull("Check CheckService availability", cs_ref);
+		CheckService cs = (CheckService) context.getService(cs_ref);
+		Properties props = cs.getProps();
+		//Check properties
+		assertTrue("check CheckService invocation - 1", ((Boolean)props.get("result")).booleanValue()); // True, a provider is here
+		assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);
+		assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);
+		assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 0);
+		assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);
+		assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 2);
+		assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);
+		assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 2);
+		assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 2);
+		assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 2.0);
+		
+		fooProvider1.stop();
+		
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+		
+		cs = (CheckService) context.getService(cs_ref);
+		props = cs.getProps();
+		//Check properties
+		assertTrue("check CheckService invocation - 3", ((Boolean)props.get("result")).booleanValue()); // True, two providers are here
+		assertEquals("check void bind invocation - 3", ((Integer)props.get("voidB")).intValue(), 0);
+		assertEquals("check void unbind callback invocation - 3", ((Integer)props.get("voidU")).intValue(), 0);
+		assertEquals("check object bind callback invocation - 3", ((Integer)props.get("objectB")).intValue(), 0);
+		assertEquals("check object unbind callback invocation - 3", ((Integer)props.get("objectU")).intValue(), 0);
+		assertEquals("check ref bind callback invocation - 3", ((Integer)props.get("refB")).intValue(), 2);
+		assertEquals("check ref unbind callback invocation - 3", ((Integer)props.get("refU")).intValue(), 1);
+		assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 1);
+		assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 1);
+		assertEquals("Check FS invocation (double) - 3", ((Double)props.get("double")).doubleValue(), 1.0);
+		
+		fooProvider2.stop();
+		
+		id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+		assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.INVALID);
+		
+		id = null;
+		cs = null;
+		context.ungetService(arch_ref);
+		instance4.stop();
+		context.ungetService(cs_ref);
+	}
+	
+	public void testBoth() {
+        instance5.start();
+        ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+        assertNotNull("Check architecture availability", arch_ref);
+        InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+        
+        ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+        assertNotNull("Check CheckService availability", cs_ref);
+        CheckService cs = (CheckService) context.getService(cs_ref);
+        Properties props = cs.getProps();
+        //Check properties
+        assertTrue("check CheckService invocation - 1", ((Boolean)props.get("result")).booleanValue()); // True, a provider is here
+        assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);
+        assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);
+        assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 0);
+        assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);
+        assertEquals("check both bind callback invocation - 1", ((Integer)props.get("bothB")).intValue(), 2);
+        assertEquals("check both unbind callback invocation - 1", ((Integer)props.get("bothU")).intValue(), 0);
+        assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 2);
+        assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 2);
+        assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 2.0);
+        
+        fooProvider1.stop();
+        
+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+        
+        cs = (CheckService) context.getService(cs_ref);
+        props = cs.getProps();
+        //Check properties
+        assertTrue("check CheckService invocation - 3", ((Boolean)props.get("result")).booleanValue()); // True, two providers are here
+        assertEquals("check void bind invocation - 3", ((Integer)props.get("voidB")).intValue(), 0);
+        assertEquals("check void unbind callback invocation - 3", ((Integer)props.get("voidU")).intValue(), 0);
+        assertEquals("check object bind callback invocation - 3", ((Integer)props.get("objectB")).intValue(), 0);
+        assertEquals("check object unbind callback invocation - 3", ((Integer)props.get("objectU")).intValue(), 0);
+        assertEquals("check both bind callback invocation - 3", ((Integer)props.get("bothB")).intValue(), 2);
+        assertEquals("check both unbind callback invocation - 3", ((Integer)props.get("bothU")).intValue(), 1);
+        assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 1);
+        assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 1);
+        assertEquals("Check FS invocation (double) - 3", ((Double)props.get("double")).doubleValue(), 1.0);
+        
+        fooProvider2.stop();
+        
+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.INVALID);
+        
+        id = null;
+        cs = null;
+        context.ungetService(arch_ref);
+        instance5.stop();
+        context.ungetService(cs_ref);
+    }
+
+	
+}

Added: felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/MethodDelayedOptionalDependencies.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/MethodDelayedOptionalDependencies.java?rev=651646&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/MethodDelayedOptionalDependencies.java (added)
+++ felix/trunk/ipojo/tests/tests.core.service.dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/MethodDelayedOptionalDependencies.java Fri Apr 25 09:49:43 2008
@@ -0,0 +1,225 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.dependency;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+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.scenarios.service.dependency.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodDelayedOptionalDependencies extends OSGiTestCase {
+
+    ComponentInstance instance3, instance4, instance5;
+
+    ComponentInstance fooProvider;
+
+    public void setUp() {
+        try {
+            Properties prov = new Properties();
+            prov.put("name", "FooProvider");
+            fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+
+            Properties i3 = new Properties();
+            i3.put("name", "Object");
+            instance3 = Utils.getFactoryByName(context, "MObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+            instance3.stop();
+
+            Properties i4 = new Properties();
+            i4.put("name", "Ref");
+            instance4 = Utils.getFactoryByName(context, "MRefOptionalCheckServiceProvider").createComponentInstance(i4);
+            instance4.stop();
+
+            Properties i5 = new Properties();
+            i5.put("name", "Both");
+            instance5 = Utils.getFactoryByName(context, "MBothOptionalCheckServiceProvider").createComponentInstance(i5);
+            instance5.stop();
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+
+    }
+
+    public void tearDown() {
+        instance3.dispose();
+        instance4.dispose();
+        instance5.dispose();
+        fooProvider.dispose();
+        instance3 = null;
+        instance4 = null;
+        instance5 = null;
+        fooProvider = null;
+    }
+
+    public void testObject() {
+        instance3.start();
+        ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+        assertNotNull("Check architecture availability", arch_ref);
+        InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+        ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+        assertNotNull("Check CheckService availability", cs_ref);
+        CheckService cs = (CheckService) context.getService(cs_ref);
+        Properties props = cs.getProps();
+        // Check properties
+        assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+        assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+        assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+        assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 1);
+        assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+        assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+        assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+        assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+        assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+        assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+        assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+        fooProvider.stop();
+
+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+        assertNotNull("Check CheckService availability", cs_ref);
+        cs = (CheckService) context.getService(cs_ref);
+        props = cs.getProps();
+        // Check properties
+        assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+        assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+        assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+        assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 1);
+        assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 1);
+        assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+        assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+        assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+        assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+        id = null;
+        cs = null;
+        context.ungetService(arch_ref);
+        context.ungetService(cs_ref);
+
+        instance3.stop();
+    }
+
+    public void testRef() {
+        instance4.start();
+
+        ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+        assertNotNull("Check architecture availability", arch_ref);
+        InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+        ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+        assertNotNull("Check CheckService availability", cs_ref);
+        CheckService cs = (CheckService) context.getService(cs_ref);
+        Properties props = cs.getProps();
+        // Check properties
+        assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+        assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+        assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+        assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+        assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+        assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 1);
+        assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+        assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+        assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+        fooProvider.stop();
+
+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+        assertNotNull("Check CheckService availability", cs_ref);
+        cs = (CheckService) context.getService(cs_ref);
+        props = cs.getProps();
+        // Check properties
+        assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+        assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+        assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+        assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+        assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+        assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
+        assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 1);
+        assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+        assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+        id = null;
+        cs = null;
+        context.ungetService(arch_ref);
+        context.ungetService(cs_ref);
+
+        instance4.stop();
+    }
+
+    public void testBoth() {
+        instance5.start();
+
+        ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+        assertNotNull("Check architecture availability", arch_ref);
+        InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+        ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+        assertNotNull("Check CheckService availability", cs_ref);
+        CheckService cs = (CheckService) context.getService(cs_ref);
+        Properties props = cs.getProps();
+        // Check properties
+        assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+        assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+        assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+        assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+        assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+        assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+        assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+        assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 1);
+        assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+        fooProvider.stop();
+
+        id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+        assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+        assertNotNull("Check CheckService availability", cs_ref);
+        cs = (CheckService) context.getService(cs_ref);
+        props = cs.getProps();
+        // Check properties
+        assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+        assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+        assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+        assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+        assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+        assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+        assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+        assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 1);
+        assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 1);
+
+        id = null;
+        cs = null;
+        context.ungetService(arch_ref);
+        context.ungetService(cs_ref);
+
+        instance4.stop();
+    }
+
+}