FELIX-3093 - migrate composite test to pax exam 3

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1450158 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/pom.xml b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/pom.xml
new file mode 100644
index 0000000..06d1540
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/pom.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <parent>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>org.apache.felix.ipojo.runtime.composite-it</artifactId>
+        <version>1.9.0-SNAPSHOT</version>
+        <relativePath>../../../pom.xml</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.felix</groupId>
+    <artifactId>ipojo-composite-instance-test</artifactId>
+
+    <name>${project.artifactId}</name>
+    
+</project>
\ No newline at end of file
diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/Baz2CheckProvider.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/Baz2CheckProvider.java
new file mode 100644
index 0000000..7e5d145
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/Baz2CheckProvider.java
@@ -0,0 +1,81 @@
+/* 

+ * 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.runtime.core.components;

+

+import org.apache.felix.ipojo.runtime.core.services.BazService;

+import org.apache.felix.ipojo.runtime.core.services.CheckService;

+import org.apache.felix.ipojo.runtime.core.services.FooService;

+import org.osgi.framework.ServiceReference;

+

+import java.util.Properties;

+

+public class Baz2CheckProvider implements CheckService {

+	

+	BazService fs;

+	

+	int simpleB = 0;

+	int objectB = 0;

+	int refB = 0;

+	int simpleU = 0;

+	int objectU = 0;

+	int refU = 0;

+

+	public boolean check() {

+		return fs.foo();

+	}

+

+	public Properties getProps() {

+		Properties props = new Properties();

+		props.put("result", new Boolean(fs.foo()));

+		props.put("voidB", new Integer(simpleB));

+		props.put("objectB", new Integer(objectB));

+		props.put("refB", new Integer(refB));

+		props.put("voidU", new Integer(simpleU));

+		props.put("objectU", new Integer(objectU));

+		props.put("refU", new Integer(refU));

+		props.put("boolean", new Boolean(fs.getBoolean()));

+		props.put("int", new Integer(fs.getInt()));

+		props.put("long", new Long(fs.getLong()));

+		props.put("double", new Double(fs.getDouble()));

+		if(fs.getObject() != null) { props.put("object", fs.getObject()); }

+		

+		return props;

+	}

+	

+	private void voidBind() {

+		simpleB++;

+	}

+	private void voidUnbind() {

+		simpleU++;

+	}

+	

+	protected void objectBind(Object o) {

+		if(o != null && o instanceof FooService) { objectB++; }

+	}

+	protected void objectUnbind(Object o) {

+		if(o != null && o instanceof FooService) { objectU++; }

+	}

+	

+	public void refBind(ServiceReference sr) {

+		if(sr != null) { refB++; }

+	}

+	public void refUnbind(ServiceReference sr) {

+		if(sr != null) { refU++; }

+	}

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/BazProviderType1.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/BazProviderType1.java
new file mode 100644
index 0000000..5ac64d3
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/BazProviderType1.java
@@ -0,0 +1,51 @@
+/* 

+ * 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.runtime.core.components;

+

+import org.apache.felix.ipojo.runtime.core.services.BazService;

+

+import java.util.Properties;

+

+public class BazProviderType1 implements BazService {

+	

+	private int m_bar;

+	private String m_foo;

+

+	public boolean foo() {

+		return true;

+	}

+

+	public Properties fooProps() {

+		Properties p = new Properties();

+		p.put("bar", new Integer(m_bar));

+		p.put("foo", m_foo);

+		return p;

+	}

+	

+	public boolean getBoolean() { return true; }

+

+	public double getDouble() { return 1.0; }

+

+	public int getInt() { return 1; }

+

+	public long getLong() { return 1; }

+

+	public Boolean getObject() { return new Boolean(true); }

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckProviderParentClass.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckProviderParentClass.java
new file mode 100644
index 0000000..7d18712
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckProviderParentClass.java
@@ -0,0 +1,51 @@
+/* 

+ * 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.runtime.core.components;

+

+import org.apache.felix.ipojo.runtime.core.services.FooService;

+import org.osgi.framework.ServiceReference;

+

+public abstract class CheckProviderParentClass {

+    

+    int simpleU = 0;

+    int objectU = 0;

+    int refU = 0;

+    int bothU = 0;

+    

+    

+    public void bothUnbind(FooService o, ServiceReference sr) {

+        if(sr != null && o != null && o instanceof FooService) { bothU++; }

+    }

+    

+    public void refUnbind(ServiceReference sr) {

+        if(sr != null) { refU++; }

+    }

+    

+    public void objectUnbind(FooService o) {

+        if(o != null && o instanceof FooService) { objectU++; }

+        else {

+            System.err.println("Unbind null : " + o);

+        }

+    }

+    

+    public void voidUnbind() {

+        simpleU++;

+    }

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckServiceProvider.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckServiceProvider.java
new file mode 100644
index 0000000..eee88a2
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckServiceProvider.java
@@ -0,0 +1,83 @@
+/* 

+ * 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.runtime.core.components;

+

+import org.apache.felix.ipojo.runtime.core.services.CheckService;

+import org.apache.felix.ipojo.runtime.core.services.FooService;

+import org.osgi.framework.ServiceReference;

+

+import java.util.Properties;

+

+public class CheckServiceProvider extends CheckProviderParentClass implements CheckService {

+    

+	FooService fs;

+	

+	int simpleB = 0;

+	int objectB = 0;

+	int refB = 0;

+	int bothB = 0;

+

+	public boolean check() {

+		return fs.foo();

+	}

+

+	public Properties getProps() {

+		Properties props = new Properties();

+		props.put("voidB", new Integer(simpleB));

+		props.put("objectB", new Integer(objectB));

+		props.put("refB", new Integer(refB));

+		props.put("bothB", new Integer(bothB));

+		props.put("voidU", new Integer(simpleU));

+		props.put("objectU", new Integer(objectU));

+		props.put("refU", new Integer(refU));

+		props.put("bothU", new Integer(bothU));

+		if (fs != null) {

+		    props.put("result", new Boolean(fs.foo()));

+		    props.put("boolean", new Boolean(fs.getBoolean()));

+		    props.put("int", new Integer(fs.getInt()));

+		    props.put("long", new Long(fs.getLong()));

+		    props.put("double", new Double(fs.getDouble()));

+		    if(fs.getObject() != null) { props.put("object", fs.getObject()); }

+		}

+        props.put("static", CheckService.foo);

+        props.put("class", CheckService.class.getName());

+		return props;

+	}

+	

+	private void voidBind() {

+		simpleB++;

+	}

+	

+	protected void objectBind(FooService o) {

+	    if (o == null) {

+	        System.err.println("Bind receive null !!! ");

+	        return;

+	    }

+		if(o != null && o instanceof FooService) { objectB++; }

+	}

+	

+	public void refBind(ServiceReference sr) {

+		if(sr != null) { refB++; }

+	}

+	

+    public void bothBind(FooService o, ServiceReference sr) {

+	    if(sr != null && o != null && o instanceof FooService) { bothB++; }

+	}

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooBarProviderType1.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooBarProviderType1.java
new file mode 100644
index 0000000..03016d3
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooBarProviderType1.java
@@ -0,0 +1,54 @@
+/* 

+ * 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.runtime.core.components;

+

+import org.apache.felix.ipojo.runtime.core.services.BarService;

+import org.apache.felix.ipojo.runtime.core.services.FooService;

+

+import java.util.Properties;

+

+public class FooBarProviderType1 implements FooService, BarService {

+

+	public boolean foo() {

+		return true;

+	}

+

+	public Properties fooProps() {

+		return new Properties();

+	}

+

+	public boolean bar() {

+		return true;

+	}

+

+	public Properties getProps() {

+		return new Properties();

+	}

+

+	public boolean getBoolean() { return true; }

+

+	public double getDouble() { return 1.0; }

+

+	public int getInt() { return 1; }

+

+	public long getLong() { return 1; }

+

+	public Boolean getObject() { return new Boolean(true); }

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderType1.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderType1.java
new file mode 100644
index 0000000..b9eda2d
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderType1.java
@@ -0,0 +1,92 @@
+/* 

+ * 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.runtime.core.components;

+

+import org.apache.felix.ipojo.runtime.core.services.FooService;

+import org.osgi.framework.BundleContext;

+

+import java.util.Properties;

+

+public class FooProviderType1 implements FooService {

+	

+	private int m_bar;

+	private String m_foo;

+    

+    private BundleContext m_context;

+    

+    private static FooProviderType1 singleton;

+    private static int count = 0;

+    

+    public FooProviderType1(BundleContext bc) {

+        if (bc ==null) {

+            throw new RuntimeException("Injected bundle context null");

+        }

+        m_context = bc;

+    }

+

+	public boolean foo() {

+		return true;

+	}

+

+	public Properties fooProps() {

+		Properties p = new Properties();

+		p.put("bar", new Integer(m_bar));

+        if(m_foo != null) {

+            p.put("foo", m_foo);

+        }

+        p.put("context", m_context);

+        

+        p.put("count", new Integer(count));

+		return p;

+	}

+    

+	public void testException() throws Exception {

+        String a = "foobarbaz";

+	    throw new Exception("foo"+a);

+    }

+    

+    public void testTry() {

+            String a = "foo";

+            a.charAt(0);

+    }

+    

+    public void testTry2(String s) {

+            String a = "foo";

+            a.charAt(0);

+    }

+    

+    private void nexttry(String  s) {

+        try {

+            s += "foo";

+        } catch(RuntimeException e) {

+            

+        }

+    }

+    

+	public boolean getBoolean() { return true; }

+

+	public double getDouble() { return 1.0; }

+

+	public int getInt() { return 1; }

+

+	public long getLong() { return 1; }

+

+	public Boolean getObject() { return new Boolean(true); }

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn.java
new file mode 100644
index 0000000..47f6ae5
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn.java
@@ -0,0 +1,63 @@
+/* 

+ * 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.runtime.core.components;

+

+import org.apache.felix.ipojo.runtime.core.services.FooService;

+

+import java.util.Properties;

+

+public class FooProviderTypeDyn implements FooService {

+	

+	private int intProp;	

+	private String strProp;

+	private String[] strAProp;

+	private int[] intAProp;

+	private boolean boolProp;

+

+	public boolean foo() {

+		intProp = 3;

+		boolProp = true;

+		if(strProp.equals("foo")) { strProp = "bar"; }

+		else { strProp = "foo"; }

+		strAProp = new String[] {"foo", "bar", "baz"};

+		intAProp = new int[] {3, 2, 1};

+		return true;

+	}

+

+	public Properties fooProps() {

+		Properties p = new Properties();

+		p.put("intProp", new Integer(intProp));

+		p.put("boolProp", new Boolean(boolProp));

+		p.put("strProp", strProp);

+		p.put("strAProp", strAProp);

+		p.put("intAProp", intAProp);

+		return p;

+	}

+	

+	public boolean getBoolean() { return true; }

+

+	public double getDouble() { return 1.0; }

+

+	public int getInt() { return 1; }

+

+	public long getLong() { return 1; }

+

+	public Boolean getObject() { return new Boolean(true); }

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn2.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn2.java
new file mode 100644
index 0000000..efec5f0
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn2.java
@@ -0,0 +1,58 @@
+/* 

+ * 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.runtime.core.components;

+

+import org.apache.felix.ipojo.runtime.core.services.FooService;

+

+import java.util.Properties;

+

+public class FooProviderTypeDyn2 implements FooService {

+	

+	private int intProp = 2;

+	private boolean boolProp = true;

+	private String strProp = "foo";

+	private String[] strAProp = new String[] {"foo", "bar"};

+	private int[] intAProp = new int[] {1, 2, 3};

+

+	public boolean foo() {

+		intAProp = null;

+		return true;

+	}

+

+	public Properties fooProps() {

+		Properties p = new Properties();

+		p.put("intProp", new Integer(intProp));

+		p.put("boolProp", new Boolean(boolProp));

+		p.put("strProp", strProp);

+		p.put("strAProp", strAProp);

+		p.put("intAProp", intAProp);

+		return p;

+	}

+	

+	public boolean getBoolean() { return true; }

+

+	public double getDouble() { return 1.0; }

+

+	public int getInt() { return 1; }

+

+	public long getLong() { return 1; }

+

+	public Boolean getObject() { return new Boolean(true); }

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ServiceConsumer.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ServiceConsumer.java
new file mode 100644
index 0000000..65295b7
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ServiceConsumer.java
@@ -0,0 +1,27 @@
+package org.apache.felix.ipojo.runtime.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.Service;
+
+import java.util.Properties;
+
+public class ServiceConsumer implements CheckService {
+
+    private Service service;
+    private Properties props = new Properties();
+
+    public ServiceConsumer() {
+        props.put("1", new Integer(service.count()));
+        props.put("2", new Integer(service.count()));
+        props.put("3", new Integer(service.count()));
+    }
+
+    public boolean check() {
+        return service.count() > 0;
+    }
+
+    public Properties getProps() {
+        return props;
+    }
+
+}
diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ServiceProvider.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ServiceProvider.java
new file mode 100644
index 0000000..702899f
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ServiceProvider.java
@@ -0,0 +1,15 @@
+package org.apache.felix.ipojo.runtime.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.Service;
+
+
+public class ServiceProvider implements Service {
+
+    private int i = 0;
+
+    public int count() {
+        i++;
+        return i;
+    }
+
+}
diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TataProvider.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TataProvider.java
new file mode 100644
index 0000000..c3ade01
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TataProvider.java
@@ -0,0 +1,222 @@
+/* 

+ * 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.runtime.core.components;

+

+import org.apache.felix.ipojo.runtime.core.services.Tata;

+

+import java.util.Properties;

+

+

+public class TataProvider implements Tata {

+    

+    int tata = 0;

+    int tataStr = 0;

+    int tataStrs = 0;

+    int tata_2 = 0;

+    int tata_3 = 0;

+    int tata1 = 0;

+    int tata1_1 = 0;

+    int tata5 = 0;

+    int tata5_1 = 0;

+    int tata5_2 = 0;

+    int tataBoolean = 0;

+    int tataBooleans = 0;

+    int tataByte = 0;

+    int tataBytes = 0;

+    private int add;

+    private int tataShorts;

+    private int tataShort;

+    private int tataLongs;

+    private int tataLong;

+    private int tataInts;

+    private int tataInt;

+    private int tataFloat;

+    private int tataFloats;

+    private int tataDoubles;

+    private int tataDouble;

+    private int tataChars;

+    private int tataChar;

+    

+    public Properties getPropsTata() {

+        Properties props = new Properties();

+        props.put("tata", new Integer(tata));

+        props.put("tataStr", new Integer(tataStr));

+        props.put("tataStrs", new Integer(tataStrs));

+        props.put("tata_2", new Integer(tata_2));

+        props.put("tata_3", new Integer(tata_3));

+        props.put("tata1", new Integer(tata1));

+        props.put("tata1_1", new Integer(tata1_1));

+        props.put("tata5", new Integer(tata5));

+        props.put("tata5_1", new Integer(tata5_1));

+        props.put("tata5_2", new Integer(tata5_2));

+        props.put("add", new Integer(add));

+        props.put("tataBoolean", new Integer(tataBoolean));

+        props.put("tataBoolean", new Integer(tataBoolean));

+        props.put("tataByte", new Integer(tataByte));

+        props.put("tataBytes", new Integer(tataBytes));

+        props.put("tataShort", new Integer(tataShort));

+        props.put("tataShorts", new Integer(tataShorts));

+        props.put("tataLongs", new Integer(tataLongs));

+        props.put("tataLong", new Integer(tataLong));

+        props.put("tataInt", new Integer(tataInt));

+        props.put("tataInts", new Integer(tataInts));

+        props.put("tataFloat", new Integer(tataFloat));

+        props.put("tataFloats", new Integer(tataFloats));

+        props.put("tataDouble", new Integer(tataDouble));

+        props.put("tataDoubles", new Integer(tataDoubles));

+        props.put("tataChar", new Integer(tataChar));

+        props.put("tataChars", new Integer(tataChars));

+        return props;

+    }

+

+    public void tata() {

+        tata++;

+    }

+

+    public String tataStr() {

+        tataStr++;

+        return "Tata";

+    }

+

+    public String[] tataStrs() {

+        tataStrs++;

+        return new String[] {"T", "A", "T", "A"};

+    }

+

+    public void tata(int i, int j) {

+        tata_2++;        

+    }

+

+    public void tata(String s) {

+        tata_3++;

+    }

+

+    public String tata1(String a) {

+        tata1++;

+       return a;

+    }

+

+    public String tata1(char[] a) {

+        tata1_1++;

+        String s = new String(a);

+        return s;

+    }

+

+    public String tata5(String a, int i) {

+       tata5++;

+       return a+i;

+    }

+

+    public String tata5(String[] a, int i) {

+       tata5_1++;

+       return ""+a.length + i;

+    }

+

+    public String tata5(String a, int[] i) {

+        tata5_2++;

+        return a + i.length;

+    }

+

+    public boolean tataBoolean(boolean b) {

+        tataBoolean++;

+        return b;

+    }

+

+    public boolean[] tataBooleans(boolean[] b) {

+        tataBooleans++;

+       return b;

+    }

+

+    public byte tataByte(byte b) {

+        tataByte++;

+        return b;

+    }

+

+    public byte[] tataBytes(byte[] b) {

+        tataBytes++;

+        return b;

+    }

+

+    public char tataChar(char c) {

+       tataChar++;

+       return c;

+    }

+

+    public char[] tataChars(char[] c) {

+        tataChars++;

+        return c;

+    }

+

+    public double tataDouble(double d) {

+        tataDouble++;

+        return d;

+    }

+

+    public double[] tataDoubles(double[] d) {

+        tataDoubles++;

+        return d;

+    }

+

+    public float tataFloat(float f) {

+        tataFloat++;

+        return f;

+    }

+

+    public float[] tataFloats(float[] f) {

+        tataFloats++;

+        return f;

+    }

+

+    public int tataInt(int i) {

+        tataInt++;

+        return i;

+    }

+

+    public int[] tataInts(int[] its) {

+        tataInts++;

+        return its;

+    }

+

+    public long tataLong(long l) {

+        tataLong++;

+        return l;

+    }

+

+    public long[] tataLongs(long[] l) {

+        tataLongs++;

+        return l;

+    }

+

+    public short tataShort(short s) {

+        tataShort++;

+        return s;

+    }

+

+    public short[] tataShorts(short[] s) {

+        tataShorts++;

+        return s;

+    }

+

+    public long add(int i, int j, int k) {

+        add++;

+        return i + j + k;

+    }

+

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TotoProvider.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TotoProvider.java
new file mode 100644
index 0000000..d230c2d
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TotoProvider.java
@@ -0,0 +1,73 @@
+/* 

+ * 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.runtime.core.components;

+

+import org.apache.felix.ipojo.runtime.core.services.Toto;

+

+import java.util.Properties;

+

+

+public class TotoProvider implements Toto {

+    

+    private int i = 0;

+    public static int toto = 0;

+    public static int toto_2 = 0;

+    public static int toto_3 = 0;

+    public static int toto_4 = 0;

+    public static int toto1 = 0;

+    

+    public int count() {

+        return i;

+    }

+    

+    public void toto() {

+        toto++;        

+    }

+

+    public void toto(int i, int j) {

+        toto_2++;

+    }

+

+    public String toto(String a) {

+        toto_3++;

+        return a;

+    }

+

+    public String toto(String[] a) {

+        toto_4++;

+        return "toto";

+    }

+

+    public void toto1(String j) {

+        i++;

+        toto1++;        

+    }

+

+    public Properties getProps() {

+        Properties props = new Properties();

+        props.put("i", new Integer(i));

+        props.put("toto", new Integer(toto));

+        props.put("toto_2", new Integer(toto_2));

+        props.put("toto_3", new Integer(toto_3));

+        props.put("toto_4", new Integer(toto_4));

+        props.put("toto1", new Integer(toto1));

+        return props;

+    }

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TotoProviderGlue.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TotoProviderGlue.java
new file mode 100644
index 0000000..f90460c
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TotoProviderGlue.java
@@ -0,0 +1,81 @@
+/* 

+ * 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.runtime.core.components;

+

+import org.apache.felix.ipojo.runtime.core.services.Toto;

+

+import java.util.Properties;

+

+

+public class TotoProviderGlue implements Toto {

+    

+    Toto m_toto;

+    

+    private int i = 0;

+    public static int toto = 0;

+    public static int toto_2 = 0;

+    public static int toto_3 = 0;

+    public static int toto_4 = 0;

+    public static int toto1 = 0;

+    

+    public int count() {

+        return i;

+    }

+    

+    public void toto() {

+        toto++;

+        m_toto.toto();

+    }

+

+    public void toto(int i, int j) {

+        toto_2++;

+        m_toto.toto(i, j);

+    }

+

+    public String toto(String a) {

+        toto_3++;

+        return a;

+    }

+

+    public String toto(String[] a) {

+        toto_4++;

+        return "toto";

+    }

+

+    public void toto1(String j) {

+        i++;

+        toto1++;

+        m_toto.toto1(j);

+    }

+

+    public Properties getProps() {

+        Properties props = new Properties();

+        props.put("i", new Integer(i));

+        props.put("gtoto", new Integer(toto));

+        props.put("gtoto_2", new Integer(toto_2));

+        props.put("gtoto_3", new Integer(toto_3));

+        props.put("gtoto_4", new Integer(toto_4));

+        props.put("gtoto1", new Integer(toto1));

+        props.put("glue", "glue");

+        Properties p2 = m_toto.getProps();

+        props.putAll(p2);

+        return props;

+    }

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/A123/CheckService2.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/A123/CheckService2.java
new file mode 100644
index 0000000..e31a24a
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/A123/CheckService2.java
@@ -0,0 +1,25 @@
+/* 

+ * 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.runtime.core.services.A123;

+

+public interface CheckService2 {

+	

+	public boolean check();

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BarService.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BarService.java
new file mode 100644
index 0000000..f704138
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BarService.java
@@ -0,0 +1,29 @@
+/* 

+ * 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.runtime.core.services;

+

+import java.util.Properties;

+

+public interface BarService {

+	

+	public boolean bar();

+	

+	public Properties getProps();

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BazService.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BazService.java
new file mode 100644
index 0000000..a4c4854
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BazService.java
@@ -0,0 +1,39 @@
+/* 

+ * 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.runtime.core.services;

+

+import java.util.Properties;

+

+public interface BazService {

+

+	boolean foo();

+	

+	Properties fooProps();

+	

+	Boolean getObject();

+	

+	boolean getBoolean();

+	

+	int getInt();

+	

+	long getLong();

+	

+	double getDouble();

+	

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java
new file mode 100644
index 0000000..eca0faa
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java
@@ -0,0 +1,31 @@
+/* 

+ * 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.runtime.core.services;

+

+import java.util.Properties;

+

+public interface CheckService {

+    

+    public static final String foo = "foo";

+	

+	public boolean check();

+	

+	public Properties getProps();

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java
new file mode 100644
index 0000000..37c1a65
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java
@@ -0,0 +1,39 @@
+/* 

+ * 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.runtime.core.services;

+

+import java.util.Properties;

+

+public interface FooService {

+

+	boolean foo();

+	

+	Properties fooProps();

+	

+	Boolean getObject();

+	

+	boolean getBoolean();

+	

+	int getInt();

+	

+	long getLong();

+	

+	double getDouble();

+	

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Service.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Service.java
new file mode 100644
index 0000000..7b85548
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Service.java
@@ -0,0 +1,7 @@
+package org.apache.felix.ipojo.runtime.core.services;
+
+public interface Service {
+    
+    public int count();
+
+}
diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tata.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tata.java
new file mode 100644
index 0000000..ba526f5
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tata.java
@@ -0,0 +1,62 @@
+/* 

+ * 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.runtime.core.services;

+

+import java.util.Properties;

+

+public interface Tata {

+    

+    public Properties getPropsTata();

+    

+    public void tata();

+    

+    public int tataInt(int i);

+    public long tataLong(long l);

+    public double tataDouble(double d);

+    public char tataChar(char c);

+    public boolean tataBoolean(boolean b);

+    public short tataShort(short s);

+    public float tataFloat(float f);

+    public byte tataByte(byte b);

+    

+    public int[] tataInts(int[] its);

+    public long[] tataLongs(long[] l);

+    public double[] tataDoubles(double[] d);

+    public char[] tataChars(char[] c);

+    public boolean[] tataBooleans(boolean[] b);

+    public short[] tataShorts(short[] s);

+    public float[] tataFloats(float[] f);

+    public byte[] tataBytes(byte[] b);

+    

+    public String tataStr();

+    public String[] tataStrs();

+    

+    public void tata(int i, int j);

+    public void tata(String s);

+    

+    public String tata1(String a);

+    public String tata1(char[] a);

+    

+    public String tata5(String a, int i);

+    public String tata5(String[] a, int i);

+    public String tata5(String a, int[] i);

+    

+    public long add(int i, int j, int k);

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tota.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tota.java
new file mode 100644
index 0000000..19bd528
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tota.java
@@ -0,0 +1,78 @@
+/* 

+ * 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.runtime.core.services;

+

+import java.util.Properties;

+

+public interface Tota {

+    

+    public static final String specification="specification { " +

+    		"requires { " +

+    		    "$specification=\"org.apache.felix.ipojo.test.composite.service.Toto\" " +

+    		    "$optional=\"true\" " +

+    		    "$aggregate=\"true\" " +

+    		    "$type=\"service\" " +

+    		"} }"; 

+    

+    public Properties getProps() throws UnsupportedOperationException;;

+    public Properties getPropsTata();

+    

+    public void tata();

+    

+    public int tataInt(int i);

+    public long tataLong(long l);

+    public double tataDouble(double d);

+    public char tataChar(char c);

+    public boolean tataBoolean(boolean b);

+    public short tataShort(short s);

+    public float tataFloat(float f);

+    public byte tataByte(byte b);

+    

+    public int[] tataInts(int[] its);

+    public long[] tataLongs(long[] l);

+    public double[] tataDoubles(double[] d);

+    public char[] tataChars(char[] c);

+    public boolean[] tataBooleans(boolean[] b);

+    public short[] tataShorts(short[] s);

+    public float[] tataFloats(float[] f);

+    public byte[] tataBytes(byte[] b);

+    

+    public String tataStr();

+    public String[] tataStrs();

+    

+    public void tata(int i, int j);

+    public void tata(String s);

+    

+    public String tata1(String a);

+    public String tata1(char[] a);

+    

+    public String tata5(String a, int i);

+    public String tata5(String[] a, int i);

+    public String tata5(String a, int[] i);

+    

+    public long add(int i, int j, int k);

+    

+    public void toto() throws UnsupportedOperationException;    

+    public void toto(int i, int j) throws UnsupportedOperationException;

+    public String toto(String a) throws UnsupportedOperationException;

+    

+    public void toto1(String j) throws UnsupportedOperationException;

+    

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Toto.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Toto.java
new file mode 100644
index 0000000..8ed22ec
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Toto.java
@@ -0,0 +1,37 @@
+/* 

+ * 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.runtime.core.services;

+

+import java.util.Properties;

+

+public interface Toto {

+    

+    public Properties getProps();

+    

+    public void toto();    

+    public void toto(int i, int j);

+    public String toto(String a);

+    public String toto(String[] a);

+    

+    public void toto1(String j);

+    

+    public int count();

+

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/resources/metadata-instance.xml b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/resources/metadata-instance.xml
new file mode 100644
index 0000000..9857648
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/resources/metadata-instance.xml
@@ -0,0 +1,89 @@
+<ipojo

+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

+	xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd

+	    org.apache.felix.composite http://felix.apache.org/ipojo/schemas/SNAPSHOT/composite.xsd"

+	xmlns="org.apache.felix.ipojo"

+	xmlns:comp="org.apache.felix.ipojo.composite"

+	xmlns:cs="org.apache.felix.ipojo.test.composite.handler.CheckServiceHandler">

+	<comp:composite name="composite.bar.1" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.runtime.core.services.BarService"/>

+	</comp:composite>

+

+	<comp:composite name="composite.bar.2" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.runtime.core.services.BarService" aggregate="true"/>

+	</comp:composite>

+

+	<comp:composite name="composite.bar.3" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.runtime.core.services.BarService" optional="true"/>

+	</comp:composite>

+

+	<comp:composite name="composite.bar.4" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.runtime.core.services.FooService" aggregate="true" optional="true"/>

+	</comp:composite>

+

+	<comp:composite name="composite.bar.5-accept" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.runtime.core.services.FooService">

+			<property name="boolean" value="true"/>

+			<property name="string" value="foo"/>

+			<property name="strAprop" value="{foo, bar, baz}"/>

+			<property name="int" value="5"/>

+		</subservice>

+	</comp:composite>

+

+	<comp:composite name="composite.bar.5-refuse1" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.runtime.core.services.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>

+	</comp:composite>

+

+	<comp:composite name="composite.bar.5-refuse2" architecture="true">

+		<subservice action="instantiate" specification="org.apache.felix.ipojo.runtime.core.services.BarService">

+			<property name="string" value="foo"/>

+			<property name="strAprop" value="{foo, bar, baz}"/>

+		</subservice>

+	</comp:composite>

+

+    <!-- Instance of a specified component -->

+	<comp:composite name="composite.inst.1" 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>

+	</comp:composite>

+

+	<!-- Scope test -->

+	<component name="SCOPE-provider" classname="org.apache.felix.ipojo.runtime.core.components.ServiceProvider">

+		<provides/>

+	</component>

+	<component name="SCOPE-cons" classname="org.apache.felix.ipojo.runtime.core.components.ServiceConsumer">

+		<provides/>

+		<requires field="service"/>

+	</component>

+	<comp:composite name="SCOPE-scope">

+		<instance component="SCOPE-provider"/>

+		<instance component="SCOPE-cons"/>

+	</comp:composite>

+	<comp:composite name="SCOPE-badscope">

+		<instance component="SCOPE-cons"/>

+	</comp:composite>

+

+	<!-- Instance configuration  -->

+	<comp:composite name="CONF-MySuperComposite">

+                <instance component="COMPO-FooProviderType-2">

+                               <property name="int" value="3"/>

+                </instance>

+                <subservice action="instantiate"

+					specification="org.apache.felix.ipojo.runtime.core.services.FooService">

+					<property name="boolean" value="true"/>

+					<property name="string" value="foo"/>

+					<property name="strAprop" value="{foo, bar, baz}"/>

+					<property name="int" value="3"/>

+				</subservice>

+	</comp:composite>

+</ipojo>

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/resources/metadata.xml b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/resources/metadata.xml
new file mode 100644
index 0000000..6143ff9
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/main/resources/metadata.xml
@@ -0,0 +1,112 @@
+<ipojo

+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

+	xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd

+	    org.apache.felix.composite http://felix.apache.org/ipojo/schemas/SNAPSHOT/composite.xsd"

+	xmlns="org.apache.felix.ipojo"

+	xmlns:comp="org.apache.felix.ipojo.composite">

+	<!-- Used component type -->

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.FooProviderType1"

+		name="COMPO-FooProviderType-1" architecture="true">

+		<provides />

+	</component>

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.FooProviderType1"

+		name="COMPO-FooProviderType-2" architecture="true">

+		<provides>

+			<property name="int" type="int" value="2" />

+			<property name="long" type="long" value="40" />

+			<property name="string" type="java.lang.String" value="foo" />

+			<property name="strAProp" type="java.lang.String[]"

+				value="{foo, bar}" />

+			<property name="intAProp" type="int[]" value="{1,2,3}" />

+		</provides>

+	</component>

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.FooProviderTypeDyn"

+		name="COMPO-FooProviderType-Dyn" architecture="true">

+		<provides>

+			<property name="int" field="intProp" value="2" />

+			<property name="boolean" field="boolProp" value="false" />

+			<property name="string" field="strProp" value="foo" />

+			<property name="strAProp" field="strAProp"

+				value="{foo, bar}" />

+			<property name="intAProp" field="intAProp" value="{ 1,2,3}" />

+		</provides>

+	</component>

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.FooProviderTypeDyn2"

+		name="COMPO-FooProviderType-Dyn2" architecture="true">

+		<provides>

+			<property name="int" field="intProp" value="4" />

+			<property name="boolean" field="boolProp" />

+			<property name="string" field="strProp" />

+			<property name="strAProp" field="strAProp" />

+			<property name="intAProp" field="intAProp"

+				value="{1, 2,3 }" />

+		</provides>

+	</component>

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.CheckServiceProvider"

+		name="COMPO-SimpleCheckServiceProvider" architecture="true">

+		<requires field="fs" />

+		<provides />

+	</component>

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.FooBarProviderType1"

+		name="COMPO-FooBarProviderType-1" architecture="true">

+		<provides />

+	</component>

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.FooBarProviderType1"

+		name="COMPO-FooBarProviderType-2" architecture="true">

+		<provides

+			specifications="{org.apache.felix.ipojo.runtime.core.services.FooService, org.apache.felix.ipojo.runtime.core.services.BarService }" />

+	</component>

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.FooBarProviderType1"

+		name="COMPO-FooBarProviderType-3" architecture="true">

+		<provides

+			specifications="{org.apache.felix.ipojo.runtime.core.services.FooService}">

+			<property name="baz" type="java.lang.String" value="foo" />

+		</provides>

+		<provides

+			specifications="{org.apache.felix.ipojo.runtime.core.services.BarService}">

+			<property name="baz" type="java.lang.String" value="bar" />

+		</provides>

+	</component>

+

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.BazProviderType1"

+		name="BazProviderType">

+		<provides />

+	</component>

+

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.TataProvider"

+		name="tata">

+		<provides />

+	</component>

+

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.TotoProvider"

+		name="toto" architecture="true">

+		<provides />

+	</component>

+

+	<component

+		classname="org.apache.felix.ipojo.runtime.core.components.TotoProviderGlue"

+		name="totoglue">

+		<requires field="m_toto" scope="composite" />

+	</component>

+

+	<!--  Composite -->

+	<comp:composite name="composite.empty" architecture="true">

+	</comp:composite>

+

+	<component classname="org.apache.felix.ipojo.runtime.core.components.Baz2CheckProvider" name="Baz2CheckProvider" architecture="true">

+		<requires field="fs" scope="composite"/>

+		<provides/>

+	</component>

+

+</ipojo>

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
new file mode 100644
index 0000000..b242001
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -0,0 +1,225 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.composite.CompositeManager;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.options.CompositeOption;
+import org.ops4j.pax.exam.options.DefaultCompositeOption;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.ow2.chameleon.testing.helpers.IPOJOHelper;
+import org.ow2.chameleon.testing.helpers.OSGiHelper;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static junit.framework.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+/**
+ * Bootstrap the test from this project
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerMethod.class)
+public class Common {
+
+    @Inject
+    protected
+    BundleContext bc;
+
+    protected OSGiHelper osgiHelper;
+    protected IPOJOHelper ipojoHelper;
+
+    protected boolean deployTestedBundle = true;
+
+    @Configuration
+    public Option[] config() throws IOException {
+        Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+        root.setLevel(Level.INFO);
+
+        if (deployTestedBundle) {
+            return options(
+                    cleanCaches(),
+                    ipojoBundles(),
+                    junitBundles(),
+                    testedBundle(),
+                    systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+            );
+        } else {
+            return options(
+                    cleanCaches(),
+                    ipojoBundles(),
+                    junitBundles(),
+                    systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+            );
+        }
+    }
+
+    public static Option junitAndMockitoBundles() {
+        return new DefaultCompositeOption(
+                // Repository required to load harmcrest (OSGi-fied version).
+                repository("http://repository.springsource.com/maven/bundles/external").id(
+                        "com.springsource.repository.bundles.external"),
+
+                // Mockito without Hamcrest and Objenesis
+                mavenBundle("org.mockito", "mockito-core", "1.9.5"),
+
+                // Hamcrest with a version matching the range expected by Mockito
+                mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
+
+                // Objenesis with a version matching the range expected by Mockito
+                wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
+                        .exports("*;version=1.2"),
+
+                // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
+                // 4.9 which does not match the Mockito import.
+                CoreOptions.junitBundles(),
+
+                /*
+                 * Felix has implicit boot delegation enabled by default. It conflicts with Mockito:
+                 * java.lang.LinkageError: loader constraint violation in interface itable initialization:
+                 * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
+                 * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the class loader
+                 * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader) of the current class,
+                 * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc, and the class loader
+                 * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for interface
+                 * org/mockito/cglib/proxy/Factory have different Class objects for the type org/mockito/cglib/
+                 * proxy/Callback used in the signature
+                 *
+                 * So we disable the bootdelegation.
+                 */
+                frameworkProperty("felix.bootdelegation.implicit").value("false")
+        );
+    }
+
+
+    @Before
+    public void commonSetUp() {
+        osgiHelper = new OSGiHelper(bc);
+        ipojoHelper = new IPOJOHelper(bc);
+
+        // Dump OSGi Framework information
+        String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
+        if (vendor == null) {
+            vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
+        }
+        String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
+        System.out.println("OSGi Framework : " + vendor + " - " + version);
+    }
+
+    @After
+    public void commonTearDown() {
+        ipojoHelper.dispose();
+        osgiHelper.dispose();
+    }
+
+    public BundleContext getContext() {
+        return bc;
+    }
+
+    public static ServiceContext getServiceContext(ComponentInstance ci) {
+        if (ci instanceof CompositeManager) {
+            return ((CompositeManager) ci).getServiceContext();
+        } else {
+            throw new RuntimeException("Cannot get the service context from a non composite instance");
+        }
+    }
+
+    public CompositeOption ipojoBundles() {
+        return new DefaultCompositeOption(
+                mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
+                mavenBundle("org.apache.felix", "org.apache.felix.ipojo.composite").versionAsInProject(),
+                mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
+                // configuration admin
+                mavenBundle("org.apache.felix",  "org.apache.felix.configadmin").versionAsInProject()
+        );
+    }
+
+    public Option testedBundle() throws MalformedURLException {
+        File out = new File("target/tested/bundle.jar");
+        if (out.exists()) {
+            return bundle(out.toURI().toURL().toExternalForm());
+        }
+
+        TinyBundle tested = TinyBundles.bundle();
+
+        // We look inside target/classes to find the class and resources
+        File classes = new File("target/classes");
+        Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
+        List<File> services = new ArrayList<File>();
+        for (File file : files) {
+            if (file.isDirectory()) {
+                // By convention we export of .services and .service package
+                if (file.getName().endsWith("services")  || file.getName().endsWith("service")) {
+                    services.add(file);
+                }
+            } else {
+                // We need to compute the path
+                String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
+                tested.add(path, file.toURI().toURL());
+                System.out.println(file.getName() + " added to " + path);
+            }
+        }
+
+        // Export the inherited package, components and strategies
+        String export = "";
+        for (File file : services) {
+            if (export.length() > 0) { export += ", "; }
+            String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
+            String packageName = path.replace('/', '.');
+            export += packageName;
+        }
+
+        System.out.println("Exported packages : " + export);
+
+        InputStream inputStream = tested
+                .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
+                .set(Constants.IMPORT_PACKAGE, "*")
+                .set(Constants.EXPORT_PACKAGE, export)
+                .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
+
+        try {
+            org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
+            return bundle(out.toURI().toURL().toExternalForm());
+        } catch (MalformedURLException e) {
+            throw new RuntimeException("Cannot compute the url of the manipulated bundle");
+        } catch (IOException e) {
+            throw new RuntimeException("Cannot write of the manipulated bundle");
+        }
+    }
+
+    public void assertContains(String s, String[] arrays, String object) {
+        for (String suspect : arrays) {
+            if (object.equals(suspect)) {
+                return;
+            }
+        }
+        fail("Assertion failed : " + s);
+    }
+
+
+}
diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestInstanceScope.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestInstanceScope.java
new file mode 100644
index 0000000..9a3ce08
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestInstanceScope.java
@@ -0,0 +1,86 @@
+package org.apache.felix.ipojo.runtime.core.instance;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.composite.CompositeFactory;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.Service;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestInstanceScope extends Common {
+
+    CompositeFactory factory;
+    ComponentInstance instance;
+
+    @Before
+    public void setUp() {
+        factory = (CompositeFactory) ipojoHelper.getFactory("SCOPE-scope");
+        assertNotNull("Factory", factory);
+        try {
+            instance = factory.createComponentInstance(null);
+        } catch (Exception e) {
+            fail("Fail instantiation : " + e.getMessage());
+        }
+
+
+    }
+
+    @After
+    public void tearDown() {
+        instance.dispose();
+        instance = null;
+    }
+
+    @Test
+    public void testScope() {
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance.getInstanceName());
+        assertNotNull("Check architecture availability", ref);
+        Architecture arch = (Architecture) getContext().getService(ref);
+        assertTrue("Validity", arch.getInstanceDescription().getState() == ComponentInstance.VALID);
+
+        // Get internal service
+        ServiceContext sc = getServiceContext(instance);
+        ServiceReference ref2 = ipojoHelper.getServiceReference(sc, CheckService.class.getName(), null);
+        assertNotNull("Check CheckService availability", ref2);
+        CheckService svc = (CheckService) sc.getService(ref2);
+        Properties props = svc.getProps();
+        assertEquals("Check props - 1", 1, ((Integer) props.get("1")).intValue());
+        assertEquals("Check props - 2", 2, ((Integer) props.get("2")).intValue());
+        assertEquals("Check props - 3", 3, ((Integer) props.get("3")).intValue());
+
+    }
+
+    @Test
+    public void testGlobalUnavailability() {
+        ServiceReference ref2 = osgiHelper.getServiceReference(Service.class.getName(), null);
+        assertNull("Check Service unavailability", ref2);
+    }
+
+    @Test
+    public void testScopeUnvailability() {
+        CompositeFactory factory2 = (CompositeFactory) ipojoHelper.getFactory("SCOPE-badscope");
+        assertNotNull("Factory", factory2);
+        ComponentInstance instance2 = null;
+        try {
+            instance2 = factory2.createComponentInstance(null);
+        } catch (Exception e) {
+            fail("Fail instantiation : " + e.getMessage());
+        }
+        //System.out.println(instance2.getInstanceDescription().getDescription());
+
+        assertEquals("Check invalidity", ComponentInstance.INVALID, instance2.getState());
+        instance2.dispose();
+
+    }
+
+
+}
diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestSimpleInstance.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestSimpleInstance.java
new file mode 100644
index 0000000..b1f0ee0
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestSimpleInstance.java
@@ -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.runtime.core.instance;

+

+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.composite.CompositeInstanceDescription;

+import org.apache.felix.ipojo.runtime.core.Common;

+import org.apache.felix.ipojo.runtime.core.services.FooService;

+import org.junit.After;

+import org.junit.Before;

+import org.junit.Test;

+import org.osgi.framework.ServiceReference;

+

+import java.util.Properties;

+

+import static junit.framework.Assert.assertEquals;

+import static org.junit.Assert.*;

+

+public class TestSimpleInstance extends Common {

+

+    private ComponentFactory fooFactory1, fooFactory2;

+    private ComponentFactory compoFactory;

+    private ComponentInstance empty;

+

+    @Before

+    public void setUp() {

+        fooFactory1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooProviderType-1");

+        fooFactory2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooProviderType-Dyn2");

+        compoFactory = (ComponentFactory) ipojoHelper.getFactory("composite.inst.1");

+        Factory fact = ipojoHelper.getFactory("composite.empty");

+        Properties props = new Properties();

+        props.put("instance.name", "empty-X");

+        try {

+            empty = fact.createComponentInstance(props);

+        } catch (Exception e) {

+            fail("Cannot create the empty composite : " + e.getMessage());

+        }

+    }

+

+    @After

+    public void tearDown() {

+        empty.dispose();

+        empty = null;

+    }

+

+    @Test

+    public void testCreation() {

+        Properties props = new Properties();

+        props.put("instance.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();

+    }

+

+    @Test

+    public void testServiceAvailability() {

+        Properties props = new Properties();

+        props.put("instance.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 = getServiceContext(under);

+

+        assertNotNull("Check service availability", sc.getServiceReference(FooService.class.getName()));

+        assertEquals("Check service provider", ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null).length,

+                2);

+

+        under.dispose();

+    }

+

+    @Test

+    public void testCreationLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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();

+    }

+

+    @Test

+    public void testServiceAvailabilityLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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 = getServiceContext(under);

+

+        assertNotNull("Check service availability", sc2.getServiceReference(FooService.class.getName()));

+        assertEquals("Check service providers", ipojoHelper.getServiceReferences(sc2, FooService.class.getName(),

+                null).length, 2);

+

+        under.dispose();

+    }

+

+    @Test

+    public void testFactoryManagement() {

+        Properties props = new Properties();

+        props.put("instance.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();

+    }

+

+    @Test

+    public void testFactoryManagementLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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 fix and reactivate the method.

+        Properties props = new Properties();

+        props.put("instance.name", "under");

+        ComponentInstance under = null;

+        try {

+            under = compoFactory.createComponentInstance(props);

+        } catch (Exception e) {

+            fail("Cannot instantiate under : " + e.getMessage());

+        }

+        ServiceReference ref = osgiHelper.getServiceReference(Architecture.class.getName(),

+                "(architecture.instance=under)");

+        assertNotNull("Check architecture availability", ref);

+        Architecture arch = (Architecture) getContext().getService(ref);

+        CompositeInstanceDescription id = (CompositeInstanceDescription) 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 instance name", id.getName(), "under");

+        assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");

+

+        ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+        ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+        ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");

+

+        fact1.stop();

+        assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+        ref = osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=under)");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 instance name", id.getName(), "under");

+        assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");

+

+        under.dispose();

+        fact2.start();

+        fact3.start();

+    }

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfigurableInstantiation.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfigurableInstantiation.java
new file mode 100644
index 0000000..b55d8f1
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfigurableInstantiation.java
@@ -0,0 +1,112 @@
+/* 

+ * 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.runtime.core.instantiator;

+

+import org.apache.felix.ipojo.ComponentFactory;

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.ServiceContext;

+import org.apache.felix.ipojo.runtime.core.Common;

+import org.apache.felix.ipojo.runtime.core.services.FooService;

+import org.junit.After;

+import org.junit.Before;

+import org.junit.Test;

+import org.osgi.framework.ServiceReference;

+

+import java.util.Properties;

+

+import static org.junit.Assert.*;

+

+public class TestConfigurableInstantiation extends Common {

+

+    private ComponentFactory acceptF;

+    private ComponentFactory refuse1F;

+    private ComponentFactory refuse2F;

+

+    @Before

+    public void setUp() {

+        acceptF = (ComponentFactory) ipojoHelper.getFactory("composite.bar.5-accept");

+        refuse1F = (ComponentFactory) ipojoHelper.getFactory("composite.bar.5-refuse1");

+        refuse2F = (ComponentFactory) ipojoHelper.getFactory("composite.bar.5-refuse2");

+

+    }

+

+    @After

+    public void tearDown() {

+    }

+

+    @Test

+    public void testAccept() {

+        Properties props = new Properties();

+        props.put("instance.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 = 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");

+        //TODO See why it fails...

+        //assertEquals("Test int", i, 5); // The code fix to 5.

+        under.dispose();

+    }

+

+    @Test

+    public void testRefuse1() {

+        Properties props = new Properties();

+        props.put("instance.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();

+    }

+

+    @Test

+    public void testRefuse2() {

+        Properties props = new Properties();

+        props.put("instance.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();

+    }

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfiguration.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfiguration.java
new file mode 100644
index 0000000..4e757cb
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfiguration.java
@@ -0,0 +1,97 @@
+/*

+ * 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.runtime.core.instantiator;

+

+import org.apache.felix.ipojo.ComponentFactory;

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.ServiceContext;

+import org.apache.felix.ipojo.runtime.core.Common;

+import org.apache.felix.ipojo.runtime.core.services.FooService;

+import org.junit.After;

+import org.junit.Before;

+import org.junit.Test;

+import org.osgi.framework.InvalidSyntaxException;

+import org.osgi.framework.ServiceReference;

+

+import java.util.Properties;

+

+import static org.junit.Assert.*;

+

+public class TestConfiguration extends Common {

+

+    private ComponentFactory compositeFactory;

+

+    @Before

+    public void setUp() {

+        compositeFactory = (ComponentFactory) ipojoHelper.getFactory("CONF-MySuperComposite");

+    }

+

+    @After

+    public void tearDown() {

+

+    }

+

+    @Test

+    public void testDefaultInstantiation() throws InvalidSyntaxException {

+        Properties props = new Properties();

+        props.put("instance.name", "under");

+        ComponentInstance under = null;

+        try {

+            under = compositeFactory.createComponentInstance(props);

+        } catch (Exception e) {

+            e.printStackTrace();

+            fail("Cannot instantiate under : " + e.getMessage());

+        }

+        assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+        ServiceContext sc = getServiceContext(under);

+        ServiceReference[] refs = sc.getServiceReferences(FooService.class.getName(), null);

+        assertEquals(2, refs.length);

+        for (int i = 0; i < refs.length; i++) {

+            assertEquals(3, ((Integer) refs[i].getProperty("int")).intValue());

+            assertEquals("foo", (String) refs[i].getProperty("string"));

+        }

+        under.dispose();

+    }

+

+    @Test

+    public void testConfiguredInstantiation() throws InvalidSyntaxException {

+        Properties props = new Properties();

+        props.put("instance.name", "under");

+        props.put("string", "bar");

+        props.put("int", "25");

+        ComponentInstance under = null;

+        try {

+            under = compositeFactory.createComponentInstance(props);

+        } catch (Exception e) {

+            e.printStackTrace();

+            fail("Cannot instantiate under : " + e.getMessage());

+        }

+        assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);

+        ServiceContext sc = getServiceContext(under);

+        ServiceReference[] refs = sc.getServiceReferences(FooService.class.getName(), null);

+        assertEquals(2, refs.length);

+        for (int i = 0; i < refs.length; i++) {

+            assertEquals(25, ((Integer) refs[i].getProperty("int")).intValue());

+            assertEquals("bar", (String) refs[i].getProperty("string"));

+        }

+        under.dispose();

+    }

+

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestMultipleInstantiation.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestMultipleInstantiation.java
new file mode 100644
index 0000000..be3f4fe
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestMultipleInstantiation.java
@@ -0,0 +1,287 @@
+/* 

+ * 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.runtime.core.instantiator;

+

+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.composite.CompositeInstanceDescription;

+import org.apache.felix.ipojo.runtime.core.Common;

+import org.apache.felix.ipojo.runtime.core.services.BarService;

+import org.junit.After;

+import org.junit.Before;

+import org.junit.Test;

+import org.osgi.framework.ServiceReference;

+

+import java.util.Properties;

+

+import static org.junit.Assert.*;

+

+public class TestMultipleInstantiation extends Common {

+

+    private ComponentFactory bar2Factory;

+    private ComponentInstance empty;

+

+    @Before

+    public void setUp() {

+        bar2Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.2");

+        Factory fact = ipojoHelper.getFactory("composite.empty");

+        Properties props = new Properties();

+        props.put("instance.name", "empty");

+        try {

+            empty = fact.createComponentInstance(props);

+        } catch (Exception e) {

+            fail("Cannot create the empty composite : " + e.getMessage());

+        }

+    }

+

+    @After

+    public void tearDown() {

+        empty.dispose();

+        empty = null;

+    }

+

+    @Test

+    public void testCreation() {

+        Properties props = new Properties();

+        props.put("instance.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();

+    }

+

+    @Test

+    public void testServiceAvailability() {

+        Properties props = new Properties();

+        props.put("instance.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 = getServiceContext(under);

+        assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));

+        int count = ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length;

+        assertEquals("Check service provider number : " + count, count, 3);

+

+        under.dispose();

+    }

+

+    @Test

+    public void testCreationLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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();

+    }

+

+    @Test

+    public void testServiceAvailabilityLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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 = getServiceContext(under);

+        assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 3);

+

+        under.dispose();

+    }

+

+    @Test

+    public void testFactoryManagement() {

+        Properties props = new Properties();

+        props.put("instance.name", "under");

+        ComponentInstance under = null;

+        try {

+            under = bar2Factory.createComponentInstance(props);

+        } catch (Exception e) {

+            fail("Cannot instantiate under : " + e.getMessage());

+        }

+        ServiceContext sc = getServiceContext(under);

+        assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+

+        ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+        ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+        ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");

+

+        fact1.stop();

+        assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 2);

+

+        fact2.stop();

+        assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 1);

+

+        fact3.stop();

+        assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 0);

+

+        fact1.start();

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 1);

+        assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+

+        under.dispose();

+        fact2.start();

+        fact3.start();

+    }

+

+    @Test

+    public void testFactoryManagementLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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 = getServiceContext(under);

+

+        ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+        ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+        ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");

+

+        fact1.stop();

+        assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 2);

+

+        fact2.stop();

+        assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);

+

+        fact3.stop();

+        assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 0);

+

+        fact1.start();

+        assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);

+

+        under.dispose();

+        fact2.start();

+        fact3.start();

+    }

+

+    @Test

+    public void testArchitecture() {

+        Properties props = new Properties();

+        props.put("instance.name", "under");

+        ComponentInstance under = null;

+        try {

+            under = bar2Factory.createComponentInstance(props);

+        } catch (Exception e) {

+            fail("Cannot instantiate under : " + e.getMessage());

+        }

+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        Architecture arch = (Architecture) getContext().getService(ref);

+        CompositeInstanceDescription id = (CompositeInstanceDescription) 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 instance name", id.getName(), "under");

+        assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.2");

+

+        ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+        ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+        ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");

+

+        fact1.stop();

+        assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+        ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 instance name", id.getName(), "under");

+        assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.2");

+

+        getContext().ungetService(ref);

+        under.dispose();

+        fact2.start();

+        fact3.start();

+    }

+

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalInstantiation.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalInstantiation.java
new file mode 100644
index 0000000..4829107
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalInstantiation.java
@@ -0,0 +1,273 @@
+/* 

+ * 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.runtime.core.instantiator;

+

+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.composite.CompositeInstanceDescription;

+import org.apache.felix.ipojo.runtime.core.Common;

+import org.apache.felix.ipojo.runtime.core.services.BarService;

+import org.junit.After;

+import org.junit.Before;

+import org.junit.Test;

+import org.osgi.framework.ServiceReference;

+

+import java.util.Properties;

+

+import static org.junit.Assert.*;

+

+public class TestOptionalInstantiation extends Common {

+

+	private ComponentFactory bar1Factory;

+	private ComponentInstance empty;

+	

+	@Before

+    public void setUp() {

+		bar1Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.3");

+		Factory fact = ipojoHelper.getFactory("composite.empty");

+		Properties props = new Properties();

+		props.put("instance.name","empty");

+		try {

+			empty = fact.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot create the empty composite : " + e.getMessage());

+		}

+	}

+	

+	@After

+    public void tearDown() {

+		empty.dispose();

+		empty = null;

+	}

+	

+	@Test

+    public void testCreation() {

+		Properties props = new Properties();

+		props.put("instance.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();

+	}

+	

+	@Test public void testServiceAvailability() {

+		Properties props = new Properties();

+		props.put("instance.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 = getServiceContext(under);

+		assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));

+		

+		under.dispose();

+	}

+	

+	@Test public void testCreationLevel2() {

+		ServiceContext sc = getServiceContext(empty);

+		Properties props = new Properties();

+		props.put("instance.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();

+	}

+	

+	@Test public void testServiceAvailabilityLevel2() {

+		ServiceContext sc = getServiceContext(empty);

+		Properties props = new Properties();

+		props.put("instance.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 = getServiceContext(under);

+		assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));

+		

+		under.dispose();

+	}

+	

+	@Test public void testFactoryManagement() {

+		Properties props = new Properties();

+		props.put("instance.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) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("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 = 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();

+	}

+	

+	@Test public void testFactoryManagementLevel2() {

+		ServiceContext sc = getServiceContext(empty);

+		Properties props = new Properties();

+		props.put("instance.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) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("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();

+	}

+	

+	@Test public void testArchitecture() {

+		Properties props = new Properties();

+		props.put("instance.name","under");

+		ComponentInstance under = null;

+		try {

+			under = bar1Factory.createComponentInstance(props);

+		} catch(Exception e) {

+			fail("Cannot instantiate under : " + e.getMessage());

+		}

+		

+		ServiceReference ref = ipojoHelper.getServiceReferenceByName( Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		Architecture arch = (Architecture) getContext().getService(ref);

+		assertNotNull("Check architecture", arch);

+        CompositeInstanceDescription id = (CompositeInstanceDescription) 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 instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");

+		

+		ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+		ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+		ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");

+		

+		

+		fact1.stop();

+		assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+		ref = ipojoHelper.getServiceReferenceByName( Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName( Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName( Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName( Architecture.class.getName(), "under");

+		assertNotNull("Check architecture availability", ref);

+		arch = (Architecture) getContext().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 instance name" , id.getName(), "under");

+		assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");

+

+		getContext().ungetService(ref);

+		under.dispose();

+		fact2.start();

+		fact3.start();

+	}

+

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalMultipleInstantiation.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalMultipleInstantiation.java
new file mode 100644
index 0000000..29eb2f6
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalMultipleInstantiation.java
@@ -0,0 +1,214 @@
+/* 

+ * 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.runtime.core.instantiator;

+

+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.runtime.core.Common;

+import org.apache.felix.ipojo.runtime.core.services.BarService;

+import org.junit.After;

+import org.junit.Before;

+import org.junit.Test;

+

+import java.util.Properties;

+

+import static org.junit.Assert.*;

+

+public class TestOptionalMultipleInstantiation extends Common {

+

+    private ComponentFactory bar2Factory;

+    private ComponentInstance empty;

+

+    @Before

+    public void setUp() {

+        bar2Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.4");

+        assertNotNull("Check bar2factory availability", bar2Factory);

+

+        Factory fact = ipojoHelper.getFactory("composite.empty");

+        Properties props = new Properties();

+        props.put("instance.name", "empty");

+        try {

+            empty = fact.createComponentInstance(props);

+        } catch (Exception e) {

+            fail("Cannot create the empty composite : " + e.getMessage());

+        }

+    }

+

+    @After

+    public void tearDown() {

+        empty.dispose();

+        empty = null;

+    }

+

+    @Test

+    public void testCreation() {

+        Properties props = new Properties();

+        props.put("instance.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();

+    }

+

+    @Test

+    public void testServiceAvailability() {

+        Properties props = new Properties();

+        props.put("instance.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 = getServiceContext(under);

+        assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));

+        int count = ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length;

+        assertEquals("Check service provider number : " + count, count, 3);

+

+        under.dispose();

+    }

+

+    @Test

+    public void testCreationLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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();

+    }

+

+    @Test

+    public void testServiceAvailabilityLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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 = getServiceContext(under);

+        assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2,

+                BarService.class.getName(), null).length, 3);

+

+        under.dispose();

+    }

+

+    @Test

+    public void testFactoryManagement() {

+        Properties props = new Properties();

+        props.put("instance.name", "under");

+        ComponentInstance under = null;

+        try {

+            under = bar2Factory.createComponentInstance(props);

+        } catch (Exception e) {

+            fail("Cannot instantiate under : " + e.getMessage());

+        }

+        ServiceContext sc = getServiceContext(under);

+        assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);

+

+        ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+        ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+        ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");

+

+        fact1.stop();

+        assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc,

+                BarService.class.getName(), null).length, 2);

+

+        fact2.stop();

+        assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc,

+                BarService.class.getName(), null).length, 1);

+

+        fact3.stop();

+        assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc,

+                BarService.class.getName(), null).length, 0);

+

+        fact1.start();

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc,

+                BarService.class.getName(), null).length, 1);

+        assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);

+

+        under.dispose();

+        fact2.start();

+        fact3.start();

+    }

+

+    @Test

+    public void testFactoryManagementLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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 = getServiceContext(under);

+

+        ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+        ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+        ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");

+

+        fact1.stop();

+        assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2,

+                BarService.class.getName(), null).length, 2);

+

+        fact2.stop();

+        assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2,

+                BarService.class.getName(), null).length, 1);

+

+        fact3.stop();

+        assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2,

+                BarService.class.getName(), null).length, 0);

+

+        fact1.start();

+        assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);

+        assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2,

+                BarService.class.getName(), null).length, 1);

+

+        under.dispose();

+        fact2.start();

+        fact3.start();

+    }

+

+}

diff --git a/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestSimpleInstantiation.java b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestSimpleInstantiation.java
new file mode 100644
index 0000000..ff18fb3
--- /dev/null
+++ b/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestSimpleInstantiation.java
@@ -0,0 +1,274 @@
+/* 

+ * 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.runtime.core.instantiator;

+

+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.composite.CompositeInstanceDescription;

+import org.apache.felix.ipojo.runtime.core.Common;

+import org.apache.felix.ipojo.runtime.core.services.BarService;

+import org.junit.After;

+import org.junit.Before;

+import org.junit.Test;

+import org.osgi.framework.ServiceReference;

+

+import java.util.Properties;

+

+import static org.junit.Assert.*;

+

+public class TestSimpleInstantiation extends Common {

+

+    private ComponentFactory bar1Factory;

+    private ComponentInstance empty;

+

+    @Before

+    public void setUp() {

+        bar1Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.1");

+        Factory fact = ipojoHelper.getFactory("composite.empty");

+        Properties props = new Properties();

+        props.put("instance.name", "empty-X");

+        try {

+            empty = fact.createComponentInstance(props);

+        } catch (Exception e) {

+            fail("Cannot create the empty composite : " + e.getMessage());

+        }

+    }

+

+    @After

+    public void tearDown() {

+        empty.dispose();

+        empty = null;

+    }

+

+    @Test

+    public void testCreation() {

+        Properties props = new Properties();

+        props.put("instance.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();

+    }

+

+    @Test

+    public void testServiceAvailability() {

+        Properties props = new Properties();

+        props.put("instance.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 = getServiceContext(under);

+        assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));

+

+        under.dispose();

+    }

+

+    @Test

+    public void testCreationLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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();

+    }

+

+    @Test

+    public void testServiceAvailabilityLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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 = getServiceContext(under);

+        assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));

+

+        under.dispose();

+    }

+

+    @Test

+    public void testFactoryManagement() {

+        Properties props = new Properties();

+        props.put("instance.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) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+        ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+        ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("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();

+    }

+

+    @Test

+    public void testFactoryManagementLevel2() {

+        ServiceContext sc = getServiceContext(empty);

+        Properties props = new Properties();

+        props.put("instance.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) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+        ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+        ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("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();

+    }

+

+    @Test

+    public void testArchitecture() {

+        Properties props = new Properties();

+        props.put("instance.name", "under");

+        ComponentInstance under = null;

+        try {

+            under = bar1Factory.createComponentInstance(props);

+        } catch (Exception e) {

+            fail("Cannot instantiate under : " + e.getMessage());

+        }

+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        Architecture arch = (Architecture) getContext().getService(ref);

+        CompositeInstanceDescription id = (CompositeInstanceDescription) 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 instance name", id.getName(), "under");

+        assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");

+

+        ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");

+        ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");

+        ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");

+

+        fact1.stop();

+        assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);

+        ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 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 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");

+        assertNotNull("Check architecture availability", ref);

+        arch = (Architecture) getContext().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 instance name", id.getName(), "under");

+        assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");

+

+        under.dispose();

+        fact2.start();

+        fact3.start();

+    }

+

+}