Update test structure to reflect changes made on the ipojo sub-project structure

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@679336 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/handler/temporal/pom.xml b/ipojo/tests/handler/temporal/pom.xml
new file mode 100644
index 0000000..5f110f7
--- /dev/null
+++ b/ipojo/tests/handler/temporal/pom.xml
@@ -0,0 +1,93 @@
+<!--

+	Licensed to the Apache Software Foundation (ASF) under one

+	or more contributor license agreements.  See the NOTICE file

+	distributed with this work for additional information

+	regarding copyright ownership.  The ASF licenses this file

+	to you under the Apache License, Version 2.0 (the

+	"License"); you may not use this file except in compliance

+	with the License.  You may obtain a copy of the License at

+	

+	http://www.apache.org/licenses/LICENSE-2.0

+	

+	Unless required by applicable law or agreed to in writing,

+	software distributed under the License is distributed on an

+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+	KIND, either express or implied.  See the License for the

+	specific language governing permissions and limitations

+	under the License.

+-->

+<project>

+	<modelVersion>4.0.0</modelVersion>

+	<packaging>bundle</packaging>

+	<name>iPOJO Temporal Dependency Test Suite</name>

+	<artifactId>tests.temporal</artifactId>

+	<groupId>ipojo.tests</groupId>

+	<version>0.9.0-SNAPSHOT</version>

+	<dependencies>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.apache.felix.ipojo</artifactId>

+			<version>0.9.0-SNAPSHOT</version>

+		</dependency>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.apache.felix.ipojo.metadata</artifactId>

+			<version>0.9.0-SNAPSHOT</version>

+		</dependency>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.osgi.core</artifactId>

+			<version>1.0.0</version>

+		</dependency>

+		<dependency>

+			<groupId>junit</groupId>

+			<artifactId>junit</artifactId>

+			<version>3.8.1</version>

+		</dependency>

+		<dependency>

+			<groupId>ipojo.examples</groupId>

+			<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>

+			<version>0.9.0-SNAPSHOT</version>

+		</dependency>

+

+

+	</dependencies>

+	<build>

+		<plugins>

+			<plugin>

+				<groupId>org.apache.felix</groupId>

+				<artifactId>maven-bundle-plugin</artifactId>

+				<version>1.4.0</version>

+				<extensions>true</extensions>

+				<configuration>

+					<instructions>

+						<Export-Package>

+							org.apache.felix.ipojo.test.scenarios.temporal.service

+						</Export-Package>

+						<Bundle-SymbolicName>

+							${pom.artifactId}

+						</Bundle-SymbolicName>

+						<Private-Package>

+							org.apache.felix.ipojo.test*

+						</Private-Package>

+						<Test-Suite>

+				org.apache.felix.ipojo.test.scenarios.temporal.TemporalTestSuite

+						</Test-Suite>

+					</instructions>

+				</configuration>

+			</plugin>

+			<plugin>

+				<groupId>org.apache.felix</groupId>

+				<artifactId>maven-ipojo-plugin</artifactId>

+				<version>0.9.0-SNAPSHOT</version>

+				<executions>

+					<execution>

+						<goals>

+							<goal>ipojo-bundle</goal>

+						</goals>

+					</execution>

+				</executions>

+			</plugin>

+		</plugins>

+	</build>

+</project>

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java
new file mode 100644
index 0000000..b654826
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java
@@ -0,0 +1,47 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.component;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;

+

+public class CheckServiceProvider implements CheckService {

+    

+    /**

+     * Temporal dependency.

+     */

+    private FooService fs;

+

+    public boolean check() {

+        if (fs != null) {

+            return fs.foo();

+        }

+        return false;

+    }

+

+    public Properties getProps() {

+        if (fs != null) {

+            return fs.fooProps();

+        }

+        return null;

+    }

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProvider.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProvider.java
new file mode 100644
index 0000000..7bd5540
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProvider.java
@@ -0,0 +1,55 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.component;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;

+

+public class FooProvider implements FooService {

+

+    public boolean foo() {

+       return true;

+    }

+

+    public Properties fooProps() {

+        return null;

+    }

+

+    public boolean getBoolean() {

+        return false;

+    }

+

+    public double getDouble() {

+        return 0;

+    }

+

+    public int getInt() {

+        return 0;

+    }

+

+    public long getLong() {

+        return 0;

+    }

+

+    public Boolean getObject() {

+        return null;

+    }

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckServiceProvider.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckServiceProvider.java
new file mode 100644
index 0000000..fb96538
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckServiceProvider.java
@@ -0,0 +1,48 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.component;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;

+

+public class MultipleCheckServiceProvider implements CheckService {

+    

+    /**

+     * Temporal dependency.

+     */

+    private FooService[] fs;

+

+    public boolean check() {

+        boolean result = true;

+        //Use a local variable to avoid to wait at each access.

+        FooService[] array = fs;

+        for (int i = 0; array != null && i < array.length; i++) {

+            result = result && array[i].foo();

+            System.out.println("Result : " + result);

+        }

+        return result;

+    }

+

+    public Properties getProps() {

+        return fs[0].fooProps();

+    }

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/NullableFooProvider.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/NullableFooProvider.java
new file mode 100644
index 0000000..821c8c8
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/NullableFooProvider.java
@@ -0,0 +1,55 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.component;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;

+

+public class NullableFooProvider implements FooService {

+

+    public boolean foo() {

+       return false;

+    }

+

+    public Properties fooProps() {

+        return null;

+    }

+

+    public boolean getBoolean() {

+        return false;

+    }

+

+    public double getDouble() {

+        return -1;

+    }

+

+    public int getInt() {

+        return -1;

+    }

+

+    public long getLong() {

+        return -1;

+    }

+

+    public Boolean getObject() {

+        return null;

+    }

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DefaultImplementationTest.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DefaultImplementationTest.java
new file mode 100644
index 0000000..619becb
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DefaultImplementationTest.java
@@ -0,0 +1,229 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.temporal;

+

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

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class DefaultImplementationTest extends OSGiTestCase {

+    

+   public void testDefaultImplementation() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-DICheckServiceProvider", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider, 200);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+      

+       assertTrue("Assert delay", (end - begin) >= 200);

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 3", cs.check());

+       

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+   }

+   

+   public void testDefaultImplementationTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-DICheckServiceProvider", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       boolean res = false;

+       try {

+           res = cs.check();

+       } catch(RuntimeException e) {

+           fail("A nullable was expected ...");

+       }   

+       assertFalse("Check nullable", res);

+

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+       return;

+   }

+   

+   public void testDelayTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-DICheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider, 200);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+       

+       assertTrue("Assert delay", (end - begin) >= 200);

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 3", cs.check());

+       

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+   }

+   

+   public void testDefaultImplementationMultipleTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-DIMultipleCheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       DelayedProvider dp = new DelayedProvider(provider, 400);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       boolean res = false;

+       try {

+           res = cs.check();

+       } catch(RuntimeException e) {

+           fail("A nullable was expected ...");

+       }   

+       assertFalse("Check nullable", res);

+       

+       dp.stop();

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+       return;

+   }

+   

+   public void testDelayOnMultipleDependency() {

+       String prov = "provider";

+       ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String prov2 = "provider2";

+       ComponentInstance provider2 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov2);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullableMultipleCheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the providers.

+       provider1.stop();

+       provider2.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider1, 250);

+       DelayedProvider dp2 = new DelayedProvider(provider2, 100);

+       dp.start();

+       dp2.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+       assertTrue("Assert delay", (end - begin) >= 100  && (end - begin) <= 250);

+       dp.stop();

+       dp2.stop();

+       

+       provider1.stop();

+       provider2.stop();

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       

+       assertFalse("Check invocation - 3", cs.check()); // Will return false as the contained DI will return false to the foo method.

+

+       provider1.dispose();

+       provider2.dispose();

+       under.stop();

+       under.dispose();

+   }

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DelayTest.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DelayTest.java
new file mode 100644
index 0000000..1db95af
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DelayTest.java
@@ -0,0 +1,228 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.temporal;

+

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

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class DelayTest extends OSGiTestCase {

+    

+   public void testDelay() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-CheckServiceProvider", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider, 200);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+       

+       assertTrue("Assert delay", (end - begin) >= 200);

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 3", cs.check());

+       

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+   }

+   

+   public void testTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-CheckServiceProvider", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       DelayedProvider dp = new DelayedProvider(provider, 4000);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       try {

+           cs.check();

+       } catch(RuntimeException e) {

+           // OK

+           dp.stop();

+           provider.stop();

+           provider.dispose();

+           under.stop();

+           under.dispose();

+           return;

+       }   

+       

+       fail("Timeout expected");

+   }

+   

+   public void testDelayTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-CheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider, 200);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+       

+       assertTrue("Assert delay", (end - begin) >= 200);

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 3", cs.check());

+       

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+   }

+   

+   public void testSetTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-CheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       DelayedProvider dp = new DelayedProvider(provider, 400);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       try {

+           cs.check();

+       } catch(RuntimeException e) {

+           // OK

+           dp.stop();

+           provider.stop();

+           provider.dispose();

+           under.stop();

+           under.dispose();

+           return;

+       }   

+       

+       fail("Timeout expected");

+   }

+   

+   public void testDelayOnMultipleDependency() {

+       String prov = "provider";

+       ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String prov2 = "provider2";

+       ComponentInstance provider2 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov2);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-MultipleCheckServiceProvider", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the providers.

+       provider1.stop();

+       provider2.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider1, 250);

+       DelayedProvider dp2 = new DelayedProvider(provider2, 100);

+       dp.start();

+       dp2.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+       assertTrue("Assert delay", (end - begin) >= 100  && (end - begin) <= 250);

+       dp.stop();

+       dp2.stop();

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 3", cs.check());

+       

+       provider1.stop();

+       provider2.stop();

+       provider1.dispose();

+       provider2.dispose();

+       under.stop();

+       under.dispose();

+   }

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DelayedProvider.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DelayedProvider.java
new file mode 100644
index 0000000..097e15b
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DelayedProvider.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.test.scenarios.temporal;

+

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

+

+public class DelayedProvider implements Runnable {

+    

+    ComponentInstance instance;

+    long delay = 400;

+    Thread thread;

+    

+    public DelayedProvider(ComponentInstance ci) {

+        instance =ci;

+    }

+    

+    public DelayedProvider(ComponentInstance ci, long time) {

+        instance =ci;

+        delay = time;

+    }    

+    

+    public void start() {

+        thread = new Thread(this);

+        thread.start();

+    }

+    

+    public void stop() {

+        if (thread != null) {

+            thread.interrupt();

+        }

+    }

+

+    public void run() {

+            System.out.println("Start sleeping for " + delay);

+            try {

+                Thread.sleep(delay);

+            } catch (InterruptedException e) {

+                System.out.println("Interrupted ...");

+                return;

+            }

+            System.out.println("Wakeup");

+            thread = null;

+            instance.start();

+            System.out.println(instance.getInstanceName() + " started");

+    }

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/EmptyArrayTest.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/EmptyArrayTest.java
new file mode 100644
index 0000000..cac0102
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/EmptyArrayTest.java
@@ -0,0 +1,116 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.temporal;

+

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

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class EmptyArrayTest extends OSGiTestCase {

+   

+   public void testEmptyArrayTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-EmptyMultipleCheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       DelayedProvider dp = new DelayedProvider(provider, 400);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       boolean res = false;

+       try {

+           res = cs.check();

+       } catch(RuntimeException e) {

+           fail("An empty array was expected ...");

+       }   

+       assertTrue("Check empty array", res);

+       

+       dp.stop();

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+       return;

+   }

+   

+   public void testDelayOnMultipleDependency() {

+       String prov = "provider";

+       ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String prov2 = "provider2";

+       ComponentInstance provider2 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov2);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-EmptyMultipleCheckServiceProvider", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the providers.

+       provider1.stop();

+       provider2.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider1, 250);

+       DelayedProvider dp2 = new DelayedProvider(provider2, 100);

+       dp.start();

+       dp2.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+       assertTrue("Assert delay", (end - begin) >= 100  && (end - begin) <= 250);

+       dp.stop();

+       dp2.stop();

+       

+       provider1.stop();

+       provider2.stop();

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       

+       assertTrue("Check invocation - 3", cs.check()); 

+       

+       provider1.dispose();

+       provider2.dispose();

+       under.stop();

+       under.dispose();

+   }

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NoDelayTest.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NoDelayTest.java
new file mode 100644
index 0000000..974af3f
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NoDelayTest.java
@@ -0,0 +1,74 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.temporal;

+

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

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class NoDelayTest extends OSGiTestCase {

+    

+   public void testNoDelay() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-CheckServiceProvider", un);

+       assertNotNull("Check creation", under);

+       assertNotNull("Check provider creation", prov);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+   }

+   

+   public void testMultipleNoDelay() {

+       String prov1 = "provider-1";

+       ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov1);

+       String un = "under-2";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-MultipleCheckServiceProvider", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov1);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       provider1.stop();

+       provider1.dispose();

+       under.stop();

+       under.dispose();

+   }

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NullTest.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NullTest.java
new file mode 100644
index 0000000..25e9635
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NullTest.java
@@ -0,0 +1,229 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.temporal;

+

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

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class NullTest extends OSGiTestCase {

+    

+   public void testNullable() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullCheckServiceProvider", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider, 200);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+       

+       assertTrue("Assert delay", (end - begin) >= 200);

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 3", cs.check());

+       

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+   }

+   

+   public void testNullableTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullCheckServiceProvider", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       boolean res = false;

+       try {

+           res = cs.check();

+       } catch(RuntimeException e) {

+           fail("A null was expected ...");

+       }   

+       assertFalse("Check null", res); // Return false when the foo service is null.

+

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+       return;

+   }

+   

+   public void testDelayTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullCheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider, 200);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+       

+       assertTrue("Assert delay", (end - begin) >= 200);

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 3", cs.check());

+       

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+   }

+   

+   public void testNullableMultipleTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullMultipleCheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       DelayedProvider dp = new DelayedProvider(provider, 400);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       boolean res = false;

+       try {

+           res = cs.check();

+       } catch(RuntimeException e) {

+           fail("A null was expected ...");

+       }   

+       assertTrue("Check nullable", res);

+       

+       dp.stop();

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+       return;

+   }

+   

+   public void testDelayOnMultipleDependency() {

+       String prov = "provider";

+       ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String prov2 = "provider2";

+       ComponentInstance provider2 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov2);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullableMultipleCheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the providers.

+       provider1.stop();

+       provider2.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider1, 250);

+       DelayedProvider dp2 = new DelayedProvider(provider2, 100);

+       dp.start();

+       dp2.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+       assertTrue("Assert delay", (end - begin) >= 100  && (end - begin) <= 250);

+       dp.stop();

+       dp2.stop();

+       

+       provider1.stop();

+       provider2.stop();

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       

+       assertFalse("Check invocation - 3", cs.check()); // Will return false as the contained nullable will return false to the foo method.

+

+       provider1.dispose();

+       provider2.dispose();

+       under.stop();

+       under.dispose();

+   }

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NullableTest.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NullableTest.java
new file mode 100644
index 0000000..a0b3eeb
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NullableTest.java
@@ -0,0 +1,229 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.temporal;

+

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

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class NullableTest extends OSGiTestCase {

+    

+   public void testNullable() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullableCheckServiceProvider", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider, 200);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+      

+       assertTrue("Assert delay", (end - begin) >= 200);

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 3", cs.check());

+       

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+   }

+   

+   public void testNullableTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullableCheckServiceProvider", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       boolean res = false;

+       try {

+           res = cs.check();

+       } catch(RuntimeException e) {

+           fail("A nullable was expected ...");

+       }   

+       assertFalse("Check nullable", res);

+       

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+       return;

+   }

+   

+   public void testDelayTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullableCheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider, 200);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+       

+       assertTrue("Assert delay", (end - begin) >= 200);

+       

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 3", cs.check());

+       

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+   }

+   

+   public void testNullableMultipleTimeout() {

+       String prov = "provider";

+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullableMultipleCheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the provider.

+       provider.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       DelayedProvider dp = new DelayedProvider(provider, 400);

+       dp.start();

+       cs = (CheckService) context.getService(ref_cs);

+       boolean res = false;

+       try {

+           res = cs.check();

+       } catch(RuntimeException e) {

+           fail("A nullable was expected ...");

+       }   

+       assertFalse("Check nullable", res);

+       

+       dp.stop();

+       provider.stop();

+       provider.dispose();

+       under.stop();

+       under.dispose();

+       return;

+   }

+   

+   public void testDelayOnMultipleDependency() {

+       String prov = "provider";

+       ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);

+       String prov2 = "provider2";

+       ComponentInstance provider2 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov2);

+       String un = "under-1";

+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullableMultipleCheckServiceProviderTimeout", un);

+       

+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);

+       assertNotNull("Check foo availability", ref_fs);

+       

+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability", ref_cs);

+       

+       CheckService cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation", cs.check());

+       

+       // Stop the providers.

+       provider1.stop();

+       provider2.stop();

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 2", ref_cs);

+       long begin = System.currentTimeMillis();

+       DelayedProvider dp = new DelayedProvider(provider1, 250);

+       DelayedProvider dp2 = new DelayedProvider(provider2, 100);

+       dp.start();

+       dp2.start();

+       cs = (CheckService) context.getService(ref_cs);

+       assertTrue("Check invocation - 2", cs.check());

+       long end = System.currentTimeMillis();

+       assertTrue("Assert delay", (end - begin) >= 100  && (end - begin) <= 250);

+       dp.stop();

+       dp2.stop();

+       

+       provider1.stop();

+       provider2.stop();

+      

+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);

+       assertNotNull("Check cs availability - 3", ref_cs);

+       cs = (CheckService) context.getService(ref_cs);

+       

+       assertFalse("Check invocation - 3", cs.check()); // Will return false as the contained nullable will return false to the foo method.

+

+       provider1.dispose();

+       provider2.dispose();

+       under.stop();

+       under.dispose();

+   }

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/TemporalTestSuite.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/TemporalTestSuite.java
new file mode 100644
index 0000000..7f5d1cd
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/TemporalTestSuite.java
@@ -0,0 +1,41 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.temporal;

+

+import junit.framework.Test;

+import junit.framework.TestSuite;

+

+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;

+import org.osgi.framework.BundleContext;

+

+public class TemporalTestSuite extends TestSuite {

+

+    public static Test suite(BundleContext bc) {

+        OSGiTestSuite ots = new OSGiTestSuite("Temporal Dependency Test Suite", bc);

+        ots.addTestSuite(NoDelayTest.class);

+        ots.addTestSuite(DelayTest.class);

+        ots.addTestSuite(NullableTest.class); 

+        ots.addTestSuite(DefaultImplementationTest.class);

+        ots.addTestSuite(NullTest.class);

+        ots.addTestSuite(EmptyArrayTest.class);

+        return ots;

+    }

+

+}

+

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/BarService.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/BarService.java
new file mode 100644
index 0000000..9e058c9
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/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.test.scenarios.temporal.service;

+

+import java.util.Properties;

+

+public interface BarService {

+	

+	public boolean bar();

+	

+	public Properties getProps();

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/CheckService.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/CheckService.java
new file mode 100644
index 0000000..f8ec6ca
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/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.test.scenarios.temporal.service;

+

+import java.util.Properties;

+

+public interface CheckService {

+    

+    public static final String foo = "foo";

+	

+	public boolean check();

+	

+	public Properties getProps();

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ChildInterface.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ChildInterface.java
new file mode 100644
index 0000000..9aec761
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ChildInterface.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.test.scenarios.temporal.service;

+

+public interface ChildInterface extends ParentInterface1, ParentInterface2 {

+    

+    public void processChild();

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/FooService.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/FooService.java
new file mode 100644
index 0000000..52537a1
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/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.test.scenarios.temporal.service;

+

+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/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ParentInterface1.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ParentInterface1.java
new file mode 100644
index 0000000..373ba7e
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ParentInterface1.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.test.scenarios.temporal.service;

+

+public interface ParentInterface1 extends ParentParentInterface {

+    

+    public void processParent1();

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ParentInterface2.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ParentInterface2.java
new file mode 100644
index 0000000..5ec4d0a
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ParentInterface2.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.test.scenarios.temporal.service;

+

+public interface ParentInterface2 {

+    

+    public void processParent2();

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ParentParentInterface.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ParentParentInterface.java
new file mode 100644
index 0000000..c4bcf4d
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/service/ParentParentInterface.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.test.scenarios.temporal.service;

+

+public interface ParentParentInterface {

+    

+    public void processParentParent();

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
new file mode 100644
index 0000000..35d034c
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
@@ -0,0 +1,353 @@
+/* 

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.test.scenarios.util;

+

+import java.util.Dictionary;

+import java.util.Properties;

+

+import junit.framework.Assert;

+

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

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

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

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

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

+import org.apache.felix.ipojo.metadata.Element;

+import org.apache.felix.ipojo.parser.ManifestMetadataParser;

+import org.apache.felix.ipojo.parser.ParseException;

+import org.osgi.framework.BundleContext;

+import org.osgi.framework.InvalidSyntaxException;

+import org.osgi.framework.ServiceReference;

+import org.osgi.service.cm.ManagedServiceFactory;

+

+public class Utils {

+    

+    public static Element getMetatadata(BundleContext bc, String component) {

+        String elem = (String) bc.getBundle().getHeaders().get("iPOJO-Components");

+        Assert.assertNotNull("iPOJO Components exists", elem);

+        try {

+            Element element = ManifestMetadataParser.parseHeaderMetadata(elem);

+            Element[] childs = element.getElements("component");

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

+                String name = childs[i].getAttribute("name");

+                String clazz = childs[i].getAttribute("classname");

+                if (name != null && name.equalsIgnoreCase(component)) {

+                    return childs[i];

+                }

+                if (clazz.equalsIgnoreCase(component)) {

+                    return childs[i];

+                }

+            }

+            Assert.fail("Component " + component + " not found in " + bc.getBundle().getSymbolicName());

+        } catch (ParseException e) {

+            Assert.fail("Cannot parse the components from " + bc.getBundle().getSymbolicName() + ": " + e.getMessage());

+        }

+        

+        return null;

+        

+    }

+

+    public static Factory getFactoryByName(BundleContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");

+            if (refs == null) {

+                System.err.println("Cannot get the factory " + factoryName);

+                return null;

+            }

+            return ((Factory) bc.getService(refs[0]));

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static HandlerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");

+            if (refs == null) {

+                System.err.println("Cannot get the factory " + factoryName);

+                return null;

+            }

+            return (HandlerFactory) bc.getService(refs[0]);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) {

+            System.err.println("Factory " + factoryName + " not found");

+            return null;

+        }

+

+        // if(fact.isAcceptable(configuration)) {

+        try {

+            return fact.createComponentInstance(configuration);

+        } catch (Exception e) {

+            e.printStackTrace();

+            Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+        // }

+        // else {

+        // System.err.println("Configuration not accepted by : " + factoryName);

+        // return null;

+        // }

+    }

+

+    public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) {

+            System.err.println("Factory " + factoryName + " not found");

+            return null;

+        }

+

+        try {

+            Properties props = new Properties();

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

+            return fact.createComponentInstance(props);

+        } catch (Exception e) {

+            System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());

+            e.printStackTrace();

+            return null;

+        }

+    }

+

+    public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return new ServiceReference[0];

+        } else {

+            return refs;

+        }

+    }

+

+    public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {

+        ServiceReference[] refs = null;

+        String filter = null;

+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {

+            filter = "(" + "factory.name" + "=" + name + ")";

+        } else {

+            filter = "(" + "instance.name" + "=" + name + ")";

+        }

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+    

+    public static ServiceReference getServiceReferenceByPID(BundleContext bc, String itf, String pid) {

+        ServiceReference[] refs = null;

+        String filter = "(" + "service.pid" + "=" + pid + ")";

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else if (refs.length == 1) {

+            return refs[0];

+        } else {

+            Assert.fail("A service lookup by PID returned several providers (" + refs.length + ")" + " for " + itf + " with " + pid);

+            return null;

+        }

+    }

+

+    public static Object getServiceObject(BundleContext bc, String itf, String filter) {

+        ServiceReference ref = getServiceReference(bc, itf, filter);

+        if (ref != null) {

+            return bc.getService(ref);

+        } else {

+            return null;

+        }

+    }

+

+    public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);

+        if (refs != null) {

+            Object[] list = new Object[refs.length];

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

+                list[i] = bc.getService(refs[i]);

+            }

+            return list;

+        } else {

+            return new Object[0];

+        }

+    }

+

+//    public static ServiceContext getServiceContext(ComponentInstance ci) {

+//        if (ci instanceof CompositeManager) {

+//            return ((CompositeManager) ci).getServiceContext();

+//        } else {

+//            throw new RuntimeException("Cannot get the service context form an non composite instance");

+//        }

+//    }

+

+    public static Factory getFactoryByName(ServiceContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");

+            if (refs == null) { return null; }

+            return ((Factory) bc.getService(refs[0]));

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) { return null; }

+

+        if (fact.isAcceptable(configuration)) {

+            try {

+                return fact.createComponentInstance(configuration);

+            } catch (Exception e) {

+                System.err.println(e.getMessage());

+                e.printStackTrace();

+                return null;

+            }

+        } else {

+            System.err.println("Configuration not accepted by : " + factoryName);

+            return null;

+        }

+    }

+

+    public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return new ServiceReference[0];

+        } else {

+            return refs;

+        }

+    }

+

+    public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {

+        ServiceReference[] refs = null;

+        String filter = null;

+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {

+            filter = "(" + "factory.name" + "=" + name + ")";

+        } else {

+            filter = "(" + "instance.name" + "=" + name + ")";

+        }

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static Object getServiceObject(ServiceContext bc, String itf, String filter) {

+        ServiceReference ref = getServiceReference(bc, itf, filter);

+        if (ref != null) {

+            return bc.getService(ref);

+        } else {

+            return null;

+        }

+    }

+

+    public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);

+        if (refs != null) {

+            Object[] list = new Object[refs.length];

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

+                list[i] = bc.getService(refs[i]);

+            }

+            return list;

+        } else {

+            return new Object[0];

+        }

+    }

+    

+    public static boolean contains(String string, String[] array) {

+        for (int i = 0; array != null && i < array.length; i++) {

+            if (array[i] != null  && array[i].equals(string)) {

+                return true;

+            }

+        }

+        return false;

+    }

+    

+    public static boolean contains(int value, int[] array) {

+        for (int i = 0; array != null && i < array.length; i++) {

+            if (array[i] == value) {

+                return true;

+            }

+        }

+        return false;

+    }

+

+}

diff --git a/ipojo/tests/handler/temporal/src/main/resources/metadata.xml b/ipojo/tests/handler/temporal/src/main/resources/metadata.xml
new file mode 100644
index 0000000..2bbf047
--- /dev/null
+++ b/ipojo/tests/handler/temporal/src/main/resources/metadata.xml
@@ -0,0 +1,94 @@
+<ipojo xmlns:temp="org.apache.felix.ipojo.handler.temporal">

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider" name="TEMPORAL-CheckServiceProvider">

+		<temp:requires field="fs"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider" name="TEMPORAL-CheckServiceProviderTimeout">

+		<temp:requires field="fs" timeout="300"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckServiceProvider" name="TEMPORAL-MultipleCheckServiceProvider">

+		<temp:requires field="fs" aggregate="true"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.FooProvider" name="TEMPORAL-FooProvider">

+		<provides/>

+	</component>

+	

+	<!-- Dependencies using nullables -->

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckServiceProvider" name="TEMPORAL-NullableMultipleCheckServiceProvider">

+		<temp:requires field="fs" onTimeout="nullable"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider" name="TEMPORAL-NullableCheckServiceProvider">

+		<temp:requires field="fs" onTimeout="nullable"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider" name="TEMPORAL-NullableCheckServiceProviderTimeout">

+		<temp:requires field="fs" timeout="300" onTimeout="nullable"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckServiceProvider" name="TEMPORAL-NullableMultipleCheckServiceProviderTimeout">

+		<temp:requires field="fs" timeout="300" onTimeout="nullable"/>

+		<provides/>

+	</component>

+	

+	<!-- Dependencies using default implementation -->

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckServiceProvider" name="TEMPORAL-DIMultipleCheckServiceProvider">

+		<temp:requires field="fs" onTimeout="org.apache.felix.ipojo.test.scenarios.component.NullableFooProvider"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider" name="TEMPORAL-DICheckServiceProvider">

+		<temp:requires field="fs" onTimeout="org.apache.felix.ipojo.test.scenarios.component.NullableFooProvider"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider" name="TEMPORAL-DICheckServiceProviderTimeout">

+		<temp:requires field="fs" timeout="300" onTimeout="org.apache.felix.ipojo.test.scenarios.component.NullableFooProvider"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckServiceProvider" name="TEMPORAL-DIMultipleCheckServiceProviderTimeout">

+		<temp:requires field="fs" timeout="300" onTimeout="org.apache.felix.ipojo.test.scenarios.component.NullableFooProvider"/>

+		<provides/>

+	</component>

+	

+	<!-- Dependencies using null -->

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckServiceProvider" name="TEMPORAL-NullMultipleCheckServiceProvider">

+		<temp:requires field="fs" onTimeout="null"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider" name="TEMPORAL-NullCheckServiceProvider">

+		<temp:requires field="fs" onTimeout="null"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider" name="TEMPORAL-NullCheckServiceProviderTimeout">

+		<temp:requires field="fs" timeout="300" onTimeout="null"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckServiceProvider" name="TEMPORAL-NullMultipleCheckServiceProviderTimeout">

+		<temp:requires field="fs" timeout="300" onTimeout="null"/>

+		<provides/>

+	</component>

+	

+		<!-- Dependencies using empty arrays -->

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckServiceProvider" name="TEMPORAL-EmptyMultipleCheckServiceProvider">

+		<temp:requires field="fs" onTimeout="empty-array"/>

+		<provides/>

+	</component>

+	

+	<component classname="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckServiceProvider" name="TEMPORAL-EmptyMultipleCheckServiceProviderTimeout">

+		<temp:requires field="fs" timeout="300" onTimeout="empty-array"/>

+		<provides/>

+	</component>

+</ipojo>
\ No newline at end of file
diff --git a/ipojo/tests/handler/whiteboard/pom.xml b/ipojo/tests/handler/whiteboard/pom.xml
new file mode 100644
index 0000000..4199193
--- /dev/null
+++ b/ipojo/tests/handler/whiteboard/pom.xml
@@ -0,0 +1,61 @@
+<project>

+  <groupId>ipojo.test</groupId>

+  <version>0.9.0-SNAPSHOT</version>

+  <modelVersion>4.0.0</modelVersion>

+  <packaging>bundle</packaging>

+  <name>iPOJO White Board Pattern Handler Test Suite</name>

+  <artifactId>tests.whiteboard</artifactId>

+  <dependencies>

+    <dependency>

+      <groupId>org.apache.felix</groupId>

+      <artifactId>org.apache.felix.ipojo</artifactId>

+      <version>0.9.0-SNAPSHOT</version>

+    </dependency>

+	<dependency>

+		<groupId>org.apache.felix</groupId>

+		<artifactId>org.osgi.core</artifactId>

+		<version>1.0.0</version>

+	</dependency>

+    <dependency>

+      <groupId>junit</groupId>

+      <artifactId>junit</artifactId>

+      <version>3.8.1</version>

+    </dependency>

+	<dependency>

+		<groupId>ipojo.examples</groupId>

+		<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>

+		<version>0.9.0-SNAPSHOT</version>

+	</dependency>

+  </dependencies>

+  <build>

+    <plugins>

+      <plugin>

+        <groupId>org.apache.felix</groupId>

+        <artifactId>maven-bundle-plugin</artifactId>

+        <version>1.4.0</version>

+        <extensions>true</extensions>

+        <configuration>

+          <instructions>

+            <Private-Package>org.apache.felix.ipojo.test, org.apache.felix.ipojo.test.scenarios.util</Private-Package>

+            <Test-Suite>org.apache.felix.ipojo.test.WbpTests</Test-Suite>

+          </instructions>

+        </configuration>

+      </plugin>

+      <plugin>

+	      <groupId>org.apache.felix</groupId>

+	      <artifactId>maven-ipojo-plugin</artifactId>

+	      <version>0.9.0-SNAPSHOT</version>

+		  <executions>

+          	<execution>

+            	<goals>

+	              <goal>ipojo-bundle</goal>

+               </goals>

+                <configuration>

+   					<ignoreAnnotations>true</ignoreAnnotations>

+            	</configuration>

+          </execution>

+        </executions>

+      </plugin>

+    </plugins>

+  </build>

+</project>

diff --git a/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/FooProvider.java b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/FooProvider.java
new file mode 100644
index 0000000..5a996cd
--- /dev/null
+++ b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/FooProvider.java
@@ -0,0 +1,15 @@
+package org.apache.felix.ipojo.test;

+

+public class FooProvider implements FooService {

+    

+    public String foo;

+

+    public void foo() { 

+        if (foo.equals("foo")) {

+            foo = "bar";

+        } else {

+            foo = "foo";

+        }

+    }

+    

+}

diff --git a/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/FooService.java b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/FooService.java
new file mode 100644
index 0000000..0040354
--- /dev/null
+++ b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/FooService.java
@@ -0,0 +1,7 @@
+package org.apache.felix.ipojo.test;

+

+public interface FooService {

+    

+    public void foo();

+

+}

diff --git a/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/FooWhiteBoardPattern.java b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/FooWhiteBoardPattern.java
new file mode 100644
index 0000000..787748e
--- /dev/null
+++ b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/FooWhiteBoardPattern.java
@@ -0,0 +1,36 @@
+package org.apache.felix.ipojo.test;

+

+import java.util.ArrayList;

+import java.util.HashMap;

+import java.util.List;

+import java.util.Map;

+

+import org.osgi.framework.ServiceReference;

+

+public class FooWhiteBoardPattern implements Observable {

+    

+    List list = new ArrayList();

+    int modifications = 0;

+    

+    public void onArrival(ServiceReference ref) {

+        list.add(ref);

+    }

+    

+    public void onDeparture(ServiceReference ref) {

+        list.remove(ref);

+    }

+    

+    public void onModification(ServiceReference ref) {

+        modifications = modifications + 1;

+    }

+

+    public Map getObservations() {

+        Map map = new HashMap();

+        map.put("list", list);

+        map.put("modifications", new Integer(modifications));

+        return map;

+    }

+    

+    

+

+}

diff --git a/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/Observable.java b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/Observable.java
new file mode 100644
index 0000000..94d7787
--- /dev/null
+++ b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/Observable.java
@@ -0,0 +1,9 @@
+package org.apache.felix.ipojo.test;

+

+import java.util.Map;

+

+public interface Observable {

+    

+    public Map getObservations();

+

+}

diff --git a/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/WbpTests.java b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/WbpTests.java
new file mode 100644
index 0000000..d25c1e1
--- /dev/null
+++ b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/WbpTests.java
@@ -0,0 +1,196 @@
+package org.apache.felix.ipojo.test;

+

+import java.util.List;

+import java.util.Map;

+import java.util.Properties;

+

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

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

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

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

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

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class WbpTests extends OSGiTestCase {

+    

+    Factory provFactory;

+    Factory factory, factory2;

+

+    public void setUp() {

+        provFactory = Utils.getFactoryByName(context, "fooprovider");

+        factory = Utils.getFactoryByName(context, "under-providers");

+        factory2 = Utils.getFactoryByName(context, "under-properties");

+    }

+    

+    public void tearDown() {

+        

+    }

+    

+    public void testServiceProviders() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {

+        ComponentInstance ci = factory.createComponentInstance(new Properties());

+        

+        ServiceReference ref = Utils.getServiceReferenceByName(context, Observable.class.getName(), ci.getInstanceName());

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

+        Observable obs = (Observable) context.getService(ref);

+        

+        Map map = obs.getObservations();

+        assertEquals("Check empty list" , ((List) map.get("list")).size(), 0);

+        

+        Properties p1 = new Properties();

+        p1.put("foo", "foo");

+        ComponentInstance prov1 = provFactory.createComponentInstance(p1);

+        

+        map = obs.getObservations();

+        assertEquals("Check list #1" , ((List) map.get("list")).size(), 1);

+       

+        Properties p2 = new Properties();

+        p2.put("foo", "foo");

+        ComponentInstance prov2 = provFactory.createComponentInstance(p2);

+        

+        map = obs.getObservations();

+        assertEquals("Check list #2" , ((List) map.get("list")).size(), 2);

+        

+        prov1.stop();

+        

+        map = obs.getObservations();

+        assertEquals("(1) Check list #1" , ((List) map.get("list")).size(), 1);

+        

+        prov2.stop();

+        

+        map = obs.getObservations();

+        assertEquals("(2) Check list #0" , ((List) map.get("list")).size(), 0);

+        

+        prov2.start();

+        

+        map = obs.getObservations();

+        assertEquals("(3) Check list #1" , ((List) map.get("list")).size(), 1);

+        

+        prov1.start();

+        

+        map = obs.getObservations();

+        assertEquals("(4) Check list #2" , ((List) map.get("list")).size(), 2);

+        

+        prov1.dispose();

+        

+        map = obs.getObservations();

+        assertEquals("(5) Check list #1" , ((List) map.get("list")).size(), 1);

+        

+        prov2.dispose();

+        

+        map = obs.getObservations();

+        assertEquals("(6) Check list #0" , ((List) map.get("list")).size(), 0);

+        

+        context.ungetService(ref);

+        ci.dispose();

+    }

+    

+    public void testPropertiesProviders() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {

+        ComponentInstance ci = factory2.createComponentInstance(new Properties());

+        

+        ServiceReference ref = Utils.getServiceReferenceByName(context, Observable.class.getName(), ci.getInstanceName());

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

+        Observable obs = (Observable) context.getService(ref);

+        

+        Map map = obs.getObservations();

+        assertEquals("Check empty list" , ((List) map.get("list")).size(), 0);

+        

+        Properties p1 = new Properties();

+        p1.put("foo", "foo");

+        ComponentInstance prov1 = provFactory.createComponentInstance(p1);

+        ServiceReference ref1 = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov1.getInstanceName());

+        FooService fs1 = (FooService) context.getService(ref1);

+        

+        map = obs.getObservations();

+        assertEquals("Check list #1" , ((List) map.get("list")).size(), 1);

+       

+        Properties p2 = new Properties();

+        p2.put("foo", "foo");

+        ComponentInstance prov2 = provFactory.createComponentInstance(p2);

+        ServiceReference ref2 = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov2.getInstanceName());

+        FooService fs2 = (FooService) context.getService(ref2);

+        

+        map = obs.getObservations();

+        assertEquals("Check list #2" , ((List) map.get("list")).size(), 2);

+        

+        fs1.foo();

+        

+        map = obs.getObservations();

+        assertEquals("(1) Check list #1" , ((List) map.get("list")).size(), 1);

+        

+        fs2.foo();

+        

+        map = obs.getObservations();

+        assertEquals("(2) Check list #0" , ((List) map.get("list")).size(), 0);

+        

+        fs2.foo();

+        

+        map = obs.getObservations();

+        assertEquals("(3) Check list #1" , ((List) map.get("list")).size(), 1);

+        

+        fs1.foo();

+        

+        map = obs.getObservations();

+        assertEquals("(4) Check list #2" , ((List) map.get("list")).size(), 2);

+        

+        prov1.dispose();

+        

+        map = obs.getObservations();

+        assertEquals("(5) Check list #1" , ((List) map.get("list")).size(), 1);

+        

+        prov2.dispose();

+        

+        map = obs.getObservations();

+        assertEquals("(6) Check list #0" , ((List) map.get("list")).size(), 0);

+        

+        context.ungetService(ref1);

+        context.ungetService(ref2);

+        context.ungetService(ref);

+        ci.dispose();

+    }

+    

+    public void testModifications() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {

+        ComponentInstance ci = factory.createComponentInstance(new Properties());

+        

+        ServiceReference ref = Utils.getServiceReferenceByName(context, Observable.class.getName(), ci.getInstanceName());

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

+        Observable obs = (Observable) context.getService(ref);

+        

+        Map map = obs.getObservations();

+        assertEquals("Check empty list" , ((List) map.get("list")).size(), 0);

+        

+        Properties p1 = new Properties();

+        p1.put("foo", "foo");

+        ComponentInstance prov1 = provFactory.createComponentInstance(p1);

+        

+        map = obs.getObservations();

+        assertEquals("Check list #1" , ((List) map.get("list")).size(), 1);

+        assertEquals("Check modification #0" , ((Integer) map.get("modifications")).intValue(), 0);

+        

+        ServiceReference ref2 = Utils.getServiceReference(context, FooService.class.getName(), null);

+        assertNotNull("Check FooService availability", ref2);

+        

+        FooService fs = (FooService) context.getService(ref2);

+        fs.foo();

+        

+        map = obs.getObservations();

+        assertEquals("Check list #1" , ((List) map.get("list")).size(), 1);

+        assertEquals("Check modification #1 (" + map.get("modifications")+")" , ((Integer) map.get("modifications")).intValue(), 1);

+        

+        fs.foo();

+        

+        map = obs.getObservations();

+        assertEquals("Check list #1" , ((List) map.get("list")).size(), 1);

+        assertEquals("Check modification #2" , ((Integer) map.get("modifications")).intValue(), 2);

+        

+        prov1.dispose();

+        map = obs.getObservations();

+        assertEquals("Check list #0" , ((List) map.get("list")).size(), 0);

+        assertEquals("Check modification #2" , ((Integer) map.get("modifications")).intValue(), 2);

+        

+        context.ungetService(ref);

+        context.ungetService(ref2);

+        ci.dispose();

+    }

+}

diff --git a/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
new file mode 100644
index 0000000..e453bed
--- /dev/null
+++ b/ipojo/tests/handler/whiteboard/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
@@ -0,0 +1,261 @@
+package org.apache.felix.ipojo.test.scenarios.util;

+

+import java.util.Dictionary;

+import java.util.Properties;

+

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

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

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

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

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

+import org.osgi.framework.BundleContext;

+import org.osgi.framework.InvalidSyntaxException;

+import org.osgi.framework.ServiceReference;

+import org.osgi.service.cm.ManagedServiceFactory;

+

+public class Utils {

+

+    public static Factory getFactoryByName(BundleContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");

+            if (refs == null) {

+                System.err.println("Cannot get the factory " + factoryName);

+                return null;

+            }

+            return ((Factory) bc.getService(refs[0]));

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static HandlerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");

+            if (refs == null) {

+                System.err.println("Cannot get the factory " + factoryName);

+                return null;

+            }

+            return (HandlerFactory) bc.getService(refs[0]);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) {

+            System.err.println("Factory " + factoryName + " not found");

+            return null;

+        }

+

+        // if(fact.isAcceptable(configuration)) {

+        try {

+            return fact.createComponentInstance(configuration);

+        } catch (Exception e) {

+            System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());

+            e.printStackTrace();

+            return null;

+        }

+        // }

+        // else {

+        // System.err.println("Configuration not accepted by : " + factoryName);

+        // return null;

+        // }

+    }

+

+    public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) {

+            System.err.println("Factory " + factoryName + " not found");

+            return null;

+        }

+

+        try {

+            Properties props = new Properties();

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

+            return fact.createComponentInstance(props);

+        } catch (Exception e) {

+            System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());

+            e.printStackTrace();

+            return null;

+        }

+    }

+

+    public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return new ServiceReference[0];

+        } else {

+            return refs;

+        }

+    }

+

+    public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {

+        ServiceReference[] refs = null;

+        String filter = null;

+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {

+            filter = "(" + "factory.name" + "=" + name + ")";

+        } else {

+            filter = "(" + "instance.name" + "=" + name + ")";

+        }

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static Object getServiceObject(BundleContext bc, String itf, String filter) {

+        ServiceReference ref = getServiceReference(bc, itf, filter);

+        if (ref != null) {

+            return bc.getService(ref);

+        } else {

+            return null;

+        }

+    }

+

+    public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);

+        if (refs != null) {

+            Object[] list = new Object[refs.length];

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

+                list[i] = bc.getService(refs[i]);

+            }

+            return list;

+        } else {

+            return new Object[0];

+        }

+    }

+

+    public static Factory getFactoryByName(ServiceContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");

+            if (refs == null) { return null; }

+            return ((Factory) bc.getService(refs[0]));

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) { return null; }

+

+        if (fact.isAcceptable(configuration)) {

+            try {

+                return fact.createComponentInstance(configuration);

+            } catch (Exception e) {

+                System.err.println(e.getMessage());

+                e.printStackTrace();

+                return null;

+            }

+        } else {

+            System.err.println("Configuration not accepted by : " + factoryName);

+            return null;

+        }

+    }

+

+    public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return new ServiceReference[0];

+        } else {

+            return refs;

+        }

+    }

+

+    public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {

+        ServiceReference[] refs = null;

+        String filter = null;

+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {

+            filter = "(" + "factory.name" + "=" + name + ")";

+        } else {

+            filter = "(" + "instance.name" + "=" + name + ")";

+        }

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static Object getServiceObject(ServiceContext bc, String itf, String filter) {

+        ServiceReference ref = getServiceReference(bc, itf, filter);

+        if (ref != null) {

+            return bc.getService(ref);

+        } else {

+            return null;

+        }

+    }

+

+    public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);

+        if (refs != null) {

+            Object[] list = new Object[refs.length];

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

+                list[i] = bc.getService(refs[i]);

+            }

+            return list;

+        } else {

+            return new Object[0];

+        }

+    }

+

+}

diff --git a/ipojo/tests/handler/whiteboard/src/main/resources/metadata.xml b/ipojo/tests/handler/whiteboard/src/main/resources/metadata.xml
new file mode 100644
index 0000000..0f1da91
--- /dev/null
+++ b/ipojo/tests/handler/whiteboard/src/main/resources/metadata.xml
@@ -0,0 +1,17 @@
+<ipojo xmlns:wbp="org.apache.felix.ipojo.white-board-pattern">

+	<component className="org.apache.felix.ipojo.test.FooProvider" name="fooprovider">

+		<provides>

+			<property field="foo" value="foo"/>

+		</provides>

+	</component>

+	

+	<component className="org.apache.felix.ipojo.test.FooWhiteBoardPattern" name="under-providers">

+		<wbp:wbp filter="(objectclass=org.apache.felix.ipojo.test.FooService)" onArrival="onArrival" onDeparture="onDeparture" onModification="onModification"/>

+		<provides/>

+	</component>

+	

+	<component className="org.apache.felix.ipojo.test.FooWhiteBoardPattern" name="under-properties">

+		<wbp:wbp filter="(foo=foo)" onArrival="onArrival" onDeparture="onDeparture" onModification="onModification"/>

+		<provides/>

+	</component>

+</ipojo>