felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r652169 [2/10] - in /felix/trunk/ipojo/tests: ./ tests.composite.service.import-export/ tests.composite.service.import-export/src/ tests.composite.service.import-export/src/main/ tests.composite.service.import-export/src/main/java/ tests.co...
Date Tue, 29 Apr 2008 22:25:45 GMT
Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/SimpleExport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/SimpleExport.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/SimpleExport.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/SimpleExport.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,234 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.exporter;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.BazService;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class SimpleExport extends OSGiTestCase {
+	
+	ComponentInstance export1;
+	Factory fooProvider;
+	ComponentInstance foo1 = null, foo2 = null;
+
+	public void setUp() {
+		fooProvider = Utils.getFactoryByName(context, "BazProviderType");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		Properties p1 = new Properties();
+		p1.put("name", "foo1");
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		
+		try {
+			foo1 = fooProvider.createComponentInstance(p1);
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Fail to create foos : " + e.getMessage());
+		}
+		
+		foo1.stop();
+		foo2.stop();
+		
+		Factory factory = Utils.getFactoryByName(context, "composite.export.1");
+		Properties props = new Properties();
+		props.put("name", "export");
+		try {
+			export1 = factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Fail to instantiate exporter " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		foo1.dispose();
+		foo2.dispose();
+		export1.dispose();
+		foo1 = null;
+		foo2 = null;
+		export1 = null;
+	}
+	
+	public void test1() {
+		export1.start();
+		
+		// Check that no foo service are available
+		assertEquals("Check no foo service", Utils.getServiceReferences(context, FooService.class.getName(), null).length, 0);
+		
+		// Test invalidity
+		assertTrue("Check invalidity - 0", export1.getState() == ComponentInstance.INVALID);
+		assertFalse("Check providing - 0", isFooServiceProvided());
+		assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+		
+		foo1.start();
+		assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 1", isFooServiceProvided());
+		assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 1", invoke());
+		
+		foo2.start();
+		assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 2", isFooServiceProvided());
+		assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 2", invoke());
+		
+		foo1.stop();
+		assertTrue("Check validity - 3", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 3", isFooServiceProvided());
+		assertEquals("Check number of provides - 3 ("+countFooServiceProvided()+")", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 3", invoke());
+		
+		foo2.stop();
+		assertTrue("Check invalidity - 4", export1.getState() == ComponentInstance.INVALID);
+		assertFalse("Check providing - 4", isFooServiceProvided());
+		assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+		
+		foo2.start();
+		assertTrue("Check validity - 5", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 5", isFooServiceProvided());
+		assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 5", invoke());
+	}
+	
+	public void test2() {
+		export1.start();
+		
+		// Test invalidity
+		assertTrue("Check invalidity - 0", export1.getState() == ComponentInstance.INVALID);
+		assertFalse("Check providing - 0", isFooServiceProvided());
+		assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+		
+		foo1.start();
+		assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 1", isFooServiceProvided());
+		assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 1", invoke());
+		
+		foo2.start();
+		assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 2", isFooServiceProvided());
+		assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 2", invoke());
+		
+		foo2.stop();
+		assertTrue("Check validity - 3", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 3", isFooServiceProvided());
+		assertEquals("Check number of provides - 3", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 3", invoke());
+		
+		foo1.stop();
+		assertTrue("Check invalidity - 4", export1.getState() == ComponentInstance.INVALID);
+		assertFalse("Check providing - 4", isFooServiceProvided());
+		assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+		
+		foo1.start();
+		assertTrue("Check validity - 5", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 5", isFooServiceProvided());
+		assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 5", invoke());
+	}
+	
+	public void test3() {
+		foo1.start();
+		foo2.start();
+		
+		export1.start();
+		assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 1", isFooServiceProvided());
+		assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 1", invoke());
+		
+		foo1.stop();
+		assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 2", isFooServiceProvided());
+		assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 2", invoke());
+		
+		foo2.stop();
+		assertTrue("Check invalidity - 3", export1.getState() == ComponentInstance.INVALID);
+		assertFalse("Check providing - 3", isFooServiceProvided());
+		assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+		
+		foo1.start();
+		assertTrue("Check validity - 4", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 4", isFooServiceProvided());
+		assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 4", invoke());
+	}
+	
+	public void test4() {
+		foo1.start();
+		foo2.start();
+		
+		export1.start();
+		assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 1", isFooServiceProvided());
+		assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 1", invoke());
+		
+		foo2.stop();
+		assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 2", isFooServiceProvided());
+		assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 2", invoke());
+		
+		foo1.stop();
+		assertTrue("Check invalidity - 3", export1.getState() == ComponentInstance.INVALID);
+		assertFalse("Check providing - 3", isFooServiceProvided());
+		assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+		
+		foo2.start();
+		assertTrue("Check validity - 4", export1.getState() == ComponentInstance.VALID);
+		assertTrue("Check providing - 4", isFooServiceProvided());
+		assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+		assertTrue("Check invocation - 4", invoke());
+	}
+	
+	
+	
+	private boolean isFooServiceProvided() {
+		ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export1.getInstanceName());
+		return ref != null;
+	}
+	
+	private int countFooServiceProvided() {
+		ServiceReference[] refs = Utils.getServiceReferences(context, BazService.class.getName(), "(instance.name="+export1.getInstanceName()+")");
+		return refs.length;
+	}
+	
+	private boolean invoke() {
+		ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export1.getInstanceName());
+		if(ref == null) { return false; }
+		BazService fs = (BazService) context.getService(ref);
+		return fs.foo();
+	}
+	
+	
+	
+	
+	
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedFilteredImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedFilteredImport.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedFilteredImport.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedFilteredImport.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,150 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedFilteredImport extends OSGiTestCase {
+	
+	ComponentInstance import1;
+	Factory fooProvider;
+	ComponentInstance foo1, foo2;
+
+	public void setUp() {
+		
+		Properties p = new Properties();
+		p.put("name", "importer");
+		Factory compFact = Utils.getFactoryByName(context, "composite.requires.1");
+		try {
+			import1 = compFact.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Cannot instantiate the component : " + e.getMessage());
+		}
+		
+		import1.stop();
+		
+		fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		Properties p1 = new Properties();
+		p1.put("name", "foo1");
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo1 = fooProvider.createComponentInstance(p1);
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Cannot instantiate foo providers : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		foo1.dispose();
+		foo2.dispose();
+		import1.dispose();
+		foo1 = null;
+		foo2 = null;
+		import1 = null;
+	}
+	
+	public void testSimple() {
+		import1.start(); 
+		//Two providers
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import1);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo1.stop();
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import1);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo2.stop();		
+		assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+		
+		foo2.start();
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import1);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}
+	
+	public void testSimple2() {
+		import1.start(); 
+		//Two providers
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import1);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo2.stop();
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import1);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo1.stop();		
+		assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+		
+		foo1.start();
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import1);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}
+	
+	
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedMultipleImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedMultipleImport.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedMultipleImport.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedMultipleImport.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,156 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedMultipleImport extends OSGiTestCase {
+	
+	ComponentInstance import2;
+	Factory fooProvider;
+	ComponentInstance foo1, foo2;
+
+	public void setUp() {
+		
+		Properties p = new Properties();
+		p.put("name", "importer");
+		Factory compFact = Utils.getFactoryByName(context, "composite.requires.2");
+		try {
+			import2 = compFact.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Cannot instantiate the component : " + e.getMessage());
+		}
+		
+		import2.stop();
+		
+		fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		Properties p1 = new Properties();
+		p1.put("name", "foo1");
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo1 = fooProvider.createComponentInstance(p1);
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Cannot instantiate foo providers : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		foo1.dispose();
+		foo2.dispose();
+		import2.dispose();
+		foo1 = null;
+		foo2 = null;
+		import2 = null;
+	}
+	
+	public void testSimple() {
+		import2.start(); 
+		//Two providers
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import2);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 2);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		fs = (FooService) sc.getService(refs[1]);
+		assertTrue("Test foo invocation (2)", fs.foo());
+		sc.ungetService(refs[1]);
+		
+		foo1.stop();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo2.stop();		
+		assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);
+		
+		foo2.start();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}
+	
+	public void testSimple2() {
+		import2.start(); 
+		//Two providers
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import2);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 2);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		fs = (FooService) sc.getService(refs[1]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[1]);
+		
+		foo2.stop();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo1.stop();		
+		assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);
+		
+		foo1.start();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}
+	
+	
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalImport.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalImport.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalImport.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,156 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedOptionalImport extends OSGiTestCase {
+	
+	ComponentInstance import3;
+	Factory fooProvider;
+	ComponentInstance foo1, foo2;
+
+	public void setUp() {
+		
+		Properties p = new Properties();
+		p.put("name", "importer");
+		Factory compFact = Utils.getFactoryByName(context, "composite.requires.3");
+		try {
+			import3 = compFact.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Cannot instantiate the component : " + e.getMessage());
+		}
+		
+		import3.stop();
+		
+		fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		Properties p1 = new Properties();
+		p1.put("name", "foo1");
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo1 = fooProvider.createComponentInstance(p1);
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Cannot instantiate foo providers : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		foo1.dispose();
+		foo2.dispose();
+		import3.dispose();
+		foo1 = null;
+		foo2 = null;
+		import3 = null;
+	}
+	
+	public void testSimple() {
+		import3.start(); 
+		//Two providers
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import3);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo1.stop();
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import3);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo2.stop();		
+		assertTrue("Test component validity - 2", import3.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import3);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertEquals("Test foo non-availability inside the composite - 3.1", refs.length, 0);
+		
+		foo2.start();
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import3);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}
+	
+	public void testSimple2() {
+		import3.start(); 
+		//Two providers
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import3);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo2.stop();
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import3);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo1.stop();		
+		assertTrue("Test component validity - 2", import3.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import3);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 0);
+		
+		foo1.start();
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import3);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}
+	
+	
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalMultipleImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalMultipleImport.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalMultipleImport.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalMultipleImport.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,162 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedOptionalMultipleImport extends OSGiTestCase {
+	
+	ComponentInstance import4;
+	Factory fooProvider;
+	ComponentInstance foo1, foo2;
+
+	public void setUp() {
+		
+		Properties p = new Properties();
+		p.put("name", "importer");
+		Factory compFact = Utils.getFactoryByName(context, "composite.requires.4");
+		try {
+			import4 = compFact.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Cannot instantiate the component : " + e.getMessage());
+		}
+		
+		import4.stop();
+		
+		fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		Properties p1 = new Properties();
+		p1.put("name", "foo1");
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo1 = fooProvider.createComponentInstance(p1);
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Cannot instantiate foo providers : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		foo1.dispose();
+		foo2.dispose();
+		import4.dispose();
+		foo1 = null;
+		foo2 = null;
+		import4 = null;
+	}
+	
+	public void testSimple() {
+		import4.start(); 
+		//Two providers
+		assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import4);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 2);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		fs = (FooService) sc.getService(refs[1]);
+		assertTrue("Test foo invocation (2)", fs.foo());
+		sc.ungetService(refs[1]);
+		
+		foo1.stop();
+		assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import4);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo2.stop();		
+		assertTrue("Test component validity - 2", import4.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import4);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertEquals("Test foo availability inside the composite - 1", refs.length, 0);
+		
+		foo2.start();
+		assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import4);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}
+	
+	public void testSimple2() {
+		import4.start(); 
+		//Two providers
+		assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import4);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 2);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		fs = (FooService) sc.getService(refs[1]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[1]);
+		
+		foo2.stop();
+		assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import4);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo1.stop();		
+		assertTrue("Test component validity - 2", import4.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import4);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertEquals("Test foo availability inside the composite - 1", refs.length, 0);
+		
+		foo1.start();
+		assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import4);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}
+	
+	
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedSimpleImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedSimpleImport.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedSimpleImport.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedSimpleImport.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,151 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedSimpleImport extends OSGiTestCase {
+	
+	ComponentInstance import1;
+	Factory fooProvider;
+	ComponentInstance foo1, foo2;
+
+	public void setUp() {
+		
+		Properties p = new Properties();
+		p.put("name", "importer");
+		Factory compFact = Utils.getFactoryByName(context, "composite.requires.1");
+		try {
+			import1 = compFact.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Cannot instantiate the component : " + e.getMessage());
+		}
+		
+		import1.stop();
+		
+		fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		Properties p1 = new Properties();
+		p1.put("name", "foo1");
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo1 = fooProvider.createComponentInstance(p1);
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Cannot instantiate foo providers : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		foo1.dispose();
+		foo2.dispose();
+		import1.dispose();
+		foo1 = null;
+		foo2 = null;
+		import1 = null;
+	}
+	
+	public void testSimple() {
+        import1.start();
+
+		//Two providers
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import1);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo1.stop();
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import1);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 2", refs);
+		assertEquals("Test foo availability inside the composite - 2.2", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo2.stop();		
+		assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+		
+		foo2.start();
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import1);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}
+	
+	public void testSimple2() {
+		import1.start(); 
+		//Two providers
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import1);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo2.stop();
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import1);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo1.stop();		
+		assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+		
+		foo1.start();
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import1);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}
+	
+	
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/FilteredImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/FilteredImport.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/FilteredImport.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/FilteredImport.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,147 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class FilteredImport extends OSGiTestCase {
+	
+	ComponentInstance import1;
+	Factory fooProvider;
+	Factory fooProvider2;
+	
+	ComponentInstance foo1, foo2;
+
+	public void setUp() {
+		Properties p = new Properties();
+		p.put("name", "importer");
+		Factory compFact = Utils.getFactoryByName(context, "composite.requires.5");
+		try {
+			import1 = compFact.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Cannot instantiate the component : " + e.getMessage());
+		}
+		import1.stop();
+		
+		fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		fooProvider2 = Utils.getFactoryByName(context, "COMPO-FooProviderType-2");
+		assertNotNull("Check fooProvider availability", fooProvider2);
+		
+		Properties p1 = new Properties();
+		p1.put("name", "foo1");
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo1 = fooProvider.createComponentInstance(p1);
+			foo2 = fooProvider2.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Cannot instantiate foo providers : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		foo1.dispose();
+		foo2.dispose();
+		import1.dispose();
+		foo1 = null;
+		foo2 = null;
+		import1 = null;
+	}
+	
+	public void testSimple() {
+		import1.start(); 
+		//Two providers
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import1);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo1.stop();
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import1);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo2.stop();		
+		assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+		
+		foo2.start();
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import1);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}
+	
+	public void testSimple2() {
+		import1.start(); 
+		//Two providers
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import1);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo2.stop();
+		assertTrue("Test component invalidity - 1", import1.getState() == ComponentInstance.INVALID);
+		
+		// Stop the second provider
+		foo1.stop();		
+		assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+		
+		foo1.start();
+		assertTrue("Test component invalidity - 3", import1.getState() == ComponentInstance.INVALID);
+		
+		foo2.start();
+		assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import1);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+	}	
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/ImportTestSuite.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/ImportTestSuite.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/ImportTestSuite.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/ImportTestSuite.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,43 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.importer;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class ImportTestSuite {
+
+	public static Test suite(BundleContext bc) {
+	    OSGiTestSuite ots = new OSGiTestSuite("Composite Import Test Suite", bc);
+	    ots.addTestSuite(SimpleImport.class);
+	    ots.addTestSuite(DelayedSimpleImport.class);
+	    ots.addTestSuite(OptionalImport.class);
+	    ots.addTestSuite(DelayedOptionalImport.class);
+	    ots.addTestSuite(MultipleImport.class);
+	    ots.addTestSuite(DelayedMultipleImport.class);
+	    ots.addTestSuite(OptionalMultipleImport.class);
+	    ots.addTestSuite(DelayedOptionalMultipleImport.class);
+	    ots.addTestSuite(FilteredImport.class);
+	    ots.addTestSuite(DelayedFilteredImport.class);
+		return ots;
+	}
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/MultipleImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/MultipleImport.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/MultipleImport.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/MultipleImport.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,190 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MultipleImport extends OSGiTestCase {
+	
+	ComponentInstance import2;
+	Factory fooProvider;
+
+	public void setUp() {
+		fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		Properties p = new Properties();
+		p.put("name", "importer");
+		Factory compFact = Utils.getFactoryByName(context, "composite.requires.2");
+		try {
+			import2 = compFact.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Cannot instantiate the component : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		import2.dispose();
+		import2 = null;
+	}
+	
+	public void testSimple() {
+		// No provider -> Invalid
+		assertTrue("Test component invalidity", import2.getState() == ComponentInstance.INVALID);
+		
+		ComponentInstance foo = null;
+		Properties p = new Properties();
+		p.put("name", "foo");
+		try {
+			foo = fooProvider.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo component " + e.getMessage());
+		}
+		
+		ComponentInstance foo2 = null;
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo2 component " + e.getMessage());
+		}
+		
+		// The foo service is available => import1 must be valid
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import2);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2 ("+refs.length+")", refs.length, 2);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		FooService fs2 = (FooService) sc.getService(refs[1]);
+		assertTrue("Test foo invocation", fs2.foo());
+		sc.ungetService(refs[0]);
+		sc.ungetService(refs[1]);
+		
+		// Stop the second provider
+		foo2.dispose();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 2", refs);
+		assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// stop the foo provider
+		foo.stop();
+		
+		// No provider -> Invalid
+		assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);
+		
+		foo.start();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo.dispose(); 
+		// No provider -> Invalid
+		assertTrue("Test component invalidity - 3", import2.getState() == ComponentInstance.INVALID);
+	}
+	
+	public void testSimple2() {
+		// No provider -> Invalid
+		assertTrue("Test component invalidity", import2.getState() == ComponentInstance.INVALID);
+		
+		ComponentInstance foo1 = null;
+		Properties p = new Properties();
+		p.put("name", "foo");
+		try {
+			foo1 = fooProvider.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo component " + e.getMessage());
+		}
+		
+		ComponentInstance foo2 = null;
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo2 component " + e.getMessage());
+		}
+		
+		// The foo service is available => import1 must be valid
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import2);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2 ("+refs.length+")", refs.length, 2);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		FooService fs2 = (FooService) sc.getService(refs[1]);
+		assertTrue("Test foo invocation", fs2.foo());
+		sc.ungetService(refs[0]);
+		sc.ungetService(refs[1]);
+		
+		// Stop the first provider
+		foo1.stop();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 2", refs);
+		assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// stop the second foo provider
+		foo2.dispose();
+		
+		// No provider -> Invalid
+		assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);
+		
+		foo1.start();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo1.dispose(); 
+		// No provider -> Invalid
+		assertTrue("Test component invalidity - 3", import2.getState() == ComponentInstance.INVALID);
+	}
+
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalImport.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalImport.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalImport.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,184 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalImport extends OSGiTestCase {
+	
+	ComponentInstance import3;
+	Factory fooProvider;
+
+	public void setUp() {
+		fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		Properties p = new Properties();
+		p.put("name", "importer");
+		Factory compFact = Utils.getFactoryByName(context, "composite.requires.3");
+		try {
+			import3 = compFact.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Cannot instantiate the component : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		import3.dispose();
+		import3 = null;
+	}
+	
+	public void testSimple() {
+		// No provider -> valid
+		assertTrue("Test component invalidity", import3.getState() == ComponentInstance.VALID);
+		
+		ComponentInstance foo = null;
+		Properties p = new Properties();
+		p.put("name", "foo");
+		try {
+			foo = fooProvider.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo component " + e.getMessage());
+		}
+		
+		ComponentInstance foo2 = null;
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo2 component " + e.getMessage());
+		}
+		
+		// The foo service is available => import1 must be valid
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import3);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo2.dispose();
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import3);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 2", refs);
+		assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// stop the foo provider
+		foo.stop();
+		
+		// No provider -> Invalid
+		assertTrue("Test component invalidity - 2", import3.getState() == ComponentInstance.VALID);
+		
+		foo.start();
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import3);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo.dispose(); 
+		// No provider -> Invalid
+		assertTrue("Test component invalidity - 3", import3.getState() == ComponentInstance.VALID);
+	}
+	
+	public void testSimple2() {
+		// No provider -> valid
+		assertTrue("Test component invalidity", import3.getState() == ComponentInstance.VALID);
+		
+		ComponentInstance foo1 = null;
+		Properties p = new Properties();
+		p.put("name", "foo");
+		try {
+			foo1 = fooProvider.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo component " + e.getMessage());
+		}
+		
+		ComponentInstance foo2 = null;
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo2 component " + e.getMessage());
+		}
+		
+		// The foo service is available => import1 must be valid
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import3);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// Stop the second provider
+		foo1.stop();
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import3);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 2", refs);
+		assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// stop the foo provider
+		foo2.dispose();
+		
+		// No provider -> Invalid
+		assertTrue("Test component invalidity - 2", import3.getState() == ComponentInstance.VALID);
+		
+		foo1.start();
+		assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import3);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo1.dispose(); 
+		// No provider -> Invalid
+		assertTrue("Test component invalidity - 3", import3.getState() == ComponentInstance.VALID);
+	}
+
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalMultipleImport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalMultipleImport.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalMultipleImport.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalMultipleImport.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,201 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalMultipleImport extends OSGiTestCase {
+	
+	ComponentInstance import2;
+	Factory fooProvider;
+
+	public void setUp() {
+		fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		Properties p = new Properties();
+		p.put("name", "importer");
+		Factory compFact = Utils.getFactoryByName(context, "composite.requires.4");
+		try {
+			import2 = compFact.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Cannot instantiate the component : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		import2.dispose();
+		import2 = null;
+	}
+	
+	public void testSimple() {
+		// No provider -> valid
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		
+		ComponentInstance foo = null;
+		Properties p = new Properties();
+		p.put("name", "foo");
+		try {
+			foo = fooProvider.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo component " + e.getMessage());
+		}
+		
+		ComponentInstance foo2 = null;
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo2 component " + e.getMessage());
+		}
+		
+		// The foo service is available => import1 must be valid
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import2);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2 ("+refs.length+")", refs.length, 2);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		FooService fs2 = (FooService) sc.getService(refs[1]);
+		assertTrue("Test foo invocation", fs2.foo());
+		sc.ungetService(refs[0]);
+		sc.ungetService(refs[1]);
+		
+		// Stop the second provider
+		foo2.dispose();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 2", refs);
+		assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// stop the foo provider
+		foo.stop();
+		
+		// No provider -> valid
+		assertTrue("Test component validity - 2", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertEquals("Test foo non-availability inside the composite - 1", refs.length, 0);
+		
+		foo.start();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo.dispose(); 
+		// No provider -> Invalid
+		assertTrue("Test component validity - 3", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertEquals("Test foo non-availability inside the composite - 2", refs.length, 0);
+	}
+	
+	public void testSimple2() {
+		// No provider -> Invalid
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		
+		ComponentInstance foo1 = null;
+		Properties p = new Properties();
+		p.put("name", "foo");
+		try {
+			foo1 = fooProvider.createComponentInstance(p);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo component " + e.getMessage());
+		}
+		
+		ComponentInstance foo2 = null;
+		Properties p2 = new Properties();
+		p2.put("name", "foo2");
+		try {
+			foo2 = fooProvider.createComponentInstance(p2);
+		} catch(Exception e) {
+			fail("Fail to instantiate the foo2 component " + e.getMessage());
+		}
+		
+		// The foo service is available => import1 must be valid
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(import2);
+		ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 1", refs);
+		assertEquals("Test foo availability inside the composite - 1.2 ("+refs.length+")", refs.length, 2);
+		FooService fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		FooService fs2 = (FooService) sc.getService(refs[1]);
+		assertTrue("Test foo invocation", fs2.foo());
+		sc.ungetService(refs[0]);
+		sc.ungetService(refs[1]);
+		
+		// Stop the first provider
+		foo1.stop();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 2", refs);
+		assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		// stop the second foo provider
+		foo2.dispose();
+		
+		// No provider -> Invalid
+		assertTrue("Test component validity - 2", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertEquals("Test foo non-availability inside the composite - 1", refs.length, 0);
+		
+		foo1.start();
+		assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertNotNull("Test foo availability inside the composite - 3", refs);
+		assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+		fs = (FooService) sc.getService(refs[0]);
+		assertTrue("Test foo invocation", fs.foo());
+		sc.ungetService(refs[0]);
+		
+		foo1.dispose(); 
+		// No provider -> Invalid
+		assertTrue("Test component invalidity - 3", import2.getState() == ComponentInstance.VALID);
+		sc = Utils.getServiceContext(import2);
+		refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+		assertEquals("Test foo non-availability inside the composite - 2", refs.length, 0);
+	}
+
+
+}



Mime
View raw message