felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r615675 [3/21] - in /felix/sandbox/clement/ipojo: ./ annotations/ ant/ arch/ core/ core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ core/src/main/java/org/apach...
Date Sun, 27 Jan 2008 23:21:37 GMT
Added: felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedSimpleImport.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedSimpleImport.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedSimpleImport.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedSimpleImport.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,132 @@
+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.util.Utils;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+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, "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/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/FilteredImport.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/FilteredImport.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/FilteredImport.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/FilteredImport.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,129 @@
+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.util.Utils;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+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, "FooProviderType-1");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		fooProvider2 = Utils.getFactoryByName(context, "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/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/ImportTestSuite.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/ImportTestSuite.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/ImportTestSuite.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/ImportTestSuite.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,25 @@
+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/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/MultipleImport.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/MultipleImport.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/MultipleImport.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/MultipleImport.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,172 @@
+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.util.Utils;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.osgi.framework.ServiceReference;
+
+public class MultipleImport extends OSGiTestCase {
+	
+	ComponentInstance import2;
+	Factory fooProvider;
+
+	public void setUp() {
+		fooProvider = Utils.getFactoryByName(context, "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/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalImport.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalImport.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalImport.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalImport.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,166 @@
+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.util.Utils;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalImport extends OSGiTestCase {
+	
+	ComponentInstance import3;
+	Factory fooProvider;
+
+	public void setUp() {
+		fooProvider = Utils.getFactoryByName(context, "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/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalMultipleImport.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalMultipleImport.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalMultipleImport.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalMultipleImport.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,183 @@
+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.util.Utils;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalMultipleImport extends OSGiTestCase {
+	
+	ComponentInstance import2;
+	Factory fooProvider;
+
+	public void setUp() {
+		fooProvider = Utils.getFactoryByName(context, "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);
+	}
+
+
+}

Added: felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/SimpleImport.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/SimpleImport.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/SimpleImport.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/importer/SimpleImport.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,166 @@
+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.util.Utils;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.osgi.framework.ServiceReference;
+
+public class SimpleImport extends OSGiTestCase {
+	
+	ComponentInstance import1;
+	Factory fooProvider;
+
+	public void setUp() {
+		fooProvider = Utils.getFactoryByName(context, "FooProviderType-1");
+		assertNotNull("Check fooProvider availability", fooProvider);
+		
+		Properties p = new Properties();
+		p.put("name", "importer");
+		Factory compFact = Utils.getFactoryByName(context, "composite.requires.1");
+		try {
+			import1 = compFact.createComponentInstance(p);
+		} catch(Exception e) {
+		    e.printStackTrace();
+			fail("Cannot instantiate the component : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		import1.dispose();
+		import1 = null;
+	}
+	
+	public void testSimple() {
+		// No provider -> Invalid
+		assertTrue("Test component invalidity", import1.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", 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]);
+		
+		// Stop the second provider
+		foo2.dispose();
+		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.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", import1.getState() == ComponentInstance.INVALID);
+		
+		foo.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]);
+		
+		foo.dispose(); 
+		// No provider -> Invalid
+		assertTrue("Test component invalidity - 3", import1.getState() == ComponentInstance.INVALID);
+	}
+	
+	public void testSimple2() {
+		// No provider -> Invalid
+		assertTrue("Test component invalidity", import1.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", 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]);
+		
+		// Stop the first provider
+		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.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", 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]);
+		
+		foo1.dispose(); 
+		// No provider -> Invalid
+		assertTrue("Test component invalidity - 3", import1.getState() == ComponentInstance.INVALID);
+	}	
+
+}

Propchange: felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Jan 27 15:21:24 2008
@@ -0,0 +1,6 @@
+target*
+bin*
+.settings*
+.classpath
+.project
+.checkstyle

Added: felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/EmptyCompositeTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/EmptyCompositeTest.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/EmptyCompositeTest.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/EmptyCompositeTest.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,204 @@
+package org.apache.felix.ipojo.test.composite.infrastructure;
+
+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.architecture.ComponentTypeDescription;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.composite.CompositeManager;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+
+public class EmptyCompositeTest extends OSGiTestCase {
+	
+	public void testEmptyCompositeCreation() {
+		Factory factory = Utils.getFactoryByName(context, "composite.empty");
+		Properties props = new Properties();
+		props.put("name", "empty");
+		
+		ComponentInstance ci = null;
+		try {
+			ci = factory.createComponentInstance(props);
+		} catch (Exception e) {
+		    e.printStackTrace();
+			fail("Unacceptable configuration : " + e.getMessage());
+		}
+		
+		ComponentTypeDescription cd = ci.getFactory().getComponentDescription();
+		assertEquals("Check component type name", cd.getName(), "composite.empty");
+//		assertEquals("Check class name (" + cd.getClassName() + ")", cd.getClassName(), "composite");
+		assertEquals("Check offered service", cd.getprovidedServiceSpecification().length, 0);
+		assertEquals("Check configurable properties", cd.getProperties().length, 0);
+		
+		InstanceDescription id = ci.getInstanceDescription();
+		assertEquals("Check composite instance name", id.getName(), "empty");
+		assertEquals("Check composite instance state (" + id.getState() + ")", id.getState(), ComponentInstance.VALID);
+		
+		assertEquals("Check contained instance", id.getContainedInstances().length, 0);
+		
+		assertTrue("Check composite manager", ci instanceof CompositeManager);
+		CompositeManager cm = (CompositeManager) ci;
+		ServiceContext sc = cm.getServiceContext();
+		try {
+			assertEquals("Check number of factories imported", sc.getServiceReferences(Factory.class.getName(), null).length, context.getServiceReferences(Factory.class.getName(), null).length);
+		} catch (InvalidSyntaxException e) {
+			fail("Invalid filter : " + e.getMessage());
+		}
+		ci.dispose();
+	}
+	
+	public void testInstanceCreation1() {
+		Factory factory = Utils.getFactoryByName(context, "composite.empty");
+		Properties props = new Properties();
+		props.put("name", "empty");
+		
+		ComponentInstance ci = null;
+		try {
+			ci = factory.createComponentInstance(props);
+		} catch(Exception e) {
+		    e.printStackTrace();
+			fail("Unacceptable configuration : " + e.getMessage());
+		}
+		
+		assertTrue("Check composite manager", ci instanceof CompositeManager);
+		CompositeManager cm = (CompositeManager) ci;
+		ServiceContext sc = cm.getServiceContext();
+		try {
+			assertEquals("Check number of factories imported", sc.getServiceReferences(Factory.class.getName(), null).length, context.getServiceReferences(Factory.class.getName(), null).length);
+		} catch (InvalidSyntaxException e) {
+			fail("Invalid filter : " + e.getMessage());
+		}
+		
+		Properties props2 = new Properties();
+		props2.put("name", "empty2");
+		ComponentInstance ci2 = null;
+		try {
+			ci2 = factory.createComponentInstance(props2, sc);
+		} catch(Exception e) {
+		    e.printStackTrace();
+			fail("Unacceptable configuration : " + e.getMessage());
+		}
+		
+		InstanceDescription id = ci.getInstanceDescription();
+		assertEquals("Check composite instance name", id.getName(), "empty");
+		assertEquals("Check composite instance state", id.getState(), ComponentInstance.VALID);
+		assertEquals("Check contained instance", id.getContainedInstances().length, 1);
+		InstanceDescription id2 = id.getContainedInstances()[0];
+		assertEquals("Check composite instance name", id2.getName(), "empty2");
+		assertEquals("Check composite instance state", id2.getState(), ComponentInstance.VALID);
+		assertEquals("Check contained instance", id2.getContainedInstances().length, 0);
+		
+		ci2.dispose();
+		id = ci.getInstanceDescription();
+		assertEquals("Check composite instance name", id.getName(), "empty");
+		assertEquals("Check composite instance state", id.getState(), ComponentInstance.VALID);
+		assertEquals("Check contained instance", id.getContainedInstances().length, 0);
+		
+		ci.dispose();
+	}
+	
+	public void testInstanceCreation2() {
+		Factory factory = Utils.getFactoryByName(context, "composite.empty");
+		Properties props = new Properties();
+		props.put("name", "empty");
+		
+		ComponentInstance ci = null;
+		try {
+			ci = factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Unacceptable configuration : " + e.getMessage());
+		}
+		
+		assertTrue("Check composite manager", ci instanceof CompositeManager);
+		CompositeManager cm = (CompositeManager) ci;
+		ServiceContext sc = cm.getServiceContext();
+		try {
+			assertEquals("Check number of factories imported", sc.getServiceReferences(Factory.class.getName(), null).length, context.getServiceReferences(Factory.class.getName(), null).length);
+		} catch (InvalidSyntaxException e) {
+			fail("Invalid filter : " + e.getMessage());
+		}
+		
+		Factory factory2 = Utils.getFactoryByName(sc, "composite.empty");
+		assertNotNull("Check factory2 not null", factory2);
+		Properties props2 = new Properties();
+		props2.put("name", "empty2");
+		ComponentInstance ci2 = null;
+		try {
+			ci2 = factory2.createComponentInstance(props2);
+		} catch(Exception e) {
+			fail("Unacceptable configuration : " + e.getMessage());
+		}
+		
+		InstanceDescription id = ci.getInstanceDescription();
+		assertEquals("Check composite instance name", id.getName(), "empty");
+		assertEquals("Check composite instance state", id.getState(), ComponentInstance.VALID);
+		assertEquals("Check contained instance", id.getContainedInstances().length, 1);
+		InstanceDescription id2 = id.getContainedInstances()[0];
+		assertEquals("Check composite instance name", id2.getName(), "empty2");
+		assertEquals("Check composite instance state", id2.getState(), ComponentInstance.VALID);
+		assertEquals("Check contained instance", id2.getContainedInstances().length, 0);
+		
+		ci2.dispose();
+		id = ci.getInstanceDescription();
+		assertEquals("Check composite instance name", id.getName(), "empty");
+		assertEquals("Check composite instance state", id.getState(), ComponentInstance.VALID);
+		assertEquals("Check contained instance", id.getContainedInstances().length, 0);
+		
+		ci.dispose();
+	}
+	
+	public void testInstanceCreation3() {
+		Factory factory = Utils.getFactoryByName(context, "composite.empty");
+		Properties props = new Properties();
+		props.put("name", "empty");
+		
+		ComponentInstance ci = null;
+		try {
+			ci = factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Unacceptable configuration : " + e.getMessage());
+		}
+		
+		assertTrue("Check composite manager", ci instanceof CompositeManager);
+		CompositeManager cm = (CompositeManager) ci;
+		ServiceContext sc = cm.getServiceContext();
+		try {
+			assertEquals("Check number of factories imported", sc.getServiceReferences(Factory.class.getName(), null).length, context.getServiceReferences(Factory.class.getName(), null).length);
+		} catch (InvalidSyntaxException e) {
+			fail("Invalid filter : " + e.getMessage());
+		}
+		
+		Factory factory2 = Utils.getFactoryByName(sc, "composite.empty");
+		assertNotNull("Check factory2 not null", factory2);
+		Properties props2 = new Properties();
+		props2.put("name", "empty2");
+		ComponentInstance ci2 = null;
+		try {
+			ci2 = factory2.createComponentInstance(props2, sc);
+		} catch(Exception e) {
+			fail("Unacceptable configuration : " + e.getMessage());
+		}
+		
+		InstanceDescription id = ci.getInstanceDescription();
+		assertEquals("Check composite instance name", id.getName(), "empty");
+		assertEquals("Check composite instance state", id.getState(), ComponentInstance.VALID);
+		assertEquals("Check contained instance", id.getContainedInstances().length, 1);
+		InstanceDescription id2 = id.getContainedInstances()[0];
+		assertEquals("Check composite instance name", id2.getName(), "empty2");
+		assertEquals("Check composite instance state", id2.getState(), ComponentInstance.VALID);
+		assertEquals("Check contained instance", id2.getContainedInstances().length, 0);
+		
+		ci2.dispose();
+		id = ci.getInstanceDescription();
+		assertEquals("Check composite instance name", id.getName(), "empty");
+		assertEquals("Check composite instance state", id.getState(), ComponentInstance.VALID);
+		assertEquals("Check contained instance", id.getContainedInstances().length, 0);
+		
+		ci.dispose();
+	}
+
+
+}

Added: felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/FactoryManagementTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/FactoryManagementTest.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/FactoryManagementTest.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/FactoryManagementTest.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,245 @@
+package org.apache.felix.ipojo.test.composite.infrastructure;
+
+import java.util.Dictionary;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.FactoryStateListener;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.UnacceptableConfiguration;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+public class FactoryManagementTest extends OSGiTestCase {
+	
+	private FakeFactory fake1 = new FakeFactory("fake");
+	private FakeFactory fake2 = new FakeFactory("fake2");
+	
+	private Factory emptyFactory;
+	private ComponentInstance empty;
+	
+	private class FakeFactory implements Factory {
+		
+		private String m_name;
+		public FakeFactory(String name) { m_name = name; } 
+
+		public ComponentInstance createComponentInstance(Dictionary arg0) throws UnacceptableConfiguration { return null; }
+		public ComponentInstance createComponentInstance(Dictionary arg0, ServiceContext arg1) throws UnacceptableConfiguration { return null; }
+		public Element getDescription() { return null; }
+		public String getName() { return m_name; }
+		public boolean isAcceptable(Dictionary arg0) { return false; }
+		public void reconfigure(Dictionary arg0) throws UnacceptableConfiguration {	}
+        public void addFactoryStateListener(FactoryStateListener arg0) { }
+        public List getMissingHandlers() { return null;  }
+        public List getRequiredHandlers() { return null;  }
+        public void removeFactoryStateListener(FactoryStateListener arg0) { }
+        public ComponentTypeDescription getComponentDescription() { return null; }
+        public String getClassName() { return ""; }
+        public int getState() { return Factory.VALID; }
+        public BundleContext getBundleContext() { return context; }
+
+	}
+	
+	public void setUp() {
+		emptyFactory = Utils.getFactoryByName(context, "composite.empty");
+		Properties props = new Properties();
+		props.put("name", "empty-1");
+		try {
+			empty = emptyFactory.createComponentInstance(props);
+		} catch (Exception e) { fail("Cannot create empty instance " + e.getMessage()); }
+	}
+	
+	public void tearDown() {
+		empty.dispose();
+		empty = null;
+	}
+	
+	public void testOneLevelExposition() {
+		ServiceReference[] parentsFactoryReferences = Utils.getServiceReferences(context, Factory.class.getName(), null);
+		ServiceContext sc = Utils.getServiceContext(empty);
+		ServiceReference[] internalFactoryReferences = Utils.getServiceReferences(sc, Factory.class.getName(), null);
+		
+		assertEquals("Check the number of available factories", parentsFactoryReferences.length, internalFactoryReferences.length);
+		
+		for(int i = 0; i < parentsFactoryReferences.length; i++) {
+			Factory factory = (Factory) context.getService(parentsFactoryReferences[i]);
+			assertTrue("Check the avaibility of " + factory.getName(), isExposed(factory, internalFactoryReferences, sc));
+		}
+	}
+	
+	public void testTwoLevelExposition() {
+		ServiceReference[] parentsFactoryReferences = Utils.getServiceReferences(context, Factory.class.getName(), null);
+		ServiceContext sc1 = Utils.getServiceContext(empty);
+		ServiceReference[] Level1FactoryReferences = Utils.getServiceReferences(sc1, Factory.class.getName(), null);
+		
+		Factory fact = Utils.getFactoryByName(sc1, "composite.empty");
+		Properties p = new Properties();
+		p.put("name", "empty2");
+		ComponentInstance empty2 = null;
+		try {
+			empty2 = fact.createComponentInstance(p);
+		} catch (Exception e) {
+			fail("Cannot instantiate empty2 instance : " + e.getMessage());
+		}
+		
+		ServiceContext sc2 = Utils.getServiceContext(empty2);
+		ServiceReference[] Level2FactoryReferences = Utils.getServiceReferences(sc2, Factory.class.getName(), null);
+		
+		assertEquals("Check the number of available factories - 1", parentsFactoryReferences.length, Level1FactoryReferences.length);
+		assertEquals("Check the number of available factories - 2", parentsFactoryReferences.length, Level2FactoryReferences.length);
+		assertEquals("Check the number of available factories - 3", Level1FactoryReferences.length, Level2FactoryReferences.length);
+		
+		for(int i = 0; i < Level1FactoryReferences.length; i++) {
+			Factory factory = (Factory) context.getService(parentsFactoryReferences[i]);
+			assertTrue("Check the avaibility of " + factory.getName(), isExposed(factory, Level2FactoryReferences, sc2));
+		}
+		
+		empty2.dispose();
+	}
+	
+	public void testDynamism() {
+		ServiceReference[] parentsFactoryReferences = Utils.getServiceReferences(context, Factory.class.getName(), null);
+		ServiceContext sc1 = Utils.getServiceContext(empty);
+		ServiceReference[] Level1FactoryReferences = Utils.getServiceReferences(sc1, Factory.class.getName(), null);
+		
+		Factory fact = Utils.getFactoryByName(sc1, "composite.empty");
+		Properties p = new Properties();
+		p.put("name", "empty2");
+		ComponentInstance empty2 = null;
+		try {
+			empty2 = fact.createComponentInstance(p);
+		} catch (Exception e) {
+			fail("Cannot instantiate empty2 instance : " + e.getMessage());
+		}
+		
+		ServiceContext sc2 = Utils.getServiceContext(empty2);
+		ServiceReference[] Level2FactoryReferences = Utils.getServiceReferences(sc2, Factory.class.getName(), null);
+		
+		assertEquals("Check the number of available factories - 1", parentsFactoryReferences.length, Level1FactoryReferences.length);
+		assertEquals("Check the number of available factories - 2", parentsFactoryReferences.length, Level2FactoryReferences.length);
+		assertEquals("Check the number of available factories - 3", Level1FactoryReferences.length, Level2FactoryReferences.length);
+		
+		for(int i = 0; i < Level1FactoryReferences.length; i++) {
+			Factory factory = (Factory) context.getService(parentsFactoryReferences[i]);
+			assertTrue("Check the avaibility of " + factory.getName(), isExposed(factory, Level2FactoryReferences, sc2));
+		}
+		
+		// Publish fake1
+		ServiceRegistration reg1 = context.registerService(Factory.class.getName(), fake1, null);
+		
+		parentsFactoryReferences = Utils.getServiceReferences(context, Factory.class.getName(), null);
+		sc1 = Utils.getServiceContext(empty);
+		Level1FactoryReferences = Utils.getServiceReferences(sc1, Factory.class.getName(), null);
+		sc2 = Utils.getServiceContext(empty2);
+		Level2FactoryReferences = Utils.getServiceReferences(sc2, Factory.class.getName(), null);
+		
+		assertEquals("Check the number of available factories - 1.1", parentsFactoryReferences.length, Level1FactoryReferences.length);
+		assertEquals("Check the number of available factories - 1.2", parentsFactoryReferences.length, Level2FactoryReferences.length);
+		assertEquals("Check the number of available factories - 1.3", Level1FactoryReferences.length, Level2FactoryReferences.length);
+		
+		// 	Publish fake2
+		ServiceRegistration reg2 = context.registerService(Factory.class.getName(), fake2, null);
+		
+		parentsFactoryReferences = Utils.getServiceReferences(context, Factory.class.getName(), null);
+		sc1 = Utils.getServiceContext(empty);
+		Level1FactoryReferences = Utils.getServiceReferences(sc1, Factory.class.getName(), null);
+		sc2 = Utils.getServiceContext(empty2);
+		Level2FactoryReferences = Utils.getServiceReferences(sc2, Factory.class.getName(), null);
+		
+		assertEquals("Check the number of available factories - 1.1", parentsFactoryReferences.length, Level1FactoryReferences.length);
+		assertEquals("Check the number of available factories - 1.2", parentsFactoryReferences.length, Level2FactoryReferences.length);
+		assertEquals("Check the number of available factories - 1.3", Level1FactoryReferences.length, Level2FactoryReferences.length);
+		
+		reg1.unregister();
+		
+		parentsFactoryReferences = Utils.getServiceReferences(context, Factory.class.getName(), null);
+		sc1 = Utils.getServiceContext(empty);
+		Level1FactoryReferences = Utils.getServiceReferences(sc1, Factory.class.getName(), null);
+		sc2 = Utils.getServiceContext(empty2);
+		Level2FactoryReferences = Utils.getServiceReferences(sc2, Factory.class.getName(), null);
+		
+		assertEquals("Check the number of available factories - 1.1", parentsFactoryReferences.length, Level1FactoryReferences.length);
+		assertEquals("Check the number of available factories - 1.2", parentsFactoryReferences.length, Level2FactoryReferences.length);
+		assertEquals("Check the number of available factories - 1.3", Level1FactoryReferences.length, Level2FactoryReferences.length);
+		
+		reg2.unregister();
+		
+		parentsFactoryReferences = Utils.getServiceReferences(context, Factory.class.getName(), null);
+		sc1 = Utils.getServiceContext(empty);
+		Level1FactoryReferences = Utils.getServiceReferences(sc1, Factory.class.getName(), null);
+		sc2 = Utils.getServiceContext(empty2);
+		Level2FactoryReferences = Utils.getServiceReferences(sc2, Factory.class.getName(), null);
+		
+		assertEquals("Check the number of available factories - 1.1", parentsFactoryReferences.length, Level1FactoryReferences.length);
+		assertEquals("Check the number of available factories - 1.2", parentsFactoryReferences.length, Level2FactoryReferences.length);
+		assertEquals("Check the number of available factories - 1.3", Level1FactoryReferences.length, Level2FactoryReferences.length);
+		
+		empty2.dispose();
+	}
+	
+	public void testInvocation() {
+		ServiceContext sc1 = Utils.getServiceContext(empty);		
+		Factory fact = Utils.getFactoryByName(sc1, "composite.empty");
+		Properties p = new Properties();
+		p.put("name", "empty2");
+		ComponentInstance empty2 = null;
+		try {
+			empty2 = fact.createComponentInstance(p);
+		} catch (Exception e) {
+			fail("Cannot instantiate empty2 instance : " + e.getMessage());
+		}
+		
+		ServiceContext sc2 = Utils.getServiceContext(empty2);
+		
+		Factory fact1 = Utils.getFactoryByName(sc2, "SimpleCheckServiceProvider");
+		Properties props = new Properties();
+		props.put("name", "client");
+		ComponentInstance client = null;
+		try {
+			client = fact1.createComponentInstance(props);
+		} catch (Exception e) { fail("Cannot instantiate the client : " + e.getMessage()); }
+		
+		Factory fact2 = Utils.getFactoryByName(sc2, "FooProviderType-1");
+		Properties props2 = new Properties();
+		props2.put("name", "provider");
+		ComponentInstance provider = null;
+		try {
+			provider = fact2.createComponentInstance(props2);
+		} catch (Exception e) {
+			fail("Cannot instantiate the provider : " + e.getMessage());
+		}
+		
+		ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());		
+		assertNotNull("Check ref existency", ref);
+		CheckService check = (CheckService) sc2.getService(ref);
+		
+		assertTrue("Check invocation", check.check());
+		client.dispose();
+		provider.dispose();
+		empty2.dispose();
+	}
+	
+	
+	
+	
+	private boolean isExposed(Factory fact, ServiceReference[] refs, ServiceContext sc) {
+		for(int i = 0; i < refs.length; i++) {
+			Factory f = (Factory) sc.getService(refs[i]);
+			if(fact.getName().equals(f.getName())) {
+				sc.ungetService(refs[i]);
+				return true; 
+			}
+			sc.ungetService(refs[i]);
+		}
+		return false;
+	}
+
+}

Added: felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/InfrastructureTestSuite.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/InfrastructureTestSuite.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/InfrastructureTestSuite.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.composite/src/main/java/org/apache/felix/ipojo/test/composite/infrastructure/InfrastructureTestSuite.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,19 @@
+package org.apache.felix.ipojo.test.composite.infrastructure;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class InfrastructureTestSuite {
+
+	public static Test suite(BundleContext bc) {
+		OSGiTestSuite ots = new OSGiTestSuite("Service Context Infrastructure Test", bc);
+		ots.addTestSuite(ServiceRegistryTest.class);
+		ots.addTestSuite(EmptyCompositeTest.class);
+		ots.addTestSuite(FactoryManagementTest.class);
+		ots.addTestSuite(ServiceRangeTest.class);
+		return ots;
+	}
+
+}



Mime
View raw message