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 2007/09/28 16:36:21 UTC

svn commit: r580371 [1/2] - in /felix/sandbox/clement/Tests/Suite: ./ src/main/java/org/apache/felix/ipojo/test/scenarios/component/ src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/ src/main/java/org/apache/felix/ipojo/test/scenarios/fac...

Author: clement
Date: Fri Sep 28 07:36:19 2007
New Revision: 580371

URL: http://svn.apache.org/viewvc?rev=580371&view=rev
Log:
Commit the new test suite (add service.pid tests, and requirement callback with (ServiceObject, ServiceReference)

Modified:
    felix/sandbox/clement/Tests/Suite/pom.xml
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodCheckServiceProvider.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodMultipleCheckService.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckService.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedMultipleDependencies.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedOptionalDependencies.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedSimpleDependencies.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedMultipleDependencies.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedOptionalDependencies.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedSimpleDependencies.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodMultipleDependencies.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodOptionalDependencies.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodSimpleDependencies.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalDependencies.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/SimpleDependencies.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/ConfigAdminTest.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/UnacceptableConfigurationTest.java
    felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/GetComponentInstanceTest.java
    felix/sandbox/clement/Tests/Suite/src/main/resources/metadata.xml

Modified: felix/sandbox/clement/Tests/Suite/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/pom.xml?rev=580371&r1=580370&r2=580371&view=diff
==============================================================================
--- felix/sandbox/clement/Tests/Suite/pom.xml (original)
+++ felix/sandbox/clement/Tests/Suite/pom.xml Fri Sep 28 07:36:19 2007
@@ -36,15 +36,15 @@
         <extensions>true</extensions>
         <configuration>
           <instructions>
-            <Export-Package>org.apache.felix.ipojo.test.*</Export-Package>
+            <Export-Package>org.apache.felix.ipojo.test.scenarios.service</Export-Package>
             <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
-            <Private-Package>fr.imag.adele.escoffier.utf.framework, fr.imag.adele.escoffier.utf.runner</Private-Package>
+            <Private-Package>org.apache.felix.ipojo.test*, fr.imag.adele.escoffier.utf.framework, fr.imag.adele.escoffier.utf.runner</Private-Package>
           </instructions>
         </configuration>
       </plugin>
       <plugin>
 	      <groupId>org.apache.felix</groupId>
-	      <artifactId>org.apache.felix.ipojo.plugin</artifactId>
+	      <artifactId>maven-ipojo-plugin</artifactId>
 		  <executions>
           	<execution>
             	<goals>

Modified: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java?rev=580371&r1=580370&r2=580371&view=diff
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java (original)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java Fri Sep 28 07:36:19 2007
@@ -13,9 +13,11 @@
 	int simpleB = 0;
 	int objectB = 0;
 	int refB = 0;
+	int bothB = 0;
 	int simpleU = 0;
 	int objectU = 0;
 	int refU = 0;
+	int bothU = 0;
 
 	public boolean check() {
 		return fs.foo();
@@ -27,9 +29,11 @@
 		props.put("voidB", new Integer(simpleB));
 		props.put("objectB", new Integer(objectB));
 		props.put("refB", new Integer(refB));
+		props.put("bothB", new Integer(bothB));
 		props.put("voidU", new Integer(simpleU));
 		props.put("objectU", new Integer(objectU));
 		props.put("refU", new Integer(refU));
+		props.put("bothU", new Integer(bothU));
 		props.put("boolean", new Boolean(fs.getBoolean()));
 		props.put("int", new Integer(fs.getInt()));
 		props.put("long", new Long(fs.getLong()));
@@ -62,5 +66,13 @@
 	}
 	public void refUnbind(ServiceReference sr) {
 		if(sr != null) { refU++; }
+	}
+	
+    public void bothBind(FooService o, ServiceReference sr) {
+	    if(sr != null && o != null && o instanceof FooService) { bothB++; }
+	}
+    
+	public void bothUnbind(FooService o, ServiceReference sr) {
+	    if(sr != null && o != null && o instanceof FooService) { bothU++; }
 	}
 }

Modified: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodCheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodCheckServiceProvider.java?rev=580371&r1=580370&r2=580371&view=diff
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodCheckServiceProvider.java (original)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodCheckServiceProvider.java Fri Sep 28 07:36:19 2007
@@ -16,9 +16,12 @@
 	int simpleB = 0;
 	int objectB = 0;
 	int refB = 0;
+	int bothB = 0;
 	int simpleU = 0;
 	int objectU = 0;
 	int refU = 0;
+	int bothU = 0;
+	
     
     public MethodCheckServiceProvider(BundleContext bc) {
         context = bc;
@@ -42,9 +45,11 @@
 		props.put("voidB", new Integer(simpleB));
 		props.put("objectB", new Integer(objectB));
 		props.put("refB", new Integer(refB));
+		props.put("bothB", new Integer(bothB));
 		props.put("voidU", new Integer(simpleU));
 		props.put("objectU", new Integer(objectU));
 		props.put("refU", new Integer(refU));
+		props.put("bothU", new Integer(bothU));
 		
 		if(fs != null) {
 		    if(fs.getObject() != null) { props.put("object", fs.getObject()); }
@@ -70,5 +75,14 @@
 		if(sr != null) { refU++; }
         context.ungetService(sr);
         fs = null;
+	}
+	
+    protected void bothBind(FooService o, ServiceReference ref) {
+	    if(ref != null && o != null && o instanceof FooService) { bothB++; }
+	    fs = o;
+	}	
+    protected void bothUnbind(FooService o, ServiceReference ref) {
+	     if(ref != null && o != null && o instanceof FooService) { bothU++; }
+	     fs = null;
 	}
 }

Modified: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodMultipleCheckService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodMultipleCheckService.java?rev=580371&r1=580370&r2=580371&view=diff
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodMultipleCheckService.java (original)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodMultipleCheckService.java Fri Sep 28 07:36:19 2007
@@ -13,13 +13,22 @@
 
 	List fs = new ArrayList();
 	BundleContext context;
-    
-	int simpleB = 0;
-	int objectB = 0;
-	int refB = 0;
-	int simpleU = 0;
-	int objectU = 0;
-	int refU = 0;
+
+    int simpleB = 0;
+
+    int objectB = 0;
+
+    int refB = 0;
+
+    int bothB = 0;
+
+    int simpleU = 0;
+
+    int objectU = 0;
+
+    int refU = 0;
+
+    int bothU = 0;
     
     public MethodMultipleCheckService(BundleContext bc) {
         context = bc;
@@ -77,9 +86,11 @@
 		props.put("voidB", new Integer(simpleB));
 		props.put("objectB", new Integer(objectB));
 		props.put("refB", new Integer(refB));
-		props.put("voidU", new Integer(simpleU));
-		props.put("objectU", new Integer(objectU));
-		props.put("refU", new Integer(refU));
+        props.put("bothB", new Integer(bothB));
+        props.put("voidU", new Integer(simpleU));
+        props.put("objectU", new Integer(objectU));
+        props.put("refU", new Integer(refU));
+        props.put("bothU", new Integer(bothU));
 		props.put("boolean", new Boolean(getBoolean()));
 		props.put("int", new Integer(getInt()));
 		props.put("long", new Long(getLong()));
@@ -106,5 +117,19 @@
         fs.remove(context.getService(sr));
         context.ungetService(sr);
 	}
+	
+	public void bothBind(FooService o, ServiceReference sr) {
+        if (o != null && o instanceof FooService && sr != null) {
+            fs.add(o);
+            bothB++;
+        }
+    }
+
+    public void bothUnbind(FooService o, ServiceReference sr) {
+        if (o != null && o instanceof FooService && sr != null) {
+            fs.remove(o);
+            bothU++;
+        }
+    }
 	
 }

Modified: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckService.java?rev=580371&r1=580370&r2=580371&view=diff
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckService.java (original)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckService.java Fri Sep 28 07:36:19 2007
@@ -8,97 +8,133 @@
 
 public class MultipleCheckService implements CheckService {
 
-	FooService fs[];
-	
-	int simpleB = 0;
-	int objectB = 0;
-	int refB = 0;
-	int simpleU = 0;
-	int objectU = 0;
-	int refU = 0;
-
-	public boolean check() {
-		boolean r = fs.length != 0;
-		for(int i = 0; i < fs.length; i++) {
-			r = r & fs[i].foo();
-		}
-		return r;
-	}
-	
-	private boolean getBoolean() {
-		return check();
-	}
-	
-	private int getInt() {
-		int r = 0;
-		for(int i = 0; i < fs.length; i++) {
-			r = r + fs[i].getInt();
-		}
-		return r;
-	}
-	
-	private long getLong() {
-		long r = 0;
-		for(int i = 0; i < fs.length; i++) {
-			r = r + fs[i].getLong();
-		}
-		return r;
-	}
-	
-	private double getDouble() {
-		double r = 0.0;
-		for(int i = 0; i < fs.length; i++) {
-			r = r + fs[i].getInt();
-		}
-		return r;
-	}
-	
-	protected Object doNothing(Object o, String s) { return null; }
-	
-//	private Object getObject() {
-//		boolean r = true;
-//		for(int i = 0; i < fs.length; i++) {
-//			r = r && ((Boolean) fs[i].getObject()).booleanValue();
-//		}
-//		return new Boolean(r);
-//	}
-
-	public Properties getProps() {
-		Properties props = new Properties();
-		props.put("result", new Boolean(check()));
-		props.put("voidB", new Integer(simpleB));
-		props.put("objectB", new Integer(objectB));
-		props.put("refB", new Integer(refB));
-		props.put("voidU", new Integer(simpleU));
-		props.put("objectU", new Integer(objectU));
-		props.put("refU", new Integer(refU));
-		props.put("boolean", new Boolean(getBoolean()));
-		props.put("int", new Integer(getInt()));
-		props.put("long", new Long(getLong()));
-		props.put("double", new Double(getDouble()));
-		
-		return props;
-	}
-	
-	public void voidBind() {
-		simpleB++;
-	}
-	public void voidUnbind() {
-		simpleU++;
-	}
-	
-	public void objectBind(FooService o) {
-		if(o != null && o instanceof FooService) { objectB++; }
-	}
-	public void objectUnbind(FooService o) {
-		if(o != null && o instanceof FooService) { objectU++; }
-	}
-	
-	public void refBind(ServiceReference sr) {
-		if(sr != null) { refB++; }
-	}
-	public void refUnbind(ServiceReference sr) {
-		if(sr != null) { refU++; }
-	}
-	
+    FooService fs[];
+
+    int simpleB = 0;
+
+    int objectB = 0;
+
+    int refB = 0;
+
+    int bothB = 0;
+
+    int simpleU = 0;
+
+    int objectU = 0;
+
+    int refU = 0;
+
+    int bothU = 0;
+
+    public boolean check() {
+        boolean r = fs.length != 0;
+        for (int i = 0; i < fs.length; i++) {
+            r = r & fs[i].foo();
+        }
+        return r;
+    }
+
+    private boolean getBoolean() {
+        return check();
+    }
+
+    private int getInt() {
+        int r = 0;
+        for (int i = 0; i < fs.length; i++) {
+            r = r + fs[i].getInt();
+        }
+        return r;
+    }
+
+    private long getLong() {
+        long r = 0;
+        for (int i = 0; i < fs.length; i++) {
+            r = r + fs[i].getLong();
+        }
+        return r;
+    }
+
+    private double getDouble() {
+        double r = 0.0;
+        for (int i = 0; i < fs.length; i++) {
+            r = r + fs[i].getInt();
+        }
+        return r;
+    }
+
+    protected Object doNothing(Object o, String s) {
+        return null;
+    }
+
+    // private Object getObject() {
+    // boolean r = true;
+    // for(int i = 0; i < fs.length; i++) {
+    // r = r && ((Boolean) fs[i].getObject()).booleanValue();
+    // }
+    // return new Boolean(r);
+    // }
+
+    public Properties getProps() {
+        Properties props = new Properties();
+        props.put("result", new Boolean(check()));
+        props.put("voidB", new Integer(simpleB));
+        props.put("objectB", new Integer(objectB));
+        props.put("refB", new Integer(refB));
+        props.put("bothB", new Integer(bothB));
+        props.put("voidU", new Integer(simpleU));
+        props.put("objectU", new Integer(objectU));
+        props.put("refU", new Integer(refU));
+        props.put("bothU", new Integer(bothU));
+        props.put("boolean", new Boolean(getBoolean()));
+        props.put("int", new Integer(getInt()));
+        props.put("long", new Long(getLong()));
+        props.put("double", new Double(getDouble()));
+
+        return props;
+    }
+
+    public void voidBind() {
+        simpleB++;
+    }
+
+    public void voidUnbind() {
+        simpleU++;
+    }
+
+    public void objectBind(FooService o) {
+        if (o != null && o instanceof FooService) {
+            objectB++;
+        }
+    }
+
+    public void objectUnbind(FooService o) {
+        if (o != null && o instanceof FooService) {
+            objectU++;
+        }
+    }
+
+    public void refBind(ServiceReference sr) {
+        if (sr != null) {
+            refB++;
+        }
+    }
+
+    public void refUnbind(ServiceReference sr) {
+        if (sr != null) {
+            refU++;
+        }
+    }
+
+    public void bothBind(FooService o, ServiceReference sr) {
+        if (o != null && o instanceof FooService && sr != null) {
+            bothB++;
+        }
+    }
+
+    public void bothUnbind(FooService o, ServiceReference sr) {
+        if (o != null && o instanceof FooService && sr != null) {
+            bothU++;
+        }
+    }
+
 }

Modified: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedMultipleDependencies.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedMultipleDependencies.java?rev=580371&r1=580370&r2=580371&view=diff
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedMultipleDependencies.java (original)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedMultipleDependencies.java Fri Sep 28 07:36:19 2007
@@ -14,7 +14,7 @@
 
 public class DelayedMultipleDependencies extends TestCase {
 
-	ComponentInstance instance1, instance2, instance3, instance4;
+	ComponentInstance instance1, instance2, instance3, instance4, instance5;
 	ComponentInstance fooProvider1, fooProvider2;
 	
 	public DelayedMultipleDependencies(BundleContext bc) {super(bc); }
@@ -40,6 +40,11 @@
 			i4.put("name", "Ref");
 			instance4 = Utils.getFactoryByName(context, "RefMultipleCheckServiceProvider").createComponentInstance(i4);
 			instance4.stop();
+			
+	         Properties i5 = new Properties();
+	            i5.put("name", "Both");
+	            instance5 = Utils.getFactoryByName(context, "BothMultipleCheckServiceProvider").createComponentInstance(i5);
+	            instance5.stop();
 		
 			Properties prov = new Properties();
 			prov.put("name", "FooProvider1");
@@ -56,12 +61,14 @@
 		instance2.dispose();
 		instance3.dispose();
 		instance4.dispose();
+		instance5.dispose();
 		fooProvider1.dispose();
 		fooProvider2.dispose();
 		instance1 = null;
 		instance2 = null;
 		instance3 = null;
 		instance4 = null;
+		instance5 = null;
 		fooProvider1 = null;
 		fooProvider2 = null;
 	}
@@ -288,6 +295,60 @@
 		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);
+    }
 
 	
 }

Modified: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedOptionalDependencies.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedOptionalDependencies.java?rev=580371&r1=580370&r2=580371&view=diff
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedOptionalDependencies.java (original)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedOptionalDependencies.java Fri Sep 28 07:36:19 2007
@@ -13,251 +13,329 @@
 import fr.imag.adele.escoffier.utf.framework.TestCase;
 
 public class DelayedOptionalDependencies extends TestCase {
-	
-	ComponentInstance instance1, instance2, instance3, instance4;
-	ComponentInstance fooProvider;
-	
-	public DelayedOptionalDependencies(BundleContext bc) {super(bc); }
-	
-	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, "SimpleOptionalCheckServiceProvider").createComponentInstance(i1);
-			instance1.stop();
-		
-			Properties i2 = new Properties();
-			i2.put("name", "Void");
-			instance2 = Utils.getFactoryByName(context, "VoidOptionalCheckServiceProvider").createComponentInstance(i2);
-			instance2.stop();
-		
-			Properties i3 = new Properties();
-			i3.put("name", "Object");
-			instance3 = Utils.getFactoryByName(context, "ObjectOptionalCheckServiceProvider").createComponentInstance(i3);
-			instance3.stop();
-		
-			Properties i4 = new Properties();
-			i4.put("name", "Ref");
-			instance4 = Utils.getFactoryByName(context, "RefOptionalCheckServiceProvider").createComponentInstance(i4);
-			instance4.stop();
-		} catch(Exception e) { fail(e.getMessage()); }
-		
-	}
-	
-	public void tearDown() {
-		instance1.dispose();
-		instance2.dispose();
-		instance3.dispose();
-		instance4.dispose();
-		fooProvider.dispose();
-		instance1 = null;
-		instance2 = null;
-		instance3 = null;
-		instance4 = 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 - 1", 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);
-		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);
-		assertNotNull("Check FS invocation (object) - 1", props.get("object"));
-		assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 1);
-		assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 1);
-		assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 1.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()); // True, a provider is here
-		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);
-		assertNull("Check FS invocation (object) - 2", props.get("object"));
-		assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 0);
-		assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 0);
-		assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 0.0);
-		
-		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 - 1", 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);
-		assertNotNull("Check FS invocation (object) - 1", props.get("object"));
-		assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 1);
-		assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 1);
-		assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 1.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(), 1);
-		assertEquals("check void unbind callback invocation -2", ((Integer)props.get("voidU")).intValue(), 1);
-		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);
-		assertNull("Check FS invocation (object) - 2", props.get("object"));
-		assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 0);
-		assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 0);
-		assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 0.0);
-		
-		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();
-		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);
-		
-		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);
-		
-		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);
-		
-		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);
-		
-		id = null;
-		cs = null;
-		context.ungetService(arch_ref);
-		context.ungetService(cs_ref);
-		
-		instance4.stop();
-	}
+
+    ComponentInstance instance1, instance2, instance3, instance4, instance5;
+
+    ComponentInstance fooProvider;
+
+    public DelayedOptionalDependencies(BundleContext bc) {
+        super(bc);
+    }
+
+    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, "SimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+            instance1.stop();
+
+            Properties i2 = new Properties();
+            i2.put("name", "Void");
+            instance2 = Utils.getFactoryByName(context, "VoidOptionalCheckServiceProvider").createComponentInstance(i2);
+            instance2.stop();
+
+            Properties i3 = new Properties();
+            i3.put("name", "Object");
+            instance3 = Utils.getFactoryByName(context, "ObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+            instance3.stop();
+
+            Properties i4 = new Properties();
+            i4.put("name", "Ref");
+            instance4 = Utils.getFactoryByName(context, "RefOptionalCheckServiceProvider").createComponentInstance(i4);
+            instance4.stop();
+
+            Properties i5 = new Properties();
+            i5.put("name", "Both");
+            instance5 = Utils.getFactoryByName(context, "BothOptionalCheckServiceProvider").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;
+        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 - 1", 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);
+        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(), 0);
+        assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+        assertNotNull("Check FS invocation (object) - 1", props.get("object"));
+        assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 1);
+        assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 1);
+        assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 1.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()); // True, a provider is here
+        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(), 0);
+        assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+        assertNull("Check FS invocation (object) - 2", props.get("object"));
+        assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 0);
+        assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 0);
+        assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 0.0);
+
+        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 - 1", 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);
+        assertNotNull("Check FS invocation (object) - 1", props.get("object"));
+        assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 1);
+        assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 1);
+        assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 1.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(), 1);
+        assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 1);
+        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(), 0);
+        assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+        assertNull("Check FS invocation (object) - 2", props.get("object"));
+        assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 0);
+        assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 0);
+        assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 0.0);
+
+        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();
+        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 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();
+    }
 
 }

Modified: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedSimpleDependencies.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedSimpleDependencies.java?rev=580371&r1=580370&r2=580371&view=diff
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedSimpleDependencies.java (original)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedSimpleDependencies.java Fri Sep 28 07:36:19 2007
@@ -14,7 +14,7 @@
 
 public class DelayedSimpleDependencies extends TestCase {
 	
-	ComponentInstance instance1, instance2, instance3, instance4;
+	ComponentInstance instance1, instance2, instance3, instance4, instance5;
 	ComponentInstance fooProvider;
 	
 	public DelayedSimpleDependencies(BundleContext bc) {super(bc); }
@@ -44,6 +44,11 @@
 			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()); } 
 		
 	}
@@ -53,11 +58,14 @@
 		instance2.dispose();
 		instance3.dispose();
 		instance4.dispose();
+		instance5.dispose();
 		fooProvider.dispose();
 		instance1 = null;
 		instance2 = null;
 		instance3 = null;
 		instance4 = null;
+		instance4 = null;
+		instance5 = null;
 		fooProvider = null;
 	}
 	
@@ -110,7 +118,9 @@
 		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();
@@ -144,7 +154,9 @@
 		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();
@@ -179,6 +191,8 @@
 		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();
 		
@@ -192,5 +206,42 @@
 		
 		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();
+    }
 
 }

Modified: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedMultipleDependencies.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedMultipleDependencies.java?rev=580371&r1=580370&r2=580371&view=diff
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedMultipleDependencies.java (original)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedMultipleDependencies.java Fri Sep 28 07:36:19 2007
@@ -14,7 +14,7 @@
 
 public class MethodDelayedMultipleDependencies extends TestCase {
 
-	ComponentInstance instance3, instance4;
+	ComponentInstance instance3, instance4, instance5;
 	ComponentInstance fooProvider1, fooProvider2;
 	
 	public MethodDelayedMultipleDependencies(BundleContext bc) {super(bc); }
@@ -31,6 +31,11 @@
 			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");
@@ -45,10 +50,12 @@
 	public void tearDown() {
 		instance3.dispose();
 		instance4.dispose();
+		instance5.dispose();
 		fooProvider1.dispose();
 		fooProvider2.dispose();
 		instance3 = null;
 		instance4 = null;
+		instance5 = null;
 		fooProvider1 = null;
 		fooProvider2 = null;
 	}
@@ -164,6 +171,60 @@
 		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);
+    }
 
 	
 }

Modified: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedOptionalDependencies.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedOptionalDependencies.java?rev=580371&r1=580370&r2=580371&view=diff
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedOptionalDependencies.java (original)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedOptionalDependencies.java Fri Sep 28 07:36:19 2007
@@ -13,129 +13,201 @@
 import fr.imag.adele.escoffier.utf.framework.TestCase;
 
 public class MethodDelayedOptionalDependencies extends TestCase {
-	
-	ComponentInstance instance3, instance4;
-	ComponentInstance fooProvider;
-	
-	public MethodDelayedOptionalDependencies(BundleContext bc) {super(bc); }
-	
-	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();
-		} catch(Exception e) { fail(e.getMessage()); }
-		
-	}
-	
-	public void tearDown() {
-		instance3.dispose();
-		instance4.dispose();
-		fooProvider.dispose();
-		instance3 = null;
-		instance4 = 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);
-		
-		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);
-		
-		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);
-		
-		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);
-		
-		id = null;
-		cs = null;
-		context.ungetService(arch_ref);
-		context.ungetService(cs_ref);
-		
-		instance4.stop();
-	}
+
+    ComponentInstance instance3, instance4, instance5;
+
+    ComponentInstance fooProvider;
+
+    public MethodDelayedOptionalDependencies(BundleContext bc) {
+        super(bc);
+    }
+
+    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();
+    }
 
 }