FELIX-3093 move dependency handler - optional test suite to its own project
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1450123 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/pom.xml b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/pom.xml
new file mode 100644
index 0000000..4f95acd
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/pom.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.runtime.core-it</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ <relativePath>../../../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>ipojo-core-service-dependency-optional-test</artifactId>
+
+ <name>${project.artifactId}</name>
+
+</project>
\ No newline at end of file
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/CheckProviderParentClass.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/CheckProviderParentClass.java
new file mode 100644
index 0000000..4f874f3
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/CheckProviderParentClass.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Dictionary;
+import java.util.Map;
+
+public abstract class CheckProviderParentClass {
+
+ int simpleU = 0;
+ int objectU = 0;
+ int refU = 0;
+ int bothU = 0;
+ int mapU = 0;
+ int dictU = 0;
+
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if(sr != null && o != null && o instanceof FooService) { bothU++; }
+ }
+
+ public void propertiesDictionaryUnbind(FooService o, Dictionary props) {
+ if (props != null && o != null && o instanceof FooService && props.size() > 0) { dictU++; }
+ }
+
+ public void propertiesMapUnbind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapU++; }
+ }
+
+
+ public void refUnbind(ServiceReference sr) {
+ if(sr != null) { refU++; }
+ }
+
+ public void objectUnbind(FooService o) {
+ if(o != null && o instanceof FooService) { objectU++; }
+ else {
+ System.err.println("Unbind null : " + o);
+ }
+ }
+
+ public void voidUnbind() {
+ simpleU++;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/CheckServiceProvider.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/CheckServiceProvider.java
new file mode 100644
index 0000000..dca6a1b
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/CheckServiceProvider.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Dictionary;
+import java.util.Map;
+import java.util.Properties;
+
+public class CheckServiceProvider extends CheckProviderParentClass implements CheckService {
+
+ FooService fs;
+
+ int simpleB = 0;
+ int objectB = 0;
+ int refB = 0;
+ int bothB = 0;
+ int mapB = 0;
+ int dictB = 0;
+
+ int modified = 0;
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ props.put("mapB", new Integer(mapB));
+ props.put("dictB", new Integer(dictB));
+ props.put("mapU", new Integer(mapU));
+ props.put("dictU", new Integer(dictU));
+ if (fs != null) {
+ // If nullable = false and proxy, a runtime exception may be launched here
+ // catch the exception and add this to props.
+ try {
+ props.put("exception", Boolean.FALSE); // Set exception to false for checking.
+ props.put("result", new Boolean(fs.foo()));
+ props.put("boolean", new Boolean(fs.getBoolean()));
+ props.put("int", new Integer(fs.getInt()));
+ props.put("long", new Long(fs.getLong()));
+ props.put("double", new Double(fs.getDouble()));
+ if(fs.getObject() != null) { props.put("object", fs.getObject()); }
+ } catch (RuntimeException e) {
+ props.put("exception", Boolean.TRUE);
+ }
+ }
+ props.put("static", CheckService.foo);
+ props.put("class", CheckService.class.getName());
+
+
+ // Add modified
+ props.put("modified", new Integer(modified));
+
+ return props;
+ }
+
+ private void voidBind() {
+ simpleB++;
+ }
+
+ public void voidModify() {
+ modified ++;
+ }
+
+ protected void objectBind(FooService o) {
+ if (o == null) {
+ System.err.println("Bind receive null !!! ");
+ return;
+ }
+ if(o != null && o instanceof FooService) { objectB++; }
+ }
+
+ protected void objectModify(FooService o) {
+ if (o == null) {
+ System.err.println("Bind receive null !!! [" + modified + "]");
+ return;
+ }
+ if(o != null && o instanceof FooService) { modified++; }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if(sr != null) { refB++; }
+ }
+
+ public void refModify(ServiceReference sr) {
+ if(sr != null) { modified++; }
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if(sr != null && o != null && o instanceof FooService) { bothB++; }
+ }
+
+ public void bothModify(FooService o, ServiceReference sr) {
+ if(sr != null && o != null && o instanceof FooService) { modified++; }
+ }
+
+ protected void propertiesDictionaryBind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictB++; }
+ fs = o;
+ }
+
+ protected void propertiesDictionaryModify(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { modified++; }
+ fs = o;
+ }
+
+ protected void propertiesMapBind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapB++; }
+ fs = o;
+ }
+
+ protected void propertiesMapModify(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { modified++; }
+ fs = o;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/CollectionCheckService.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/CollectionCheckService.java
new file mode 100644
index 0000000..f07f1f1
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/CollectionCheckService.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+import java.util.Properties;
+import java.util.*;
+
+public class CollectionCheckService implements CheckService {
+
+ Collection fs;
+
+ int simpleB = 0;
+
+ int objectB = 0;
+
+ int refB = 0;
+
+ int bothB = 0;
+
+ int simpleU = 0;
+
+ int objectU = 0;
+
+ int refU = 0;
+
+ int bothU = 0;
+
+ int mapB, mapU, dictB, dictU;
+
+ public boolean check() {
+ boolean r = fs.size() != 0;
+ Iterator it = fs.iterator();
+ while(it.hasNext()) {
+ r = r & ((FooService) it.next()).foo();
+ }
+ return r;
+ }
+
+ private boolean getBoolean() {
+ return check();
+ }
+
+ private int getInt() {
+ int r = 0;
+ Iterator it = fs.iterator();
+ while(it.hasNext()) {
+ r = r + ((FooService) it.next()).getInt();
+ }
+ return r;
+ }
+
+ private long getLong() {
+ long r = 0;
+ Iterator it = fs.iterator();
+ while(it.hasNext()) {
+ r = r + ((FooService) it.next()).getLong();
+ }
+ return r;
+ }
+
+ private double getDouble() {
+ double r = 0.0;
+ Iterator it = fs.iterator();
+ while(it.hasNext()) {
+ r = r + ((FooService) it.next()).getLong();
+ }
+ return r;
+ }
+
+ protected Object doNothing(Object o, String s) {
+ return null;
+ }
+
+ // private Object getObject() {
+ // boolean r = true;
+ // for(int i = 0; i < fs.length; i++) {
+ // r = r && ((Boolean) fs[i].getObject()).booleanValue();
+ // }
+ // return new Boolean(r);
+ // }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("result", new Boolean(check()));
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ props.put("mapB", new Integer(mapB));
+ props.put("mapU", new Integer(mapU));
+ props.put("dictB", new Integer(dictB));
+ props.put("dictU", new Integer(dictU));
+
+ props.put("boolean", new Boolean(getBoolean()));
+ props.put("int", new Integer(getInt()));
+ props.put("long", new Long(getLong()));
+ props.put("double", new Double(getDouble()));
+
+ return props;
+ }
+
+ public void voidBind() {
+ simpleB++;
+ }
+
+ public void voidUnbind() {
+ simpleU++;
+ }
+
+ public void objectBind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectB++;
+ }
+ }
+
+ public void objectUnbind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectU++;
+ }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if (sr != null) {
+ refB++;
+ }
+ }
+
+ public void refUnbind(ServiceReference sr) {
+ if (sr != null) {
+ refU++;
+ }
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothB++;
+ }
+ }
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothU++;
+ }
+ }
+
+ protected void propertiesMapBind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapB++; }
+ }
+ protected void propertiesMapUnbind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapU++; }
+ }
+
+ protected void propertiesDictionaryBind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictB++; }
+ }
+ protected void propertiesDictionaryUnbind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictU++; }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/DynCheckServiceProvider.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/DynCheckServiceProvider.java
new file mode 100644
index 0000000..eb415bf
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/DynCheckServiceProvider.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Dictionary;
+import java.util.Map;
+import java.util.Properties;
+
+public class DynCheckServiceProvider extends CheckProviderParentClass implements CheckService {
+
+ FooService fs;
+
+ int simpleB = 0;
+ int objectB = 0;
+ int refB = 0;
+ int bothB = 0;
+ int mapB, mapU, dictB, dictU;
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ props.put("mapB", new Integer(mapB));
+ props.put("mapU", new Integer(mapU));
+ props.put("dictB", new Integer(dictB));
+ props.put("dictU", new Integer(dictU));
+
+ if (fs != null) {
+ props.put("int", new Integer(fs.getInt()));
+ if(fs.getObject() != null) { props.put("object", fs.getObject()); }
+ }
+ props.put("static", CheckService.foo);
+ props.put("class", CheckService.class.getName());
+ return props;
+ }
+
+ private void voidBind() {
+ simpleB++;
+ }
+
+ protected void objectBind(FooService o) {
+ if (o == null) {
+ System.err.println("Bind receive null !!! ");
+ return;
+ }
+ if(o != null && o instanceof FooService) { objectB++; }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if(sr != null) { refB++; }
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if(sr != null && o != null && o instanceof FooService) { bothB++; }
+ }
+
+ protected void propertiesMapBind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapB++; }
+ }
+
+
+ protected void propertiesDictionaryBind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictB++; }
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooProviderType1.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooProviderType1.java
new file mode 100644
index 0000000..07342e1
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooProviderType1.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.BundleContext;
+
+import java.util.Properties;
+
+public class FooProviderType1 implements FooService {
+
+ private int m_bar;
+ private String m_foo;
+
+ private BundleContext m_context;
+
+ private static FooProviderType1 singleton;
+ private static int count = 0;
+
+ private static FooProviderType1 singleton(BundleContext bc) {
+ if (singleton == null) {
+ count++;
+ singleton = new FooProviderType1(bc);
+ }
+ return singleton;
+ }
+
+ public static FooProviderType1 several(BundleContext bc) {
+ count++;
+ return new FooProviderType1(bc);
+ }
+
+ public FooProviderType1(BundleContext bc) {
+ if (bc ==null) {
+ throw new RuntimeException("Injected bundle context null");
+ }
+ m_context = bc;
+ }
+
+ public boolean foo() {
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("bar", new Integer(m_bar));
+ if(m_foo != null) {
+ p.put("foo", m_foo);
+ }
+ p.put("context", m_context);
+
+ p.put("count", new Integer(count));
+ return p;
+ }
+
+ public void testException() throws Exception {
+ String a = "foobarbaz";
+ throw new Exception("foo"+a);
+ }
+
+ public void testTry() {
+ String a = "foo";
+ a.charAt(0);
+ }
+
+ public void testTry2(String s) {
+ String a = "foo";
+ a.charAt(0);
+ }
+
+ public boolean getBoolean() { return true; }
+
+ public double getDouble() { return 1.0; }
+
+ public int getInt() { return 1; }
+
+ public long getLong() { return 1; }
+
+ public Boolean getObject() { return new Boolean(true); }
+
+ /**
+ * Custom constructor.
+ * @param bar
+ * @param foo
+ * @param bc
+ */
+ public FooProviderType1(int bar, String foo, BundleContext bc) {
+ m_bar = bar;
+ m_foo = foo;
+ m_context = bc;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooProviderType2.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooProviderType2.java
new file mode 100644
index 0000000..0081c98
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooProviderType2.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.BundleContext;
+
+import java.util.Properties;
+
+public class FooProviderType2 implements FooService {
+
+ private int m_bar; // Service property.
+ private String m_foo;
+
+ private BundleContext m_context;
+
+ private static int count = 0;
+
+
+ public boolean foo() {
+ // Update
+ if (m_foo.equals("foo")) {
+ m_foo = "bar";
+ } else {
+ m_foo = "foo";
+ }
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("bar", new Integer(m_bar));
+ if(m_foo != null) {
+ p.put("foo", m_foo);
+ }
+ p.put("context", m_context);
+
+ p.put("count", new Integer(count));
+ return p;
+ }
+
+ public boolean getBoolean() { return true; }
+
+ public double getDouble() { return 1.0; }
+
+ public int getInt() { return 1; }
+
+ public long getLong() { return 1; }
+
+ public Boolean getObject() { return new Boolean(true); }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooServiceDefaultImpl.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooServiceDefaultImpl.java
new file mode 100644
index 0000000..e95dc53
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/FooServiceDefaultImpl.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.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+
+import java.util.Properties;
+
+public class FooServiceDefaultImpl implements FooService {
+
+ public boolean foo() {
+ return false;
+ }
+
+ public Properties fooProps() {
+ return null;
+ }
+
+ public boolean getBoolean() {
+ return false;
+ }
+
+ public double getDouble() {
+ return 5;
+ }
+
+ public int getInt() {
+ return 5;
+ }
+
+ public long getLong() {
+ return 5;
+ }
+
+ public Boolean getObject() {
+ return null;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/ListCheckService.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/ListCheckService.java
new file mode 100644
index 0000000..c08bad3
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/ListCheckService.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Dictionary;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+public class ListCheckService implements CheckService {
+
+ List fs;
+
+ int simpleB = 0;
+
+ int objectB = 0;
+
+ int refB = 0;
+
+ int bothB = 0;
+
+ int simpleU = 0;
+
+ int objectU = 0;
+
+ int refU = 0;
+
+ int bothU = 0;
+
+ int mapB, mapU, dictB, dictU;
+
+
+ public boolean check() {
+ boolean r = fs.size() != 0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r & ((FooService) fs.get(i)).foo();
+ }
+ return r;
+ }
+
+ private boolean getBoolean() {
+ return check();
+ }
+
+ private int getInt() {
+ int r = 0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getInt();
+ }
+ return r;
+ }
+
+ private long getLong() {
+ long r = 0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getLong();
+ }
+ return r;
+ }
+
+ private double getDouble() {
+ double r = 0.0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getDouble();
+ }
+ return r;
+ }
+
+ protected Object doNothing(Object o, String s) {
+ return null;
+ }
+
+ // private Object getObject() {
+ // boolean r = true;
+ // for(int i = 0; i < fs.length; i++) {
+ // r = r && ((Boolean) fs[i].getObject()).booleanValue();
+ // }
+ // return new Boolean(r);
+ // }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("result", new Boolean(check()));
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+
+ props.put("mapB", new Integer(mapB));
+ props.put("mapU", new Integer(mapU));
+ props.put("dictB", new Integer(dictB));
+ props.put("dictU", new Integer(dictU));
+
+ props.put("boolean", new Boolean(getBoolean()));
+ props.put("int", new Integer(getInt()));
+ props.put("long", new Long(getLong()));
+ props.put("double", new Double(getDouble()));
+
+ return props;
+ }
+
+ public void voidBind() {
+ simpleB++;
+ }
+
+ public void voidUnbind() {
+ simpleU++;
+ }
+
+ public void objectBind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectB++;
+ }
+ }
+
+ public void objectUnbind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectU++;
+ }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if (sr != null) {
+ refB++;
+ }
+ }
+
+ public void refUnbind(ServiceReference sr) {
+ if (sr != null) {
+ refU++;
+ }
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothB++;
+ }
+ }
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothU++;
+ }
+ }
+
+ protected void propertiesMapBind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapB++; }
+ }
+ protected void propertiesMapUnbind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapU++; }
+ }
+
+ protected void propertiesDictionaryBind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictB++; }
+ }
+ protected void propertiesDictionaryUnbind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictU++; }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MethodCheckServiceProvider.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MethodCheckServiceProvider.java
new file mode 100644
index 0000000..2a5bfce
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MethodCheckServiceProvider.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Dictionary;
+import java.util.Map;
+import java.util.Properties;
+
+public class MethodCheckServiceProvider implements CheckService {
+
+ FooService fs;
+
+ BundleContext context;
+
+ int simpleB = 0;
+ int objectB = 0;
+ int refB = 0;
+ int bothB = 0;
+ int mapB = 0;
+ int dictB = 0;
+ int simpleU = 0;
+ int objectU = 0;
+ int refU = 0;
+ int bothU = 0;
+ int mapU = 0;
+ int dictU = 0;
+
+
+ public MethodCheckServiceProvider(BundleContext bc) {
+ context = bc;
+ }
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ if(fs != null) {
+ props.put("result", new Boolean(fs.foo()));
+ props.put("boolean", new Boolean(fs.getBoolean()));
+ props.put("int", new Integer(fs.getInt()));
+ props.put("long", new Long(fs.getLong()));
+ props.put("double", new Double(fs.getDouble()));
+ } else {
+ props.put("result", new Boolean(false));
+ }
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("mapB", new Integer(mapB));
+ props.put("dictB", new Integer(dictB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ props.put("mapU", new Integer(mapU));
+ props.put("dictU", new Integer(dictU));
+
+ if(fs != null) {
+ if(fs.getObject() != null) { props.put("object", fs.getObject()); }
+ }
+
+ return props;
+ }
+
+ protected void objectBind(FooService o) {
+ if(o != null && o instanceof FooService) { objectB++; }
+ fs = o;
+ }
+ protected void objectUnbind(FooService o) {
+ if(o != null && o instanceof FooService) { objectU++; }
+ fs = null;
+ }
+
+ public void refBind(ServiceReference sr) {
+ if(sr != null) { refB++; }
+ fs = (FooService) context.getService(sr);
+ }
+ public void refUnbind(ServiceReference sr) {
+ if(sr != null) { refU++; }
+ context.ungetService(sr);
+ fs = null;
+ }
+
+ protected void bothBind(FooService o, ServiceReference ref) {
+ if(ref != null && o != null && o instanceof FooService) { bothB++; }
+ fs = o;
+ }
+ protected void bothUnbind(FooService o, ServiceReference ref) {
+ if(ref != null && o != null && o instanceof FooService) { bothU++; }
+ fs = null;
+ }
+
+ protected void propertiesMapBind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapB++; }
+ fs = o;
+ }
+ protected void propertiesMapUnbind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapU++; }
+ fs = null;
+ }
+
+ protected void propertiesDictionaryBind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictB++; }
+ fs = o;
+ }
+ protected void propertiesDictionaryUnbind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictU++; }
+ fs = null;
+ }
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MethodMultipleCheckService.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MethodMultipleCheckService.java
new file mode 100644
index 0000000..742f0fd
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MethodMultipleCheckService.java
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import java.util.Properties;
+
+import java.util.*;
+
+public class MethodMultipleCheckService implements CheckService {
+
+ List fs = new ArrayList();
+ BundleContext context;
+
+ int simpleB = 0;
+
+ int objectB = 0;
+
+ int refB = 0;
+
+ int bothB = 0;
+
+ int simpleU = 0;
+
+ int objectU = 0;
+
+ int refU = 0;
+
+ int bothU = 0;
+
+ int mapB = 0;
+ int mapU = 0;
+ int dictB = 0, dictU=0;
+
+ public MethodMultipleCheckService(BundleContext bc) {
+ context = bc;
+ }
+
+ public boolean check() {
+ boolean r = fs.size() != 0;
+ for(int i = 0; i < fs.size(); i++) {
+ r = r & ((FooService) fs.get(i)).foo();
+ }
+ return r;
+ }
+
+ private boolean getBoolean() {
+ return check();
+ }
+
+ private int getInt() {
+ int r = 0;
+ for(int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getInt();
+ }
+ return r;
+ }
+
+ private long getLong() {
+ long r = 0;
+ for(int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getLong();
+ }
+ return r;
+ }
+
+ private double getDouble() {
+ double r = 0.0;
+ for(int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getInt();
+ }
+ return r;
+ }
+
+ protected Object doNothing(Object o, String s) { return null; }
+
+// private Object getObject() {
+// boolean r = true;
+// for(int i = 0; i < fs.length; i++) {
+// r = r && ((Boolean) fs[i].getObject()).booleanValue();
+// }
+// return new Boolean(r);
+// }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("result", check());
+ props.put("voidB", simpleB);
+ props.put("objectB", objectB);
+ props.put("refB", refB);
+ props.put("bothB", bothB);
+ props.put("voidU", simpleU);
+ props.put("objectU", objectU);
+ props.put("refU", refU);
+ props.put("bothU", bothU);
+ props.put("mapU", mapU);
+ props.put("mapB", mapB);
+ props.put("dictU", dictU);
+ props.put("dictB", dictB);
+ props.put("boolean", getBoolean());
+ props.put("int", getInt());
+ props.put("long", getLong());
+ props.put("double", getDouble());
+
+ return props;
+ }
+
+ public void objectBind(FooService o) {
+ if(o != null && o instanceof FooService) { objectB++; }
+ fs.add(o);
+ }
+ public void objectUnbind(FooService o) {
+ if(o != null && o instanceof FooService) { objectU++; }
+ fs.remove(o);
+ }
+
+ public void refBind(ServiceReference sr) {
+ if(sr != null) { refB++; }
+ fs.add(context.getService(sr));
+ }
+ public void refUnbind(ServiceReference sr) {
+ if(sr != null) { refU++; }
+ fs.remove(context.getService(sr));
+ context.ungetService(sr);
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ fs.add(o);
+ bothB++;
+ }
+ }
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ fs.remove(o);
+ bothU++;
+ }
+ }
+
+ protected void propertiesMapBind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapB++; }
+ fs.add(o);
+ }
+ protected void propertiesMapUnbind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapU++; }
+ fs.remove(o);
+ }
+
+ protected void propertiesDictionaryBind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictB++; }
+ fs.add(o);
+ }
+ protected void propertiesDictionaryUnbind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictU++; }
+ fs.remove(o);
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MultipleCheckService.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MultipleCheckService.java
new file mode 100644
index 0000000..991f9ec
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MultipleCheckService.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Dictionary;
+import java.util.Map;
+import java.util.Properties;
+
+public class MultipleCheckService implements CheckService {
+
+ FooService fs[];
+
+ int simpleB = 0;
+
+ int objectB = 0;
+
+ int refB = 0;
+
+ int bothB = 0;
+
+ int simpleU = 0;
+
+ int objectU = 0;
+
+ int refU = 0;
+
+ int bothU = 0;
+
+ int mapB, mapU, dictB, dictU;
+
+
+ public boolean check() {
+ boolean r = fs.length != 0;
+ for (int i = 0; i < fs.length; i++) {
+ r = r & fs[i].foo();
+ }
+ return r;
+ }
+
+ private boolean getBoolean() {
+ return check();
+ }
+
+ private int getInt() {
+ int r = 0;
+ for (int i = 0; i < fs.length; i++) {
+ r = r + fs[i].getInt();
+ }
+ return r;
+ }
+
+ private long getLong() {
+ long r = 0;
+ for (int i = 0; i < fs.length; i++) {
+ r = r + fs[i].getLong();
+ }
+ return r;
+ }
+
+ private double getDouble() {
+ double r = 0.0;
+ for (int i = 0; i < fs.length; i++) {
+ r = r + fs[i].getInt();
+ }
+ return r;
+ }
+
+ protected Object doNothing(Object o, String s) {
+ return null;
+ }
+
+ // private Object getObject() {
+ // boolean r = true;
+ // for(int i = 0; i < fs.length; i++) {
+ // r = r && ((Boolean) fs[i].getObject()).booleanValue();
+ // }
+ // return new Boolean(r);
+ // }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("result", new Boolean(check()));
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ props.put("boolean", new Boolean(getBoolean()));
+ props.put("int", new Integer(getInt()));
+ props.put("long", new Long(getLong()));
+ props.put("double", new Double(getDouble()));
+
+ props.put("mapB", new Integer(mapB));
+ props.put("mapU", new Integer(mapU));
+ props.put("dictB", new Integer(dictB));
+ props.put("dictU", new Integer(dictU));
+
+ return props;
+ }
+
+ public void voidBind() {
+ simpleB++;
+ }
+
+ public void voidUnbind() {
+ simpleU++;
+ }
+
+ public void objectBind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectB++;
+ }
+ }
+
+ public void objectUnbind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectU++;
+ }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if (sr != null) {
+ refB++;
+ }
+ }
+
+ public void refUnbind(ServiceReference sr) {
+ if (sr != null) {
+ refU++;
+ }
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothB++;
+ }
+ }
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothU++;
+ }
+ }
+
+ protected void propertiesMapBind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapB++; }
+ }
+ protected void propertiesMapUnbind(FooService o, Map props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { mapU++; }
+ }
+
+ protected void propertiesDictionaryBind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictB++; }
+ }
+ protected void propertiesDictionaryUnbind(FooService o, Dictionary props) {
+ if(props != null && o != null && o instanceof FooService && props.size() > 0) { dictU++; }
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MultipleFilterCheckSubscriber.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MultipleFilterCheckSubscriber.java
new file mode 100644
index 0000000..0f425f5
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/MultipleFilterCheckSubscriber.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+
+import java.util.Properties;
+
+public class MultipleFilterCheckSubscriber implements CheckService {
+
+ private FooService[] m_foo;
+
+ private int binded;
+
+ public MultipleFilterCheckSubscriber(){
+ }
+
+ public boolean check() {
+ for (int i = 0; i < m_foo.length; i++) {
+ m_foo[i].foo();
+ }
+ return true;
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("Bind", new Integer(binded));
+ props.put("Size", new Integer(m_foo.length));
+ return props;
+ }
+
+ private void Bind() {
+ binded++;
+ }
+ private void Unbind() {
+ binded--;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/ParentClass.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/ParentClass.java
new file mode 100644
index 0000000..a46be0d
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/ParentClass.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+public class ParentClass {
+
+ public void parentStart() {
+
+ }
+
+ public void parentStop() {
+
+ }
+
+ protected String[] strings;
+
+ protected String string;
+
+ protected int upStrings;
+
+ protected int upString;
+
+ public void updateStrings(String[] bb) {
+ strings = bb;
+ upStrings++;
+ }
+
+ public void updateString(String bb) {
+ string = bb;
+ upString++;
+ }
+
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/RankedFooProviderType1.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/RankedFooProviderType1.java
new file mode 100644
index 0000000..04e9b8a
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/RankedFooProviderType1.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+
+import java.util.Properties;
+
+public class RankedFooProviderType1 implements FooService {
+ private int m_grade;
+
+
+ public boolean foo() {
+ m_grade = m_grade + 2;
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("grade", new Integer(m_grade));
+
+ return p;
+ }
+
+ public boolean getBoolean() { return true; }
+
+ public double getDouble() { return 1.0; }
+
+ public int getInt() {
+ return m_grade; }
+
+ public long getLong() { return 1; }
+
+ public Boolean getObject() { return new Boolean(true); }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/SetCheckService.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/SetCheckService.java
new file mode 100644
index 0000000..abee121
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/SetCheckService.java
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+public class SetCheckService implements CheckService {
+
+ Set fs;
+
+ int simpleB = 0;
+
+ int objectB = 0;
+
+ int refB = 0;
+
+ int bothB = 0;
+
+ int simpleU = 0;
+
+ int objectU = 0;
+
+ int refU = 0;
+
+ int bothU = 0;
+
+ public boolean check() {
+ boolean r = fs.size() != 0;
+ Iterator it = fs.iterator();
+ while(it.hasNext()) {
+ r = r & ((FooService) it.next()).foo();
+ }
+ return r;
+ }
+
+ private boolean getBoolean() {
+ return check();
+ }
+
+ private int getInt() {
+ int r = 0;
+ Iterator it = fs.iterator();
+ while(it.hasNext()) {
+ r = r + ((FooService) it.next()).getInt();
+ }
+ return r;
+ }
+
+ private long getLong() {
+ long r = 0;
+ Iterator it = fs.iterator();
+ while(it.hasNext()) {
+ r = r + ((FooService) it.next()).getLong();
+ }
+ return r;
+ }
+
+ private double getDouble() {
+ double r = 0.0;
+ Iterator it = fs.iterator();
+ while(it.hasNext()) {
+ r = r + ((FooService) it.next()).getLong();
+ }
+ return r;
+ }
+
+ protected Object doNothing(Object o, String s) {
+ return null;
+ }
+
+ // private Object getObject() {
+ // boolean r = true;
+ // for(int i = 0; i < fs.length; i++) {
+ // r = r && ((Boolean) fs[i].getObject()).booleanValue();
+ // }
+ // return new Boolean(r);
+ // }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("result", new Boolean(check()));
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ props.put("boolean", new Boolean(getBoolean()));
+ props.put("int", new Integer(getInt()));
+ props.put("long", new Long(getLong()));
+ props.put("double", new Double(getDouble()));
+
+ return props;
+ }
+
+ public void voidBind() {
+ simpleB++;
+ }
+
+ public void voidUnbind() {
+ simpleU++;
+ }
+
+ public void objectBind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectB++;
+ }
+ }
+
+ public void objectUnbind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectU++;
+ }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if (sr != null) {
+ refB++;
+ }
+ }
+
+ public void refUnbind(ServiceReference sr) {
+ if (sr != null) {
+ refU++;
+ }
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothB++;
+ }
+ }
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothU++;
+ }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/VectorCheckService.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/VectorCheckService.java
new file mode 100644
index 0000000..3762751
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/VectorCheckService.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+import java.util.Vector;
+
+public class VectorCheckService implements CheckService {
+
+ Vector fs;
+
+ int simpleB = 0;
+
+ int objectB = 0;
+
+ int refB = 0;
+
+ int bothB = 0;
+
+ int simpleU = 0;
+
+ int objectU = 0;
+
+ int refU = 0;
+
+ int bothU = 0;
+
+ public boolean check() {
+ boolean r = fs.size() != 0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r & ((FooService) fs.get(i)).foo();
+ }
+ return r;
+ }
+
+ private boolean getBoolean() {
+ return check();
+ }
+
+ private int getInt() {
+ int r = 0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getInt();
+ }
+ return r;
+ }
+
+ private long getLong() {
+ long r = 0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getLong();
+ }
+ return r;
+ }
+
+ private double getDouble() {
+ double r = 0.0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getDouble();
+ }
+ return r;
+ }
+
+ protected Object doNothing(Object o, String s) {
+ return null;
+ }
+
+ // private Object getObject() {
+ // boolean r = true;
+ // for(int i = 0; i < fs.length; i++) {
+ // r = r && ((Boolean) fs[i].getObject()).booleanValue();
+ // }
+ // return new Boolean(r);
+ // }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("result", new Boolean(check()));
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ props.put("boolean", new Boolean(getBoolean()));
+ props.put("int", new Integer(getInt()));
+ props.put("long", new Long(getLong()));
+ props.put("double", new Double(getDouble()));
+
+ return props;
+ }
+
+ public void voidBind() {
+ // simpleB++;
+ }
+
+ public void voidUnbind() {
+ // simpleU++;
+ }
+
+ public void objectBind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ // objectB++;
+ }
+ }
+
+ public void objectUnbind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ // objectU++;
+ }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if (sr != null) {
+ refB++;
+ }
+ }
+
+ public void refUnbind(ServiceReference sr) {
+ if (sr != null) {
+ refU++;
+ }
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothB++;
+ }
+ }
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothU++;
+ }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/comparator/CheckServiceProvider.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/comparator/CheckServiceProvider.java
new file mode 100644
index 0000000..fc25b5e
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/comparator/CheckServiceProvider.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components.comparator;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+
+import java.util.Properties;
+
+public class CheckServiceProvider implements CheckService {
+
+ FooService fs;
+
+ FooService fs2;
+
+ FooService[] fss;
+
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("fs", new Integer(fs.getInt()));
+ props.put("fs2", new Integer(fs2.getInt()));
+
+ int[] grades = new int[fss.length];
+
+ for (int i = 0; i < grades.length; i++) {
+ grades[i] = fss[i].getInt();
+ }
+
+ props.put("fss", grades);
+
+ return props;
+ }
+
+ void bind(FooService svc) {
+ fs2 = svc;
+ }
+
+ void unbind(FooService svc) {
+ fs2 = null;
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/comparator/GradeComparator.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/comparator/GradeComparator.java
new file mode 100644
index 0000000..2070117
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/comparator/GradeComparator.java
@@ -0,0 +1,31 @@
+package org.apache.felix.ipojo.runtime.core.test.components.comparator;
+
+import org.osgi.framework.ServiceReference;
+
+import java.util.Comparator;
+
+public class GradeComparator implements Comparator {
+
+ public int compare(Object arg0, Object arg1) {
+ ServiceReference ref0 = null;
+ ServiceReference ref1 = null;
+ Integer grade0 = null;
+ Integer grade1 = null;
+ if (arg0 instanceof ServiceReference) {
+ ref0 = (ServiceReference) arg0;
+ grade0 = (Integer) ref0.getProperty("grade");
+ }
+ if (arg1 instanceof ServiceReference) {
+ ref1 = (ServiceReference) arg1;
+ grade1 = (Integer) ref1.getProperty("grade");
+ }
+
+ if (ref0 != null && ref1 != null
+ && grade0 != null && grade1 != null) {
+ return grade1.compareTo(grade0); // Best grade first.
+ } else {
+ return 0; // Equals
+ }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/comparator/GradedFooServiceProvider.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/comparator/GradedFooServiceProvider.java
new file mode 100644
index 0000000..99b0995
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/comparator/GradedFooServiceProvider.java
@@ -0,0 +1,40 @@
+package org.apache.felix.ipojo.runtime.core.test.components.comparator;
+
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+
+import java.util.Properties;
+
+public class GradedFooServiceProvider implements FooService {
+
+
+ private int grade;
+
+ public boolean foo() {
+ return grade > 0;
+ }
+
+ public Properties fooProps() {
+ return null;
+ }
+
+ public boolean getBoolean() {
+ return false;
+ }
+
+ public double getDouble() {
+ return 0;
+ }
+
+ public int getInt() {
+ return grade;
+ }
+
+ public long getLong() {
+ return 0;
+ }
+
+ public Boolean getObject() {
+ return null;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/filter/FilterCheckProvider.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/filter/FilterCheckProvider.java
new file mode 100644
index 0000000..f8b00c8
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/filter/FilterCheckProvider.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components.filter;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+
+import java.util.Properties;
+
+public class FilterCheckProvider implements CheckService, FooService {
+
+ private String m_toto;
+
+ private int bind;
+
+ private int unbind;
+
+ public FilterCheckProvider() {
+ m_toto = "A";
+ }
+
+ public boolean check() {
+ if (m_toto.equals("A")) {
+ m_toto = "B";
+ return true;
+ } else {
+ m_toto = "A";
+ return false;
+ }
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("Bind", new Integer(bind - unbind));
+ return null;
+ }
+
+ private void Bind() {
+ bind++;
+ }
+
+ private void Unbind() {
+ unbind++;
+ }
+
+ 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/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/filter/FilterCheckSubscriber.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/filter/FilterCheckSubscriber.java
new file mode 100644
index 0000000..51bde2d
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/filter/FilterCheckSubscriber.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components.filter;
+
+import org.apache.felix.ipojo.Nullable;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+
+import java.util.Properties;
+
+public class FilterCheckSubscriber implements CheckService {
+
+ private FooService m_foo;
+
+ private int bound;
+
+ public FilterCheckSubscriber() {
+ }
+
+ public boolean check() {
+ m_foo.foo();
+ return true;
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("Bind", new Integer(bound));
+ props.put("Nullable", new Boolean(m_foo instanceof Nullable));
+ return props;
+ }
+
+ private void Bind() {
+ bound++;
+ }
+
+ private void Unbind() {
+ bound--;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/filter/MultipleFilterCheckSubscriber.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/filter/MultipleFilterCheckSubscriber.java
new file mode 100644
index 0000000..0ac8add
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/filter/MultipleFilterCheckSubscriber.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components.filter;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+
+import java.util.Properties;
+
+public class MultipleFilterCheckSubscriber implements CheckService {
+
+ private FooService[] m_foo;
+
+ private int bound;
+
+ public MultipleFilterCheckSubscriber() {
+ }
+
+ public boolean check() {
+ for (int i = 0; i < m_foo.length; i++) {
+ m_foo[i].foo();
+ }
+ return true;
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("Bind", new Integer(bound));
+ props.put("Size", new Integer(m_foo.length));
+ return props;
+ }
+
+ private void Bind() {
+ bound++;
+ }
+
+ private void Unbind() {
+ bound--;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/C1.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/C1.java
new file mode 100644
index 0000000..7beaee3
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/C1.java
@@ -0,0 +1,11 @@
+package org.apache.felix.ipojo.runtime.core.test.components.inner;
+
+import org.apache.felix.ipojo.runtime.core.test.services.Call;
+
+public class C1 implements Call {
+
+ public String callMe() {
+ return "called";
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/C2.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/C2.java
new file mode 100644
index 0000000..526f4d8
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/C2.java
@@ -0,0 +1,13 @@
+package org.apache.felix.ipojo.runtime.core.test.components.inner;
+
+import org.apache.felix.ipojo.runtime.core.test.services.Call;
+
+public class C2 {
+
+ private Call c1;
+
+ public String authenticate() {
+ return c1.callMe();
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/C3.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/C3.java
new file mode 100644
index 0000000..ea3790a
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/C3.java
@@ -0,0 +1,19 @@
+package org.apache.felix.ipojo.runtime.core.test.components.inner;
+
+public class C3 {
+
+ private C2 c2;
+
+ public MyFilter getFilter() {
+ return new MyFilter() {
+ public String authenticate() {
+ System.out.println("My Filter ...");
+ String r = c2.authenticate();
+ System.out.println(" ... " + r);
+ return r;
+ }
+ };
+
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/MyFilter.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/MyFilter.java
new file mode 100644
index 0000000..54819cb
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/inner/MyFilter.java
@@ -0,0 +1,7 @@
+package org.apache.felix.ipojo.runtime.core.test.components.inner;
+
+public interface MyFilter {
+
+ public String authenticate();
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/optional/MyComponent.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/optional/MyComponent.java
new file mode 100644
index 0000000..62f13f6
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/optional/MyComponent.java
@@ -0,0 +1,23 @@
+package org.apache.felix.ipojo.runtime.core.test.components.optional;
+
+import org.apache.felix.ipojo.Nullable;
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Requires;
+import org.osgi.service.log.LogService;
+
+
+@Component(immediate=true, name="optional-log-cons")
+public class MyComponent {
+
+ @Requires(optional=true, proxy=false)
+ private LogService log;
+
+
+ public MyComponent() {
+ System.out.println("Created ! : " + (log instanceof Nullable) + " - " + log);
+ log.log(LogService.LOG_INFO, "Created !");
+
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/CheckProviderParentClass.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/CheckProviderParentClass.java
new file mode 100644
index 0000000..1ec6a73
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/CheckProviderParentClass.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components.policies;
+
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+public abstract class CheckProviderParentClass {
+
+ int simpleU = 0;
+ int objectU = 0;
+ int refU = 0;
+ int bothU = 0;
+
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if(sr != null && o != null && o instanceof FooService) { bothU++; }
+ }
+
+ public void refUnbind(ServiceReference sr) {
+ if(sr != null) { refU++; }
+ }
+
+ public void objectUnbind(FooService o) {
+ if(o != null && o instanceof FooService) { objectU++; }
+ else {
+ System.err.println("Unbind null : " + o);
+ }
+ }
+
+ public void voidUnbind() {
+ simpleU++;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/CheckServiceProvider.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/CheckServiceProvider.java
new file mode 100644
index 0000000..69003e7
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/CheckServiceProvider.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components.policies;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+public class CheckServiceProvider extends CheckProviderParentClass implements CheckService {
+
+ FooService fs;
+
+ int simpleB = 0;
+ int objectB = 0;
+ int refB = 0;
+ int bothB = 0;
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ if (fs != null) {
+ props.put("result", new Boolean(fs.foo()));
+ props.put("boolean", new Boolean(fs.getBoolean()));
+ props.put("int", new Integer(fs.getInt()));
+ props.put("long", new Long(fs.getLong()));
+ props.put("double", new Double(fs.getDouble()));
+ if (fs.getObject() != null) {
+ props.put("object", fs.getObject());
+ }
+ }
+ props.put("static", CheckService.foo);
+ props.put("class", CheckService.class.getName());
+ return props;
+ }
+
+ private void voidBind() {
+ simpleB++;
+ }
+
+ protected void objectBind(FooService o) {
+ if (o == null) {
+ System.err.println("Bind receive null !!! ");
+ return;
+ }
+ if (o != null && o instanceof FooService) {
+ objectB++;
+ }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if (sr != null) {
+ refB++;
+ }
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if (sr != null && o != null && o instanceof FooService) {
+ bothB++;
+ }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/DynCheckServiceProvider.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/DynCheckServiceProvider.java
new file mode 100644
index 0000000..a042c25
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/DynCheckServiceProvider.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components.policies;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+public class DynCheckServiceProvider extends CheckProviderParentClass implements CheckService {
+
+ FooService fs;
+
+ int simpleB = 0;
+ int objectB = 0;
+ int refB = 0;
+ int bothB = 0;
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ if (fs != null) {
+ props.put("int", new Integer(fs.getInt()));
+ if (fs.getObject() != null) {
+ props.put("object", fs.getObject());
+ }
+ }
+ props.put("static", CheckService.foo);
+ props.put("class", CheckService.class.getName());
+ return props;
+ }
+
+ private void voidBind() {
+ simpleB++;
+ }
+
+ protected void objectBind(FooService o) {
+ if (o == null) {
+ System.err.println("Bind receive null !!! ");
+ return;
+ }
+ if (o != null && o instanceof FooService) {
+ objectB++;
+ }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if (sr != null) {
+ refB++;
+ }
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if (sr != null && o != null && o instanceof FooService) {
+ bothB++;
+ }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/MethodCheckServiceProvider.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/MethodCheckServiceProvider.java
new file mode 100644
index 0000000..65583c5
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/MethodCheckServiceProvider.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components.policies;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+public class MethodCheckServiceProvider implements CheckService {
+
+ FooService fs;
+
+ BundleContext context;
+
+ int simpleB = 0;
+ int objectB = 0;
+ int refB = 0;
+ int bothB = 0;
+ int simpleU = 0;
+ int objectU = 0;
+ int refU = 0;
+ int bothU = 0;
+
+
+ public MethodCheckServiceProvider(BundleContext bc) {
+ context = bc;
+ }
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ if (fs != null) {
+ props.put("result", new Boolean(fs.foo()));
+ props.put("boolean", new Boolean(fs.getBoolean()));
+ props.put("int", new Integer(fs.getInt()));
+ props.put("long", new Long(fs.getLong()));
+ props.put("double", new Double(fs.getDouble()));
+ } else {
+ props.put("result", new Boolean(false));
+ }
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+
+ if (fs != null) {
+ if (fs.getObject() != null) {
+ props.put("object", fs.getObject());
+ }
+ }
+
+ return props;
+ }
+
+ protected void objectBind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectB++;
+ }
+ fs = o;
+ }
+
+ protected void objectUnbind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectU++;
+ }
+ fs = null;
+ }
+
+ public void refBind(ServiceReference sr) {
+ if (sr != null) {
+ refB++;
+ }
+ fs = (FooService) context.getService(sr);
+ }
+
+ public void refUnbind(ServiceReference sr) {
+ if (sr != null) {
+ refU++;
+ }
+ context.ungetService(sr);
+ fs = null;
+ }
+
+ protected void bothBind(FooService o, ServiceReference ref) {
+ if (ref != null && o != null && o instanceof FooService) {
+ bothB++;
+ }
+ fs = o;
+ }
+
+ protected void bothUnbind(FooService o, ServiceReference ref) {
+ if (ref != null && o != null && o instanceof FooService) {
+ bothU++;
+ }
+ fs = null;
+ }
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/MethodMultipleCheckService.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/MethodMultipleCheckService.java
new file mode 100644
index 0000000..4f2d89f
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/MethodMultipleCheckService.java
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components.policies;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+public class MethodMultipleCheckService implements CheckService {
+
+ List fs = new ArrayList();
+ BundleContext context;
+
+ int simpleB = 0;
+
+ int objectB = 0;
+
+ int refB = 0;
+
+ int bothB = 0;
+
+ int simpleU = 0;
+
+ int objectU = 0;
+
+ int refU = 0;
+
+ int bothU = 0;
+
+ public MethodMultipleCheckService(BundleContext bc) {
+ context = bc;
+ }
+
+ public boolean check() {
+ boolean r = fs.size() != 0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r & ((FooService) fs.get(i)).foo();
+ }
+ return r;
+ }
+
+ private boolean getBoolean() {
+ return check();
+ }
+
+ private int getInt() {
+ int r = 0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getInt();
+ }
+ return r;
+ }
+
+ private long getLong() {
+ long r = 0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getLong();
+ }
+ return r;
+ }
+
+ private double getDouble() {
+ double r = 0.0;
+ for (int i = 0; i < fs.size(); i++) {
+ r = r + ((FooService) fs.get(i)).getInt();
+ }
+ return r;
+ }
+
+ protected Object doNothing(Object o, String s) {
+ return null;
+ }
+
+// private Object getObject() {
+// boolean r = true;
+// for(int i = 0; i < fs.length; i++) {
+// r = r && ((Boolean) fs[i].getObject()).booleanValue();
+// }
+// return new Boolean(r);
+// }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("result", new Boolean(check()));
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ props.put("boolean", new Boolean(getBoolean()));
+ props.put("int", new Integer(getInt()));
+ props.put("long", new Long(getLong()));
+ props.put("double", new Double(getDouble()));
+
+ return props;
+ }
+
+ public void objectBind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectB++;
+ }
+ fs.add(o);
+ }
+
+ public void objectUnbind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectU++;
+ }
+ fs.remove(o);
+ }
+
+ public void refBind(ServiceReference sr) {
+ if (sr != null) {
+ refB++;
+ }
+ fs.add(context.getService(sr));
+ }
+
+ public void refUnbind(ServiceReference sr) {
+ if (sr != null) {
+ refU++;
+ }
+ fs.remove(context.getService(sr));
+ context.ungetService(sr);
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ fs.add(o);
+ bothB++;
+ }
+ }
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ fs.remove(o);
+ bothU++;
+ }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/MultipleCheckService.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/MultipleCheckService.java
new file mode 100644
index 0000000..925a0ab
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/MultipleCheckService.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components.policies;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+public class MultipleCheckService implements CheckService {
+
+ FooService fs[];
+
+ int simpleB = 0;
+
+ int objectB = 0;
+
+ int refB = 0;
+
+ int bothB = 0;
+
+ int simpleU = 0;
+
+ int objectU = 0;
+
+ int refU = 0;
+
+ int bothU = 0;
+
+ public boolean check() {
+ boolean r = fs.length != 0;
+ for (int i = 0; i < fs.length; i++) {
+ r = r & fs[i].foo();
+ }
+ return r;
+ }
+
+ private boolean getBoolean() {
+ return check();
+ }
+
+ private int getInt() {
+ int r = 0;
+ for (int i = 0; i < fs.length; i++) {
+ r = r + fs[i].getInt();
+ }
+ return r;
+ }
+
+ private long getLong() {
+ long r = 0;
+ for (int i = 0; i < fs.length; i++) {
+ r = r + fs[i].getLong();
+ }
+ return r;
+ }
+
+ private double getDouble() {
+ double r = 0.0;
+ for (int i = 0; i < fs.length; i++) {
+ r = r + fs[i].getInt();
+ }
+ return r;
+ }
+
+ protected Object doNothing(Object o, String s) {
+ return null;
+ }
+
+ // private Object getObject() {
+ // boolean r = true;
+ // for(int i = 0; i < fs.length; i++) {
+ // r = r && ((Boolean) fs[i].getObject()).booleanValue();
+ // }
+ // return new Boolean(r);
+ // }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("result", new Boolean(check()));
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ props.put("boolean", new Boolean(getBoolean()));
+ props.put("int", new Integer(getInt()));
+ props.put("long", new Long(getLong()));
+ props.put("double", new Double(getDouble()));
+
+ return props;
+ }
+
+ public void voidBind() {
+ simpleB++;
+ }
+
+ public void voidUnbind() {
+ simpleU++;
+ }
+
+ public void objectBind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectB++;
+ }
+ }
+
+ public void objectUnbind(FooService o) {
+ if (o != null && o instanceof FooService) {
+ objectU++;
+ }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if (sr != null) {
+ refB++;
+ }
+ }
+
+ public void refUnbind(ServiceReference sr) {
+ if (sr != null) {
+ refU++;
+ }
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothB++;
+ }
+ }
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if (o != null && o instanceof FooService && sr != null) {
+ bothU++;
+ }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/RankedFooProviderType1.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/RankedFooProviderType1.java
new file mode 100644
index 0000000..b9548e6
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/policies/RankedFooProviderType1.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.components.policies;
+
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+
+import java.util.Properties;
+
+public class RankedFooProviderType1 implements FooService {
+ private int m_grade;
+
+
+ public boolean foo() {
+ m_grade = m_grade + 2;
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("grade", new Integer(m_grade));
+
+ return p;
+ }
+
+ public boolean getBoolean() {
+ return true;
+ }
+
+ public double getDouble() {
+ return 1.0;
+ }
+
+ public int getInt() {
+ return m_grade;
+ }
+
+ public long getLong() {
+ return 1;
+ }
+
+ public Boolean getObject() {
+ return new Boolean(true);
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceDelegator.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceDelegator.java
new file mode 100644
index 0000000..852163d
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceDelegator.java
@@ -0,0 +1,31 @@
+package org.apache.felix.ipojo.runtime.core.test.components.proxy;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.BundleContext;
+
+import java.util.Properties;
+
+public class CheckServiceDelegator implements CheckService {
+
+ private FooService fs;
+
+ private Helper helper;
+
+ public CheckServiceDelegator(BundleContext bc) {
+ helper = new Helper(bc, fs);
+ }
+
+ public boolean check() {
+ // Don't access the service
+ // Just delegate
+ return helper.check();
+ }
+
+ public Properties getProps() {
+ // Don't access the service
+ // Just delegate
+ return helper.getProps();
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceGetAndDelegate.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceGetAndDelegate.java
new file mode 100644
index 0000000..c00b83e
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceGetAndDelegate.java
@@ -0,0 +1,29 @@
+package org.apache.felix.ipojo.runtime.core.test.components.proxy;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.BundleContext;
+
+import java.util.Properties;
+
+public class CheckServiceGetAndDelegate implements CheckService {
+
+ private FooService fs;
+
+ private Helper helper;
+
+ public CheckServiceGetAndDelegate(BundleContext bc) {
+ helper = new Helper(bc, fs);
+ }
+
+ public boolean check() {
+ fs.foo();
+ return helper.check();
+ }
+
+ public Properties getProps() {
+ fs.getBoolean();
+ return helper.getProps();
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceNoDelegate.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceNoDelegate.java
new file mode 100644
index 0000000..64b7440
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceNoDelegate.java
@@ -0,0 +1,42 @@
+package org.apache.felix.ipojo.runtime.core.test.components.proxy;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.BundleContext;
+
+import java.util.Properties;
+
+public class CheckServiceNoDelegate implements CheckService {
+
+ private FooService fs;
+
+ private Helper helper;
+
+ private BundleContext context;
+
+ public CheckServiceNoDelegate(BundleContext bc) {
+ context = bc;
+ helper = new Helper(context, fs);
+ }
+
+ public void start() {
+ helper.publish();
+ }
+
+ public void stop() {
+ helper.unpublish();
+ }
+
+ public boolean check() {
+ // Don't access the service
+ // Just delegate
+ return helper.check();
+ }
+
+ public Properties getProps() {
+ // Don't access the service
+ // Just delegate
+ return helper.getProps();
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceUsingStringService.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceUsingStringService.java
new file mode 100644
index 0000000..4ac47d4
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/CheckServiceUsingStringService.java
@@ -0,0 +1,28 @@
+package org.apache.felix.ipojo.runtime.core.test.components.proxy;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+
+import java.util.AbstractMap;
+import java.util.Properties;
+
+public class CheckServiceUsingStringService implements CheckService {
+
+ private String string;
+ private AbstractMap map;
+
+
+ public CheckServiceUsingStringService() {
+ System.out.println("Service : " + string);
+ System.out.println("Map : " + map);
+ }
+
+ public boolean check() {
+ return string != null
+ && map != null;
+ }
+
+ public Properties getProps() {
+ return null;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/Helper.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/Helper.java
new file mode 100644
index 0000000..12df058
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/proxy/Helper.java
@@ -0,0 +1,50 @@
+package org.apache.felix.ipojo.runtime.core.test.components.proxy;
+
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Properties;
+
+public class Helper implements CheckService {
+
+
+ private FooService fs;
+ private BundleContext context;
+ private ServiceRegistration reg;
+
+ public Helper(BundleContext bc, FooService svc) {
+ fs = svc;
+ context = bc;
+ }
+
+ public void publish() {
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put(Constants.SERVICE_PID, "Helper");
+ context.registerService(CheckService.class, this, props);
+ reg = context.registerService(CheckService.class.getName(), this, props);
+ }
+
+ public void unpublish() {
+ if (reg != null) {
+ reg.unregister();
+ }
+ reg = null;
+ }
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ fs.getBoolean();
+ props.put("helper.fs", fs);
+ return props;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/Call.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/Call.java
new file mode 100644
index 0000000..a9ecb28
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/Call.java
@@ -0,0 +1,8 @@
+package org.apache.felix.ipojo.runtime.core.test.services;
+
+public interface Call {
+
+
+ public String callMe();
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/CheckService.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/CheckService.java
new file mode 100644
index 0000000..ecb327b
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/CheckService.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.services;
+
+import java.util.Properties;
+
+public interface CheckService {
+
+ public static final String foo = "foo";
+
+ public boolean check();
+
+ public Properties getProps();
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/FooService.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/FooService.java
new file mode 100644
index 0000000..4c5b3b4
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/FooService.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.services;
+
+import java.util.Properties;
+
+public interface FooService {
+
+ boolean foo();
+
+ Properties fooProps();
+
+ Boolean getObject();
+
+ boolean getBoolean();
+
+ int getInt();
+
+ long getLong();
+
+ double getDouble();
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata-comparator.xml b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata-comparator.xml
new file mode 100644
index 0000000..a7d0cce
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata-comparator.xml
@@ -0,0 +1,36 @@
+<ipojo
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd"
+ xmlns="org.apache.felix.ipojo"
+>
+ <component classname="org.apache.felix.ipojo.runtime.core.test.components.comparator.GradedFooServiceProvider"
+ name="COMPARATOR-gradedFooProvider">
+ <provides>
+ <property field="grade"/>
+ </provides>
+ </component>
+
+
+ <component classname="org.apache.felix.ipojo.runtime.core.test.components.comparator.CheckServiceProvider"
+ name="COMPARATOR-DynamicCheckService">
+ <provides/>
+ <requires field="fs" comparator="org.apache.felix.ipojo.runtime.core.test.components.comparator.GradeComparator"/>
+ <requires field="fss" comparator="org.apache.felix.ipojo.runtime.core.test.components.comparator.GradeComparator"/>
+ <requires comparator="org.apache.felix.ipojo.runtime.core.test.components.comparator.GradeComparator">
+ <callback type="bind" method="bind"/>
+ <callback type="unbind" method="unbind"/>
+ </requires>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.runtime.core.test.components.comparator.CheckServiceProvider"
+ name="COMPARATOR-DynamicPriorityCheckService">
+ <provides/>
+ <requires policy="dynamic-priority" field="fs" comparator="org.apache.felix.ipojo.runtime.core.test.components.comparator.GradeComparator"/>
+ <requires policy="dynamic-priority" field="fss" comparator="org.apache.felix.ipojo.runtime.core.test.components.comparator.GradeComparator"/>
+ <requires policy="dynamic-priority" comparator="org.apache.felix.ipojo.runtime.core.test.components.comparator.GradeComparator">
+ <callback type="bind" method="bind"/>
+ <callback type="unbind" method="unbind"/>
+ </requires>
+ </component>
+
+</ipojo>
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata-filter.xml b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata-filter.xml
new file mode 100644
index 0000000..7494e34
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata-filter.xml
@@ -0,0 +1,122 @@
+<ipojo
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd"
+ xmlns="org.apache.felix.ipojo">
+
+ <!-- Simple Filter Dependencies -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.filter.FilterCheckProvider"
+ name="SimpleFilterCheckServiceProvider" architecture="true">
+ <provides>
+ <property field="m_toto" name="toto" value="A" />
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.filter.FilterCheckSubscriber"
+ name="SimpleFilterCheckServiceSubscriber" architecture="true">
+ <requires field="m_foo" filter="(toto=B)" id="id1" proxy="false">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.filter.FilterCheckSubscriber"
+ name="SimpleFromCheckServiceSubscriber" architecture="true">
+ <requires field="m_foo" from="A" id="id1" proxy="false">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.filter.FilterCheckProvider"
+ name="SimplePIDCheckServiceProvider" architecture="true">
+ <provides>
+ <property type="String" name="service.pid" />
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.filter.FilterCheckSubscriber"
+ name="SimpleFilterCheckServiceSubscriber2" architecture="true">
+ <requires field="m_foo" id="id2" proxy="false">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Optional Simple Filter Dependencies -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.filter.FilterCheckSubscriber"
+ name="OptionalSimpleFilterCheckServiceSubscriber"
+ architecture="true">
+ <requires field="m_foo" filter="(toto=B)" id="id1"
+ optional="true" proxy="false">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.filter.FilterCheckSubscriber"
+ name="OptionalSimpleFilterCheckServiceSubscriber2"
+ architecture="true">
+ <requires field="m_foo" id="id2" optional="true" proxy="false">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Aggregate filter Dependencies-->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.filter.MultipleFilterCheckSubscriber"
+ name="MultipleFilterCheckServiceSubscriber" architecture="true">
+ <requires field="m_foo" filter="(toto=B)" id="id1" proxy="false">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.filter.MultipleFilterCheckSubscriber"
+ name="MultipleFilterCheckServiceSubscriber2" architecture="true">
+ <requires field="m_foo" id="id2" proxy="false">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Optional Aggregate Filter Dependencies -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.filter.MultipleFilterCheckSubscriber"
+ name="OptionalMultipleFilterCheckServiceSubscriber"
+ architecture="true">
+ <requires field="m_foo" filter="(toto=B)" id="id1" proxy="false"
+ optional="true">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.filter.MultipleFilterCheckSubscriber"
+ name="OptionalMultipleFilterCheckServiceSubscriber2"
+ architecture="true">
+ <requires field="m_foo" id="id2" optional="true" proxy="false">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+</ipojo>
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata-policies.xml b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata-policies.xml
new file mode 100644
index 0000000..05ffe27
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata-policies.xml
@@ -0,0 +1,264 @@
+<ipojo
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd"
+ xmlns="org.apache.felix.ipojo"
+>
+
+ <!-- Static Dependencies -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
+ name="StaticSimpleCheckServiceProvider" architecture="true">
+ <requires field="fs" policy="static" />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
+ name="StaticVoidCheckServiceProvider" architecture="true">
+ <requires field="fs" policy="static">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
+ name="StaticObjectCheckServiceProvider" architecture="true">
+ <requires field="fs" policy="static">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
+ name="StaticRefCheckServiceProvider" architecture="true">
+ <requires field="fs" policy="static">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
+ name="StaticBothCheckServiceProvider" architecture="true">
+ <requires field="fs" policy="static">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
+ name="StaticMObjectCheckServiceProvider" architecture="true">
+ <requires policy="static">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
+ name="StaticMRefCheckServiceProvider" architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ policy="static">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
+ name="StaticMBothCheckServiceProvider" architecture="true">
+ <requires policy="static">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Static Simple & Optional Dependencies -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
+ name="StaticSimpleOptionalCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true" policy="static" />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
+ name="StaticVoidOptionalCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true" policy="static">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
+ name="StaticObjectOptionalCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true" policy="static">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
+ name="StaticRefOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" policy="static">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
+ name="StaticBothOptionalCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true" policy="static">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
+ name="StaticMObjectOptionalCheckServiceProvider"
+ architecture="true">
+ <requires optional="true" policy="static">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
+ name="StaticMRefOptionalCheckServiceProvider"
+ architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ optional="true" policy="static">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
+ name="StaticMBothOptionalCheckServiceProvider"
+ architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ optional="true" policy="static">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <!-- Static Multiple Dependencies -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MultipleCheckService"
+ name="StaticSimpleMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" policy="static" />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MultipleCheckService"
+ name="StaticVoidMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" policy="static">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MultipleCheckService"
+ name="StaticObjectMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" policy="static">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MultipleCheckService"
+ name="StaticRefMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs" policy="static">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MultipleCheckService"
+ name="StaticBothMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" policy="static">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodMultipleCheckService"
+ name="StaticMObjectMultipleCheckServiceProvider"
+ architecture="true">
+ <requires aggregate="true" policy="static">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodMultipleCheckService"
+ name="StaticMRefMultipleCheckServiceProvider"
+ architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ aggregate="true" policy="static">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodMultipleCheckService"
+ name="StaticMBothMultipleCheckServiceProvider"
+ architecture="true">
+ <requires aggregate="true" policy="static">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Dynamic-Priority -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.RankedFooProviderType1"
+ name="RankedFooProviderType" architecture="true">
+ <provides>
+ <property field="m_grade" name="service.ranking"/>
+ </provides>
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.DynCheckServiceProvider"
+ name="DPSimpleCheckServiceProvider" architecture="true">
+ <requires field="fs" policy="dynamic-priority" />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.policies.DynCheckServiceProvider"
+ name="DPObjectCheckServiceProvider" architecture="true">
+ <requires field="fs" policy="dynamic-priority">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+</ipojo>
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata.xml b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata.xml
new file mode 100644
index 0000000..43a2ba2
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/main/resources/metadata.xml
@@ -0,0 +1,1064 @@
+<ipojo>
+<!--
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd"
+ xmlns="org.apache.felix.ipojo"
+ -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.FooProviderType1"
+ name="FooProviderType-1" architecture="true">
+ <provides />
+ </component>
+
+ <!-- Simple Dependencies -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="SimpleCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="VoidCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ObjectCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="RefCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="BothCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="MapCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DictCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedSimpleCheckServiceProvider" architecture="true">
+ <requires field="fs" />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedVoidCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedObjectCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedRefCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedBothCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedMapCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedDictCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DoubleCheckServiceProvider" architecture="true">
+ <requires>
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <requires field="fs" proxy="true"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedDoubleCheckServiceProvider" architecture="true">
+ <requires>
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <requires field="fs" />
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="MObjectCheckServiceProvider" architecture="true">
+ <requires>
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="MRefCheckServiceProvider" architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="MBothCheckServiceProvider" architecture="true">
+ <requires>
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="MMapCheckServiceProvider" architecture="true">
+ <requires>
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="MDictCheckServiceProvider" architecture="true">
+ <requires>
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Simple & Optional Dependencies -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="SimpleOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" id="FooService" proxy="false"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="SimpleOptionalNoNullableCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" nullable="false" />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="VoidOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" proxy="false">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="VoidOptionalNoNullableCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" nullable="false">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ObjectOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" proxy="false">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ObjectOptionalNoNullableCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" nullable="false">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="RefOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" proxy="false">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="RefOptionalNoNullableCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" nullable="false">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="BothOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" proxy="false">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="MapOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" proxy="false">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DictOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" proxy="false">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedSimpleOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" id="FooService"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedVoidOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedObjectOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedRefOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedBothOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedMapOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ProxiedDictOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="BothOptionalNoNullableCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" nullable="false">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="MapOptionalNoNullableCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" nullable="false">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DictOptionalNoNullableCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" nullable="false">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="MObjectOptionalCheckServiceProvider" architecture="true">
+ <requires optional="true">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="MRefOptionalCheckServiceProvider" architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ optional="true">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="MBothOptionalCheckServiceProvider" architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ optional="true">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="MMapOptionalCheckServiceProvider" architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ optional="true">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="MDictOptionalCheckServiceProvider" architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ optional="true">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+
+ <!-- Simple & Optional Dependencies with default-implementation -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DISimpleOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl" />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DIVoidOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DIObjectOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DIRefOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DIBothOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DIMapOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DIDictOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="DIMObjectOptionalCheckServiceProvider" architecture="true">
+ <requires optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="DIMRefOptionalCheckServiceProvider" architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="DIMBothOptionalCheckServiceProvider" architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="DIMMapOptionalCheckServiceProvider" architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
+ name="DIMDictOptionalCheckServiceProvider" architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ optional="true"
+ default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Multiple Dependencies -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="SimpleMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ProxiedSimpleMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs" />
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="VoidMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ProxiedVoidMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ObjectMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ProxiedObjectMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="RefMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ProxiedRefMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="BothMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ProxiedBothMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="MapMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ProxiedMapMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="DictMultipleCheckServiceProvider" architecture="true" >
+ <requires field="fs" proxy="false">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ProxiedDictMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodMultipleCheckService"
+ name="MObjectMultipleCheckServiceProvider" architecture="true">
+ <requires aggregate="true">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodMultipleCheckService"
+ name="MRefMultipleCheckServiceProvider" architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ aggregate="true">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodMultipleCheckService"
+ name="MBothMultipleCheckServiceProvider" architecture="true">
+ <requires aggregate="true">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodMultipleCheckService"
+ name="MMapMultipleCheckServiceProvider" architecture="true">
+ <requires aggregate="true">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodMultipleCheckService"
+ name="MDictMultipleCheckServiceProvider" architecture="true">
+ <requires aggregate="true">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Multiple & Optional Dependencies -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="SimpleOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true" proxy="false"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="VoidOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true" proxy="false">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ObjectOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true" proxy="false">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="RefOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true" proxy="false">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ProxiedSimpleOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true" />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ProxiedVoidOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ProxiedObjectOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
+ name="ProxiedRefOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodMultipleCheckService"
+ name="MObjectOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires aggregate="true" optional="true">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.MethodMultipleCheckService"
+ name="MRefOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
+ aggregate="true" optional="true">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Aggregate dependency as List -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.ListCheckService"
+ name="SimpleListCheckServiceProvider" architecture="true">
+ <requires proxy="false"
+ field="fs" specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.ListCheckService"
+ name="OptionalListCheckServiceProvider"
+ architecture="true">
+ <requires proxy="false"
+ specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true" />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.ListCheckService"
+ name="ProxiedSimpleListCheckServiceProvider" architecture="true">
+ <requires field="fs" specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.ListCheckService"
+ name="ProxiedOptionalListCheckServiceProvider"
+ architecture="true">
+ <requires specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true" />
+ <provides />
+ </component>
+
+ <!-- Aggregate dependency as Vector -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.VectorCheckService"
+ name="SimpleVectorCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="objectBind"/>
+ <callback type="unbind" method="objectUnbind"/>
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.VectorCheckService"
+ name="OptionalVectorCheckServiceProvider"
+ architecture="true">
+ <requires specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true" />
+ <provides />
+ </component>
+
+ <!-- Aggregate dependency as Set -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.SetCheckService"
+ name="SimpleSetCheckServiceProvider" architecture="true">
+ <requires proxy="false" field="fs" specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.SetCheckService"
+ name="OptionalSetCheckServiceProvider"
+ architecture="true">
+ <requires proxy="false" specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true" />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.SetCheckService"
+ name="ProxiedSimpleSetCheckServiceProvider" architecture="true">
+ <requires field="fs" specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.SetCheckService"
+ name="ProxiedOptionalSetCheckServiceProvider"
+ architecture="true">
+ <requires specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true" />
+ <provides />
+ </component>
+
+ <!-- Aggregate dependency as Collection -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CollectionCheckService"
+ name="SimpleCollectionCheckServiceProvider" architecture="true">
+ <requires field="fs" specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" proxy="false"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CollectionCheckService"
+ name="ProxiedSimpleCollectionCheckServiceProvider" architecture="true">
+ <requires field="fs" specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"/>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CollectionCheckService"
+ name="OptionalCollectionCheckServiceProvider"
+ architecture="true">
+ <requires specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true"
+ proxy="false"
+ />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CollectionCheckService"
+ name="ProxiedOptionalCollectionCheckServiceProvider"
+ architecture="true">
+ <requires specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true"
+ proxy="false"
+ />
+ <provides />
+ </component>
+
+
+ <!-- Modify method test -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.FooProviderType2"
+ name="FooProviderType-Updatable" architecture="true">
+ <provides>
+ <property name="foo" field="m_foo" value="foo"/>
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="VoidModifyCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ <callback type="modified" method="voidModify"/>
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="ObjectModifyCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ <callback type="modified" method="objectModify" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="RefModifyCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ <callback type="modified" method="refModify" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="BothModifyCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ <callback type="modified" method="bothModify" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="MapModifyCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="propertiesMapBind" />
+ <callback type="unbind" method="propertiesMapUnbind" />
+ <callback type="modified" method="propertiesMapModify" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
+ name="DictModifyCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="propertiesDictionaryBind" />
+ <callback type="unbind" method="propertiesDictionaryUnbind" />
+ <callback type="modified" method="propertiesDictionaryModify" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Proxy Tests -->
+ <component classname="org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceDelegator">
+ <provides/>
+ <requires field="fs" optional="true"/>
+ </component>
+ <component classname="org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceGetAndDelegate">
+ <provides/>
+ <requires field="fs" optional="true"/>
+ </component>
+ <component classname="org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceNoDelegate">
+ <provides/>
+ <requires field="fs" optional="true"/>
+ <callback transition="validate" method="start"/>
+ <callback transition="invalidate" method="stop"/>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceUsingStringService"
+ immediate="true">
+ <provides/>
+ <requires field="string"/>
+ <requires field="map"/>
+ </component>
+
+ <!-- Inner + Proxy mix -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.inner.C1">
+ <provides/>
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.inner.C2">
+ <provides specifications="org.apache.felix.ipojo.runtime.core.test.components.inner.C2"/>
+ <requires field="c1"/>
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.test.components.inner.C3">
+ <provides specifications="org.apache.felix.ipojo.runtime.core.test.components.inner.C3"/>
+ <requires field="c2"/>
+ </component>
+
+</ipojo>
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
new file mode 100644
index 0000000..d4a3640
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
@@ -0,0 +1,254 @@
+package org.apache.felix.ipojo.runtime.core.test.dependencies;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.options.CompositeOption;
+import org.ops4j.pax.exam.options.DefaultCompositeOption;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.ow2.chameleon.testing.helpers.IPOJOHelper;
+import org.ow2.chameleon.testing.helpers.OSGiHelper;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+/**
+ * Bootstrap the test from this project
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class Common {
+
+ @Inject
+ BundleContext bc;
+
+ protected OSGiHelper osgiHelper;
+ protected IPOJOHelper ipojoHelper;
+
+ Bundle testedBundle;
+
+ @Configuration
+ public Option[] config() throws MalformedURLException {
+ Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ root.setLevel(Level.INFO);
+
+ return options(
+ cleanCaches(),
+ ipojoBundles(),
+ junitBundles(),
+ testedBundle(),
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+ );
+ }
+
+ @Before
+ public void commonSetUp() {
+ osgiHelper = new OSGiHelper(bc);
+ ipojoHelper = new IPOJOHelper(bc);
+
+ testedBundle = osgiHelper.getBundle("test.bundle");
+
+ // Dump OSGi Framework information
+ String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
+ if (vendor == null) {
+ vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
+ }
+ String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
+ System.out.println("OSGi Framework : " + vendor + " - " + version);
+
+ // Wait for stability.
+ waitForStability(bc);
+ }
+
+ /**
+ * Waits for stability:
+ * <ul>
+ * <li>all bundles are activated
+ * <li>service count is stable
+ * </ul>
+ * If the stability can't be reached after a specified time,
+ * the method throws a {@link IllegalStateException}.
+ *
+ * @param context the bundle context
+ * @throws IllegalStateException when the stability can't be reach after a several attempts.
+ */
+ private void waitForStability(BundleContext context) throws IllegalStateException {
+ // Wait for bundle initialization.
+ boolean bundleStability = getBundleStability(context);
+ int count = 0;
+ while (!bundleStability && count < 500) {
+ try {
+ Thread.sleep(5);
+ } catch (InterruptedException e) {
+ // Interrupted
+ }
+ count++;
+ bundleStability = getBundleStability(context);
+ }
+
+ if (count == 500) {
+ System.out.println("Bundle stability isn't reached after 500 tries");
+ dumpBundles(context);
+ throw new IllegalStateException("Cannot reach the bundle stability");
+ }
+
+ boolean serviceStability = false;
+ count = 0;
+ int count1 = 0;
+ int count2 = 0;
+ while (!serviceStability && count < 500) {
+ try {
+ ServiceReference[] refs = context.getServiceReferences((String) null, null);
+ count1 = refs.length;
+ Thread.sleep(500);
+ refs = context.getServiceReferences((String) null, null);
+ count2 = refs.length;
+ serviceStability = count1 == count2;
+ } catch (Exception e) {
+ System.err.println(e);
+ serviceStability = false;
+ // Nothing to do, while recheck the condition
+ }
+ count++;
+ }
+
+ if (count == 500) {
+ System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
+ dumpBundles(context);
+ throw new IllegalStateException("Cannot reach the service stability");
+ }
+
+ }
+
+ /**
+ * Are bundle stables.
+ *
+ * @param bc the bundle context
+ * @return <code>true</code> if every bundles are activated.
+ */
+ private boolean getBundleStability(BundleContext bc) {
+ boolean stability = true;
+ Bundle[] bundles = bc.getBundles();
+ for (int i = 0; i < bundles.length; i++) {
+ stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
+ }
+ return stability;
+ }
+
+ /**
+ * Prints the bundle list.
+ *
+ * @param bc the bundle context.
+ */
+ public void dumpBundles(BundleContext bc) {
+ System.out.println("Bundles:");
+ Bundle[] bundles = bc.getBundles();
+ for (int i = 0; i < bundles.length; i++) {
+ System.out.println(bundles[i].getSymbolicName() + " - " + bundles[i].getState());
+ }
+ }
+
+
+ @After
+ public void commonTearDown() {
+ osgiHelper.dispose();
+ ipojoHelper.dispose();
+ }
+
+ public CompositeOption ipojoBundles() {
+ return new DefaultCompositeOption(
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
+ mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject());
+ }
+
+ public CompositeOption eventadmin() {
+ return new DefaultCompositeOption(
+ mavenBundle("org.apache.felix", "org.apache.felix.eventadmin", "1.3.0"),
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo.handler.eventadmin",
+ "1.8.0").versionAsInProject());
+ }
+
+ public Option testedBundle() throws MalformedURLException {
+ File out = new File("target/bundles/bundle.jar");
+ if (out.exists()) {
+ return bundle(out.toURI().toURL().toExternalForm());
+ }
+
+ TinyBundle tested = TinyBundles.bundle();
+
+ // We look inside target/classes to find the class and resources
+ File classes = new File("target/classes");
+ Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
+ List<File> services = new ArrayList<File>();
+ for (File file : files) {
+ if (file.isDirectory()) {
+ // By convention we export of .services and .service package
+ if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
+ services.add(file);
+ }
+ } else {
+ // We need to compute the path
+ String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
+ tested.add(path, file.toURI().toURL());
+ System.out.println(file.getName() + " added to " + path);
+ }
+ }
+
+ // We export 'inner'
+ String export = "org.apache.felix.ipojo.runtime.core.test.components.inner";
+ for (File file : services) {
+ if (export.length() > 0) {
+ export += ", ";
+ }
+ String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
+ String packageName = path.replace('/', '.');
+ export += packageName;
+ }
+
+ System.out.println("Exported packages : " + export);
+
+ InputStream inputStream = tested
+ .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
+ .set(Constants.IMPORT_PACKAGE, "*")
+ .set(Constants.EXPORT_PACKAGE, export)
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
+
+ try {
+ org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
+ return bundle(out.toURI().toURL().toExternalForm());
+ } catch (MalformedURLException e) {
+ throw new RuntimeException("Cannot compute the url of the manipulated bundle");
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot write of the manipulated bundle");
+ }
+ }
+
+ public BundleContext getContext() {
+ return bc;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestDelayedOptionalDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestDelayedOptionalDependencies.java
new file mode 100644
index 0000000..93b6291
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestDelayedOptionalDependencies.java
@@ -0,0 +1,365 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.di;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.*;
+
+public class TestDelayedOptionalDependencies extends Common {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5;
+
+ ComponentInstance fooProvider;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider");
+ fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+
+ Properties i1 = new Properties();
+ i1.put("instance.name", "Simple");
+ instance1 = ipojoHelper.getFactory("DISimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+ instance1.stop();
+
+ Properties i2 = new Properties();
+ i2.put("instance.name", "Void");
+ instance2 = ipojoHelper.getFactory("DIVoidOptionalCheckServiceProvider").createComponentInstance(i2);
+ instance2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("DIObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("DIRefOptionalCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("instance.name", "Both");
+ instance5 = ipojoHelper.getFactory("DIBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ @After
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+ @Test
+ public void testSimple() {
+ instance1.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+
+ // Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 1", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 1.0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, a provider is here
+ assertEquals("check void bind invocation - 2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 5);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 5);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 5.0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance1.stop();
+ }
+
+ @Test
+ public void testVoid() {
+ instance2.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 1", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 1.0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 1);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 5);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 5);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 5.0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance2.stop();
+ }
+
+ @Test
+ public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance3.stop();
+ }
+
+ @Test
+ public void testRef() {
+ instance4.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 1);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+ @Test
+ public void testBoth() {
+ instance5.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestMethodDelayedOptionalDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestMethodDelayedOptionalDependencies.java
new file mode 100644
index 0000000..1ced9e9
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestMethodDelayedOptionalDependencies.java
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.di;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.*;
+
+public class TestMethodDelayedOptionalDependencies extends Common {
+
+ ComponentInstance instance3, instance4, instance5;
+
+ ComponentInstance fooProvider;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider");
+ fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("DIMObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("DIMRefOptionalCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("instance.name", "Both");
+ instance5 = ipojoHelper.getFactory("DIMBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ @After
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+ @Test
+ public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance3.stop();
+ }
+
+ @Test
+ public void testRef() {
+ instance4.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 1);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+ @Test
+ public void testBoth() {
+ instance5.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestMethodOptionalDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestMethodOptionalDependencies.java
new file mode 100644
index 0000000..7aa8423
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestMethodOptionalDependencies.java
@@ -0,0 +1,275 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.di;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestMethodOptionalDependencies extends Common {
+
+ ComponentInstance instance3, instance4, instance5;
+
+ ComponentInstance fooProvider;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider");
+ fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("DIMObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("DIMRefOptionalCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("instance.name", "Both");
+ instance5 = ipojoHelper.getFactory("DIMBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+ @Test
+ public void testObject() {
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+
+ Properties props = cs.getProps();
+
+ // Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test
+ public void testRef() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 1);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test
+ public void testBoth() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestOptionalDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestOptionalDependencies.java
new file mode 100644
index 0000000..f68b7b5
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestOptionalDependencies.java
@@ -0,0 +1,399 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.di;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestOptionalDependencies extends Common {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5;
+ ComponentInstance fooProvider;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider");
+ fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i1 = new Properties();
+ i1.put("instance.name", "Simple");
+ instance1 = ipojoHelper.getFactory("DISimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("instance.name", "Void");
+ instance2 = ipojoHelper.getFactory("DIVoidOptionalCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("DIObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("DIRefOptionalCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("instance.name", "Both");
+ instance5 = ipojoHelper.getFactory("DIBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+ @Test
+ public void testSimple() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+
+ //Check properties
+ assertFalse("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 1", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 5);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 5);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 5.0, 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, a provider is there
+ assertEquals("check void bind invocation - 2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer) props.get("refU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test
+ public void testVoid() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 1", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 5);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 5);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 5.0, 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation -3 (" + ((Integer) props.get("voidU")) + ")", ((Integer) props.get("voidU")).intValue(), 1);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 3", props.get("object"));
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 5);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 5);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 5.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test
+ public void testObject() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2 (" + ((Integer) props.get("objectB")).intValue() + ")", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test
+ public void testRef() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test
+ public void testBoth() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) getContext().getService(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) getContext().getService(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestDelayedOptionalDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestDelayedOptionalDependencies.java
new file mode 100644
index 0000000..230ab60
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestDelayedOptionalDependencies.java
@@ -0,0 +1,498 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+
+public class TestDelayedOptionalDependencies extends Common {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5, instance6, instance7;
+
+ ComponentInstance fooProvider;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider");
+ fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+
+ Properties i1 = new Properties();
+ i1.put("instance.name", "Simple");
+ instance1 = ipojoHelper.getFactory("SimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+ instance1.stop();
+
+ Properties i2 = new Properties();
+ i2.put("instance.name", "Void");
+ instance2 = ipojoHelper.getFactory("VoidOptionalCheckServiceProvider").createComponentInstance(i2);
+ instance2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("ObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("RefOptionalCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("instance.name", "Both");
+ instance5 = ipojoHelper.getFactory("BothOptionalCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+
+ Properties i6 = new Properties();
+ i6.put("instance.name", "Map");
+ instance6 = ipojoHelper.getFactory("MapOptionalCheckServiceProvider").createComponentInstance(i6);
+ instance6.stop();
+
+ Properties i7 = new Properties();
+ i7.put("instance.name", "Dict");
+ instance7 = ipojoHelper.getFactory("DictOptionalCheckServiceProvider").createComponentInstance(i7);
+ instance7.stop();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ @After
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ instance6.dispose();
+ instance7.dispose();
+ fooProvider.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ instance6 = null;
+ instance7 = null;
+ fooProvider = null;
+ }
+
+ @Test public void testSimple() {
+ instance1.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+
+ // Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 1", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, a provider is here
+ assertEquals("check void bind invocation - 2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance1.stop();
+ }
+
+ @Test public void testVoid() {
+ instance2.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 1", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 1);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance2.stop();
+ }
+
+ @Test public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance3.stop();
+ }
+
+ @Test public void testRef() {
+ instance4.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 1);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+ @Test public void testBoth() {
+ instance5.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 1);
+ assertEquals("check map bind callback invocation - 2", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 2", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance5.stop();
+ }
+
+ @Test public void testMap() {
+ instance6.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 1", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation - 1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 2", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation - 2", ((Integer) props.get("mapU")).intValue(), 1);
+ assertEquals("check dict bind callback invocation - 2", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance6.stop();
+ }
+
+ @Test public void testDict() {
+ instance7.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 1", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation - 1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 2", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 2", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation - 2", ((Integer) props.get("dictU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance7.stop();
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestDelayedOptionalMultipleDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestDelayedOptionalMultipleDependencies.java
new file mode 100644
index 0000000..8b19db8
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestDelayedOptionalMultipleDependencies.java
@@ -0,0 +1,368 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestDelayedOptionalMultipleDependencies extends Common {
+
+ ComponentInstance instance1, instance2, instance3, instance4;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties i1 = new Properties();
+ i1.put("instance.name", "Simple");
+ instance1 = ipojoHelper.getFactory("SimpleOptionalMultipleCheckServiceProvider").createComponentInstance(i1);
+ instance1.stop();
+
+ Properties i2 = new Properties();
+ i2.put("instance.name", "Void");
+ instance2 = ipojoHelper.getFactory("VoidOptionalMultipleCheckServiceProvider").createComponentInstance(i2);
+ instance2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("ObjectOptionalMultipleCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("RefOptionalMultipleCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider1");
+ fooProvider1 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+
+ Properties prov2 = new Properties();
+ prov2.put("instance.name", "FooProvider2");
+ fooProvider2 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov2);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ @Test
+ public void testSimple() {
+ instance1.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue()); // True, it still one provider.
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 4", ((Boolean) props.get("result")).booleanValue()); // False, no more provider.
+ assertEquals("check void bind invocation - 4", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 4", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 4", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 4", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 4", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 4", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 4", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 4", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 4", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ instance1.stop();
+ }
+
+ @Test
+ public void testVoid() {
+ instance2.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 2);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 2);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 1);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 4", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 4", ((Integer) props.get("voidB")).intValue(), 2);
+ assertEquals("check void unbind callback invocation - 4", ((Integer) props.get("voidU")).intValue(), 2);
+ assertEquals("check object bind callback invocation - 4", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 4", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 4", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 4", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 4", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 4", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 4", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ instance2.stop();
+ }
+
+ @Test
+ public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 2);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ instance3.stop();
+ }
+
+ @Test
+ public void testRef() {
+ instance4.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 1);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 2);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ instance4.stop();
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodDelayedOptionalDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodDelayedOptionalDependencies.java
new file mode 100644
index 0000000..afbffdd
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodDelayedOptionalDependencies.java
@@ -0,0 +1,369 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestMethodDelayedOptionalDependencies extends Common {
+
+ ComponentInstance instance3, instance4, instance5, instance6, instance7;
+
+ ComponentInstance fooProvider;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider");
+ fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("MObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("MRefOptionalCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("instance.name", "Both");
+ instance5 = ipojoHelper.getFactory("MBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+
+ Properties i6 = new Properties();
+ i6.put("instance.name", "Map");
+ instance6 = ipojoHelper.getFactory("MMapOptionalCheckServiceProvider").createComponentInstance(i6);
+ instance6.stop();
+
+ Properties i7 = new Properties();
+ i7.put("instance.name", "Dict");
+ instance7 = ipojoHelper.getFactory("MDictOptionalCheckServiceProvider").createComponentInstance(i7);
+ instance7.stop();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ @After
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ instance6.dispose();
+ instance7.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ instance6 = null;
+ instance7 = null;
+ fooProvider = null;
+ }
+
+ @Test public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance3.stop();
+ }
+
+ @Test public void testRef() {
+ instance4.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 1);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+ @Test public void testBoth() {
+ instance5.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 1);
+ assertEquals("check map bind callback invocation - 2", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 2", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance5.stop();
+ }
+
+ @Test public void testMap() {
+ instance6.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 1", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation - 1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 2", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation - 2", ((Integer) props.get("mapU")).intValue(), 1);
+ assertEquals("check dict bind callback invocation - 2", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance6.stop();
+ }
+
+ @Test public void testDict() {
+ instance7.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 1", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation - 1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 2", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 2", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation - 2", ((Integer) props.get("dictU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance7.stop();
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodDelayedOptionalMultipleDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodDelayedOptionalMultipleDependencies.java
new file mode 100644
index 0000000..cb7168e
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodDelayedOptionalMultipleDependencies.java
@@ -0,0 +1,215 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestMethodDelayedOptionalMultipleDependencies extends Common {
+
+ ComponentInstance instance3, instance4;
+ ComponentInstance fooProvider1, fooProvider2;
+
+
+ @Before
+ public void setUp() {
+ try {
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("MObjectOptionalMultipleCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("MRefOptionalMultipleCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider1");
+ fooProvider1 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+
+ Properties prov2 = new Properties();
+ prov2.put("instance.name", "FooProvider2");
+ fooProvider2 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov2);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance3 = null;
+ instance4 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ @Test public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", (Boolean) props.get("result")); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 2);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ instance3.stop();
+ }
+
+ @Test public void testRef() {
+ instance4.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 1);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 2);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ instance4.stop();
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodOptionalDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodOptionalDependencies.java
new file mode 100644
index 0000000..adf9555
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodOptionalDependencies.java
@@ -0,0 +1,436 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestMethodOptionalDependencies extends Common {
+
+ ComponentInstance instance3, instance4, instance5, instance6, instance7;
+
+ ComponentInstance fooProvider;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider");
+ fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("MObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("MRefOptionalCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("instance.name", "Both");
+ instance5 = ipojoHelper.getFactory("MBothOptionalCheckServiceProvider").createComponentInstance(i5);
+
+ Properties i6 = new Properties();
+ i6.put("instance.name", "Map");
+ instance6 = ipojoHelper.getFactory("MMapOptionalCheckServiceProvider").createComponentInstance(i6);
+
+ Properties i7 = new Properties();
+ i7.put("instance.name", "Dictionary");
+ instance7 = ipojoHelper.getFactory("MDictOptionalCheckServiceProvider").createComponentInstance(i7);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ instance6.dispose();
+ instance7.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ instance6 = null;
+ instance7 = null;
+ fooProvider = null;
+ }
+
+ @Test public void testObject() {
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+
+ Properties props = cs.getProps();
+
+ // Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testRef() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 1);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testBoth() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testMap() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -2", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation -2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -2", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -3", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation -3", ((Integer) props.get("mapU")).intValue(), 1);
+ assertEquals("check dict bind callback invocation -3", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -3", ((Integer) props.get("dictU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testDict() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -2", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -2", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation -2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -3", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -3", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -3", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation -3", ((Integer) props.get("dictU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodOptionalMultipleDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodOptionalMultipleDependencies.java
new file mode 100644
index 0000000..7446790
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestMethodOptionalMultipleDependencies.java
@@ -0,0 +1,288 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestMethodOptionalMultipleDependencies extends Common {
+
+ ComponentInstance instance3, instance4;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider1");
+ fooProvider1 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ Properties prov2 = new Properties();
+ prov2.put("instance.name", "FooProvider2");
+ fooProvider2 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov2);
+ fooProvider2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("MObjectOptionalMultipleCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("MRefOptionalMultipleCheckServiceProvider").createComponentInstance(i4);
+
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ @After
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance3 = null;
+ instance4 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ @Test public void testObject() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ fooProvider1.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue()); // True, a provider is here
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 2);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testRef() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ fooProvider1.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue()); // True, a provider is here
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 1);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 2);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestNullableTransitiveClassloading.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestNullableTransitiveClassloading.java
new file mode 100644
index 0000000..bb1d1a0
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestNullableTransitiveClassloading.java
@@ -0,0 +1,22 @@
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.*;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.junit.Test;
+
+
+/**
+ * Reproduces FELIX-2093
+ * iPOJO doesn't always use the correct class loader to load nullable object.
+ */
+public class TestNullableTransitiveClassloading extends Common {
+
+
+ @Test
+ public void testCreation() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+ Factory factory = ipojoHelper.getFactory("optional-log-cons");
+ ComponentInstance ci = factory.createComponentInstance(null);
+ ci.dispose();
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestOptionalDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestOptionalDependencies.java
new file mode 100644
index 0000000..09badfd
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestOptionalDependencies.java
@@ -0,0 +1,551 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestOptionalDependencies extends Common {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5, instance6, instance7;
+ ComponentInstance fooProvider;
+
+ @Before public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name","FooProvider");
+ fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i1 = new Properties();
+ i1.put("instance.name","Simple");
+ instance1 = ipojoHelper.getFactory("SimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("instance.name","Void");
+ instance2 = ipojoHelper.getFactory("VoidOptionalCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("instance.name","Object");
+ instance3 = ipojoHelper.getFactory("ObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("instance.name","Ref");
+ instance4 = ipojoHelper.getFactory("RefOptionalCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("instance.name","Both");
+ instance5 = ipojoHelper.getFactory("BothOptionalCheckServiceProvider").createComponentInstance(i5);
+
+ Properties i6 = new Properties();
+ i6.put("instance.name","Map");
+ instance6 = ipojoHelper.getFactory("MapOptionalCheckServiceProvider").createComponentInstance(i6);
+
+ Properties i7 = new Properties();
+ i7.put("instance.name","Dictionary");
+ instance7 = ipojoHelper.getFactory("DictOptionalCheckServiceProvider").createComponentInstance(i7);
+ } catch(Exception e) { fail(e.getMessage()); }
+ }
+
+ @After
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ instance6.dispose();
+ instance7.dispose();
+ fooProvider.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ instance6 = null;
+ instance7 = null;
+ fooProvider = null;
+ }
+
+ @Test public void testSimple() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+
+ //Check properties
+ assertFalse("check CheckService invocation - 1", ((Boolean)props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 1 ("+props.get("object")+")", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 0.0, 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean)props.get("result")).booleanValue()); // True, a provider is there
+ assertEquals("check void bind invocation - 2", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 2", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer)props.get("refU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testVoid() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 1", ((Boolean)props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 1", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 0.0, 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean)props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer)props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation -2", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer)props.get("refU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean)props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer)props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation -3 ("+((Integer)props.get("voidU")) + ")", ((Integer)props.get("voidU")).intValue(), 1);
+ assertEquals("check object bind callback invocation -3", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer)props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 3", props.get("object"));
+ assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 3", ((Double)props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testObject() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean)props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer)props.get("refU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean)props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2 (" + ((Integer)props.get("objectB")).intValue() + ")", ((Integer)props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -2", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer)props.get("refU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean)props.get("result")).booleanValue()); // Nullable object.
+ assertEquals("check void bind invocation -3", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer)props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -3", ((Integer)props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation -3", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer)props.get("refU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testRef() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean)props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer)props.get("refU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean)props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer)props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -2", ((Integer)props.get("refU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean)props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer)props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -3", ((Integer)props.get("refU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testBoth() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean)props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer)props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer)props.get("bothU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean)props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer)props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -2", ((Integer)props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean)props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer)props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -3", ((Integer)props.get("bothU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testMap() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean)props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer)props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer)props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -1", ((Integer)props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -1", ((Integer)props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -1", ((Integer)props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -1", ((Integer)props.get("dictU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean)props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer)props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer)props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -2", ((Integer)props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation -2", ((Integer)props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -2", ((Integer)props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -2", ((Integer)props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean)props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer)props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer)props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -3", ((Integer)props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation -3", ((Integer)props.get("mapU")).intValue(), 1);
+ assertEquals("check dict bind callback invocation -3", ((Integer)props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -3", ((Integer)props.get("dictU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testDict() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean)props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer)props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer)props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -1", ((Integer)props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -1", ((Integer)props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -1", ((Integer)props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -1", ((Integer)props.get("dictU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean)props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer)props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer)props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -2", ((Integer)props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -2", ((Integer)props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -2", ((Integer)props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation -2", ((Integer)props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean)props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer)props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer)props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -3", ((Integer)props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -3", ((Integer)props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -3", ((Integer)props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation -3", ((Integer)props.get("dictU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestOptionalMultipleDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestOptionalMultipleDependencies.java
new file mode 100644
index 0000000..133a133
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestOptionalMultipleDependencies.java
@@ -0,0 +1,485 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestOptionalMultipleDependencies extends Common {
+
+ ComponentInstance instance1, instance2, instance3, instance4;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ @Before public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name","FooProvider1");
+ fooProvider1 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ Properties prov2 = new Properties();
+ prov2.put("instance.name","FooProvider2");
+ fooProvider2 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov2);
+ fooProvider2.stop();
+
+ Properties i1 = new Properties();
+ i1.put("instance.name","Simple");
+ instance1 = ipojoHelper.getFactory("SimpleOptionalMultipleCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("instance.name","Void");
+ instance2 = ipojoHelper.getFactory("VoidOptionalMultipleCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("instance.name","Object");
+ instance3 = ipojoHelper.getFactory("ObjectOptionalMultipleCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("instance.name","Ref");
+ instance4 = ipojoHelper.getFactory("RefOptionalMultipleCheckServiceProvider").createComponentInstance(i4);
+ } catch(Exception e) { fail(e.getMessage()); }
+
+ }
+
+ @After
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ @Test public void testSimple() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean)props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer)props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long)props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 0", ((Double)props.get("double")).doubleValue(), 0.0, 0);
+
+ fooProvider1.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean)props.get("result")).booleanValue()); // True, a provider is here
+ assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 1);
+
+ fooProvider2.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 2", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 2", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 2);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue()); // True, it still one provider.
+ assertEquals("check void bind invocation - 3", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 3", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 3", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 1);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 4", ((Boolean) props.get("result")).booleanValue()); // False, no more provider.
+ assertEquals("check void bind invocation - 4", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 4", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 4", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 4", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 4", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 4", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 4", ((Integer)props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 4", ((Long)props.get("long")).longValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testVoid() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer)props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long)props.get("long")).longValue(), 0);
+
+ fooProvider1.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue()); // True, a provider is here
+ assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 1);
+
+ fooProvider2.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 2", ((Integer)props.get("voidB")).intValue(), 2);
+ assertEquals("check void unbind callback invocation - 2", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 2", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 2);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 3", ((Integer)props.get("voidB")).intValue(), 2);
+ assertEquals("check void unbind callback invocation - 3", ((Integer)props.get("voidU")).intValue(), 1);
+ assertEquals("check object bind callback invocation - 3", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 3", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 3", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 1);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 4", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 4", ((Integer)props.get("voidB")).intValue(), 2);
+ assertEquals("check void unbind callback invocation - 4", ((Integer)props.get("voidU")).intValue(), 2);
+ assertEquals("check object bind callback invocation - 4", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 4", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 4", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 4", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 4", ((Integer)props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 4", ((Long)props.get("long")).longValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testObject() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer)props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long)props.get("long")).longValue(), 0);
+
+ fooProvider1.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue()); // True, a provider is here
+ assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 1);
+
+ fooProvider2.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 2", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer)props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 2", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 2);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 3", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer)props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 3", ((Integer)props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation - 3", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 1);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer)props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 0", ((Integer)props.get("objectU")).intValue(), 2);
+ assertEquals("check ref bind callback invocation - 0", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer)props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long)props.get("long")).longValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testRef() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer)props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer)props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long)props.get("long")).longValue(), 0);
+
+ fooProvider1.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue()); // True, a provider is here
+ assertEquals("check void bind invocation - 1", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer)props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 1);
+
+ fooProvider2.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 2", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 2", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer)props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 2", ((Integer)props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 2", ((Long)props.get("long")).longValue(), 2);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 3", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 3", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 3", ((Integer)props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer)props.get("refU")).intValue(), 1);
+ assertEquals("Check FS invocation (int) - 3", ((Integer)props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long)props.get("long")).longValue(), 1);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer)props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer)props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer)props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer)props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer)props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer)props.get("refU")).intValue(), 2);
+ assertEquals("Check FS invocation (int) - 0", ((Integer)props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long)props.get("long")).longValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestOptionalNoNullableDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestOptionalNoNullableDependencies.java
new file mode 100644
index 0000000..5f02fe2
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestOptionalNoNullableDependencies.java
@@ -0,0 +1,550 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestOptionalNoNullableDependencies extends Common {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5, instance6, instance7;
+ ComponentInstance fooProvider;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider");
+ fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i1 = new Properties();
+ i1.put("instance.name", "Simple");
+ instance1 = ipojoHelper.getFactory("SimpleOptionalNoNullableCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("instance.name", "Void");
+ instance2 = ipojoHelper.getFactory("VoidOptionalNoNullableCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("ObjectOptionalNoNullableCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("RefOptionalNoNullableCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("instance.name", "Both");
+ instance5 = ipojoHelper.getFactory("BothOptionalNoNullableCheckServiceProvider").createComponentInstance(i5);
+
+ Properties i6 = new Properties();
+ i6.put("instance.name", "Map");
+ instance6 = ipojoHelper.getFactory("MapOptionalNoNullableCheckServiceProvider").createComponentInstance(i6);
+
+ Properties i7 = new Properties();
+ i7.put("instance.name", "Dictionary");
+ instance7 = ipojoHelper.getFactory("DictOptionalNoNullableCheckServiceProvider").createComponentInstance(i7);
+ } catch (Exception e) {
+ e.getMessage();
+ fail(e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ instance6.dispose();
+ instance7.dispose();
+ fooProvider.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ instance6 = null;
+ instance7 = null;
+ fooProvider = null;
+ }
+
+ @Test public void testSimple() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+
+ //Check properties
+ // no service, no nullable => runtime exception expected
+ assertTrue("check excepted exception", ((Boolean) props.get("exception")).booleanValue());
+ assertNull("check CheckService invocation - 1 (" + props.get("result") + ")", props.get("result")); // Null
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 1 (" + props.get("object") + ")", props.get("object"));
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, a provider is there
+ // No exception expected
+ assertFalse("check unexcepted exception", ((Boolean) props.get("exception")).booleanValue());
+ assertEquals("check void bind invocation - 2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer) props.get("refU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testVoid() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation - 1", props.get("result")); // Null, no provider
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 1", props.get("object"));
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation -3", props.get("result"));
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation -3 (" + ((Integer) props.get("voidU")) + ")", ((Integer) props.get("voidU")).intValue(), 1);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 3", props.get("object"));
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testObject() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation -1", props.get("result")); // Null, no provider
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2 (" + ((Integer) props.get("objectB")).intValue() + ")", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation -3", props.get("result")); // No provider.
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testRef() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation -1", props.get("result")); //Null, no provider
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation -3", props.get("result")); // Null, no provider
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testBoth() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation -1", props.get("result")); // Null, no provider
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation -3", props.get("result")); // Null, no provider
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testDict() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation -1", props.get("result")); // Null, no provider
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -2", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -2", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation -2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation -3", props.get("result")); // Null, no provider
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -3", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -3", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -3", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation -3", ((Integer) props.get("dictU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testMap() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation -1", props.get("result")); // Null, no provider
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -2", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation -2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -2", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertNull("check CheckService invocation -3", props.get("result")); // Null, no provider
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -3", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation -3", ((Integer) props.get("mapU")).intValue(), 1);
+ assertEquals("check dict bind callback invocation -3", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -3", ((Integer) props.get("dictU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestProxiedDelayedOptionalDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestProxiedDelayedOptionalDependencies.java
new file mode 100644
index 0000000..5249604
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestProxiedDelayedOptionalDependencies.java
@@ -0,0 +1,498 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+
+public class TestProxiedDelayedOptionalDependencies extends Common {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5, instance6, instance7;
+
+ ComponentInstance fooProvider;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider");
+ fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+
+ Properties i1 = new Properties();
+ i1.put("instance.name", "Simple");
+ instance1 = ipojoHelper.getFactory("ProxiedSimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+ instance1.stop();
+
+ Properties i2 = new Properties();
+ i2.put("instance.name", "Void");
+ instance2 = ipojoHelper.getFactory("ProxiedVoidOptionalCheckServiceProvider").createComponentInstance(i2);
+ instance2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("ProxiedObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("ProxiedRefOptionalCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("instance.name", "Both");
+ instance5 = ipojoHelper.getFactory("ProxiedBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+
+ Properties i6 = new Properties();
+ i6.put("instance.name", "Map");
+ instance6 = ipojoHelper.getFactory("ProxiedMapOptionalCheckServiceProvider").createComponentInstance(i6);
+ instance6.stop();
+
+ Properties i7 = new Properties();
+ i7.put("instance.name", "Dict");
+ instance7 = ipojoHelper.getFactory("ProxiedDictOptionalCheckServiceProvider").createComponentInstance(i7);
+ instance7.stop();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ @After
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ instance6.dispose();
+ instance7.dispose();
+ fooProvider.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ instance6 = null;
+ instance7 = null;
+ fooProvider = null;
+ }
+
+ @Test public void testSimple() {
+ instance1.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+
+ // Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 1", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, a provider is here
+ assertEquals("check void bind invocation - 2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance1.stop();
+ }
+
+ @Test public void testVoid() {
+ instance2.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 1", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 1);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance2.stop();
+ }
+
+ @Test public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance3.stop();
+ }
+
+ @Test public void testRef() {
+ instance4.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ // Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 1);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+ @Test public void testBoth() {
+ instance5.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 1);
+ assertEquals("check map bind callback invocation - 2", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 2", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance5.stop();
+ }
+
+ @Test public void testMap() {
+ instance6.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 1", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation - 1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 2", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation - 2", ((Integer) props.get("mapU")).intValue(), 1);
+ assertEquals("check dict bind callback invocation - 2", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation - 2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance6.stop();
+ }
+
+ @Test public void testDict() {
+ instance7.start();
+
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ // Check properties
+ assertTrue("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 1", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation - 1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation - 2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation - 2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation - 2", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation - 2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation - 2", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation - 2", ((Integer) props.get("dictU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+
+ instance7.stop();
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestProxiedDelayedOptionalMultipleDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestProxiedDelayedOptionalMultipleDependencies.java
new file mode 100644
index 0000000..30500e0
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestProxiedDelayedOptionalMultipleDependencies.java
@@ -0,0 +1,364 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestProxiedDelayedOptionalMultipleDependencies extends Common {
+
+ ComponentInstance instance1, instance2, instance3, instance4;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties i1 = new Properties();
+ i1.put("instance.name", "Simple");
+ instance1 = ipojoHelper.getFactory("ProxiedSimpleOptionalMultipleCheckServiceProvider").createComponentInstance(i1);
+ instance1.stop();
+
+ Properties i2 = new Properties();
+ i2.put("instance.name", "Void");
+ instance2 = ipojoHelper.getFactory("ProxiedVoidOptionalMultipleCheckServiceProvider").createComponentInstance(i2);
+ instance2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("ProxiedObjectOptionalMultipleCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("ProxiedRefOptionalMultipleCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider1");
+ fooProvider1 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+
+ Properties prov2 = new Properties();
+ prov2.put("instance.name", "FooProvider2");
+ fooProvider2 = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov2);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ @Test public void testSimple() {
+ instance1.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue()); // True, it still one provider.
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 4", ((Boolean) props.get("result")).booleanValue()); // False, no more provider.
+ assertEquals("check void bind invocation - 4", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 4", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 4", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 4", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 4", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 4", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 4", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 4", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 4", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ instance1.stop();
+ }
+
+ @Test public void testVoid() {
+ instance2.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 2);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue()); // True, two providers are here
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 2);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 1);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 4", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 4", ((Integer) props.get("voidB")).intValue(), 2);
+ assertEquals("check void unbind callback invocation - 4", ((Integer) props.get("voidU")).intValue(), 2);
+ assertEquals("check object bind callback invocation - 4", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 4", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 4", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 4", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 4", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 4", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 4", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ instance2.stop();
+ }
+
+ @Test public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 2);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 2);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ instance3.stop();
+ }
+
+ @Test public void testRef() {
+ instance4.start();
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation - 3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation - 3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 3", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 3", ((Integer) props.get("refU")).intValue(), 1);
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 0", ((Boolean) props.get("result")).booleanValue()); // False : no provider
+ assertEquals("check void bind invocation - 0", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 0", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 0", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 0", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 0", ((Integer) props.get("refB")).intValue(), 2);
+ assertEquals("check ref unbind callback invocation - 0", ((Integer) props.get("refU")).intValue(), 2);
+ assertEquals("Check FS invocation (int) - 0", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 0", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 0", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ instance4.stop();
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestProxiedOptionalDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestProxiedOptionalDependencies.java
new file mode 100644
index 0000000..d4f3d55
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/optional/TestProxiedOptionalDependencies.java
@@ -0,0 +1,554 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.test.dependencies.optional;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestProxiedOptionalDependencies extends Common {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5, instance6, instance7;
+ ComponentInstance fooProvider;
+
+ @Before
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("instance.name", "FooProvider");
+ fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i1 = new Properties();
+ i1.put("instance.name", "Simple");
+ instance1 = ipojoHelper.getFactory("ProxiedSimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("instance.name", "Void");
+ instance2 = ipojoHelper.getFactory("ProxiedVoidOptionalCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("instance.name", "Object");
+ instance3 = ipojoHelper.getFactory("ProxiedObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("instance.name", "Ref");
+ instance4 = ipojoHelper.getFactory("ProxiedRefOptionalCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("instance.name", "Both");
+ instance5 = ipojoHelper.getFactory("ProxiedBothOptionalCheckServiceProvider").createComponentInstance(i5);
+
+ Properties i6 = new Properties();
+ i6.put("instance.name", "Map");
+ instance6 = ipojoHelper.getFactory("ProxiedMapOptionalCheckServiceProvider").createComponentInstance(i6);
+
+ Properties i7 = new Properties();
+ i7.put("instance.name", "Dictionary");
+ instance7 = ipojoHelper.getFactory("ProxiedDictOptionalCheckServiceProvider").createComponentInstance(i7);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ instance6.dispose();
+ instance7.dispose();
+ fooProvider.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ instance6 = null;
+ instance7 = null;
+ fooProvider = null;
+ }
+
+ @Test public void testSimple() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+
+ //Check properties
+ assertFalse("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 1 (" + props.get("object") + ")", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, a provider is there
+ assertEquals("check void bind invocation - 2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer) props.get("refU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testVoid() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 1", props.get("object"));
+ assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertNotNull("Check FS invocation (object) - 2", props.get("object"));
+ assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 1);
+ assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 1);
+ assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 1.0, 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 1);
+ assertEquals("check void unbind callback invocation -3 (" + ((Integer) props.get("voidU")) + ")", ((Integer) props.get("voidU")).intValue(), 1);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertNull("Check FS invocation (object) - 3", props.get("object"));
+ assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 0);
+ assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 0);
+ assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 0.0, 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testObject() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2 (" + ((Integer) props.get("objectB")).intValue() + ")", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue()); // Nullable object.
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 1);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 1);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testRef() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 1);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testBoth() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 1);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testMap() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -2", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation -2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -2", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -3", ((Integer) props.get("mapB")).intValue(), 1);
+ assertEquals("check map unbind callback invocation -3", ((Integer) props.get("mapU")).intValue(), 1);
+ assertEquals("check dict bind callback invocation -3", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -3", ((Integer) props.get("dictU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+ @Test public void testDict() {
+ ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance7.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ Properties props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
+ assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -1", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -1", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -1", ((Integer) props.get("dictB")).intValue(), 0);
+ assertEquals("check dict unbind callback invocation -1", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.start();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -2", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -2", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -2", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation -2", ((Integer) props.get("dictU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) osgiHelper.getServiceObject(cs_ref);
+ props = cs.getProps();
+ //Check properties
+ assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
+ assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
+ assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
+ assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
+ assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
+ assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
+ assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
+ assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+ assertEquals("check map bind callback invocation -3", ((Integer) props.get("mapB")).intValue(), 0);
+ assertEquals("check map unbind callback invocation -3", ((Integer) props.get("mapU")).intValue(), 0);
+ assertEquals("check dict bind callback invocation -3", ((Integer) props.get("dictB")).intValue(), 1);
+ assertEquals("check dict unbind callback invocation -3", ((Integer) props.get("dictU")).intValue(), 1);
+
+ id = null;
+ cs = null;
+ getContext().ungetService(arch_ref);
+ getContext().ungetService(cs_ref);
+ }
+
+
+}