felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r1450158 [8/9] - in /felix/trunk/ipojo/runtime/composite-it: ./ src/ src/it/ src/it/ipojo-composite-import-export-test/ src/it/ipojo-composite-import-export-test/src/ src/it/ipojo-composite-import-export-test/src/main/ src/it/ipojo-composit...
Date Tue, 26 Feb 2013 13:02:40 GMT
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tata.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tata.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tata.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tata.java Tue Feb 26 13:02:34 2013
@@ -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);
+
+}

Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tota.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tota.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tota.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tota.java Tue Feb 26 13:02:34 2013
@@ -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.runtime.core.services.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;
+    
+
+}

Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Toto.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Toto.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Toto.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Toto.java Tue Feb 26 13:02:34 2013
@@ -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();
+
+
+}

Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/resources/metadata-providing.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/resources/metadata-providing.xml?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/resources/metadata-providing.xml (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/resources/metadata-providing.xml Tue Feb 26 13:02:34 2013
@@ -0,0 +1,155 @@
+<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">
+	<comp:composite name="composite.test.3" architecture="true">
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+			aggregate="true" filter="(factory.name=BazProviderType)" />
+		<comp:provides action="export"
+			specification="org.apache.felix.ipojo.runtime.core.services.BazService" />
+	</comp:composite>
+
+	<comp:composite name="composite.test.2" architecture="true">
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.CheckService"
+			filter="(factory.name=Baz2CheckProvider)" />
+		<comp:provides action="export"
+			specification="org.apache.felix.ipojo.runtime.core.services.CheckService" />
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+			scope="composite" />
+	</comp:composite>
+
+	<comp:composite name="composite.test.1" architecture="true">
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+			filter="(factory.name=composite.test.3)" />
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.CheckService"
+			filter="(factory.name=composite.test.2)" />
+		<comp:provides action="export"
+			specification="org.apache.felix.ipojo.runtime.core.services.CheckService" />
+	</comp:composite>
+
+	<comp:composite name="composite.instantiator" architecture="true">
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+			filter="(factory.name=composite.test.3)" />
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.FooService" />
+		<comp:provides action="export"
+			specification="org.apache.felix.ipojo.runtime.core.services.BazService" />
+		<comp:provides action="export"
+			specification="org.apache.felix.ipojo.runtime.core.services.FooService" />
+	</comp:composite>
+
+	<!-- Test composition provides -->
+
+	<comp:composite name="comp-0" architecture="true">
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tata" />
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.runtime.core.services.Toto" />
+		<comp:provides action="implement"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tota" />
+	</comp:composite>
+
+	<comp:composite name="comp-1" architecture="true">
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tata" />
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.runtime.core.services.Toto" />
+		<comp:provides action="implement"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tota">
+			<delegation method="tataInt" policy="One" />
+			<delegation method="toto1" policy="All" />
+		</comp:provides>
+	</comp:composite>
+
+	<comp:composite name="comp-2" architecture="true">
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tata"
+			aggregate="true" />
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.runtime.core.services.Toto"
+			aggregate="true" />
+		<comp:provides action="implement"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tota">
+			<delegation method="tataInt" policy="One" />
+			<delegation method="toto1" policy="All" />
+		</comp:provides>
+	</comp:composite>
+
+	<comp:composite name="comp-3" architecture="true">
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tata" />
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.runtime.core.services.Toto"
+			optional="true" />
+		<comp:provides action="implement"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tota">
+		</comp:provides>
+	</comp:composite>
+
+	<comp:composite name="comp-4" architecture="true">
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tata" />
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.runtime.core.services.Toto"
+			optional="true" />
+		<comp:provides action="implement"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tota">
+			<delegation method="tataInt" policy="One" />
+			<delegation method="toto1" policy="All" />
+		</comp:provides>
+	</comp:composite>
+
+	<comp:composite name="comp-5" architecture="true">
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tata"
+			aggregate="true" />
+		<!-- <subservice action="import" specification="org.apache.felix.ipojo.test.comp:composite.service.Toto" aggregate ="true" optional="true"/> -->
+		<comp:provides action="implement"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tota">
+			<delegation method="tataInt" policy="One" />
+			<delegation method="toto1" policy="All" />
+		</comp:provides>
+	</comp:composite>
+
+	<comp:composite name="comp-6" architecture="true">
+		<subservice action="instantiate"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tata"
+			aggregate="true" />
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.runtime.core.services.Toto"
+			aggregate="true" optional="true" />
+		<comp:provides action="implement"
+			specification="org.apache.felix.ipojo.runtime.core.services.Toto">
+			<delegation method="toto1" policy="All" />
+		</comp:provides>
+		<comp:provides action="implement"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tata">
+			<delegation method="tataInt" policy="One" />
+		</comp:provides>
+	</comp:composite>
+
+	<comp:composite name="comp-7" architecture="true">
+		<instance component="tata" />
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.runtime.core.services.Toto" />
+		<comp:provides action="implement"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tota" />
+	</comp:composite>
+
+	<comp:composite name="comp-8" architecture="true">
+		<instance component="tata" />
+		<instance component="totoglue" />
+		<subservice action="import"
+			specification="org.apache.felix.ipojo.runtime.core.services.Toto" />
+		<comp:provides action="implement"
+			specification="org.apache.felix.ipojo.runtime.core.services.Tota" />
+	</comp:composite>
+</ipojo>

Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/resources/metadata.xml?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/resources/metadata.xml (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/main/resources/metadata.xml Tue Feb 26 13:02:34 2013
@@ -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>

Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java Tue Feb 26 13:02:34 2013
@@ -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 = "org.apache.felix.ipojo.runtime.core.components";
+        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);
+    }
+
+
+}

Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestCompositeAPI.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestCompositeAPI.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestCompositeAPI.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestCompositeAPI.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,184 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core;
+
+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.services.BazService;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+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 TestCompositeAPI extends Common {
+
+    @Test
+    public void testAPI() {
+        Factory fact1 = ipojoHelper.getFactory("composite.empty");
+        Properties p = new Properties();
+        p.put("instance.name", "empty-1");
+        ComponentInstance empty = null;
+        try {
+            empty = fact1.createComponentInstance(p);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+
+        ServiceContext sc = getServiceContext(empty);
+
+        Factory fact2 = ipojoHelper.getFactory("composite.test.2");
+        Properties props2 = new Properties();
+        props2.put("instance.name", "2"); // 2
+        Factory fact3 = ipojoHelper.getFactory("composite.test.3");
+        Properties props3 = new Properties();
+        props3.put("instance.name", "3");
+        ComponentInstance comp2 = null;
+        ComponentInstance comp3 = null;
+        try {
+            comp2 = fact2.createComponentInstance(props2, sc);
+            comp3 = fact3.createComponentInstance(props3, sc);
+        } catch (Throwable e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+
+        assertTrue("Test comp3", comp3.getState() == ComponentInstance.VALID);
+        assertTrue("Test comp2", comp2.getState() == ComponentInstance.VALID);
+
+        ServiceReference ref = null;
+
+        ref = ipojoHelper.getServiceReferenceByName(sc, CheckService.class.getName(), "2"); // 2
+
+        assertNotNull("Check ref", ref);
+        CheckService cs = (CheckService) sc.getService(ref);
+        assertTrue("Check invoke", cs.check());
+
+        comp3.dispose();
+        comp2.dispose();
+        empty.dispose();
+    }
+
+    @Test
+    public void testInstantiator() {
+        String type = "composite.instantiator";
+        Factory fact = ipojoHelper.getFactory(type);
+        ComponentInstance ci = null;
+        Properties p = new Properties();
+        p.put("instance.name", "mon_coeur");
+        try {
+            ci = fact.createComponentInstance(p);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        assertTrue("Check ci", ci.getState() == ComponentInstance.VALID);
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), "mon_coeur");
+        assertNotNull("Check ref", ref);
+        BazService bs = (BazService) getContext().getService(ref);
+        assertTrue("Check invocation", bs.foo());
+        getContext().ungetService(ref);
+        ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "mon_coeur");
+        assertNotNull("Check ref 2 ", ref);
+        FooService fs = (FooService) getContext().getService(ref);
+        assertTrue("Check invocation", fs.foo());
+        getContext().ungetService(ref);
+        ci.dispose();
+    }
+
+    @Test
+    public void testAPI2() {
+        Factory fact1 = ipojoHelper.getFactory("composite.empty");
+        Properties p = new Properties();
+        p.put("instance.name", "empty-2");
+        ComponentInstance empty = null;
+        try {
+            empty = fact1.createComponentInstance(p);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        ServiceContext sc = getServiceContext(empty);
+
+        Factory fact2 = ipojoHelper.getFactory(sc, "composite.test.2");
+        Properties props2 = new Properties();
+        props2.put("instance.name", "4");
+        Factory fact3 = ipojoHelper.getFactory(sc, "composite.test.3");
+        Properties props3 = new Properties();
+        props3.put("instance.name", "5");
+        ComponentInstance comp2 = null;
+        ComponentInstance comp3 = null;
+        try {
+            comp2 = fact2.createComponentInstance(props2, sc);
+            comp3 = fact3.createComponentInstance(props3, sc);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        assertTrue("Test comp3", comp3.getState() == ComponentInstance.VALID);
+        assertTrue("Test comp2", comp2.getState() == ComponentInstance.VALID);
+
+        ServiceReference ref = null;
+
+        ref = ipojoHelper.getServiceReferenceByName(sc, CheckService.class.getName(), "4");
+
+        assertNotNull("Check ref", ref);
+        CheckService cs = (CheckService) sc.getService(ref);
+        assertTrue("Check invoke", cs.check());
+
+        comp3.dispose();
+        comp2.dispose();
+        empty.dispose();
+    }
+
+    @Test
+    public void testApplication() {
+        Factory factory = ipojoHelper.getFactory("composite.test.1");
+        ComponentInstance ci = null;
+        Properties props = new Properties();
+        props.put("instance.name", "Test");
+        try {
+            ci = factory.createComponentInstance(props);
+        } catch (Exception e) {
+            fail("Cannot instantiate Test " + e.getMessage());
+        }
+
+        assertTrue("Check ci state", ci.getState() == ComponentInstance.VALID);
+
+        ServiceReference[] refs = null;
+        try {
+            refs = getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=Test)");
+        } catch (InvalidSyntaxException e) {
+            fail("Invalid filter : " + e.getMessage());
+        }
+        assertNotNull("Check refs not null", refs);
+        CheckService cs = (CheckService) getContext().getService(refs[0]);
+
+        assertTrue("Check invocation", cs.check());
+        ci.dispose();
+
+    }
+
+}

Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp0.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp0.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp0.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp0.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,343 @@
+/* 
+ * 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.providing;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.components.TotoProvider;
+import org.apache.felix.ipojo.runtime.core.services.Tota;
+import org.apache.felix.ipojo.runtime.core.services.Toto;
+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 TestComp0 extends Common {
+
+    private ComponentFactory tataFactory;
+    private ComponentFactory totoFactory;
+    private ComponentFactory tataFactory2;
+    private ComponentInstance totoProv, totoProv2;
+    private ComponentInstance under;
+
+    @Before
+    public void setUp() {
+        tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
+        totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
+        tataFactory2 = (ComponentFactory) ipojoHelper.getFactory("comp-6");
+        tataFactory2.stop();
+        tataFactory.stop();
+
+        Properties props = new Properties();
+        props.put("instance.name", "toto provider");
+        try {
+            totoProv = totoFactory.createComponentInstance(props);
+        } catch (Exception e) {
+            fail("Cannot create an instance : " + e.getMessage());
+        }
+
+        Properties props3 = new Properties();
+        props3.put("instance.name", "toto provider 2");
+        try {
+            totoProv2 = totoFactory.createComponentInstance(props3);
+        } catch (Exception e) {
+            fail("Cannot create an instance : " + e.getMessage());
+        }
+
+        totoProv.stop();
+        totoProv2.stop();
+
+        Factory factory = ipojoHelper.getFactory("comp-0");
+        Properties props2 = new Properties();
+        props2.put("instance.name", "ff");
+        try {
+            under = factory.createComponentInstance(props2);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Cannot create an instance : " + e.getMessage());
+        }
+    }
+
+    @After
+    public void tearDown() {
+        tataFactory.start();
+        totoProv.dispose();
+        totoProv = null;
+        totoProv2.dispose();
+        totoProv2 = null;
+        tataFactory2.start();
+
+        // Reset counters
+        TotoProvider.toto = 0;
+        TotoProvider.toto_2 = 0;
+        TotoProvider.toto_3 = 0;
+        TotoProvider.toto_4 = 0;
+        TotoProvider.toto1 = 0;
+    }
+
+    @Test
+    public void testSimple() {
+        // Neither factory nor instance
+        assertTrue("Assert under state - 1", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 1", getContext().getServiceReference(Tota.class.getName()));
+
+        // Start the importer
+        totoProv.start();
+        assertNotNull("Assert toto service - 1", getContext().getServiceReference(Toto.class.getName()));
+        assertTrue("Assert under state - 2", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 2", getContext().getServiceReference(Tota.class.getName()));
+
+        // Start the factory
+        tataFactory.start();
+        assertTrue("Assert under state - 3", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 3", getContext().getServiceReference(Tota.class.getName()));
+        ServiceReference ref = getContext().getServiceReference(Tota.class.getName());
+        Tota tota = (Tota) getContext().getService(ref);
+        invokeAll(tota);
+        // Check toto
+        Properties props = tota.getProps();
+        Integer toto = (Integer) props.get("toto");
+        Integer toto_2 = (Integer) props.get("toto_2");
+        Integer toto_3 = (Integer) props.get("toto_3");
+        Integer toto_4 = (Integer) props.get("toto_4");
+        assertEquals("Assert toto - 3", toto.intValue(), 1);
+        assertEquals("Assert toto_2 - 3", toto_2.intValue(), 1);
+        assertEquals("Assert toto_3 - 3", toto_3.intValue(), 1);
+        assertEquals("Assert toto_4 - 3", toto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        Integer tata = (Integer) props.get("tata");
+        Integer tataStr = (Integer) props.get("tataStr");
+        Integer tataStrs = (Integer) props.get("tataStrs");
+        Integer tata_2 = (Integer) props.get("tata_2");
+        Integer tata_3 = (Integer) props.get("tata_3");
+        Integer tata1 = (Integer) props.get("tata1");
+        Integer tata1_1 = (Integer) props.get("tata1_1");
+        Integer tata5 = (Integer) props.get("tata5");
+        Integer tata5_1 = (Integer) props.get("tata5_1");
+        Integer tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 3", tata.intValue(), 1);
+        assertEquals("Assert tataStr - 3", tataStr.intValue(), 1);
+        assertEquals("Assert tataStrs - 3", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 3", tata_2.intValue(), 1);
+        assertEquals("Assert tata_3 - 3", tata_3.intValue(), 1);
+        assertEquals("Assert tata1 - 3", tata1.intValue(), 1);
+        assertEquals("Assert tata1_1 - 3", tata1_1.intValue(), 1);
+        assertEquals("Assert tata5 - 3", tata5.intValue(), 1);
+        assertEquals("Assert tata5_1 - 3", tata5_1.intValue(), 1);
+        assertEquals("Assert tata5_2 - 3", tata5_2.intValue(), 1);
+
+        getContext().ungetService(ref);
+        tota = null;
+
+        // Start a second import
+        totoProv2.start();
+        assertTrue("Assert under state - 4", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 4", getContext().getServiceReference(Tota.class.getName()));
+        ref = getContext().getServiceReference(Tota.class.getName());
+        tota = (Tota) getContext().getService(ref);
+        invokeAll(tota);
+        // Check toto
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        assertEquals("Assert toto - 4", toto.intValue(), 2);
+        assertEquals("Assert toto_2 - 4", toto_2.intValue(), 2);
+        assertEquals("Assert toto_3 - 4", toto_3.intValue(), 2);
+        assertEquals("Assert toto_4 - 4", toto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        tataStr = (Integer) props.get("tataStr");
+        tataStrs = (Integer) props.get("tataStrs");
+        tata_2 = (Integer) props.get("tata_2");
+        tata_3 = (Integer) props.get("tata_3");
+        tata1 = (Integer) props.get("tata1");
+        tata1_1 = (Integer) props.get("tata1_1");
+        tata5 = (Integer) props.get("tata5");
+        tata5_1 = (Integer) props.get("tata5_1");
+        tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 4", tata.intValue(), 2);
+        assertEquals("Assert tataStr - 4", tataStr.intValue(), 2);
+        assertEquals("Assert tataStrs - 4", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 4", tata_2.intValue(), 2);
+        assertEquals("Assert tata_3 - 4", tata_3.intValue(), 2);
+        assertEquals("Assert tata1 - 4", tata1.intValue(), 2);
+        assertEquals("Assert tata1_1 - 4", tata1_1.intValue(), 2);
+        assertEquals("Assert tata5 - 4", tata5.intValue(), 2);
+        assertEquals("Assert tata5_1 - 4", tata5_1.intValue(), 2);
+        assertEquals("Assert tata5_2 - 4", tata5_2.intValue(), 2);
+
+        getContext().ungetService(ref);
+        tota = null;
+
+        tataFactory.stop();
+        assertTrue("Assert under state - 5", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 5", getContext().getServiceReference(Tota.class.getName()));
+
+        totoProv2.stop();
+        tataFactory.start();
+        assertTrue("Assert under state - 6", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 6", getContext().getServiceReference(Tota.class.getName()));
+        ref = getContext().getServiceReference(Tota.class.getName());
+        tota = (Tota) getContext().getService(ref);
+        invokeAll(tota);
+        // Check toto
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        assertEquals("Assert toto - 6", toto.intValue(), 3);
+        assertEquals("Assert toto_2 - 6", toto_2.intValue(), 3);
+        assertEquals("Assert toto_3 - 6", toto_3.intValue(), 3);
+        assertEquals("Assert toto_4 - 6", toto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        tataStr = (Integer) props.get("tataStr");
+        tataStrs = (Integer) props.get("tataStrs");
+        tata_2 = (Integer) props.get("tata_2");
+        tata_3 = (Integer) props.get("tata_3");
+        tata1 = (Integer) props.get("tata1");
+        tata1_1 = (Integer) props.get("tata1_1");
+        tata5 = (Integer) props.get("tata5");
+        tata5_1 = (Integer) props.get("tata5_1");
+        tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 6", tata.intValue(), 1);
+        assertEquals("Assert tataStr - 6", tataStr.intValue(), 1);
+        assertEquals("Assert tataStrs - 6", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 6", tata_2.intValue(), 1);
+        assertEquals("Assert tata_3 - 6", tata_3.intValue(), 1);
+        assertEquals("Assert tata1 - 6", tata1.intValue(), 1);
+        assertEquals("Assert tata1_1 - 6", tata1_1.intValue(), 1);
+        assertEquals("Assert tata5 - 6", tata5.intValue(), 1);
+        assertEquals("Assert tata5_1 - 6", tata5_1.intValue(), 1);
+        assertEquals("Assert tata5_2 - 6", tata5_2.intValue(), 1);
+
+        getContext().ungetService(ref);
+        tota = null;
+
+        // Is arch exposed
+        assertNotNull("Test arch", ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "ff"));
+
+        totoProv.stop();
+
+        assertTrue("Assert under state - 7", under.getState() == ComponentInstance.INVALID);
+        assertNotNull("Test arch-2", ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "ff"));
+        assertNull("Assert no tota service - 7", getContext().getServiceReference(Tota.class.getName()));
+
+        under.dispose();
+        under = null;
+    }
+
+    private void invoke(Tota tota) {
+        tota.tata();
+
+        assertEquals("Assert invoke tataint", tota.tataInt(2), 2);
+        assertEquals("Assert invoke tataLong", tota.tataLong(2), 2);
+        assertEquals("Assert invoke tataDouble", tota.tataDouble(2), 2, 0);
+        assertEquals("Assert invoke tataChar", tota.tataChar('a'), 'a');
+        assertTrue("Assert invoke tataBoolean", tota.tataBoolean(true));
+        assertEquals("Assert invoke tataByte", tota.tataByte((byte) 2), 2);
+        assertEquals("Assert invoke tataShort", tota.tataShort((short) 5), 5);
+        assertEquals("Assert invoke tataFloat", tota.tataFloat(5), 5, 0);
+
+    }
+
+    private void invokeArrays(Tota tota) {
+
+        int[] a = new int[]{1, 2, 3};
+        assertEquals("Assert invoke tataint[]", tota.tataInts(a), a);
+
+        long[] b = new long[]{1, 2, 3};
+        assertEquals("Assert invoke tataLong[]", tota.tataLongs(b), b);
+
+        double[] c = new double[]{1, 2, 3};
+        assertEquals("Assert invoke tataDouble[]", tota.tataDoubles(c), c);
+
+        char[] d = new char[]{'a', 'b', 'c'};
+        assertEquals("Assert invoke tataChar[]", tota.tataChars(d), d);
+
+        boolean[] e = new boolean[]{true, false};
+        assertEquals("Assert invoke tataBoolean[]", tota.tataBooleans(e), e);
+
+        byte[] f = new byte[]{(byte) 1};
+        assertEquals("Assert invoke tataByte[]", tota.tataBytes(f), f);
+
+        short[] g = new short[]{(short) 1};
+        assertEquals("Assert invoke tataShort[]", tota.tataShorts(g), g);
+
+        float[] h = new float[]{5, 6, 7};
+        assertEquals("Assert invoke tataFloat[]", tota.tataFloats(h), h);
+
+    }
+
+    private void invokeStr(Tota tota) {
+        tota.tataStr();
+    }
+
+    private void invokeTata(Tota tota) {
+        tota.tata(1, 2);
+        tota.tata("tototototo");
+    }
+
+    private void invokeTata1(Tota tota) {
+        assertEquals("Assert tata1", tota.tata1("foo"), "foo");
+        assertEquals("Assert tata1 - 2", tota.tata1(new char[]{'a', 'b', 'c'}), "abc");
+    }
+
+    private void invokeTata5(Tota tota) {
+        assertEquals("Assert tata5 -1", tota.tata5("foo", 1), "foo" + 1);
+        assertEquals("Assert tata5 - 2", tota.tata5(new String[]{"a", "b", "c"}, 1), "31");
+        assertEquals("Assert tata5 - 3", tota.tata5("foo", new int[]{1, 2, 3}), "foo3");
+    }
+
+    private void invokeAdd(Tota tota) {
+        assertEquals("Assert add", tota.add(1, 1, 1), 3);
+    }
+
+    private void invokeToto(Tota tota) {
+        tota.toto();
+        assertEquals("Assert toto", tota.toto("foo"), "foo");
+        tota.toto(1, 2);
+    }
+
+    private void invokeAll(Tota tota) {
+        invoke(tota);
+        invokeArrays(tota);
+        invokeStr(tota);
+        invokeTata(tota);
+        invokeTata1(tota);
+        invokeTata5(tota);
+        invokeAdd(tota);
+        invokeToto(tota);
+    }
+
+
+}

Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp1.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp1.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp1.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp1.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,341 @@
+/* 
+ * 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.providing;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.components.TotoProvider;
+import org.apache.felix.ipojo.runtime.core.services.Tota;
+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 TestComp1 extends Common {
+
+    private ComponentFactory tataFactory;
+    private ComponentFactory totoFactory;
+    private ComponentInstance totoProv, totoProv2;
+    private ComponentInstance under;
+    private ComponentFactory tataFactory2;
+
+    @Before
+    public void setUp() {
+        tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
+        totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
+        tataFactory2 = (ComponentFactory) ipojoHelper.getFactory("comp-6");
+        tataFactory2.stop();
+
+        tataFactory.stop();
+
+        Properties props = new Properties();
+        props.put("instance.name", "toto provider");
+        try {
+            totoProv = totoFactory.createComponentInstance(props);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        Properties props3 = new Properties();
+        props3.put("instance.name", "toto provider 2");
+        try {
+            totoProv2 = totoFactory.createComponentInstance(props3);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        totoProv.stop();
+        totoProv2.stop();
+
+        Factory factory = ipojoHelper.getFactory("comp-1");
+        Properties props2 = new Properties();
+        try {
+            under = factory.createComponentInstance(props2);
+        } catch (Exception e) {
+            fail("Cannot create the instance : " + e.getMessage());
+        }
+
+    }
+
+    @After
+    public void tearDown() {
+        tataFactory.start();
+        totoProv.dispose();
+        totoProv = null;
+        totoProv2.dispose();
+        totoProv2 = null;
+        tataFactory2.start();
+
+        // Reset counters
+        TotoProvider.toto = 0;
+        TotoProvider.toto_2 = 0;
+        TotoProvider.toto_3 = 0;
+        TotoProvider.toto_4 = 0;
+        TotoProvider.toto1 = 0;
+    }
+
+    @Test
+    public void testSimple() {
+        // Neither factory nor instance
+        assertTrue("Assert under state - 1", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 1", getContext().getServiceReference(Tota.class.getName()));
+
+        // Start the importer
+        totoProv.start();
+        assertTrue("Assert under state - 2 (" + under.getState() + ")", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 2", getContext().getServiceReference(Tota.class.getName()));
+
+        // Start the factory
+        tataFactory.start();
+        assertTrue("Assert under state - 3", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 3", getContext().getServiceReference(Tota.class.getName()));
+        ServiceReference ref = getContext().getServiceReference(Tota.class.getName());
+        Tota tota = (Tota) getContext().getService(ref);
+        invokeAll(tota);
+        // Check toto
+        Properties props = tota.getProps();
+        Integer toto = (Integer) props.get("toto");
+        Integer toto_2 = (Integer) props.get("toto_2");
+        Integer toto_3 = (Integer) props.get("toto_3");
+        Integer toto_4 = (Integer) props.get("toto_4");
+        assertEquals("Assert toto - 3 (" + toto.intValue() + ")", toto.intValue(), 1);
+        assertEquals("Assert toto_2 - 3", toto_2.intValue(), 1);
+        assertEquals("Assert toto_3 - 3", toto_3.intValue(), 1);
+        assertEquals("Assert toto_4 - 3", toto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        Integer tata = (Integer) props.get("tata");
+        Integer tataStr = (Integer) props.get("tataStr");
+        Integer tataStrs = (Integer) props.get("tataStrs");
+        Integer tata_2 = (Integer) props.get("tata_2");
+        Integer tata_3 = (Integer) props.get("tata_3");
+        Integer tata1 = (Integer) props.get("tata1");
+        Integer tata1_1 = (Integer) props.get("tata1_1");
+        Integer tata5 = (Integer) props.get("tata5");
+        Integer tata5_1 = (Integer) props.get("tata5_1");
+        Integer tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 3", tata.intValue(), 1);
+        assertEquals("Assert tataStr - 3", tataStr.intValue(), 1);
+        assertEquals("Assert tataStrs - 3", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 3", tata_2.intValue(), 1);
+        assertEquals("Assert tata_3 - 3", tata_3.intValue(), 1);
+        assertEquals("Assert tata1 - 3", tata1.intValue(), 1);
+        assertEquals("Assert tata1_1 - 3", tata1_1.intValue(), 1);
+        assertEquals("Assert tata5 - 3", tata5.intValue(), 1);
+        assertEquals("Assert tata5_1 - 3", tata5_1.intValue(), 1);
+        assertEquals("Assert tata5_2 - 3", tata5_2.intValue(), 1);
+
+        getContext().ungetService(ref);
+        tota = null;
+
+        // Start a second import
+        totoProv2.start();
+        assertTrue("Assert under state - 4", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 4", getContext().getServiceReference(Tota.class.getName()));
+        ref = getContext().getServiceReference(Tota.class.getName());
+        tota = (Tota) getContext().getService(ref);
+        invokeAll(tota);
+        // Check toto
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        assertEquals("Assert toto - 4", toto.intValue(), 2);
+        assertEquals("Assert toto_2 - 4", toto_2.intValue(), 2);
+        assertEquals("Assert toto_3 - 4", toto_3.intValue(), 2);
+        assertEquals("Assert toto_4 - 4", toto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        tataStr = (Integer) props.get("tataStr");
+        tataStrs = (Integer) props.get("tataStrs");
+        tata_2 = (Integer) props.get("tata_2");
+        tata_3 = (Integer) props.get("tata_3");
+        tata1 = (Integer) props.get("tata1");
+        tata1_1 = (Integer) props.get("tata1_1");
+        tata5 = (Integer) props.get("tata5");
+        tata5_1 = (Integer) props.get("tata5_1");
+        tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 4", tata.intValue(), 2);
+        assertEquals("Assert tataStr - 4", tataStr.intValue(), 2);
+        assertEquals("Assert tataStrs - 4", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 4", tata_2.intValue(), 2);
+        assertEquals("Assert tata_3 - 4", tata_3.intValue(), 2);
+        assertEquals("Assert tata1 - 4", tata1.intValue(), 2);
+        assertEquals("Assert tata1_1 - 4", tata1_1.intValue(), 2);
+        assertEquals("Assert tata5 - 4", tata5.intValue(), 2);
+        assertEquals("Assert tata5_1 - 4", tata5_1.intValue(), 2);
+        assertEquals("Assert tata5_2 - 4", tata5_2.intValue(), 2);
+
+        getContext().ungetService(ref);
+        tota = null;
+
+        tataFactory.stop();
+        assertTrue("Assert under state - 5", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 5", getContext().getServiceReference(Tota.class.getName()));
+
+        totoProv2.stop();
+        tataFactory.start();
+        assertTrue("Assert under state - 6", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 6", getContext().getServiceReference(Tota.class.getName()));
+        ref = getContext().getServiceReference(Tota.class.getName());
+        tota = (Tota) getContext().getService(ref);
+        invokeAll(tota);
+        // Check toto
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        assertEquals("Assert toto - 6", toto.intValue(), 3);
+        assertEquals("Assert toto_2 - 6", toto_2.intValue(), 3);
+        assertEquals("Assert toto_3 - 6", toto_3.intValue(), 3);
+        assertEquals("Assert toto_4 - 6", toto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        tataStr = (Integer) props.get("tataStr");
+        tataStrs = (Integer) props.get("tataStrs");
+        tata_2 = (Integer) props.get("tata_2");
+        tata_3 = (Integer) props.get("tata_3");
+        tata1 = (Integer) props.get("tata1");
+        tata1_1 = (Integer) props.get("tata1_1");
+        tata5 = (Integer) props.get("tata5");
+        tata5_1 = (Integer) props.get("tata5_1");
+        tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 6", tata.intValue(), 1);
+        assertEquals("Assert tataStr - 6", tataStr.intValue(), 1);
+        assertEquals("Assert tataStrs - 6", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 6", tata_2.intValue(), 1);
+        assertEquals("Assert tata_3 - 6", tata_3.intValue(), 1);
+        assertEquals("Assert tata1 - 6", tata1.intValue(), 1);
+        assertEquals("Assert tata1_1 - 6", tata1_1.intValue(), 1);
+        assertEquals("Assert tata5 - 6", tata5.intValue(), 1);
+        assertEquals("Assert tata5_1 - 6", tata5_1.intValue(), 1);
+        assertEquals("Assert tata5_2 - 6", tata5_2.intValue(), 1);
+
+        getContext().ungetService(ref);
+        tota = null;
+
+        // Is arch exposed
+        assertNotNull("Test arch", ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), under.getInstanceName()));
+
+        totoProv.stop();
+
+        assertTrue("Assert under state - 7", under.getState() == ComponentInstance.INVALID);
+        assertNotNull("Test arch-2", ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), under.getInstanceName()));
+        assertNull("Assert no tota service - 7", getContext().getServiceReference(Tota.class.getName()));
+
+        under.dispose();
+        under = null;
+    }
+
+    private void invoke(Tota tota) {
+        tota.tata();
+
+        assertEquals("Assert invoke tataint", tota.tataInt(2), 2);
+        assertEquals("Assert invoke tataLong", tota.tataLong(2), 2);
+        assertEquals("Assert invoke tataDouble", tota.tataDouble(2), 2, 0);
+        assertEquals("Assert invoke tataChar", tota.tataChar('a'), 'a');
+        assertTrue("Assert invoke tataBoolean", tota.tataBoolean(true));
+        assertEquals("Assert invoke tataByte", tota.tataByte((byte) 2), 2);
+        assertEquals("Assert invoke tataShort", tota.tataShort((short) 5), 5);
+        assertEquals("Assert invoke tataFloat", tota.tataFloat(5), 5, 0);
+
+    }
+
+    private void invokeArrays(Tota tota) {
+
+        int[] a = new int[]{1, 2, 3};
+        assertEquals("Assert invoke tataint[]", tota.tataInts(a), a);
+
+        long[] b = new long[]{1, 2, 3};
+        assertEquals("Assert invoke tataLong[]", tota.tataLongs(b), b);
+
+        double[] c = new double[]{1, 2, 3};
+        assertEquals("Assert invoke tataDouble[]", tota.tataDoubles(c), c);
+
+        char[] d = new char[]{'a', 'b', 'c'};
+        assertEquals("Assert invoke tataChar[]", tota.tataChars(d), d);
+
+        boolean[] e = new boolean[]{true, false};
+        assertEquals("Assert invoke tataBoolean[]", tota.tataBooleans(e), e);
+
+        byte[] f = new byte[]{(byte) 1};
+        assertEquals("Assert invoke tataByte[]", tota.tataBytes(f), f);
+
+        short[] g = new short[]{(short) 1};
+        assertEquals("Assert invoke tataShort[]", tota.tataShorts(g), g);
+
+        float[] h = new float[]{5, 6, 7};
+        assertEquals("Assert invoke tataFloat[]", tota.tataFloats(h), h);
+
+    }
+
+    private void invokeStr(Tota tota) {
+        tota.tataStr();
+    }
+
+    private void invokeTata(Tota tota) {
+        tota.tata(1, 2);
+        tota.tata("tototototo");
+    }
+
+    private void invokeTata1(Tota tota) {
+        assertEquals("Assert tata1", tota.tata1("foo"), "foo");
+        assertEquals("Assert tata1 - 2", tota.tata1(new char[]{'a', 'b', 'c'}), "abc");
+    }
+
+    private void invokeTata5(Tota tota) {
+        assertEquals("Assert tata5 -1", tota.tata5("foo", 1), "foo" + 1);
+        assertEquals("Assert tata5 - 2", tota.tata5(new String[]{"a", "b", "c"}, 1), "31");
+        assertEquals("Assert tata5 - 3", tota.tata5("foo", new int[]{1, 2, 3}), "foo3");
+    }
+
+    private void invokeAdd(Tota tota) {
+        assertEquals("Assert add", tota.add(1, 1, 1), 3);
+    }
+
+    private void invokeToto(Tota tota) {
+        tota.toto();
+        assertEquals("Assert toto", tota.toto("foo"), "foo");
+        tota.toto(1, 2);
+    }
+
+    private void invokeAll(Tota tota) {
+        invoke(tota);
+        invokeArrays(tota);
+        invokeStr(tota);
+        invokeTata(tota);
+        invokeTata1(tota);
+        invokeTata5(tota);
+        invokeAdd(tota);
+        invokeToto(tota);
+    }
+
+
+}

Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp2.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp2.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp2.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/providing/TestComp2.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,238 @@
+/* 
+ * 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.providing;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.components.TotoProvider;
+import org.apache.felix.ipojo.runtime.core.services.Tota;
+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 TestComp2 extends Common {
+
+    private ComponentFactory tataFactory;
+    private ComponentFactory totoFactory;
+    private ComponentInstance totoProv, totoProv2;
+    private ComponentInstance under;
+    private ComponentFactory tataFactory2;
+
+    @Before
+    public void setUp() {
+        tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
+        totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
+        tataFactory2 = (ComponentFactory) ipojoHelper.getFactory("comp-6");
+        tataFactory2.stop();
+        tataFactory.stop();
+
+        Properties props = new Properties();
+        props.put("instance.name", "toto provider");
+        try {
+            totoProv = totoFactory.createComponentInstance(props);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        Properties props3 = new Properties();
+        props3.put("instance.name", "toto provider 2");
+        try {
+            totoProv2 = totoFactory.createComponentInstance(props3);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        totoProv.stop();
+        totoProv2.stop();
+
+        Factory factory = ipojoHelper.getFactory("comp-2");
+        Properties props2 = new Properties();
+        props2.put("instance.name", "ff");
+        try {
+            under = factory.createComponentInstance(props2);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    @After
+    public void tearDown() {
+        tataFactory.start();
+        totoProv.dispose();
+        totoProv = null;
+        totoProv2.dispose();
+        totoProv2 = null;
+        tataFactory2.start();
+
+        // Reset counters
+        TotoProvider.toto = 0;
+        TotoProvider.toto_2 = 0;
+        TotoProvider.toto_3 = 0;
+        TotoProvider.toto_4 = 0;
+        TotoProvider.toto1 = 0;
+    }
+
+    @Test
+    public void testSimple() {
+        // Neither factory nor instance
+        assertTrue("Assert under state - 1", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 1", getContext().getServiceReference(Tota.class.getName()));
+
+        // Start the importer
+        totoProv.start();
+        assertTrue("Assert under state - 2 (" + under.getState() + ")", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 2", getContext().getServiceReference(Tota.class.getName()));
+
+        // Start the factory
+        tataFactory.start();
+        assertTrue("Assert under state - 3", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 3", getContext().getServiceReference(Tota.class.getName()));
+        ServiceReference ref = getContext().getServiceReference(Tota.class.getName());
+        Tota tota = (Tota) getContext().getService(ref);
+
+        invokeAll(tota);
+
+        // Check toto
+        Properties props = tota.getProps();
+        Integer toto = (Integer) props.get("toto");
+        Integer toto_2 = (Integer) props.get("toto_2");
+        Integer toto_3 = (Integer) props.get("toto_3");
+        Integer toto_4 = (Integer) props.get("toto_4");
+        Integer toto_1 = (Integer) props.get("toto1");
+        assertEquals("Assert toto - 3 (" + toto.intValue() + ")", toto.intValue(), 1);
+        assertEquals("Assert toto_2 - 3", toto_2.intValue(), 1);
+        assertEquals("Assert toto_3 - 3", toto_3.intValue(), 1);
+        assertEquals("Assert toto_4 - 3", toto_4.intValue(), 0);
+        assertEquals("Assert toto1 - 3 (" + toto_1.intValue() + ")", toto_1.intValue(), 1);
+        //Check tata
+        props = tota.getPropsTata();
+        Integer tata = (Integer) props.get("tata");
+        assertEquals("Assert tata - 3", tata.intValue(), 1);
+
+        getContext().ungetService(ref);
+        tota = null;
+
+        // Start a second import
+        totoProv2.start();
+        assertTrue("Assert under state - 4", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 4", getContext().getServiceReference(Tota.class.getName()));
+        ref = getContext().getServiceReference(Tota.class.getName());
+        tota = (Tota) getContext().getService(ref);
+        invokeAll(tota);
+        // Check toto
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        toto_1 = (Integer) props.get("toto1");
+        assertEquals("Assert toto - 4 (" + toto.intValue() + ")", toto.intValue(), 2);
+        assertEquals("Assert toto_2 - 4 (" + toto_2.intValue() + ")", toto_2.intValue(), 2);
+        assertEquals("Assert toto_3 - 4", toto_3.intValue(), 2);
+        assertEquals("Assert toto_4 - 4", toto_4.intValue(), 0);
+        assertEquals("Assert toto1 - 4", toto_1.intValue(), 3);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        assertEquals("Assert tata - 4", tata.intValue(), 2);
+
+        getContext().ungetService(ref);
+        tota = null;
+
+        tataFactory.stop();
+        assertTrue("Assert under state - 5", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 5", getContext().getServiceReference(Tota.class.getName()));
+
+        totoProv2.stop();
+        tataFactory.start();
+        assertTrue("Assert under state - 6", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 6", getContext().getServiceReference(Tota.class.getName()));
+        ref = getContext().getServiceReference(Tota.class.getName());
+        tota = (Tota) getContext().getService(ref);
+        invokeAll(tota);
+        // Check toto
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        toto_1 = (Integer) props.get("toto1");
+        assertEquals("Assert toto - 6 (" + toto.intValue() + ")", toto.intValue(), 3);
+        assertEquals("Assert toto_2 - 6 (" + toto_2.intValue() + ")", toto_2.intValue(), 3);
+        assertEquals("Assert toto_3 - 6", toto_3.intValue(), 3);
+        assertEquals("Assert toto_4 - 6", toto_4.intValue(), 0);
+        assertEquals("Assert toto1 - 6", toto_1.intValue(), 4);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        assertEquals("Assert tata - 6", tata.intValue(), 1);
+
+        getContext().ungetService(ref);
+        tota = null;
+
+        // Is arch exposed
+        assertNotNull("Test arch", ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "ff"));
+
+        totoProv.stop();
+
+        assertTrue("Assert under state - 7", under.getState() == ComponentInstance.INVALID);
+        assertNotNull("Test arch-2", ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "ff"));
+        assertNull("Assert no tota service - 7", getContext().getServiceReference(Tota.class.getName()));
+
+        under.dispose();
+        under = null;
+    }
+
+    private void invoke(Tota tota) {
+        tota.tata();
+
+        assertEquals("Assert invoke tataint", tota.tataInt(2), 2);
+        assertEquals("Assert invoke tataLong", tota.tataLong(2), 2);
+        assertEquals("Assert invoke tataDouble", tota.tataDouble(2), 2, 0);
+        assertEquals("Assert invoke tataChar", tota.tataChar('a'), 'a');
+        assertTrue("Assert invoke tataBoolean", tota.tataBoolean(true));
+        assertEquals("Assert invoke tataByte", tota.tataByte((byte) 2), 2);
+        assertEquals("Assert invoke tataShort", tota.tataShort((short) 5), 5);
+        assertEquals("Assert invoke tataFloat", tota.tataFloat(5), 5, 0);
+
+    }
+
+    private void invokeToto(Tota tota) {
+        tota.toto();
+        assertEquals("Assert toto", tota.toto("foo"), "foo");
+        tota.toto(1, 2);
+        tota.toto1("foo2");
+    }
+
+    private void invokeAll(Tota tota) {
+        invoke(tota);
+        invokeToto(tota);
+    }
+
+
+}



Mime
View raw message