felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r652169 [3/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/importer/SimpleImport.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/SimpleImport.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/SimpleImport.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/SimpleImport.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 SimpleImport extends OSGiTestCase {
+	
+	ComponentInstance import1;
+	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.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 - 0 ("+import1.getState()+")", 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 - 1", 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 - 2", 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 - 3", 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);
+	}	
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/resources/metadata.xml?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/resources/metadata.xml (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.import-export/src/main/resources/metadata.xml Tue Apr 29 15:25:39 2008
@@ -0,0 +1,82 @@
+<ipojo
+	xmlns:cs="org.apache.felix.ipojo.test.composite.handler.CheckServiceHandler">
+	<composite name="composite.requires.1" architecture="true">
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.test.composite.service.FooService"
+			scope="composite" />
+	</composite>
+
+	<composite name="composite.requires.2" architecture="true">
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.test.composite.service.FooService"
+			aggregate="true" scope="composite" />
+	</composite>
+
+	<composite name="composite.requires.3" architecture="true">
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.test.composite.service.FooService"
+			optional="true" scope="composite" />
+	</composite>
+
+	<composite name="composite.requires.4" architecture="true">
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.test.composite.service.FooService"
+			optional="true" aggregate="true" scope="composite" />
+	</composite>
+
+	<composite name="composite.requires.5" architecture="true">
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.test.composite.service.FooService"
+			filter="(&amp;(int=2)(long=40))" scope="composite" />
+	</composite>
+
+	<composite name="composite.export.1" architecture="true">
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.test.composite.service.BazService"
+			aggregate="true" optional="true" filter="(!(instance.name=export))"
+			scope="composite" />
+		<provides action="export"
+			specification="org.apache.felix.ipojo.test.composite.service.BazService" />
+	</composite>
+
+	<composite name="composite.export.2" architecture="true">
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.test.composite.service.BazService"
+			scope="composite" aggregate="true" optional="true"
+			filter="(!(instance.name=export))" />
+		<provides action="export"
+			specification="org.apache.felix.ipojo.test.composite.service.BazService"
+			optional="true" />
+	</composite>
+
+	<composite name="composite.export.3" architecture="true">
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.test.composite.service.BazService"
+			scope="composite" aggregate="true" optional="true"
+			filter="(!(instance.name=export))" />
+		<provides action="export"
+			specification="org.apache.felix.ipojo.test.composite.service.BazService"
+			aggregate="true" />
+	</composite>
+
+	<composite name="composite.export.4" architecture="true">
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.test.composite.service.BazService"
+			aggregate="true" optional="true" filter="(!(instance.name=export))"
+			scope="composite" />
+		<provides action="export"
+			specification="org.apache.felix.ipojo.test.composite.service.BazService"
+			aggregate="true" optional="true" />
+	</composite>
+
+	<composite name="composite.export.5" architecture="true">
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.test.composite.service.BazService"
+			aggregate="true" optional="true" filter="(!(instance.name=export))"
+			scope="composite" />
+		<provides action="export"
+			specification="org.apache.felix.ipojo.test.composite.service.BazService"
+			filter="(instance.name=foo1)" />
+	</composite>
+
+</ipojo>

Propchange: felix/trunk/ipojo/tests/tests.composite.service.instance/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Apr 29 15:25:39 2008
@@ -0,0 +1,9 @@
+target*
+bin*
+.settings*
+.classpath
+.project
+.checkstyle
+maven-eclipse.xml
+.externalToolBuilders
+

Added: felix/trunk/ipojo/tests/tests.composite.service.instance/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.instance/pom.xml?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.instance/pom.xml (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.instance/pom.xml Tue Apr 29 15:25:39 2008
@@ -0,0 +1,101 @@
+<!--
+	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.
+-->
+<project>
+	<modelVersion>4.0.0</modelVersion>
+	<packaging>bundle</packaging>
+	<name>iPOJO Composite (Service Instance) Test Suite</name>
+	<artifactId>tests.composite.service.instance</artifactId>
+	<groupId>ipojo.tests</groupId>
+	<version>0.7.6-SNAPSHOT</version>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo</artifactId>
+			<version>0.7.6-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo.composite</artifactId>
+			<version>0.7.6-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo.metadata</artifactId>
+			<version>0.7.6-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.8.1</version>
+		</dependency>
+		<dependency>
+			<groupId>ipojo.examples</groupId>
+			<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
+			<version>0.7.6-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>ipojo.tests</groupId>
+			<artifactId>tests.composite</artifactId>
+			<version>0.7.6-SNAPSHOT</version>
+		</dependency>
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<version>1.4.0</version>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Bundle-SymbolicName>
+							${pom.artifactId}
+						</Bundle-SymbolicName>
+						<Private-Package>
+							org.apache.felix.ipojo.test.composite.instantiator*, org.apache.felix.ipojo.test.composite.instance
+						</Private-Package>
+						<Test-Suite>
+							org.apache.felix.ipojo.test.composite.instantiator.InstantiatorTestSuite
+						</Test-Suite>
+					</instructions>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-ipojo-plugin</artifactId>
+				<version>0.7.6-SNAPSHOT</version>
+				<executions>
+					<execution>
+						<goals>
+							<goal>ipojo-bundle</goal>
+						</goals>
+						<configuration>
+							<ignoreAnnotations>true</ignoreAnnotations>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>

Added: felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instance/SimpleInstance.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instance/SimpleInstance.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instance/SimpleInstance.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instance/SimpleInstance.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,268 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.instance;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class SimpleInstance extends OSGiTestCase {
+
+	private ComponentFactory fooFactory1, fooFactory2;
+    private ComponentFactory compoFactory;
+	private ComponentInstance empty;
+	
+	
+	public void setUp() {
+        fooFactory1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+        fooFactory2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooProviderType-Dyn2");
+        compoFactory = (ComponentFactory) Utils.getFactoryByName(context, "composite.inst.1");
+		Factory fact = Utils.getFactoryByName(context, "composite.empty");
+		Properties props = new Properties();
+		props.put("name", "empty-X");
+		try {
+			empty = fact.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot create the empty composite : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		empty.dispose();
+		empty = null;
+	}
+	
+	public void testCreation() {
+		Properties props = new Properties();
+		props.put("name", "under-A");
+		ComponentInstance under = null;
+		try {
+			under = compoFactory.createComponentInstance(props);
+		} catch(Exception e) {
+		    e.printStackTrace();
+			fail("Cannot instantiate under from " + compoFactory.getName() + " -> " + e.getMessage());
+		}      
+		
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		under.dispose();
+	}
+	
+	public void testServiceAvailability() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = compoFactory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}	
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(under);
+       
+		assertNotNull("Check service availability", sc.getServiceReference(FooService.class.getName()));
+        assertEquals("Check service provider", Utils.getServiceReferences(sc, FooService.class.getName(), null).length, 2);
+		
+		under.dispose();
+	}
+	
+	public void testCreationLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = compoFactory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+		    e.printStackTrace();
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		under.dispose();
+	}
+	
+	public void testServiceAvailabilityLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under-X");
+		ComponentInstance under = null;
+		try {
+			under = compoFactory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}	
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc2 = Utils.getServiceContext(under);
+        
+        assertNotNull("Check service availability", sc2.getServiceReference(FooService.class.getName()));
+        assertEquals("Check service providers", Utils.getServiceReferences(sc2, FooService.class.getName(), null).length, 2);
+		
+		under.dispose();
+	}
+	
+	public void testFactoryManagement() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = compoFactory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+		
+		fooFactory1.stop();
+		assertTrue("Check instance invalidity - 2", under.getState() == ComponentInstance.INVALID);
+        
+        fooFactory1.start();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+        
+		fooFactory2.stop();
+        assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+		
+		fooFactory2.start();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		
+		under.dispose();
+		fooFactory1.start();
+		fooFactory2.start();
+	}
+	
+	public void testFactoryManagementLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = compoFactory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+		
+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+        
+        fooFactory1.stop();
+        assertTrue("Check instance invalidity - 2", under.getState() == ComponentInstance.INVALID);
+        
+        fooFactory1.start();
+        assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+        
+        fooFactory2.stop();
+        assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+        
+        fooFactory2.start();
+        assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+        
+        under.dispose();
+        fooFactory1.start();
+        fooFactory2.start();
+	}
+	
+	public void atestArchitecture() { //TODO : to reactive
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = compoFactory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		ServiceReference ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		Architecture arch = (Architecture) context.getService(ref);
+		InstanceDescription id = arch.getInstanceDescription();
+		
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		InstanceDescription[] contained = id.getContainedInstances();
+		assertEquals("Check contained instances count (" + contained.length + ")", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");
+
+		fact3.stop();
+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.INVALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 0);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");
+
+		fact1.start();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");
+
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/ConfigurableInstantiation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/ConfigurableInstantiation.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/ConfigurableInstantiation.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/ConfigurableInstantiation.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,103 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.instantiator;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class ConfigurableInstantiation extends OSGiTestCase {
+
+	private ComponentFactory acceptF;
+	private ComponentFactory refuse1F;
+	private ComponentFactory refuse2F;
+	
+	public void setUp() {
+		acceptF = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.5-accept");
+		refuse1F = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.5-refuse1");
+		refuse2F = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.5-refuse2");
+		
+	}
+	
+	public void tearDown() { }
+	
+	public void testAccept() {
+		Properties props = new Properties();
+		props.put("name", "under-A");
+		ComponentInstance under = null;
+		try {
+			under = acceptF.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(under);
+		ServiceReference ref = sc.getServiceReference(FooService.class.getName());
+		assertNotNull("Check refs not null", ref);
+		FooService foo = (FooService) sc.getService(ref);
+		Properties p = foo.fooProps();
+		boolean b = ((Boolean) p.get("boolProp")).booleanValue();
+		String s = (String) p.get("strProp");
+		int i = ( (Integer) p.get("intProp")).intValue();
+		assertTrue("Test boolean", b);
+		assertEquals("Test string", s, "foo");
+		
+		assertEquals("Test int", i, 5); // The code fix to 5.
+		under.dispose();
+	}
+	
+	public void testRefuse1() {
+		Properties props = new Properties();
+		props.put("name", "under-ref1");
+		ComponentInstance under = null;
+		try {
+			under = refuse1F.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		
+		assertTrue("Check that under is not valid", under.getState() == ComponentInstance.INVALID);
+        
+        under.dispose();
+	}
+	
+	public void testRefuse2() {
+		Properties props = new Properties();
+		props.put("name", "under-ref2");
+		ComponentInstance under = null;
+		try {
+			under = refuse2F.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		
+		assertTrue("Check that under is not valid", under.getState() == ComponentInstance.INVALID);
+        
+        under.dispose();
+	}
+	
+}

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

Added: felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/MultipleInstantiation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/MultipleInstantiation.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/MultipleInstantiation.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/MultipleInstantiation.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,288 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.instantiator;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.BarService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MultipleInstantiation extends OSGiTestCase {
+
+	private ComponentFactory bar2Factory;
+	private ComponentInstance empty;
+	
+	public void setUp() {
+		bar2Factory = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.2");
+		Factory fact = Utils.getFactoryByName(context, "composite.empty");
+		Properties props = new Properties();
+		props.put("name", "empty");
+		try {
+			empty = fact.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot create the empty composite : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		empty.dispose();
+		empty = null;
+	}
+	
+	public void testCreation() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		under.dispose();
+	}
+	
+	public void testServiceAvailability() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}	
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(under);
+		assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));
+		int count = Utils.getServiceReferences(sc, BarService.class.getName(), null).length;
+		assertEquals("Check service provider number : " + count, count, 3);
+		
+		under.dispose();
+	}
+	
+	public void testCreationLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		under.dispose();
+	}
+	
+	public void testServiceAvailabilityLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}	
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc2 = Utils.getServiceContext(under);
+		assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 3);
+		
+		under.dispose();
+	}
+	
+	public void testFactoryManagement() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		ServiceContext sc = Utils.getServiceContext(under);
+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 2);
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 1);
+		
+		fact3.stop();
+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 0);
+		
+		fact1.start();
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 1);
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+	
+	public void testFactoryManagementLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc2 = Utils.getServiceContext(under);
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 2);
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);
+		
+		fact3.stop();
+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 0);
+		
+		fact1.start();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);
+		
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+	public void testArchitecture() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		ServiceReference ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		Architecture arch = (Architecture) context.getService(ref);
+		InstanceDescription id = arch.getInstanceDescription();
+		
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		InstanceDescription[] contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 3);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.2");
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 2);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.2");
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.2");
+
+		fact3.stop();
+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.INVALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 0);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.2");
+
+		fact1.start();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.2");
+
+		context.ungetService(ref);
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalInstantiation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalInstantiation.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalInstantiation.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalInstantiation.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,279 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.instantiator;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.BarService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalInstantiation extends OSGiTestCase {
+
+	private ComponentFactory bar1Factory;
+	private ComponentInstance empty;
+	
+	public void setUp() {
+		bar1Factory = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.3");
+		Factory fact = Utils.getFactoryByName(context, "composite.empty");
+		Properties props = new Properties();
+		props.put("name", "empty");
+		try {
+			empty = fact.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot create the empty composite : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		empty.dispose();
+		empty = null;
+	}
+	
+	public void testCreation() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		under.dispose();
+	}
+	
+	public void testServiceAvailability() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}	
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(under);
+		assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));
+		
+		under.dispose();
+	}
+	
+	public void testCreationLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		under.dispose();
+	}
+	
+	public void testServiceAvailabilityLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}	
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc2 = Utils.getServiceContext(under);
+		assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));
+		
+		under.dispose();
+	}
+	
+	public void testFactoryManagement() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		
+		fact3.stop();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(under);
+		assertNull("Check that no Bar Service is available", sc.getServiceReference(BarService.class.getName()));
+		
+		fact1.start();
+		assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);
+		
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+	
+	public void testFactoryManagementLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		
+		fact3.stop();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		
+		fact1.start();
+		assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);
+		
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+	
+	public void testArchitecture() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		
+		ServiceReference ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		Architecture arch = (Architecture) context.getService(ref);
+		assertNotNull("Check architecture", arch);
+		InstanceDescription id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		InstanceDescription[] contained = id.getContainedInstances();
+		assertNotNull("Check contained not null", contained);
+		assertEquals("Check contained instances count ("+contained.length+") - 1", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");
+
+		fact3.stop();
+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 0);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");
+
+		fact1.start();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");
+
+		context.ungetService(ref);
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalMultipleInstantiation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalMultipleInstantiation.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalMultipleInstantiation.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/OptionalMultipleInstantiation.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,203 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.instantiator;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.BarService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+
+public class OptionalMultipleInstantiation extends OSGiTestCase {
+
+	private ComponentFactory bar2Factory;
+	private ComponentInstance empty;
+	
+	public void setUp() {
+		bar2Factory = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.4");
+		assertNotNull("Check bar2factory availability", bar2Factory);
+		
+		Factory fact = Utils.getFactoryByName(context, "composite.empty");
+		Properties props = new Properties();
+		props.put("name", "empty");
+		try {
+			empty = fact.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot create the empty composite : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		empty.dispose();
+		empty = null;
+	}
+	
+	public void testCreation() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		under.dispose();
+	}
+	
+	public void testServiceAvailability() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}	
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(under);
+		assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));
+		int count = Utils.getServiceReferences(sc, BarService.class.getName(), null).length;
+		assertEquals("Check service provider number : " + count, count, 3);
+		
+		under.dispose();
+	}
+	
+	public void testCreationLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		under.dispose();
+	}
+	
+	public void testServiceAvailabilityLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}	
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc2 = Utils.getServiceContext(under);
+		assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 3);
+		
+		under.dispose();
+	}
+	
+	public void testFactoryManagement() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		ServiceContext sc = Utils.getServiceContext(under);
+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 2);
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 1);
+		
+		fact3.stop();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 0);
+		
+		fact1.start();
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc, BarService.class.getName(), null).length, 1);
+		assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);
+		
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+	
+	public void testFactoryManagementLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar2Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc2 = Utils.getServiceContext(under);
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 2);
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);
+		
+		fact3.stop();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 0);
+		
+		fact1.start();
+		assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);
+		assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);
+		
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/SimpleInstantiation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/SimpleInstantiation.java?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/SimpleInstantiation.java (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/java/org/apache/felix/ipojo/test/composite/instantiator/SimpleInstantiation.java Tue Apr 29 15:25:39 2008
@@ -0,0 +1,265 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.composite.instantiator;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.BarService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class SimpleInstantiation extends OSGiTestCase {
+
+	private ComponentFactory bar1Factory;
+	private ComponentInstance empty;
+	
+	public void setUp() {
+		bar1Factory = (ComponentFactory) Utils.getFactoryByName(context, "composite.bar.1");
+		Factory fact = Utils.getFactoryByName(context, "composite.empty");
+		Properties props = new Properties();
+		props.put("name", "empty-X");
+		try {
+			empty = fact.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot create the empty composite : " + e.getMessage());
+		}
+	}
+	
+	public void tearDown() {
+		empty.dispose();
+		empty = null;
+	}
+	
+	public void testCreation() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props);
+		} catch(Exception e) {
+		    e.printStackTrace();
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		under.dispose();
+	}
+	
+	public void testServiceAvailability() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}	
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc = Utils.getServiceContext(under);
+		assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));
+		
+		under.dispose();
+	}
+	
+	public void testCreationLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		under.dispose();
+	}
+	
+	public void testServiceAvailabilityLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under-X");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}	
+		assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+		ServiceContext sc2 = Utils.getServiceContext(under);
+		assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));
+		
+		under.dispose();
+	}
+	
+	public void testFactoryManagement() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		
+		fact3.stop();
+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+		
+		fact1.start();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+	
+	public void testFactoryManagementLevel2() {
+		ServiceContext sc = Utils.getServiceContext(empty);
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props, sc);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		
+		fact3.stop();
+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+		
+		fact1.start();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+	
+	public void testArchitecture() {
+		Properties props = new Properties();
+		props.put("name", "under");
+		ComponentInstance under = null;
+		try {
+			under = bar1Factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate under : " + e.getMessage());
+		}
+		ServiceReference ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		Architecture arch = (Architecture) context.getService(ref);
+		InstanceDescription id = arch.getInstanceDescription();
+		
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		InstanceDescription[] contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");
+		
+		ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-1");
+		ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-2");
+		ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(context, "COMPO-FooBarProviderType-3");
+		
+		fact1.stop();
+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");
+		
+		fact2.stop();
+		assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");
+
+		fact3.stop();
+		assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.INVALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 0);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");
+
+		fact1.start();
+		assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+		ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "under");
+		assertNotNull("Check architecture availability", ref);
+		arch = (Architecture) context.getService(ref);
+		id = arch.getInstanceDescription();
+		assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+		contained = id.getContainedInstances();
+		assertEquals("Check contained instances count", contained.length, 1);
+		assertEquals("Check that no object are created" , id.getCreatedObjects().length, 0);
+		assertEquals("Check instance name" , id.getName(), "under");
+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.1");
+
+		under.dispose();
+		fact2.start();
+		fact3.start();
+	}
+
+}

Added: felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/resources/metadata.xml?rev=652169&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/resources/metadata.xml (added)
+++ felix/trunk/ipojo/tests/tests.composite.service.instance/src/main/resources/metadata.xml Tue Apr 29 15:25:39 2008
@@ -0,0 +1,54 @@
+<ipojo xmlns:cs="org.apache.felix.ipojo.test.composite.handler.CheckServiceHandler">	
+	<composite name="composite.bar.1" architecture="true">
+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService"/>
+	</composite>
+	
+	<composite name="composite.bar.2" architecture="true">
+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService" aggregate="true"/>
+	</composite>
+	
+	<composite name="composite.bar.3" architecture="true">
+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService" optional="true"/>
+	</composite>
+	
+	<composite name="composite.bar.4" architecture="true">
+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.FooService" aggregate="true" optional="true"/>
+	</composite>
+	
+	<composite name="composite.bar.5-accept" architecture="true">
+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.FooService">
+			<property name="boolean" value="true"/>
+			<property name="string" value="foo"/>
+			<property name="strAprop" value="{foo, bar, baz}"/>
+			<property name="int" value="5"/>
+		</subservice>
+	</composite>
+	
+	<composite name="composite.bar.5-refuse1" architecture="true">
+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService">
+			<property name="foo" value="bar"/>
+			<property name="boolean" value="true"/>
+			<property name="string" value="foo"/>
+			<property name="strAprop" value="{foo, bar, baz}"/>
+			<property name="int" value="5"/>
+		</subservice>
+	</composite>
+	
+	<composite name="composite.bar.5-refuse2" architecture="true">
+		<subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService">
+			<property name="string" value="foo"/>
+			<property name="strAprop" value="{foo, bar, baz}"/>
+		</subservice>
+	</composite>
+
+    <!-- Instance of a specified component -->
+	<composite name="composite.inst.1" factory="true" architecture="true">
+		<instance component="COMPO-FooProviderType-1" /> <!-- name="FooProv"  -->
+		<instance component="COMPO-FooProviderType-Dyn2">
+			<property name="boolean" value="true"/>
+			<property name="string" value="foo"/>
+			<property name="strAProp" value="{a,b,c}"/>
+		</instance>
+	</composite>
+
+</ipojo>

Modified: felix/trunk/ipojo/tests/tests.composite/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite/pom.xml?rev=652169&r1=652168&r2=652169&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/tests.composite/pom.xml (original)
+++ felix/trunk/ipojo/tests/tests.composite/pom.xml Tue Apr 29 15:25:39 2008
@@ -65,7 +65,7 @@
 				<configuration>
 					<instructions>
 						<Export-Package>
-							org.apache.felix.ipojo.test.composite.service
+							org.apache.felix.ipojo.test.composite.service, org.apache.felix.ipojo.test.composite.component, org.apache.felix.ipojo.test.composite.util
 						</Export-Package>
 						<Bundle-SymbolicName>
 							${pom.artifactId}



Mime
View raw message