Commit the new iPOJO version (0.7.6).
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@642265 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/tests.core/pom.xml b/ipojo/tests/tests.core/pom.xml
new file mode 100644
index 0000000..8b95285
--- /dev/null
+++ b/ipojo/tests/tests.core/pom.xml
@@ -0,0 +1,111 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+ <parent>
+ <groupId>ipojo.tests</groupId>
+ <artifactId>ipojo.tests</artifactId>
+ <version>0.7.6-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <name>iPOJO Test Suite</name>
+ <artifactId>tests.core</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ <version>0.7.6-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.composite</artifactId>
+ <version>0.7.6-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.metadata</artifactId>
+ <version>0.7.6-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>ipojo.examples</groupId>
+ <artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
+ <version>0.7.6-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.felix.ipojo.test.scenarios.service
+ </Export-Package>
+ <Bundle-SymbolicName>
+ ${pom.artifactId}
+ </Bundle-SymbolicName>
+ <Private-Package>
+ org.apache.felix.ipojo.test*
+ </Private-Package>
+ <Test-Suite>
+ org.apache.felix.ipojo.test.IPOJOTestSuite
+ </Test-Suite>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <version>0.7.6-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ <configuration>
+ <ignoreAnnotations>true</ignoreAnnotations>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/IPOJOTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/IPOJOTestSuite.java
new file mode 100644
index 0000000..b9fbeb9
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/IPOJOTestSuite.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.apache.felix.ipojo.test.scenarios.architecture.ArchitectureTestSuite;
+import org.apache.felix.ipojo.test.scenarios.bad.BadTestSuite;
+import org.apache.felix.ipojo.test.scenarios.configuration.ConfigurationTestSuite;
+import org.apache.felix.ipojo.test.scenarios.controller.LifeCycleControllerTestSuite;
+import org.apache.felix.ipojo.test.scenarios.core.CoreTestSuite;
+import org.apache.felix.ipojo.test.scenarios.dependency.DependencyTestSuite;
+import org.apache.felix.ipojo.test.scenarios.factory.FactoryTestSuite;
+import org.apache.felix.ipojo.test.scenarios.handler.ExternalHandlerTestSuite;
+import org.apache.felix.ipojo.test.scenarios.lifecycle.LifeCycleCallbackTest;
+import org.apache.felix.ipojo.test.scenarios.manipulation.ManipulationTestSuite;
+import org.apache.felix.ipojo.test.scenarios.service.providing.ProvidedServiceTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class IPOJOTestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("IPojo Core Test Suite", bc);
+ ots.addTest(ManipulationTestSuite.suite(bc));
+ ots.addTest(CoreTestSuite.suite(bc));
+ ots.addTest(FactoryTestSuite.suite(bc));
+ ots.addTest(ProvidedServiceTestSuite.suite(bc));
+ ots.addTest(LifeCycleControllerTestSuite.suite(bc));
+ ots.addTest(LifeCycleCallbackTest.suite(bc));
+ ots.addTest(DependencyTestSuite.suite(bc));
+ ots.addTest(ArchitectureTestSuite.suite(bc));
+ ots.addTest(ConfigurationTestSuite.suite(bc));
+ ots.addTest(ExternalHandlerTestSuite.suite(bc));
+ ots.addTest(BadTestSuite.suite(bc));
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/handler/CheckServiceHandler.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/handler/CheckServiceHandler.java
new file mode 100644
index 0000000..865234c
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/handler/CheckServiceHandler.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.handler;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.osgi.framework.ServiceRegistration;
+
+public class CheckServiceHandler extends PrimitiveHandler implements CheckService {
+
+ ServiceRegistration sr;
+ boolean isValid;
+ int changes = 0;
+ static final String NAMESPACE = org.apache.felix.ipojo.test.handler.CheckServiceHandler.class.getName();
+
+ Properties props = new Properties();
+
+ public void configure(Element metadata, Dictionary configuration) {
+ Element[] meta = metadata.getElements("Check", NAMESPACE);
+ if(meta.length == 0) { return; }
+ // Get handler props
+ props.put("instance.name", configuration.get("name"));
+ if(configuration.get("csh.simple") != null) { props.put("Simple", configuration.get("csh.simple")); }
+ if(configuration.get("csh.map") != null) {
+ Dictionary m = (Dictionary) configuration.get("csh.map");
+ props.put("Map1", m.get("a"));
+ props.put("Map2", m.get("b"));
+ props.put("Map3", m.get("c"));
+ }
+ props.put("changes", new Integer(changes));
+
+ }
+
+ public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) {
+ cd.addProperty(new PropertyDescription("csh.simple", "java.lang.String", null));
+ cd.addProperty(new PropertyDescription("csh.map", "java.util.Dictionary", null));
+ }
+
+ public void start() {
+ if(sr == null) {
+ sr = getInstanceManager().getContext().registerService(CheckService.class.getName(), this, props);
+ }
+ isValid = true;
+ }
+
+ public void stop() {
+ isValid = false;
+ synchronized(this) {
+ if(sr != null) { sr.unregister(); }
+ }
+ }
+
+ public boolean check() {
+ if(isValid) { isValid = false;}
+ else { isValid = true; }
+ return isValid;
+ }
+
+ public Properties getProps() {
+ return props;
+ }
+
+ public void stateChanged(int state) {
+ changes++;
+ props.put("changes", new Integer(changes));
+ sr.setProperties(props);
+ }
+
+ public String getName() {
+ return NAMESPACE;
+ }
+
+ public HandlerDescription getDescription() {
+ return new CheckServiceHandlerDescription(this);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/handler/CheckServiceHandlerDescription.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/handler/CheckServiceHandlerDescription.java
new file mode 100644
index 0000000..fb43042
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/handler/CheckServiceHandlerDescription.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.handler;
+
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+
+public class CheckServiceHandlerDescription extends HandlerDescription {
+
+ public CheckServiceHandlerDescription(Handler h) {
+ super(h);
+ }
+
+ public Element getHandlerInfo() {
+ Element elem = super.getHandlerInfo();
+ elem.addAttribute(new Attribute("isValid", isValid()+""));
+ return elem;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/log/DefaultLogImpl.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/log/DefaultLogImpl.java
new file mode 100644
index 0000000..bbde9eb
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/log/DefaultLogImpl.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.test.log;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+public class DefaultLogImpl implements LogService {
+
+
+ public void log(int arg0, String arg1) {
+ dispatch(arg0, arg1);
+ }
+
+ public void log(int arg0, String arg1, Throwable arg2) {
+ dispatch(arg0, arg1 + " (" + arg2.getMessage() + ")");
+ }
+
+ public void log(ServiceReference arg0, int arg1, String arg2) {
+ dispatch(arg1, arg2 + " (" + arg0.toString() + ")");
+ }
+
+ public void log(ServiceReference arg0, int arg1, String arg2, Throwable arg3) {
+ dispatch(arg1, arg2 + " (" + arg0.toString() + ")" + " (" + arg3.getMessage() + ")");
+ }
+
+
+ private void dispatch(int level, String message) {
+ switch (level) {
+ case LogService.LOG_DEBUG:
+ System.out.println("[DEBUG] " + message);
+ break;
+ case LogService.LOG_INFO:
+ System.out.println("[INFO] " + message);
+ break;
+ case LogService.LOG_WARNING:
+ System.out.println("[WARNING] " + message);
+ break;
+ case LogService.LOG_ERROR:
+ System.out.println("[ERROR] " + message);
+ break;
+ default:
+ System.out.println("[" + level + "] " + message);
+ break;
+ }
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/log/LogImpl.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/log/LogImpl.java
new file mode 100644
index 0000000..9f23faf
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/log/LogImpl.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.log;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogListener;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+
+public class LogImpl implements LogService, LogReaderService {
+
+ Vector m_messages = new Vector();
+
+ public void log(int arg0, String arg1) {
+ add(new LogEntryImpl(arg0, arg1, null, null));
+ }
+
+ public void log(final int arg0, final String arg1, final Throwable arg2) {
+ Runnable runnable = new Runnable() {
+ public void run() {
+ add(new LogEntryImpl(arg0, arg1, arg2, null));
+ }
+ };
+ Thread thread = new Thread(runnable);
+ thread.start();
+ }
+
+ public void log(final ServiceReference arg0, final int arg1, final String arg2) {
+ Runnable runnable = new Runnable() {
+ public void run() {
+ add(new LogEntryImpl(arg1, arg2, null, arg0));
+ }
+ };
+ Thread thread = new Thread(runnable);
+ thread.start();
+ }
+
+ public void log(final ServiceReference arg0, final int arg1, final String arg2, final Throwable arg3) {
+// Runnable runnable = new Runnable() {
+// public void run() {
+// add(new LogEntryImpl(arg1, arg2, arg3, arg0));
+// }
+// };
+// Thread thread = new Thread(runnable);
+// thread.start();
+ }
+
+ private void add(LogEntry entry) {
+ m_messages.add(entry);
+ }
+
+ public void addLogListener(LogListener arg0) {
+ throw new UnsupportedOperationException("Log Listener not supported");
+
+ }
+
+ public Enumeration getLog() {
+ return m_messages.elements();
+ }
+
+ public void removeLogListener(LogListener arg0) {
+ throw new UnsupportedOperationException("Log Listener not supported");
+
+ }
+
+ private class LogEntryImpl implements LogEntry {
+
+ private int level;
+ private String message;
+ private Throwable exception;
+ private ServiceReference reference;
+ private long time;
+
+
+ LogEntryImpl(int l, String m, Throwable e, ServiceReference ref) {
+ level = l;
+ message = m;
+ exception = e;
+ reference = ref;
+ time = System.currentTimeMillis();
+ }
+
+
+ public Bundle getBundle() {
+ return null;
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ public int getLevel() {
+ return level;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public ServiceReference getServiceReference() {
+ return reference;
+ }
+
+ public long getTime() {
+ return time;
+ }
+
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/architecture/ArchitectureTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/architecture/ArchitectureTestSuite.java
new file mode 100644
index 0000000..ef287b6
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/architecture/ArchitectureTestSuite.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.architecture;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class ArchitectureTestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Architecture Test Suite", bc);
+ ots.addTestSuite(ProvidedServiceTest.class);
+ ots.addTestSuite(DependencyTest.class);
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/architecture/DependencyTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/architecture/DependencyTest.java
new file mode 100644
index 0000000..102df0b
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/architecture/DependencyTest.java
@@ -0,0 +1,600 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.architecture;
+
+import java.util.Properties;
+
+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.handlers.dependency.DependencyHandlerDescription;
+import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DependencyTest extends OSGiTestCase {
+
+ ComponentInstance fooProvider1, fooProvider2;
+
+ ComponentInstance instance1, instance2, instance3, instance4;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ Properties prov2 = new Properties();
+ prov2.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+ fooProvider2.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "SimpleCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Optional");
+ instance2 = Utils.getFactoryByName(context, "SimpleOptionalCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Multiple");
+ instance3 = Utils.getFactoryByName(context, "SimpleMultipleCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "OptionalMultiple");
+ instance4 = Utils.getFactoryByName(context, "SimpleOptionalMultipleCheckServiceProvider").createComponentInstance(i4);
+ } catch(Exception e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ 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;
+ }
+
+ private DependencyHandlerDescription getDependencyDesc(InstanceDescription id) {
+ for(int i = 0; i < id.getHandlers().length; i++) {
+ if(id.getHandlers()[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.dependency.DependencyHandler")) {
+ return (DependencyHandlerDescription) id.getHandlers()[i];
+ }
+ }
+ fail("Dependency Handler not found");
+ return null;
+ }
+
+ private ProvidedServiceHandlerDescription getPSDesc(InstanceDescription id) {
+ for(int i = 0; i < id.getHandlers().length; i++) {
+ if(id.getHandlers()[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler")) {
+ return (ProvidedServiceHandlerDescription) id.getHandlers()[i];
+ }
+ }
+ fail("Provided Service Handler not found");
+ return null;
+ }
+
+ public void testSimpleDependency() {
+ ServiceReference arch_dep = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_dep);
+ InstanceDescription id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
+
+ // Check dependency handler invalidity
+ DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
+ assertFalse("Check dependency handler invalidity", dhd.isValid());
+
+ // Check dependency metadata
+ assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
+ assertFalse("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
+ assertFalse("Check dependency optionality", dhd.getDependencies()[0].isOptional());
+ assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
+
+ fooProvider1.start();
+
+ ServiceReference arch_ps = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps);
+ InstanceDescription id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+ assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+ ProvidedServiceHandlerDescription psh = getPSDesc(id_ps);
+ assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+ assertEquals("Check POJO creation", id_ps.getCreatedObjects().length, 1);
+ assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+
+ fooProvider1.stop();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
+ dhd = getDependencyDesc(id_dep);
+ assertFalse("Check dependency handler invalidity", dhd.isValid());
+
+ fooProvider1.start();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ arch_ps = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps);
+ id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
+ psh = getPSDesc(id_ps);
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+
+ assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+ psh = getPSDesc(id_ps);
+ assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+ assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+
+ fooProvider1.stop();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
+ dhd = getDependencyDesc(id_dep);
+ assertFalse("Check dependency handler invalidity", dhd.isValid());
+
+ id_dep = null;
+ cs = null;
+ context.ungetService(arch_dep);
+ context.ungetService(cs_ref);
+ }
+
+ public void testOptionalDependency() {
+ ServiceReference arch_dep = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_dep);
+ InstanceDescription id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check dependency handler invalidity
+ DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler invalidity", dhd.isValid());
+
+ // Check dependency metadata
+ assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
+ assertFalse("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
+ assertTrue("Check dependency optionality", dhd.getDependencies()[0].isOptional());
+ assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
+
+ fooProvider1.start();
+
+ ServiceReference arch_ps = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps);
+ InstanceDescription id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+ assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+ ProvidedServiceHandlerDescription psh = getPSDesc(id_ps);
+ assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+ assertEquals("Check POJO creation", id_ps.getCreatedObjects().length, 1);
+ assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+
+ fooProvider1.stop();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler invalidity", dhd.isValid());
+
+ fooProvider1.start();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ arch_ps = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps);
+ id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
+ psh = getPSDesc(id_ps);
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+
+ assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps = ((Architecture) context.getService(arch_ps)).getInstanceDescription();
+ psh = getPSDesc(id_ps);
+ assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+ assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+
+ fooProvider1.stop();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler invalidity", dhd.isValid());
+
+ id_dep = null;
+ cs = null;
+ context.ungetService(arch_dep);
+ context.ungetService(cs_ref);
+ }
+
+ public void testMultipleDependency() {
+ ServiceReference arch_dep = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_dep);
+ InstanceDescription id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
+
+ // Check dependency handler invalidity
+ DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
+ assertFalse("Check dependency handler invalidity", dhd.isValid());
+
+ // Check dependency metadata
+ assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
+ assertTrue("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
+ assertFalse("Check dependency optionality", dhd.getDependencies()[0].isOptional());
+ assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
+
+ fooProvider1.start();
+
+ ServiceReference arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps1);
+ InstanceDescription id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id_ps1.getState() == ComponentInstance.VALID);
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+ assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+ assertEquals("Check used ref - 1 (" + dhd.getDependencies()[0].getUsedServices().size() + ")", dhd.getDependencies()[0].getUsedServices().size(), 0);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ ProvidedServiceHandlerDescription psh = getPSDesc(id_ps1);
+ assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+ assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+ assertTrue("Check service reference - 2", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+
+ // Start a second foo service provider
+ fooProvider2.start();
+
+ arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+ ServiceReference arch_ps2 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps1);
+ assertNotNull("Check architecture 2 availability", arch_ps2);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ InstanceDescription id_ps2 = ((Architecture) context.getService(arch_ps2)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
+ assertTrue("Check instance 2 invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+ assertEquals("Check dependency ref - 3 ", dhd.getDependencies()[0].getServiceReferences().size(), 2);
+ assertEquals("Check used ref - 2 ", dhd.getDependencies()[0].getUsedServices().size(), 1); // provider 2 not already used
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ id_ps2 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ ProvidedServiceHandlerDescription psh1 = getPSDesc(id_ps1);
+ ProvidedServiceHandlerDescription psh2 = getPSDesc(id_ps2);
+ assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+ assertEquals("Check POJO creation", id_ps2.getCreatedObjects().length, 1);
+ assertTrue("Check service reference - 3.1", dhd.getDependencies()[0].getUsedServices().contains(psh1.getProvidedServices()[0].getServiceReference()));
+ assertTrue("Check service reference - 3.2", dhd.getDependencies()[0].getUsedServices().contains(psh2.getProvidedServices()[0].getServiceReference()));
+ assertEquals("Check used ref - 3 ("+dhd.getDependencies()[0].getUsedServices().size()+")", dhd.getDependencies()[0].getUsedServices().size(), 2);
+
+ fooProvider2.stop();
+
+ arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps1);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id_ps1.getState() == ComponentInstance.VALID);
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+ assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+ assertEquals("Check used ref - 4 ", dhd.getDependencies()[0].getUsedServices().size(), 1);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ psh = getPSDesc(id_ps1);
+ assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+ assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+ assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+ assertEquals("Check used ref - 5 ", dhd.getDependencies()[0].getUsedServices().size(), 1);
+
+ fooProvider1.stop();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertFalse("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertFalse("Check dependency handler invalidity", dhd.isValid());
+
+ fooProvider2.start();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps1);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
+ psh = getPSDesc(id_ps1);
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+
+ assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+ assertEquals("Check used ref - 6 ", dhd.getDependencies()[0].getUsedServices().size(), 0);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ psh = getPSDesc(id_ps1);
+ assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+ assertTrue("Check service reference - 4", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+ assertEquals("Check used ref - 7 ", dhd.getDependencies()[0].getUsedServices().size(), 1);
+
+ fooProvider2.stop();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertFalse("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertFalse("Check dependency handler invalidity", dhd.isValid());
+
+ id_dep = null;
+ cs = null;
+ context.ungetService(arch_dep);
+ context.ungetService(cs_ref);
+ }
+
+ public void testMultipleOptionalDependency() {
+ ServiceReference arch_dep = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_dep);
+ InstanceDescription id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check dependency handler invalidity
+ DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler invalidity", dhd.isValid());
+
+ // Check dependency metadata
+ assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
+ assertTrue("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
+ assertTrue("Check dependency optionality", dhd.getDependencies()[0].isOptional());
+ assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
+
+ fooProvider1.start();
+
+ ServiceReference arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps1);
+ InstanceDescription id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+ assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ ProvidedServiceHandlerDescription psh = getPSDesc(id_ps1);
+ assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+ assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+ assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+
+ // Start a second foo service provider
+ fooProvider2.start();
+
+ arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+ ServiceReference arch_ps2 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps1);
+ assertNotNull("Check architecture 2 availability", arch_ps2);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ InstanceDescription id_ps2 = ((Architecture) context.getService(arch_ps2)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
+ assertTrue("Check instance 2 invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+ assertEquals("Check dependency ref - 3 ", dhd.getDependencies()[0].getServiceReferences().size(), 2);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ id_ps2 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ ProvidedServiceHandlerDescription psh1 = getPSDesc(id_ps1);
+ ProvidedServiceHandlerDescription psh2 = getPSDesc(id_ps2);
+ assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+ assertEquals("Check POJO creation", id_ps2.getCreatedObjects().length, 1);
+ assertTrue("Check service reference - 2.1", dhd.getDependencies()[0].getUsedServices().contains(psh1.getProvidedServices()[0].getServiceReference()));
+ assertTrue("Check service reference - 2.2", dhd.getDependencies()[0].getUsedServices().contains(psh2.getProvidedServices()[0].getServiceReference()));
+
+ fooProvider2.stop();
+
+ arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps1);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+ assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ psh = getPSDesc(id_ps1);
+ assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+ assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
+ assertTrue("Check service reference - 3", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+
+ fooProvider1.stop();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler invalidity", dhd.isValid());
+
+ fooProvider2.start();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ arch_ps1 = Utils.getServiceReferenceByName(context, Architecture.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ps1);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
+ psh = getPSDesc(id_ps1);
+ assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
+ assertTrue("Check dependency handler validity", dhd.isValid());
+
+ assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check object graph
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ dhd = getDependencyDesc(id_dep);
+ id_ps1 = ((Architecture) context.getService(arch_ps1)).getInstanceDescription();
+ psh = getPSDesc(id_ps1);
+ assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
+ assertTrue("Check service reference - 4", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
+
+ fooProvider2.stop();
+
+ id_dep = ((Architecture) context.getService(arch_dep)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
+ dhd = getDependencyDesc(id_dep);
+ assertTrue("Check dependency handler invalidity", dhd.isValid());
+
+ id_dep = null;
+ cs = null;
+ context.ungetService(arch_dep);
+ context.ungetService(cs_ref);
+ }
+
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/architecture/ProvidedServiceTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/architecture/ProvidedServiceTest.java
new file mode 100644
index 0000000..efcd2da
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/architecture/ProvidedServiceTest.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.architecture;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription;
+import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.BarService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class ProvidedServiceTest extends OSGiTestCase {
+
+
+ public void testExposition() {
+ String factName = "FooProviderType-1";
+ String compName = "FooProvider-1";
+
+ // Get the factory to create a component instance
+ Factory fact = Utils.getFactoryByName(context, factName);
+ assertNotNull("Cannot find the factory FooProvider-1", fact);
+
+ Properties props = new Properties();
+ props.put("name", compName);
+ ComponentInstance ci = null;
+ try {
+ ci = fact.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "FooProvider-1");
+ assertNotNull("Architecture not available", arch_ref);
+
+ Architecture arch = (Architecture) context.getService(arch_ref);
+ InstanceDescription id = arch.getInstanceDescription();
+
+ assertEquals("Check component instance name (" + id.getName() + ")", id.getName(), compName);
+ assertEquals("Check component type implementation class", id.getComponentDescription().getClassName(), "org.apache.felix.ipojo.test.scenarios.component.FooProviderType1");
+
+ HandlerDescription[] handlers = id.getHandlers();
+ assertEquals("Number of handlers", handlers.length, 2);
+
+ //Look for the ProvidedService Handler
+ ProvidedServiceHandlerDescription pshd = null;
+ for(int i = 0; i < handlers.length; i++) {
+ if(handlers[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler")) {
+ pshd = (ProvidedServiceHandlerDescription) handlers[i];
+ }
+ }
+
+ assertNotNull("Check ProvidedServiceHandlerDescription", pshd);
+ ProvidedServiceDescription[] ps = pshd.getProvidedServices();
+
+ assertEquals("Check ProvidedService number", ps.length, 1);
+ assertEquals("Check Provided Service Specs - 1", ps[0].getServiceSpecification().length, 1);
+ assertEquals("Check Provided Service Specs - 2", ps[0].getServiceSpecification()[0], FooService.class.getName());
+ assertEquals("Check Provided Service availability", ps[0].getState(), ProvidedServiceDescription.REGISTERED);
+ Properties prop = ps[0].getProperties();
+ assertNotNull("Check Props", prop);
+ assertEquals("Check service properties number", prop.size(), 2);
+ assertEquals("Check instance.name property", prop.getProperty("instance.name"), compName);
+ assertEquals("Check factory.name property", prop.getProperty("factory.name"), factName);
+
+ ci.dispose();
+ }
+
+ public void testProps() {
+ String factName = "FooProviderType-3";
+ String compName = "FooProvider";
+
+ // Get the factory to create a component instance
+ Factory fact = Utils.getFactoryByName(context, factName);
+ assertNotNull("Cannot find the factory FooProvider", fact);
+
+ Properties props = new Properties();
+ props.put("name", compName);
+ props.put("foo", "foo");
+ props.put("bar", "2");
+ props.put("baz", "baz");
+ ComponentInstance ci = null;
+ try {
+ ci = fact.createComponentInstance(props);
+ } catch (Exception e) { fail(e.getMessage()); }
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), compName);
+ assertNotNull("Architecture not available", arch_ref);
+
+ Architecture arch = (Architecture) context.getService(arch_ref);
+ InstanceDescription id = arch.getInstanceDescription();
+
+ assertEquals("Check component instance name (" + id.getName() + ")", id.getName(), compName);
+ assertEquals("Check component type implementation class", id.getComponentDescription().getClassName(), "org.apache.felix.ipojo.test.scenarios.component.FooProviderType1");
+
+ HandlerDescription[] handlers = id.getHandlers();
+ assertEquals("Number of handlers", handlers.length, 3);
+
+ //Look for the ProvidedService Handler
+ ProvidedServiceHandlerDescription pshd = null;
+ for(int i = 0; i < handlers.length; i++) {
+ if(handlers[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler")) {
+ pshd = (ProvidedServiceHandlerDescription) handlers[i];
+ }
+ }
+
+ assertNotNull("Check ProvidedServiceHandlerDescription", pshd);
+ ProvidedServiceDescription[] ps = pshd.getProvidedServices();
+
+ assertEquals("Check ProvidedService number", ps.length, 1);
+ assertEquals("Check Provided Service Specs - 1", ps[0].getServiceSpecification().length, 1);
+ assertEquals("Check Provided Service Specs - 2", ps[0].getServiceSpecification()[0], FooService.class.getName());
+ assertEquals("Check Provided Service availability", ps[0].getState(), ProvidedServiceDescription.REGISTERED);
+
+ Properties prop = ps[0].getProperties();
+ assertNotNull("Check Props", prop);
+ assertEquals("Check service properties number (#" + prop + "?=5)" , prop.size(), 5);
+ assertEquals("Check instance.name property", prop.getProperty("instance.name"), compName);
+ assertEquals("Check factory.name property", prop.getProperty("factory.name"), factName);
+ assertEquals("Check foo property", prop.getProperty("foo"), "foo");
+ assertEquals("Check bar property", prop.getProperty("bar"), "2");
+ assertEquals("Check baz property", prop.getProperty("baz"), "baz");
+
+ ci.dispose();
+ }
+
+ public void testDoubleProviding() {
+ String factName = "FooBarProviderType-1";
+ String compName = "FooProvider";
+
+ // Get the factory to create a component instance
+ Factory fact = Utils.getFactoryByName(context, factName);
+ assertNotNull("Cannot find the factory FooProvider", fact);
+
+ Properties props = new Properties();
+ props.put("name", compName);
+ ComponentInstance ci = null;
+ try {
+ ci = fact.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), compName);
+ assertNotNull("Architecture not available", arch_ref);
+
+ Architecture arch = (Architecture) context.getService(arch_ref);
+ InstanceDescription id = arch.getInstanceDescription();
+
+ assertEquals("Check component instance name (" + id.getName() + ")", id.getName(), compName);
+ assertEquals("Check component type implementation class", id.getComponentDescription().getClassName(), "org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1");
+
+ HandlerDescription[] handlers = id.getHandlers();
+ assertEquals("Number of handlers", handlers.length, 2);
+
+ //Look for the ProvidedService Handler
+ ProvidedServiceHandlerDescription pshd = null;
+ for(int i = 0; i < handlers.length; i++) {
+ if(handlers[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler")) {
+ pshd = (ProvidedServiceHandlerDescription) handlers[i];
+ }
+ }
+
+ assertNotNull("Check ProvidedServiceHandlerDescription", pshd);
+ ProvidedServiceDescription[] ps = pshd.getProvidedServices();
+
+ assertEquals("Check ProvidedService number", ps.length, 1);
+ assertEquals("Check Provided Service Specs - 1", ps[0].getServiceSpecification().length, 2);
+ assertContains("Check provided service specs - 2", ps[0].getServiceSpecification(), FooService.class.getName());;
+ assertContains("Check provided service specs - 2", ps[0].getServiceSpecification(), BarService.class.getName());
+ assertEquals("Check Provided Service availability", ps[0].getState(), ProvidedServiceDescription.REGISTERED);
+
+ ci.dispose();
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadFactories.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadFactories.java
new file mode 100644
index 0000000..baa6fee
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadFactories.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.bad;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.HandlerFactory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+
+public class BadFactories extends OSGiTestCase {
+
+ private Element getElementFactoryWithNoClassName() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("name", "noclassname"));
+ return elem;
+ }
+
+ private Element getElementHandlerFactoryWithNoClassName() {
+ Element elem = new Element("handler", "");
+ elem.addAttribute(new Attribute("name", "noclassname"));
+ return elem;
+ }
+
+ private Element getElementHandlerFactoryWithNoName() {
+ Element elem = new Element("handler", "");
+ elem.addAttribute(new Attribute("className", "noclassname"));
+ return elem;
+ }
+
+ public void testBadFactory() {
+ try {
+ new ComponentFactory(context, getElementFactoryWithNoClassName());
+ fail("A factory with no class name must be rejected");
+ } catch (ConfigurationException e) {
+ // OK.
+ }
+ }
+
+ public void testBadHandlerFactory1() {
+ try {
+ new HandlerFactory(context, getElementHandlerFactoryWithNoClassName());
+ fail("An handler factory with no class name must be rejected");
+ } catch (ConfigurationException e) {
+ // OK.
+ }
+ }
+
+ public void testBadHandlerFactory2() {
+ try {
+ new HandlerFactory(context, getElementHandlerFactoryWithNoName());
+ fail("An handler factory with no name must be rejected");
+ } catch (ConfigurationException e) {
+ // OK.
+ }
+ }
+
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadLFCCallback.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadLFCCallback.java
new file mode 100644
index 0000000..8be6ac4
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadLFCCallback.java
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.bad;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.MissingHandlerException;
+import org.apache.felix.ipojo.UnacceptableConfiguration;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.parser.ManifestMetadataParser;
+import org.apache.felix.ipojo.parser.ParseException;
+
+public class BadLFCCallback extends OSGiTestCase {
+
+ private String clazz = "org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService";
+ private String type = "CallbackCheckService";
+ private Element manipulation;
+ private Properties props;
+
+ public void setUp() {
+ manipulation = getManipulationForComponent();
+ props = new Properties();
+ props.put("name", "BAD");
+ }
+
+
+ private Element getNothing() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("callback", "");
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getNoTransition() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("callback", "");
+ callback.addAttribute(new Attribute("method", "start"));
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getNoMethod() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("callback", "");
+ callback.addAttribute(new Attribute("transition", "validate"));
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getBadMethod() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("callback", "");
+ callback.addAttribute(new Attribute("transition", "validate"));
+ callback.addAttribute(new Attribute("method", "start_")); // Missing method.
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getBadMethod2() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("callback", "");
+ callback.addAttribute(new Attribute("transition", "invalidate"));
+ callback.addAttribute(new Attribute("method", "stop_")); // Missing method.
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getBadTransition() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("callback", "");
+ callback.addAttribute(new Attribute("method", "start"));
+ callback.addAttribute(new Attribute("transition", "validate_"));
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getManipulationForComponent() {
+ String header = (String) context.getBundle().getHeaders().get("iPOJO-Components");
+ Element elem = null;
+ try {
+ elem = ManifestMetadataParser.parse(header);
+ } catch (ParseException e) {
+ fail("Parse Exception when parsing iPOJO-Component");
+ }
+
+ assertNotNull("Check elem not null", elem);
+
+ Element manip = getManipulationForComponent(elem, type);
+ assertNotNull("Check manipulation metadata not null for " + type, manip);
+ return manip;
+ }
+
+ private Element getManipulationForComponent(Element metadata, String comp_name) {
+ Element[] comps = metadata.getElements("component");
+ for(int i = 0; i < comps.length; i++) {
+ if(comps[i].containsAttribute("factory") && comps[i].getAttribute("factory").equals(comp_name)) {
+ return comps[i].getElements("manipulation")[0];
+ }
+ if(comps[i].containsAttribute("name") && comps[i].getAttribute("name").equals(comp_name)) {
+ return comps[i].getElements("manipulation")[0];
+ }
+ }
+ return null;
+ }
+
+ public void testNothing() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getNothing());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.dispose();
+ cf.stop();
+ fail("A lifecycle callback with a missing method and transition must be rejected " + cf);
+ } catch (ConfigurationException e) {
+ // OK
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+
+ public void testNoTransition() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getNoTransition());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.dispose();
+ cf.stop();
+ fail("A lifecycle callback with a missing transition must be rejected " + cf);
+ } catch (ConfigurationException e) {
+ // OK
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+
+ public void testNoMethod() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getNoMethod());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.dispose();
+ cf.stop();
+ fail("A lifecycle callback with a missing method must be rejected " + cf);
+ }catch (ConfigurationException e) {
+ // OK
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+
+ public void testBadMethod() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getBadMethod());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ if (ci.isStarted()) {
+ fail("A lifecycle callback with a bad method must be rejected (instance stills valid)" + cf);
+ }
+ ci.dispose();
+ cf.stop();
+ } catch (ConfigurationException e) {
+ //The check does not happen in the configure method.
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+
+ public void testBadMethod2() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getBadMethod2());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.stop();
+ if (ci.isStarted()) {
+ fail("A lifecycle callback with a bad method must be rejected (instance stills valid)" + cf);
+ }
+ ci.dispose();
+ cf.stop();
+ } catch (ConfigurationException e) {
+ //The check does not happen in the configure method.
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+
+ public void testBadTransition() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getBadTransition());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.dispose();
+ cf.stop();
+ fail("A lifecycle callback with a bad transition must be rejected " + cf);
+ } catch (ConfigurationException e) {
+ // OK
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadLFCController.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadLFCController.java
new file mode 100644
index 0000000..8816530
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadLFCController.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.bad;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.parser.ManifestMetadataParser;
+import org.apache.felix.ipojo.parser.ParseException;
+
+public class BadLFCController extends OSGiTestCase {
+
+ private String clazz = "org.apache.felix.ipojo.test.scenarios.component.LifecycleControllerTest";
+
+ private Element getNoFieldController() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element controller = new Element("controller", "");
+ elem.addElement(controller);
+ return elem;
+ }
+
+ private Element getBadFieldController() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element controller = new Element("controller", "");
+ controller.addAttribute(new Attribute("field", "controller")); // Missing field
+ elem.addElement(controller);
+ elem.addElement(getManipulationForComponent("lcTest"));
+ return elem;
+ }
+
+ private Element getManipulationForComponent(String comp_name) {
+ String header = (String) context.getBundle().getHeaders().get("iPOJO-Components");
+ Element elem = null;
+ try {
+ elem = ManifestMetadataParser.parse(header);
+ } catch (ParseException e) {
+ fail("Parse Exception when parsing iPOJO-Component");
+ }
+
+ assertNotNull("Check elem not null", elem);
+
+ Element manip = getManipulationForComponent(elem, comp_name);
+ assertNotNull("Check manipulation metadata not null for " + comp_name, manip);
+ return manip;
+ }
+
+ private Element getManipulationForComponent(Element metadata, String comp_name) {
+ Element[] comps = metadata.getElements("component");
+ for(int i = 0; i < comps.length; i++) {
+ if(comps[i].containsAttribute("factory") && comps[i].getAttribute("factory").equals(comp_name)) {
+ return comps[i].getElements("manipulation")[0];
+ }
+ if(comps[i].containsAttribute("name") && comps[i].getAttribute("name").equals(comp_name)) {
+ return comps[i].getElements("manipulation")[0];
+ }
+ }
+ return null;
+ }
+
+ public void testNoField() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getNoFieldController());
+ cf.start();
+ cf.stop();
+ fail("A lifecycle controller with a missing field must be rejected " + cf);
+ } catch (Exception e) {
+ // OK
+ }
+ }
+
+ public void testBadField() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getBadFieldController());
+ cf.start();
+ cf.stop();
+ fail("A lifecycle controller with a bad field must be rejected " + cf);
+ } catch (Exception e) {
+ // OK
+ }
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadServiceDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadServiceDependencies.java
new file mode 100644
index 0000000..5bd57c0
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadServiceDependencies.java
@@ -0,0 +1,231 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.bad;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.MissingHandlerException;
+import org.apache.felix.ipojo.UnacceptableConfiguration;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.parser.ManifestMetadataParser;
+import org.apache.felix.ipojo.parser.ParseException;
+import org.apache.felix.ipojo.test.scenarios.service.BarService;
+
+public class BadServiceDependencies extends OSGiTestCase {
+
+ private String clazz = "org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider";
+ private String type = "BothCheckServiceProvider";
+ private Element manipulation;
+ private Properties props;
+
+ public void setUp() {
+ manipulation = getManipulationForComponent();
+ props = new Properties();
+ props.put("name", "BAD");
+ }
+
+
+ private Element getNothing() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("requires", "");
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getNoField() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("requires", "");
+ callback.addAttribute(new Attribute("filter", "(foo=bar)"));
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getBadField() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("requires", "");
+ callback.addAttribute(new Attribute("field", "BAD_FIELD")); // missing field.
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getBadFilter() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("requires", "");
+ callback.addAttribute(new Attribute("field", "fs"));
+ callback.addAttribute(new Attribute("filter", "(foo=bar)&(bar=foo)")); // Incorrect filter
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getBadType() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("requires", "");
+ callback.addAttribute(new Attribute("field", "fs"));
+ callback.addAttribute(new Attribute("interface", BarService.class.getName()));
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getBadAggregate() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ Element callback = new Element("requires", "");
+ callback.addAttribute(new Attribute("field", "fs"));
+ callback.addAttribute(new Attribute("aggregate", "true"));
+ elem.addElement(callback);
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+
+ private Element getManipulationForComponent() {
+ String header = (String) context.getBundle().getHeaders().get("iPOJO-Components");
+ Element elem = null;
+ try {
+ elem = ManifestMetadataParser.parse(header);
+ } catch (ParseException e) {
+ fail("Parse Exception when parsing iPOJO-Component");
+ }
+
+ assertNotNull("Check elem not null", elem);
+
+ Element manip = getManipulationForComponent(elem, type);
+ assertNotNull("Check manipulation metadata not null for " + type, manip);
+ return manip;
+ }
+
+ private Element getManipulationForComponent(Element metadata, String comp_name) {
+ Element[] comps = metadata.getElements("component");
+ for(int i = 0; i < comps.length; i++) {
+ if(comps[i].containsAttribute("factory") && comps[i].getAttribute("factory").equals(comp_name)) {
+ return comps[i].getElements("manipulation")[0];
+ }
+ if(comps[i].containsAttribute("name") && comps[i].getAttribute("name").equals(comp_name)) {
+ return comps[i].getElements("manipulation")[0];
+ }
+ }
+ return null;
+ }
+
+ public void testNothing() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getNothing());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.dispose();
+ cf.stop();
+ fail("A service requirement with neither field and method must be rejected " + cf);
+ } catch (ConfigurationException e) {
+ // OK
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+
+ public void testNoField() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getNoField());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.dispose();
+ cf.stop();
+ fail("A service requirement with neither field and method must be rejected " + cf);
+ } catch (ConfigurationException e) {
+ // OK
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+
+ public void testBadField() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getBadField());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.dispose();
+ cf.stop();
+ fail("A service requirement with a bad field must be rejected " + cf);
+ }catch (ConfigurationException e) {
+ // OK
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+
+ public void testBadFilter() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getBadFilter());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.dispose();
+ cf.stop();
+ fail("A service requirement with a bad filter must be rejected " + cf);
+ }catch (ConfigurationException e) {
+ //OK
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+
+ public void testBadType() {
+ try {
+ ComponentFactory cf = new ComponentFactory(context, getBadType());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.dispose();
+ cf.stop();
+ fail("A service requirement with a bad type must be rejected " + cf);
+ }catch (ConfigurationException e) {
+ // OK
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+ }
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadTestSuite.java
new file mode 100644
index 0000000..71d7db0
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/bad/BadTestSuite.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.bad;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class BadTestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Bad configuration test suite", bc);
+ ots.addTestSuite(BadFactories.class);
+ ots.addTestSuite(BadLFCController.class);
+ ots.addTestSuite(BadLFCCallback.class);
+ ots.addTestSuite(BadServiceDependencies.class);
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/A123/CheckService2Provider.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/A123/CheckService2Provider.java
new file mode 100644
index 0000000..9202b1d
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/A123/CheckService2Provider.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component.A123;
+
+import org.apache.felix.ipojo.test.scenarios.service.A123.CheckService2;
+
+public class CheckService2Provider implements CheckService2 {
+
+ public boolean check() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/A123/Manipulation23Tester.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/A123/Manipulation23Tester.java
new file mode 100644
index 0000000..fe17b96
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/A123/Manipulation23Tester.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component.A123;
+
+import org.apache.felix.ipojo.test.scenarios.service.PrimitiveManipulationTestService;
+
+
+public class Manipulation23Tester implements PrimitiveManipulationTestService {
+
+
+ // Integer types
+ byte b = 1;
+ short s = 1;
+ int i = 1;
+ long l = 1;
+
+ // Floatting types
+ double d = 1.1;
+ float f = 1.1f;
+
+ // Character
+ char c = 'a';
+
+ // Boolean
+ boolean bool = false;
+
+ // Integer arrays
+ byte[] bs = new byte[] {0,1,2};
+ short[] ss = new short[] {0,1,2};
+ int[] is = new int[] {0,1,2};
+ long[] ls = new long[] {0,1,2};
+
+ double[] ds = new double[] {0.0, 1.1, 2.2};
+ float[] fs = new float[] {0.0f, 1.1f, 2.2f};
+
+ char[] cs = new char[] {'a', 'b', 'c'};
+
+ boolean[] bools = new boolean[] {false, true, false};
+
+ public boolean getBoolean() { return bool; }
+
+ public boolean[] getBooleans() { return bools; }
+
+ public byte getByte() { return b; }
+
+ public byte[] getBytes() { return bs; }
+
+ public char getChar() { return c; }
+
+ public char[] getChars() { return cs; }
+
+ public double getDouble() { return d; }
+
+ public double[] getDoubles() { return ds; }
+
+ public float getFloat() { return f; }
+
+ public float[] getFloats() { return fs; }
+
+ public int getInt() { return i; }
+
+ public int[] getInts() { return is; }
+
+ public long getLong() { return l; }
+
+ public long[] getLongs() { return ls; }
+
+ public short getShort() { return s; }
+
+ public short[] getShorts() { return ss; }
+
+ public void setBoolean(boolean b) { this.bool = b; }
+
+ public void setBooleans(boolean[] bs) { this.bools = bs; }
+
+ public void setByte(byte b) { this.b = b; }
+
+ public void setBytes(byte[] bs) { this.bs = bs; }
+
+ public void setChar(char c) { this.c = c; }
+
+ public void setChars(char[] cs) { this.cs = cs; }
+
+ public void setDouble(double d) { this.d = d; }
+
+ public void setDoubles(double[] ds) { this.ds = ds; }
+
+ public void setFloat(float f) { this.f = f; }
+
+ public void setFloats(float[] fs) { this.fs = fs; }
+
+ public void setInt(int i) { this.i = i; }
+
+ public void setInts(int[] is) { this.is = is; }
+
+ public void setLong(long l) { this.l = l; }
+
+ public void setLongs(long[] ls) { this.ls = ls; }
+
+ public void setShort(short s) { this.s = s; }
+
+ public void setShorts(short[] ss) { this.ss = ss; }
+
+ public void setLong(long l, String s) {
+ this.l = l;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Baz2CheckProvider.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Baz2CheckProvider.java
new file mode 100644
index 0000000..1e7cb1d
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Baz2CheckProvider.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.BazService;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.osgi.framework.ServiceReference;
+
+public class Baz2CheckProvider implements CheckService {
+
+ BazService fs;
+
+ int simpleB = 0;
+ int objectB = 0;
+ int refB = 0;
+ int simpleU = 0;
+ int objectU = 0;
+ int refU = 0;
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("result", new Boolean(fs.foo()));
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("boolean", new Boolean(fs.getBoolean()));
+ props.put("int", new Integer(fs.getInt()));
+ props.put("long", new Long(fs.getLong()));
+ props.put("double", new Double(fs.getDouble()));
+ if(fs.getObject() != null) { props.put("object", fs.getObject()); }
+
+ return props;
+ }
+
+ private void voidBind() {
+ simpleB++;
+ }
+ private void voidUnbind() {
+ simpleU++;
+ }
+
+ protected void objectBind(Object o) {
+ if(o != null && o instanceof FooService) { objectB++; }
+ }
+ protected void objectUnbind(Object o) {
+ if(o != null && o instanceof FooService) { objectU++; }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if(sr != null) { refB++; }
+ }
+ public void refUnbind(ServiceReference sr) {
+ if(sr != null) { refU++; }
+ }
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/BazProviderType1.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/BazProviderType1.java
new file mode 100644
index 0000000..4d9a9bb
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/BazProviderType1.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.BazService;
+
+public class BazProviderType1 implements BazService {
+
+ private int m_bar;
+ private String m_foo;
+
+ public boolean foo() {
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("bar", new Integer(m_bar));
+ p.put("foo", m_foo);
+ return p;
+ }
+
+ public boolean getBoolean() { return true; }
+
+ public double getDouble() { return 1.0; }
+
+ public int getInt() { return 1; }
+
+ public long getLong() { return 1; }
+
+ public Boolean getObject() { return new Boolean(true); }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CallbackCheckService.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CallbackCheckService.java
new file mode 100644
index 0000000..76176c8
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CallbackCheckService.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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+
+public class CallbackCheckService extends ParentClass implements CheckService {
+
+ int i = 0;
+
+ FooService fs;
+
+ public static CallbackCheckService singleton;
+
+ public static int count = 0;
+
+ private static CallbackCheckService singleton() {
+ if (singleton == null) {
+ count++;
+ singleton = new CallbackCheckService();
+ }
+ return singleton;
+ }
+
+ public static CallbackCheckService several() {
+ count++;
+ return new CallbackCheckService();
+ }
+
+ private void start() {
+ i++;
+ }
+
+ protected void stop() {
+ i++;
+ }
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties p = new Properties();
+ p.put("int", new Integer(i));
+ p.put("count", new Integer(count));
+ return p;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckProviderParentClass.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckProviderParentClass.java
new file mode 100644
index 0000000..675fe41
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/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.test.scenarios.component;
+
+import org.apache.felix.ipojo.test.scenarios.service.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/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java
new file mode 100644
index 0000000..ffaab9f
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CheckServiceProvider.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.osgi.framework.ServiceReference;
+
+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("result", new Boolean(fs.foo()));
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("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(fs.getBoolean()));
+ props.put("int", new Integer(fs.getInt()));
+ props.put("long", new Long(fs.getLong()));
+ props.put("double", new Double(fs.getDouble()));
+ props.put("static", CheckService.foo);
+ props.put("class", CheckService.class.getName());
+ if(fs.getObject() != null) { props.put("object", fs.getObject()); }
+ 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/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ConfigurableCheckServiceProvider.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ConfigurableCheckServiceProvider.java
new file mode 100644
index 0000000..5ae13cb
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ConfigurableCheckServiceProvider.java
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+
+public class ConfigurableCheckServiceProvider implements CheckService {
+
+ // Integer types
+ byte b;
+ short s;
+ int i;
+ long l;
+
+ // Floatting types
+ double d;
+ float f;
+
+ // Character
+ char c;
+
+ // Boolean
+ boolean bool;
+
+ // Integer arrays
+ byte[] bs;
+ short[] ss;
+ int[] is;
+ long[] ls;
+
+ double[] ds;
+ float[] fs;
+
+ char[] cs;
+
+ boolean[] bools;
+
+ String string;
+ String[] strings;
+
+ int upB, upS, upI, upL, upD, upF, upC, upBool, upBs, upSs, upIs, upLs, upDs, upFs, upCs, upBools, upString, upStrings;
+
+
+ public boolean check() {
+ return true;
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("b", new Byte(b));
+ props.put("s", new Short(s));
+ props.put("i", new Integer(i));
+ props.put("l", new Long(l));
+ props.put("d", new Double(d));
+ props.put("f", new Float(f));
+ props.put("c", new Character(c));
+ props.put("bool", new Boolean(bool));
+
+ props.put("bs", bs);
+ props.put("ss", ss);
+ props.put("is", is);
+ props.put("ls", ls);
+ props.put("ds", ds);
+ props.put("fs", fs);
+ props.put("cs", cs);
+ props.put("bools", bools);
+
+ props.put("upb", new Integer(upB));
+ props.put("ups", new Integer(upS));
+ props.put("upi", new Integer(upI));
+ props.put("upl", new Integer(upL));
+ props.put("upd", new Integer(upD));
+ props.put("upf", new Integer(upF));
+ props.put("upc", new Integer(upC));
+ props.put("upbool", new Integer(upBool));
+
+ props.put("upbs", new Integer(upBs));
+ props.put("upss", new Integer(upSs));
+ props.put("upis", new Integer(upIs));
+ props.put("upls", new Integer(upLs));
+ props.put("upds", new Integer(upDs));
+ props.put("upfs", new Integer(upFs));
+ props.put("upcs", new Integer(upCs));
+ props.put("upbools", new Integer(upBools));
+
+ props.put("string", string);
+ props.put("strings", strings);
+ props.put("upstring", new Integer(upString));
+ props.put("upstrings", new Integer(upStrings));
+
+ return props;
+ }
+
+ public void updateB(byte bb) {
+ b = bb;
+ upB++;
+ }
+
+ public void updateS(short bb) {
+ s = bb;
+ upS++;
+ }
+
+ public void updateI(int bb) {
+ i = bb;
+ upI++;
+ }
+
+ public void updateL(long bb) {
+ l = bb;
+ upL++;
+ }
+
+ public void updateD(double bb) {
+ d = bb;
+ upD++;
+ }
+
+ public void updateF(float bb) {
+ f = bb;
+ upF++;
+ }
+
+ public void updateC(char bb) {
+ c = bb;
+ upC++;
+ }
+
+ public void updateBool(boolean bb) {
+ bool = bb;
+ upBool++;
+ }
+
+ public void updateBs(byte[] bb) {
+ bs = bb;
+ upBs++;
+ }
+
+ public void updateSs(short[] bb) {
+ ss = bb;
+ upSs++;
+ }
+
+ public void updateIs(int[] bb) {
+ is = bb;
+ upIs++;
+ }
+
+ public void updateLs(long[] bb) {
+ ls = bb;
+ upLs++;
+ }
+
+ public void updateDs(double[] bb) {
+ ds = bb;
+ upDs++;
+ }
+
+ public void updateFs(float[] bb) {
+ fs = bb;
+ upFs++;
+ }
+
+ public void updateCs(char[] bb) {
+ cs = bb;
+ upCs++;
+ }
+
+ public void updateBools(boolean[] bb) {
+ bools = bb;
+ upBools++;
+ }
+
+ public void updateStrings(String[] bb) {
+ strings = bb;
+ upStrings++;
+ }
+
+ public void updateString(String bb) {
+ string = bb;
+ upString++;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FilterCheckProvider.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FilterCheckProvider.java
new file mode 100644
index 0000000..c05090d
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FilterCheckProvider.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+
+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() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean getBoolean() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public double getDouble() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getInt() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long getLong() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Boolean getObject() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FilterCheckSubscriber.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FilterCheckSubscriber.java
new file mode 100644
index 0000000..2c25e8c
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FilterCheckSubscriber.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.Nullable;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+
+public class FilterCheckSubscriber implements CheckService {
+
+ private FooService m_foo;
+
+ private int binded;
+
+ public FilterCheckSubscriber(){
+ }
+
+ public boolean check() {
+ m_foo.foo();
+ return true;
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("Bind", new Integer(binded));
+ props.put("Nullable", new Boolean(m_foo instanceof Nullable));
+ return props;
+ }
+
+ private void Bind() {
+ binded++;
+ }
+ private void Unbind() {
+ binded--;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooBarProviderType1.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooBarProviderType1.java
new file mode 100644
index 0000000..2b739b4
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooBarProviderType1.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.BarService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+
+public class FooBarProviderType1 implements FooService, BarService {
+
+ public boolean foo() {
+ return true;
+ }
+
+ public Properties fooProps() {
+ return new Properties();
+ }
+
+ public boolean bar() {
+ return true;
+ }
+
+ public Properties getProps() {
+ return new Properties();
+ }
+
+ public boolean getBoolean() { return true; }
+
+ public double getDouble() { return 1.0; }
+
+ public int getInt() { return 1; }
+
+ public long getLong() { return 1; }
+
+ public Boolean getObject() { return new Boolean(true); }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java
new file mode 100644
index 0000000..3fe9bad
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.osgi.framework.BundleContext;
+
+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);
+ }
+
+ private void nexttry(String s) {
+ try {
+ s += "foo";
+ } catch(RuntimeException e) {
+
+ }
+ }
+
+ public boolean getBoolean() { return true; }
+
+ public double getDouble() { return 1.0; }
+
+ public int getInt() { return 1; }
+
+ public long getLong() { return 1; }
+
+ public Boolean getObject() { return new Boolean(true); }
+
+ /**
+ * 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/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java
new file mode 100644
index 0000000..39f3918
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+
+public class FooProviderTypeDyn implements FooService {
+
+ private int intProp;
+ private String strProp;
+ private String[] strAProp;
+ private int[] intAProp;
+ private boolean boolProp;
+
+ public boolean foo() {
+ intProp = 3;
+ boolProp = true;
+ if(strProp.equals("foo")) { strProp = "bar"; }
+ else { strProp = "foo"; }
+ strAProp = new String[] {"foo", "bar", "baz"};
+ intAProp = new int[] {3, 2, 1};
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("intProp", new Integer(intProp));
+ p.put("boolProp", new Boolean(boolProp));
+ p.put("strProp", strProp);
+ p.put("strAProp", strAProp);
+ p.put("intAProp", intAProp);
+ return p;
+ }
+
+ public boolean getBoolean() { return true; }
+
+ public double getDouble() { return 1.0; }
+
+ public int getInt() { return 1; }
+
+ public long getLong() { return 1; }
+
+ public Boolean getObject() { return new Boolean(true); }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn2.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn2.java
new file mode 100644
index 0000000..f5f233a
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn2.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+
+public class FooProviderTypeDyn2 implements FooService {
+
+ private int intProp = 2;
+ private boolean boolProp = true;
+ private String strProp = "foo";
+ private String[] strAProp = new String[] {"foo", "bar"};
+ private int[] intAProp = new int[] {1, 2, 3};
+
+ public boolean foo() {
+ intAProp = null;
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("intProp", new Integer(intProp));
+ p.put("boolProp", new Boolean(boolProp));
+ p.put("strProp", strProp);
+ p.put("strAProp", strAProp);
+ p.put("intAProp", intAProp);
+ return p;
+ }
+
+ public boolean getBoolean() { return true; }
+
+ public double getDouble() { return 1.0; }
+
+ public int getInt() { return 1; }
+
+ public long getLong() { return 1; }
+
+ public Boolean getObject() { return new Boolean(true); }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooServiceDefaultImpl.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooServiceDefaultImpl.java
new file mode 100644
index 0000000..8455c23
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+
+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/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/LifecycleControllerTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/LifecycleControllerTest.java
new file mode 100644
index 0000000..c69bad5
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/LifecycleControllerTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+
+public class LifecycleControllerTest implements CheckService {
+
+ private boolean m_state = true;
+ private String m_conf;
+
+ public void setConf(String newConf) {
+ if (newConf.equals("foo")) {
+ m_state = true;
+ } else {
+ m_state = false;
+ }
+ }
+
+ public boolean check() {
+ return m_state;
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("conf", m_conf);
+ props.put("state", new Boolean(m_state));
+ return props;
+ }
+}
+
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Manipulation23Tester.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Manipulation23Tester.java
new file mode 100644
index 0000000..deff64e
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Manipulation23Tester.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import org.apache.felix.ipojo.test.scenarios.service.PrimitiveManipulationTestService;
+
+
+public class Manipulation23Tester implements PrimitiveManipulationTestService {
+
+ // Integer types
+ byte b = 1;
+ short s = 1;
+ int i = 1;
+ long l = 1;
+
+ // Floatting types
+ double d = 1.1;
+ float f = 1.1f;
+
+ // Character
+ char c = 'a';
+
+ // Boolean
+ boolean bool = false;
+
+ // Integer arrays
+ byte[] bs = new byte[] {0,1,2};
+ short[] ss = new short[] {0,1,2};
+ int[] is = new int[] {0,1,2};
+ long[] ls = new long[] {0,1,2};
+
+ double[] ds = new double[] {0.0, 1.1, 2.2};
+ float[] fs = new float[] {0.0f, 1.1f, 2.2f};
+
+ char[] cs = new char[] {'a', 'b', 'c'};
+
+ boolean[] bools = new boolean[] {false, true, false};
+
+ public boolean getBoolean() { return bool; }
+
+ public boolean[] getBooleans() { return bools; }
+
+ public byte getByte() { return b; }
+
+ public byte[] getBytes() { return bs; }
+
+ public char getChar() { return c; }
+
+ public char[] getChars() { return cs; }
+
+ public double getDouble() { return d; }
+
+ public double[] getDoubles() { return ds; }
+
+ public float getFloat() { return f; }
+
+ public float[] getFloats() { return fs; }
+
+ public int getInt() { return i; }
+
+ public int[] getInts() { return is; }
+
+ public long getLong() { return l; }
+
+ public long[] getLongs() { return ls; }
+
+ public short getShort() { return s; }
+
+ public short[] getShorts() { return ss; }
+
+ public void setBoolean(boolean b) { this.bool = b; }
+
+ public void setBooleans(boolean[] bs) { this.bools = bs; }
+
+ public void setByte(byte b) { this.b = b; }
+
+ public void setBytes(byte[] bs) { this.bs = bs; }
+
+ public void setChar(char c) { this.c = c; }
+
+ public void setChars(char[] cs) { this.cs = cs; }
+
+ public void setDouble(double d) { this.d = d; }
+
+ public void setDoubles(double[] ds) { this.ds = ds; }
+
+ public void setFloat(float f) { this.f = f; }
+
+ public void setFloats(float[] fs) { this.fs = fs; }
+
+ public void setInt(int i) { this.i = i; }
+
+ public void setInts(int[] is) { this.is = is; }
+
+ public void setLong(long l) { this.l = l; }
+
+ public void setLongs(long[] ls) { this.ls = ls; }
+
+ public void setShort(short s) { this.s = s; }
+
+ public void setShorts(short[] ss) { this.ss = ss; }
+
+ // This method has been added to test an issue when autoboxing.
+ public void setLong(long l, String s) {
+ this.l = l;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodCheckServiceProvider.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodCheckServiceProvider.java
new file mode 100644
index 0000000..c069b09
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodCheckServiceProvider.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+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/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodMultipleCheckService.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodMultipleCheckService.java
new file mode 100644
index 0000000..32d4b1d
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MethodMultipleCheckService.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+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/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckService.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleCheckService.java
new file mode 100644
index 0000000..efbc972
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.osgi.framework.ServiceReference;
+
+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/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleFilterCheckSubscriber.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/MultipleFilterCheckSubscriber.java
new file mode 100644
index 0000000..6b7370e
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/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.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+
+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/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentClass.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentClass.java
new file mode 100644
index 0000000..f7fb580
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/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.test.scenarios.component;
+
+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/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentConfigurableCheckServiceProvider.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentConfigurableCheckServiceProvider.java
new file mode 100644
index 0000000..304b83f
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentConfigurableCheckServiceProvider.java
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+
+public class ParentConfigurableCheckServiceProvider extends ParentClass implements CheckService {
+
+ // Integer types
+ byte b;
+ short s;
+ int i;
+ long l;
+
+ // Floatting types
+ double d;
+ float f;
+
+ // Character
+ char c;
+
+ // Boolean
+ boolean bool;
+
+ // Integer arrays
+ byte[] bs;
+ short[] ss;
+ int[] is;
+ long[] ls;
+
+ double[] ds;
+ float[] fs;
+
+ char[] cs;
+
+ boolean[] bools;
+
+ //String string;
+ //String[] strings;
+
+ int upB, upS, upI, upL, upD, upF, upC, upBool, upBs, upSs, upIs, upLs, upDs, upFs, upCs, upBools/*, upString, upStrings*/;
+
+
+ public boolean check() {
+ return true;
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("b", new Byte(b));
+ props.put("s", new Short(s));
+ props.put("i", new Integer(i));
+ props.put("l", new Long(l));
+ props.put("d", new Double(d));
+ props.put("f", new Float(f));
+ props.put("c", new Character(c));
+ props.put("bool", new Boolean(bool));
+
+ props.put("bs", bs);
+ props.put("ss", ss);
+ props.put("is", is);
+ props.put("ls", ls);
+ props.put("ds", ds);
+ props.put("fs", fs);
+ props.put("cs", cs);
+ props.put("bools", bools);
+
+ props.put("upb", new Integer(upB));
+ props.put("ups", new Integer(upS));
+ props.put("upi", new Integer(upI));
+ props.put("upl", new Integer(upL));
+ props.put("upd", new Integer(upD));
+ props.put("upf", new Integer(upF));
+ props.put("upc", new Integer(upC));
+ props.put("upbool", new Integer(upBool));
+
+ props.put("upbs", new Integer(upBs));
+ props.put("upss", new Integer(upSs));
+ props.put("upis", new Integer(upIs));
+ props.put("upls", new Integer(upLs));
+ props.put("upds", new Integer(upDs));
+ props.put("upfs", new Integer(upFs));
+ props.put("upcs", new Integer(upCs));
+ props.put("upbools", new Integer(upBools));
+
+ props.put("string", string);
+ props.put("strings", strings);
+ props.put("upstring", new Integer(upString));
+ props.put("upstrings", new Integer(upStrings));
+
+ return props;
+ }
+
+ public void updateB(byte bb) {
+ b = bb;
+ upB++;
+ }
+
+ public void updateS(short bb) {
+ s = bb;
+ upS++;
+ }
+
+ public void updateI(int bb) {
+ i = bb;
+ upI++;
+ }
+
+ public void updateL(long bb) {
+ l = bb;
+ upL++;
+ }
+
+ public void updateD(double bb) {
+ d = bb;
+ upD++;
+ }
+
+ public void updateF(float bb) {
+ f = bb;
+ upF++;
+ }
+
+ public void updateC(char bb) {
+ c = bb;
+ upC++;
+ }
+
+ public void updateBool(boolean bb) {
+ bool = bb;
+ upBool++;
+ }
+
+ public void updateBs(byte[] bb) {
+ bs = bb;
+ upBs++;
+ }
+
+ public void updateSs(short[] bb) {
+ ss = bb;
+ upSs++;
+ }
+
+ public void updateIs(int[] bb) {
+ is = bb;
+ upIs++;
+ }
+
+ public void updateLs(long[] bb) {
+ ls = bb;
+ upLs++;
+ }
+
+ public void updateDs(double[] bb) {
+ ds = bb;
+ upDs++;
+ }
+
+ public void updateFs(float[] bb) {
+ fs = bb;
+ upFs++;
+ }
+
+ public void updateCs(char[] bb) {
+ cs = bb;
+ upCs++;
+ }
+
+ public void updateBools(boolean[] bb) {
+ bools = bb;
+ upBools++;
+ }
+
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation1.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation1.java
new file mode 100644
index 0000000..3ffab2f
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation1.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component.inherited;
+
+import org.apache.felix.ipojo.test.scenarios.service.ChildInterface;
+
+public class ProcessImplementation1 implements ChildInterface {
+
+ public void processChild() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParent1() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParentParent() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParent2() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation2.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation2.java
new file mode 100644
index 0000000..49e9267
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation2.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component.inherited;
+
+
+public class ProcessImplementation2 extends ProcessParentImplementation {
+
+ public void processChild() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParent1() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParentParent() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParent2() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation3.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation3.java
new file mode 100644
index 0000000..cc576d8
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessImplementation3.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component.inherited;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+
+public class ProcessImplementation3 extends ProcessParentImplementation implements FooService {
+
+ public void processChild() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParent1() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParentParent() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParent2() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean foo() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public Properties fooProps() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean getBoolean() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public double getDouble() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getInt() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long getLong() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Boolean getObject() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessParentImplementation.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessParentImplementation.java
new file mode 100644
index 0000000..69ebace
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/component/inherited/ProcessParentImplementation.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component.inherited;
+
+import org.apache.felix.ipojo.test.scenarios.service.ChildInterface;
+
+public class ProcessParentImplementation implements ChildInterface {
+
+ public void processChild() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParent1() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParentParent() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processParent2() {
+ // TODO Auto-generated method stub
+
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java
new file mode 100644
index 0000000..012f642
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class ConfigurationTestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Configuration Test Suite", bc);
+ ots.addTestSuite(SimpleProperties.class);
+ ots.addTestSuite(DynamicallyConfigurableProperties.class);
+ ots.addTestSuite(TestFieldProperties.class);
+ ots.addTestSuite(TestMethodProperties.class);
+ ots.addTestSuite(TestBothProperties.class);
+ ots.addTestSuite(TestSuperMethodProperties.class);
+
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java
new file mode 100644
index 0000000..204d1b4
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class DynamicallyConfigurableProperties extends OSGiTestCase {
+
+ ComponentInstance instance;
+
+ public void setUp() {
+ String type = "FooProviderType-3";
+
+ Properties p1 = new Properties();
+ p1.put("name", "instance");
+ p1.put("foo", "foo");
+ p1.put("bar", "2");
+ p1.put("baz", "baz");
+ instance = Utils.getComponentInstance(context, type, p1);
+ }
+
+ public void tearDown() {
+ instance.dispose();
+ instance = null;
+ }
+
+ public void testStatic() {
+ ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check FS availability", fooRef);
+ String fooP = (String) fooRef.getProperty("foo");
+ Integer barP = (Integer) fooRef.getProperty("bar");
+ String bazP = (String) fooRef.getProperty("baz");
+ assertEquals("Check foo equality -1", fooP, "foo");
+ assertEquals("Check bar equality -1", barP, new Integer(2));
+ assertEquals("Check baz equality -1", bazP, "baz");
+
+ ServiceReference msRef = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), instance.getFactory().getName());
+ assertNotNull("Check ManagedServiceFactory availability", msRef);
+
+
+ // Configuration of baz
+ Properties conf = new Properties();
+ conf.put("baz", "zab");
+ conf.put("bar", new Integer(2));
+ conf.put("foo", "foo");
+ ManagedServiceFactory ms = (ManagedServiceFactory) context.getService(msRef);
+ try {
+ ms.updated(instance.getInstanceName(), conf);
+ } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+
+ // Recheck props
+ fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ fooP = (String) fooRef.getProperty("foo");
+ barP = (Integer) fooRef.getProperty("bar");
+ bazP = (String) fooRef.getProperty("baz");
+ assertEquals("Check foo equality -2", fooP, "foo");
+ assertEquals("Check bar equality -2", barP, new Integer(2));
+ assertEquals("Check baz equality -2", bazP, "zab");
+ context.ungetService(msRef);
+ }
+
+ public void testDynamic() {
+ ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check FS availability", fooRef);
+
+ String fooP = (String) fooRef.getProperty("foo");
+ Integer barP = (Integer) fooRef.getProperty("bar");
+ String bazP = (String) fooRef.getProperty("baz");
+
+ assertEquals("Check foo equality", fooP, "foo");
+ assertEquals("Check bar equality", barP, new Integer(2));
+ assertEquals("Check baz equality", bazP, "baz");
+
+ ServiceReference msRef = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), instance.getFactory().getName());
+ assertNotNull("Check ManagedServiceFactory availability", msRef);
+
+ // Configuration of baz
+ Properties conf = new Properties();
+ conf.put("baz", "zab");
+ conf.put("foo", "oof");
+ conf.put("bar", new Integer(0));
+ ManagedServiceFactory ms = (ManagedServiceFactory) context.getService(msRef);
+ try {
+ ms.updated(instance.getInstanceName(), conf);
+ } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+
+ // Recheck props
+ fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ fooP = (String) fooRef.getProperty("foo");
+ barP = (Integer) fooRef.getProperty("bar");
+ bazP = (String) fooRef.getProperty("baz");
+
+ assertEquals("Check foo equality", fooP, "oof");
+ assertEquals("Check bar equality", barP, new Integer(0));
+ assertEquals("Check baz equality", bazP, "zab");
+
+ // Check field value
+ FooService fs = (FooService) context.getService(fooRef);
+ Properties p = fs.fooProps();
+ fooP = (String) p.get("foo");
+ barP = (Integer) p.get("bar");
+
+ assertEquals("Check foo field equality", fooP, "oof");
+ assertEquals("Check bar field equality", barP, new Integer(0));
+
+ context.ungetService(fooRef);
+ context.ungetService(msRef);
+ }
+
+ public void testDynamicString() {
+ ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check FS availability", fooRef);
+
+ String fooP = (String) fooRef.getProperty("foo");
+ Integer barP = (Integer) fooRef.getProperty("bar");
+ String bazP = (String) fooRef.getProperty("baz");
+
+ assertEquals("Check foo equality", fooP, "foo");
+ assertEquals("Check bar equality", barP, new Integer(2));
+ assertEquals("Check baz equality", bazP, "baz");
+
+ ServiceReference msRef = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), instance.getFactory().getName());
+ assertNotNull("Check ManagedServiceFactory availability", msRef);
+
+ // Configuration of baz
+ Properties conf = new Properties();
+ conf.put("baz", "zab");
+ conf.put("foo", "oof");
+ conf.put("bar", "0");
+ ManagedServiceFactory ms = (ManagedServiceFactory) context.getService(msRef);
+ try {
+ ms.updated(instance.getInstanceName(), conf);
+ } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+
+ // Recheck props
+ fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ fooP = (String) fooRef.getProperty("foo");
+ barP = (Integer) fooRef.getProperty("bar");
+ bazP = (String) fooRef.getProperty("baz");
+
+ assertEquals("Check foo equality", fooP, "oof");
+ assertEquals("Check bar equality", barP, new Integer(0));
+ assertEquals("Check baz equality", bazP, "zab");
+
+ // Check field value
+ FooService fs = (FooService) context.getService(fooRef);
+ Properties p = fs.fooProps();
+ fooP = (String) p.get("foo");
+ barP = (Integer) p.get("bar");
+
+ assertEquals("Check foo field equality", fooP, "oof");
+ assertEquals("Check bar field equality", barP, new Integer(0));
+
+ context.ungetService(fooRef);
+ context.ungetService(msRef);
+ }
+
+ public void testPropagation() {
+ ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check FS availability", fooRef);
+
+ String fooP = (String) fooRef.getProperty("foo");
+ Integer barP = (Integer) fooRef.getProperty("bar");
+ String bazP = (String) fooRef.getProperty("baz");
+
+ assertEquals("Check foo equality", fooP, "foo");
+ assertEquals("Check bar equality", barP, new Integer(2));
+ assertEquals("Check baz equality", bazP, "baz");
+
+ ServiceReference msRef = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), instance.getFactory().getName());
+ assertNotNull("Check ManagedServiceFactory availability", msRef);
+
+ // Configuration of baz
+ Properties conf = new Properties();
+ conf.put("baz", "zab");
+ conf.put("foo", "foo");
+ conf.put("bar", new Integer(2));
+ conf.put("propagated1", "propagated");
+ conf.put("propagated2", new Integer(1));
+ ManagedServiceFactory ms = (ManagedServiceFactory) context.getService(msRef);
+ try {
+ ms.updated(instance.getInstanceName(), conf);
+ } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+
+ // Recheck props
+ fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ fooP = (String) fooRef.getProperty("foo");
+ barP = (Integer) fooRef.getProperty("bar");
+ bazP = (String) fooRef.getProperty("baz");
+ assertNotNull("Check the propagated1 existency", fooRef.getProperty("propagated1"));
+ String prop1 = (String) fooRef.getProperty("propagated1");
+ assertNotNull("Check the propagated2 existency", fooRef.getProperty("propagated2"));
+ Integer prop2 = (Integer) fooRef.getProperty("propagated2");
+
+ assertEquals("Check foo equality", fooP, "foo");
+ assertEquals("Check bar equality", barP, new Integer(2));
+ assertEquals("Check baz equality", bazP, "zab");
+ assertEquals("Check propagated1 equality", prop1, "propagated");
+ assertEquals("Check propagated2 equality", prop2, new Integer(1));
+
+ context.ungetService(msRef);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java
new file mode 100644
index 0000000..318304e
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class SimpleProperties extends OSGiTestCase {
+
+ ComponentInstance fooProvider1;
+ ComponentInstance fooProvider2;
+
+ public void setUp() {
+ String type = "FooProviderType-Conf";
+
+ Properties p1 = new Properties();
+ p1.put("name", "FooProvider-1");
+ fooProvider1 = Utils.getComponentInstance(context, type, p1);
+
+ Properties p2 = new Properties();
+ p2.put("name", "FooProvider-2");
+ p2.put("int", new Integer(4));
+ p2.put("boolean", new Boolean(false));
+ p2.put("string", new String("bar"));
+ p2.put("strAProp", new String[] {"bar", "foo"});
+ p2.put("intAProp", new int[] {1, 2, 3});
+ fooProvider2 = Utils.getComponentInstance(context, type, p2);
+ }
+
+ public void tearDown() {
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ public void testComponentTypeConfiguration() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check FooService availability", ref);
+ FooService fs = (FooService) context.getService(ref);
+ Properties toCheck = fs.fooProps();
+
+ Integer intProp = (Integer) toCheck.get("intProp");
+ Boolean boolProp = (Boolean) toCheck.get("boolProp");
+ String strProp = (String) toCheck.get("strProp");
+ String[] strAProp = (String[]) toCheck.get("strAProp");
+ int[] intAProp = (int[]) toCheck.get("intAProp");
+
+ assertEquals("Check intProp equality (1)", intProp, new Integer(2));
+ assertEquals("Check longProp equality (1)", boolProp, new Boolean(false));
+ assertEquals("Check strProp equality (1)", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity (1)", strAProp);
+ String[] v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality (1) : " + strAProp[i] + " != " + v[i]); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality (1) : " + intAProp[i] + " != " + v2[i]); }
+ }
+
+ // change the field value
+ assertTrue("Invoke the fs service", fs.foo());
+ toCheck = fs.fooProps();
+
+
+ // Re-check the property (change)
+ intProp = (Integer) toCheck.get("intProp");
+ boolProp = (Boolean) toCheck.get("boolProp");
+ strProp = (String) toCheck.get("strProp");
+ strAProp = (String[]) toCheck.get("strAProp");
+ intAProp = (int[]) toCheck.get("intAProp");
+
+ assertEquals("Check intProp equality (2) ("+intProp+")", intProp, new Integer(3));
+ assertEquals("Check longProp equality (2)", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality (2)", strProp, new String("bar"));
+ assertNotNull("Check strAProp not nullity (2)", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality (2)"); }
+ }
+ assertNotNull("Check intAProp not nullity (2)", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality (2) : " + intAProp[i] + " != " + v2[i]); }
+ }
+
+ fs = null;
+ context.ungetService(ref);
+ }
+
+ public void testInstanceConfiguration() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ FooService fs = (FooService) context.getService(sr);
+ Properties toCheck = fs.fooProps();
+
+ // Check service properties
+ Integer intProp = (Integer) toCheck.get("intProp");
+ Boolean boolProp = (Boolean) toCheck.get("boolProp");
+ String strProp = (String) toCheck.get("strProp");
+ String[] strAProp = (String[]) toCheck.get("strAProp");
+ int[] intAProp = (int[]) toCheck.get("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(4));
+ assertEquals("Check longProp equality", boolProp, new Boolean(false));
+ assertEquals("Check strProp equality", strProp, new String("bar"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"bar", "foo"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+
+ assertTrue("invoke fs", fs.foo());
+ toCheck = fs.fooProps();
+
+ // Re-check the property (change)
+ intProp = (Integer) toCheck.get("intProp");
+ boolProp = (Boolean) toCheck.get("boolProp");
+ strProp = (String) toCheck.get("strProp");
+ strAProp = (String[]) toCheck.get("strAProp");
+ intAProp = (int[]) toCheck.get("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(3));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ fs = null;
+ context.ungetService(sr);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestBothProperties.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestBothProperties.java
new file mode 100644
index 0000000..695d61e
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestBothProperties.java
@@ -0,0 +1,618 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class TestBothProperties extends OSGiTestCase {
+
+ ComponentInstance instance;
+
+
+ public void setUp() {
+ Factory fact = Utils.getFactoryByName(context, "BothConfigurableCheckService");
+ Properties props = new Properties();
+ props.put("name", "under-test");
+ props.put("b", "1");
+ props.put("s", "1");
+ props.put("i", "1");
+ props.put("l", "1");
+ props.put("d", "1");
+ props.put("f", "1");
+ props.put("c", "a");
+ props.put("bool", "true");
+ props.put("bs", "{1,2,3}");
+ props.put("ss", "{1,2,3}");
+ props.put("is", "{1,2,3}");
+ props.put("ls", "{1,2,3}");
+ props.put("ds", "{1,2,3}");
+ props.put("fs", "{1,2,3}");
+ props.put("cs", "{a,b,c}");
+ props.put("bools", "{true,true,true}");
+ props.put("string", "foo");
+ props.put("strings", "{foo, bar, baz}");
+
+ try {
+ instance = fact.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Cannot create the under-test instance : " + e.getMessage());
+ }
+
+
+ }
+
+ public void tearDown() {
+ instance.dispose();
+ instance = null;
+ }
+
+ public void testConfigurationPrimitive() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ Byte b = (Byte) props.get("b");
+ Short s = (Short) props.get("s");
+ Integer i = (Integer) props.get("i");
+ Long l = (Long) props.get("l");
+ Double d = (Double) props.get("d");
+ Float f = (Float) props.get("f");
+ Character c = (Character) props.get("c");
+ Boolean bool = (Boolean) props.get("bool");
+
+ assertEquals("Check b", b, new Byte("1"));
+ assertEquals("Check s", s, new Short("1"));
+ assertEquals("Check i", i, new Integer("1"));
+ assertEquals("Check l", l, new Long("1"));
+ assertEquals("Check d", d, new Double("1"));
+ assertEquals("Check f", f, new Float("1"));
+ assertEquals("Check c", c, new Character('a'));
+ assertEquals("Check bool", bool, new Boolean("true"));
+
+ Integer upb = (Integer) props.get("upb");
+ Integer ups = (Integer) props.get("ups");
+ Integer upi = (Integer) props.get("upi");
+ Integer upl = (Integer) props.get("upl");
+ Integer upd = (Integer) props.get("upd");
+ Integer upf = (Integer) props.get("upf");
+ Integer upc = (Integer) props.get("upc");
+ Integer upbool = (Integer) props.get("upbool");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigure();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (Byte) props.get("b");
+ s = (Short) props.get("s");
+ i = (Integer) props.get("i");
+ l = (Long) props.get("l");
+ d = (Double) props.get("d");
+ f = (Float) props.get("f");
+ c = (Character) props.get("c");
+ bool = (Boolean) props.get("bool");
+
+ assertEquals("2) Check b ("+b+")", b, new Byte("2"));
+ assertEquals("2) Check s", s, new Short("2"));
+ assertEquals("2) Check i", i, new Integer("2"));
+ assertEquals("2) Check l", l, new Long("2"));
+ assertEquals("2) Check d", d, new Double("2"));
+ assertEquals("2) Check f", f, new Float("2"));
+ assertEquals("2) Check c", c, new Character('b'));
+ assertEquals("2) Check bool", bool, new Boolean("false"));
+
+ upb = (Integer) props.get("upb");
+ ups = (Integer) props.get("ups");
+ upi = (Integer) props.get("upi");
+ upl = (Integer) props.get("upl");
+ upd = (Integer) props.get("upd");
+ upf = (Integer) props.get("upf");
+ upc = (Integer) props.get("upc");
+ upbool = (Integer) props.get("upbool");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitiveString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ Byte b = (Byte) props.get("b");
+ Short s = (Short) props.get("s");
+ Integer i = (Integer) props.get("i");
+ Long l = (Long) props.get("l");
+ Double d = (Double) props.get("d");
+ Float f = (Float) props.get("f");
+ Character c = (Character) props.get("c");
+ Boolean bool = (Boolean) props.get("bool");
+
+ assertEquals("Check b", b, new Byte("1"));
+ assertEquals("Check s", s, new Short("1"));
+ assertEquals("Check i", i, new Integer("1"));
+ assertEquals("Check l", l, new Long("1"));
+ assertEquals("Check d", d, new Double("1"));
+ assertEquals("Check f", f, new Float("1"));
+ assertEquals("Check c", c, new Character('a'));
+ assertEquals("Check bool", bool, new Boolean("true"));
+
+ Integer upb = (Integer) props.get("upb");
+ Integer ups = (Integer) props.get("ups");
+ Integer upi = (Integer) props.get("upi");
+ Integer upl = (Integer) props.get("upl");
+ Integer upd = (Integer) props.get("upd");
+ Integer upf = (Integer) props.get("upf");
+ Integer upc = (Integer) props.get("upc");
+ Integer upbool = (Integer) props.get("upbool");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigureString();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (Byte) props.get("b");
+ s = (Short) props.get("s");
+ i = (Integer) props.get("i");
+ l = (Long) props.get("l");
+ d = (Double) props.get("d");
+ f = (Float) props.get("f");
+ c = (Character) props.get("c");
+ bool = (Boolean) props.get("bool");
+
+ assertEquals("2) Check b ("+b+")", b, new Byte("2"));
+ assertEquals("2) Check s", s, new Short("2"));
+ assertEquals("2) Check i", i, new Integer("2"));
+ assertEquals("2) Check l", l, new Long("2"));
+ assertEquals("2) Check d", d, new Double("2"));
+ assertEquals("2) Check f", f, new Float("2"));
+ assertEquals("2) Check c", c, new Character('b'));
+ assertEquals("2) Check bool", bool, new Boolean("false"));
+
+ upb = (Integer) props.get("upb");
+ ups = (Integer) props.get("ups");
+ upi = (Integer) props.get("upi");
+ upl = (Integer) props.get("upl");
+ upd = (Integer) props.get("upd");
+ upf = (Integer) props.get("upf");
+ upc = (Integer) props.get("upc");
+ upbool = (Integer) props.get("upbool");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitiveArrays() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ byte[] b = (byte[]) props.get("bs");
+ short[] s = (short[]) props.get("ss");
+ int[] i = (int[]) props.get("is");
+ long[] l = (long[]) props.get("ls");
+ double[] d = (double[]) props.get("ds");
+ float[] f = (float[]) props.get("fs");
+ char[] c = (char[]) props.get("cs");
+ boolean[] bool = (boolean[]) props.get("bools");
+
+ assertEquals("Check b 0", b[0], 1);
+ assertEquals("Check b 1", b[1], 2);
+ assertEquals("Check b 2", b[2], 3);
+ assertEquals("Check s 0", s[0], 1);
+ assertEquals("Check s 1", s[1], 2);
+ assertEquals("Check s 2", s[2], 3);
+ assertEquals("Check i 0", i[0], 1);
+ assertEquals("Check i 1", i[1], 2);
+ assertEquals("Check i 2", i[2], 3);
+ assertEquals("Check l 0", l[0], 1);
+ assertEquals("Check l 1", l[1], 2);
+ assertEquals("Check l 2", l[2], 3);
+ assertEquals("Check d 0", d[0], 1);
+ assertEquals("Check d 1", d[1], 2);
+ assertEquals("Check d 2", d[2], 3);
+ assertEquals("Check f 0", f[0], 1);
+ assertEquals("Check f 1", f[1], 2);
+ assertEquals("Check f 2", f[2], 3);
+ assertEquals("Check c 0", c[0], 'a');
+ assertEquals("Check c 1", c[1], 'b');
+ assertEquals("Check c 2", c[2], 'c');
+ assertTrue("Check bool 0", bool[0]);
+ assertTrue("Check bool 1", bool[0]);
+ assertTrue("Check bool 2", bool[0]);
+
+ Integer upb = (Integer) props.get("upbs");
+ Integer ups = (Integer) props.get("upss");
+ Integer upi = (Integer) props.get("upis");
+ Integer upl = (Integer) props.get("upls");
+ Integer upd = (Integer) props.get("upds");
+ Integer upf = (Integer) props.get("upfs");
+ Integer upc = (Integer) props.get("upcs");
+ Integer upbool = (Integer) props.get("upbools");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigure();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (byte[]) props.get("bs");
+ s = (short[]) props.get("ss");
+ i = (int[]) props.get("is");
+ l = (long[]) props.get("ls");
+ d = (double[]) props.get("ds");
+ f = (float[]) props.get("fs");
+ c = (char[]) props.get("cs");
+ bool = (boolean[]) props.get("bools");
+
+ assertEquals("2) Check b 0", b[0], 3);
+ assertEquals("2) Check b 1", b[1], 2);
+ assertEquals("2) Check b 2", b[2], 1);
+ assertEquals("2) Check s 0", s[0], 3);
+ assertEquals("2) Check s 1", s[1], 2);
+ assertEquals("2) Check s 2", s[2], 1);
+ assertEquals("2) Check i 0", i[0], 3);
+ assertEquals("2) Check i 1", i[1], 2);
+ assertEquals("2) Check i 2", i[2], 1);
+ assertEquals("2) Check l 0", l[0], 3);
+ assertEquals("2) Check l 1", l[1], 2);
+ assertEquals("2) Check l 2", l[2], 1);
+ assertEquals("2) Check d 0", d[0], 3);
+ assertEquals("2) Check d 1", d[1], 2);
+ assertEquals("2) Check d 2", d[2], 1);
+ assertEquals("2) Check f 0", f[0], 3);
+ assertEquals("2) Check f 1", f[1], 2);
+ assertEquals("2) Check f 2", f[2], 1);
+ assertEquals("2) Check c 0", c[0], 'c');
+ assertEquals("2) Check c 1", c[1], 'b');
+ assertEquals("2) Check c 2", c[2], 'a');
+ assertFalse("2) Check bool 0", bool[0]);
+ assertFalse("2) Check bool 1", bool[0]);
+ assertFalse("2) Check bool 2", bool[0]);
+
+ upb = (Integer) props.get("upbs");
+ ups = (Integer) props.get("upss");
+ upi = (Integer) props.get("upis");
+ upl = (Integer) props.get("upls");
+ upd = (Integer) props.get("upds");
+ upf = (Integer) props.get("upfs");
+ upc = (Integer) props.get("upcs");
+ upbool = (Integer) props.get("upbools");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitiveArraysString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ byte[] b = (byte[]) props.get("bs");
+ short[] s = (short[]) props.get("ss");
+ int[] i = (int[]) props.get("is");
+ long[] l = (long[]) props.get("ls");
+ double[] d = (double[]) props.get("ds");
+ float[] f = (float[]) props.get("fs");
+ char[] c = (char[]) props.get("cs");
+ boolean[] bool = (boolean[]) props.get("bools");
+
+ assertEquals("Check b 0", b[0], 1);
+ assertEquals("Check b 1", b[1], 2);
+ assertEquals("Check b 2", b[2], 3);
+ assertEquals("Check s 0", s[0], 1);
+ assertEquals("Check s 1", s[1], 2);
+ assertEquals("Check s 2", s[2], 3);
+ assertEquals("Check i 0", i[0], 1);
+ assertEquals("Check i 1", i[1], 2);
+ assertEquals("Check i 2", i[2], 3);
+ assertEquals("Check l 0", l[0], 1);
+ assertEquals("Check l 1", l[1], 2);
+ assertEquals("Check l 2", l[2], 3);
+ assertEquals("Check d 0", d[0], 1);
+ assertEquals("Check d 1", d[1], 2);
+ assertEquals("Check d 2", d[2], 3);
+ assertEquals("Check f 0", f[0], 1);
+ assertEquals("Check f 1", f[1], 2);
+ assertEquals("Check f 2", f[2], 3);
+ assertEquals("Check c 0", c[0], 'a');
+ assertEquals("Check c 1", c[1], 'b');
+ assertEquals("Check c 2", c[2], 'c');
+ assertTrue("Check bool 0", bool[0]);
+ assertTrue("Check bool 1", bool[0]);
+ assertTrue("Check bool 2", bool[0]);
+
+ Integer upb = (Integer) props.get("upbs");
+ Integer ups = (Integer) props.get("upss");
+ Integer upi = (Integer) props.get("upis");
+ Integer upl = (Integer) props.get("upls");
+ Integer upd = (Integer) props.get("upds");
+ Integer upf = (Integer) props.get("upfs");
+ Integer upc = (Integer) props.get("upcs");
+ Integer upbool = (Integer) props.get("upbools");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigureString();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (byte[]) props.get("bs");
+ s = (short[]) props.get("ss");
+ i = (int[]) props.get("is");
+ l = (long[]) props.get("ls");
+ d = (double[]) props.get("ds");
+ f = (float[]) props.get("fs");
+ c = (char[]) props.get("cs");
+ bool = (boolean[]) props.get("bools");
+
+ assertEquals("2) Check b 0", b[0], 3);
+ assertEquals("2) Check b 1", b[1], 2);
+ assertEquals("2) Check b 2", b[2], 1);
+ assertEquals("2) Check s 0", s[0], 3);
+ assertEquals("2) Check s 1", s[1], 2);
+ assertEquals("2) Check s 2", s[2], 1);
+ assertEquals("2) Check i 0", i[0], 3);
+ assertEquals("2) Check i 1", i[1], 2);
+ assertEquals("2) Check i 2", i[2], 1);
+ assertEquals("2) Check l 0", l[0], 3);
+ assertEquals("2) Check l 1", l[1], 2);
+ assertEquals("2) Check l 2", l[2], 1);
+ assertEquals("2) Check d 0", d[0], 3);
+ assertEquals("2) Check d 1", d[1], 2);
+ assertEquals("2) Check d 2", d[2], 1);
+ assertEquals("2) Check f 0", f[0], 3);
+ assertEquals("2) Check f 1", f[1], 2);
+ assertEquals("2) Check f 2", f[2], 1);
+ assertEquals("2) Check c 0", c[0], 'c');
+ assertEquals("2) Check c 1", c[1], 'b');
+ assertEquals("2) Check c 2", c[2], 'a');
+ assertFalse("2) Check bool 0", bool[0]);
+ assertFalse("2) Check bool 1", bool[0]);
+ assertFalse("2) Check bool 2", bool[0]);
+
+ upb = (Integer) props.get("upbs");
+ ups = (Integer) props.get("upss");
+ upi = (Integer) props.get("upis");
+ upl = (Integer) props.get("upls");
+ upd = (Integer) props.get("upds");
+ upf = (Integer) props.get("upfs");
+ upc = (Integer) props.get("upcs");
+ upbool = (Integer) props.get("upbools");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationObj() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ String s = (String) props.get("string");
+ String[] ss = (String[]) props.get("strings");
+
+ assertEquals("Check string", s, "foo");
+ assertEquals("Check strings 0", ss[0], "foo");
+ assertEquals("Check strings 1", ss[1], "bar");
+ assertEquals("Check strings 2", ss[2], "baz");
+
+ Integer upString = (Integer) props.get("upstring");
+ Integer upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("Check upString", upString, new Integer(1));
+ assertEquals("Check upStrings", upStrings, new Integer(1));
+
+ reconfigure();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ s = (String) props.get("string");
+ ss = (String[]) props.get("strings");
+
+ assertEquals("2) Check string", s, "bar");
+ assertEquals("2) Check strings 0", ss[0], "baz");
+ assertEquals("2) Check strings 1", ss[1], "bar");
+ assertEquals("2) Check strings 2", ss[2], "foo");
+
+ upString = (Integer) props.get("upstring");
+ upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("2) Check upstring", upString, new Integer(2));
+ assertEquals("2) Check upstrings", upStrings, new Integer(2));
+ }
+
+ public void testConfigurationObjString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ String s = (String) props.get("string");
+ String[] ss = (String[]) props.get("strings");
+
+ assertEquals("Check string", s, "foo");
+ assertEquals("Check strings 0", ss[0], "foo");
+ assertEquals("Check strings 1", ss[1], "bar");
+ assertEquals("Check strings 2", ss[2], "baz");
+
+ Integer upString = (Integer) props.get("upstring");
+ Integer upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("Check upString", upString, new Integer(1));
+ assertEquals("Check upStrings", upStrings, new Integer(1));
+
+ reconfigureString();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ s = (String) props.get("string");
+ ss = (String[]) props.get("strings");
+
+ assertEquals("2) Check string", s, "bar");
+ assertEquals("2) Check strings 0", ss[0], "baz");
+ assertEquals("2) Check strings 1", ss[1], "bar");
+ assertEquals("2) Check strings 2", ss[2], "foo");
+
+ upString = (Integer) props.get("upstring");
+ upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("2) Check upstring", upString, new Integer(2));
+ assertEquals("2) Check upstrings", upStrings, new Integer(2));
+ }
+
+ private void reconfigure() {
+ Properties props2 = new Properties();
+ props2.put("name", "under-test");
+ props2.put("b", new Byte("2"));
+ props2.put("s", new Short("2"));
+ props2.put("i", new Integer("2"));
+ props2.put("l", new Long("2"));
+ props2.put("d", new Double("2"));
+ props2.put("f", new Float("2"));
+ props2.put("c", new Character('b'));
+ props2.put("bool", new Boolean(false));
+ props2.put("bs", new byte[]{(byte)3,(byte)2,(byte)1});
+ props2.put("ss", new short[]{(short)3,(short)2,(short)1});
+ props2.put("is", new int[]{3,2,1});
+ props2.put("ls", new long[]{3,2,1});
+ props2.put("ds", new double[]{3,2,1});
+ props2.put("fs", new float[]{3,2,1});
+ props2.put("cs", new char[]{'c','b','a'});
+ props2.put("bools", new boolean[]{false,false,false});
+ props2.put("string", "bar");
+ props2.put("strings", new String[]{"baz", "bar", "foo"});
+
+ instance.reconfigure(props2);
+ }
+
+ private void reconfigureString() {
+ Properties props2 = new Properties();
+ props2.put("name", "under-test");
+ props2.put("b", "2");
+ props2.put("s", "2");
+ props2.put("i", "2");
+ props2.put("l", "2");
+ props2.put("d", "2");
+ props2.put("f", "2");
+ props2.put("c", "b");
+ props2.put("bool", "false");
+ props2.put("bs", "{3, 2,1}");
+ props2.put("ss", "{3, 2,1}");
+ props2.put("is", "{3, 2,1}");
+ props2.put("ls", "{3, 2,1}");
+ props2.put("ds", "{3, 2,1}");
+ props2.put("fs", "{3, 2,1}");
+ props2.put("cs", "{c, b , a}");
+ props2.put("bools", "{false,false,false}");
+ props2.put("string", "bar");
+ props2.put("strings", "{baz, bar, foo}");
+
+ instance.reconfigure(props2);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestFieldProperties.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestFieldProperties.java
new file mode 100644
index 0000000..b49c823
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestFieldProperties.java
@@ -0,0 +1,449 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class TestFieldProperties extends OSGiTestCase {
+
+ ComponentInstance instance;
+
+ public void setUp() {
+ Factory fact = Utils.getFactoryByName(context, "FieldConfigurableCheckService");
+ Properties props = new Properties();
+ props.put("name", "under-test");
+ props.put("b", "1");
+ props.put("s", "1");
+ props.put("i", "1");
+ props.put("l", "1");
+ props.put("d", "1");
+ props.put("f", "1");
+ props.put("c", "a");
+ props.put("bool", "true");
+ props.put("bs", "{1,2,3}");
+ props.put("ss", "{1,2,3}");
+ props.put("is", "{1,2,3}");
+ props.put("ls", "{1,2,3}");
+ props.put("ds", "{1,2,3}");
+ props.put("fs", "{1,2,3}");
+ props.put("cs", "{a,b,c}");
+ props.put("bools", "{true,true,true}");
+ props.put("string", "foo");
+ props.put("strings", "{foo, bar, baz}");
+
+ try {
+ instance = fact.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Cannot create the under-test instance : " + e.getMessage());
+ }
+
+
+ }
+
+ public void tearDown() {
+ instance.dispose();
+ instance = null;
+ }
+
+ public void testConfigurationPrimitive() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ Byte b = (Byte) props.get("b");
+ Short s = (Short) props.get("s");
+ Integer i = (Integer) props.get("i");
+ Long l = (Long) props.get("l");
+ Double d = (Double) props.get("d");
+ Float f = (Float) props.get("f");
+ Character c = (Character) props.get("c");
+ Boolean bool = (Boolean) props.get("bool");
+
+ assertEquals("Check b", b, new Byte("1"));
+ assertEquals("Check s", s, new Short("1"));
+ assertEquals("Check i", i, new Integer("1"));
+ assertEquals("Check l", l, new Long("1"));
+ assertEquals("Check d", d, new Double("1"));
+ assertEquals("Check f", f, new Float("1"));
+ assertEquals("Check c", c, new Character('a'));
+ assertEquals("Check bool", bool, new Boolean("true"));
+
+ reconfigure();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (Byte) props.get("b");
+ s = (Short) props.get("s");
+ i = (Integer) props.get("i");
+ l = (Long) props.get("l");
+ d = (Double) props.get("d");
+ f = (Float) props.get("f");
+ c = (Character) props.get("c");
+ bool = (Boolean) props.get("bool");
+
+ assertEquals("2) Check b", b, new Byte("2"));
+ assertEquals("2) Check s", s, new Short("2"));
+ assertEquals("2) Check i", i, new Integer("2"));
+ assertEquals("2) Check l", l, new Long("2"));
+ assertEquals("2) Check d", d, new Double("2"));
+ assertEquals("2) Check f", f, new Float("2"));
+ assertEquals("2) Check c", c, new Character('b'));
+ assertEquals("2) Check bool", bool, new Boolean("false"));
+
+ }
+
+ public void testConfigurationPrimitiveString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ Byte b = (Byte) props.get("b");
+ Short s = (Short) props.get("s");
+ Integer i = (Integer) props.get("i");
+ Long l = (Long) props.get("l");
+ Double d = (Double) props.get("d");
+ Float f = (Float) props.get("f");
+ Character c = (Character) props.get("c");
+ Boolean bool = (Boolean) props.get("bool");
+
+ assertEquals("Check b", b, new Byte("1"));
+ assertEquals("Check s", s, new Short("1"));
+ assertEquals("Check i", i, new Integer("1"));
+ assertEquals("Check l", l, new Long("1"));
+ assertEquals("Check d", d, new Double("1"));
+ assertEquals("Check f", f, new Float("1"));
+ assertEquals("Check c", c, new Character('a'));
+ assertEquals("Check bool", bool, new Boolean("true"));
+
+ reconfigureString();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (Byte) props.get("b");
+ s = (Short) props.get("s");
+ i = (Integer) props.get("i");
+ l = (Long) props.get("l");
+ d = (Double) props.get("d");
+ f = (Float) props.get("f");
+ c = (Character) props.get("c");
+ bool = (Boolean) props.get("bool");
+
+ assertEquals("2) Check b", b, new Byte("2"));
+ assertEquals("2) Check s", s, new Short("2"));
+ assertEquals("2) Check i", i, new Integer("2"));
+ assertEquals("2) Check l", l, new Long("2"));
+ assertEquals("2) Check d", d, new Double("2"));
+ assertEquals("2) Check f", f, new Float("2"));
+ assertEquals("2) Check c", c, new Character('b'));
+ assertEquals("2) Check bool", bool, new Boolean("false"));
+
+ }
+
+ public void testConfigurationPrimitiveArrays() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ byte[] b = (byte[]) props.get("bs");
+ short[] s = (short[]) props.get("ss");
+ int[] i = (int[]) props.get("is");
+ long[] l = (long[]) props.get("ls");
+ double[] d = (double[]) props.get("ds");
+ float[] f = (float[]) props.get("fs");
+ char[] c = (char[]) props.get("cs");
+ boolean[] bool = (boolean[]) props.get("bools");
+
+ assertEquals("Check b 0", b[0], 1);
+ assertEquals("Check b 1", b[1], 2);
+ assertEquals("Check b 2", b[2], 3);
+ assertEquals("Check s 0", s[0], 1);
+ assertEquals("Check s 1", s[1], 2);
+ assertEquals("Check s 2", s[2], 3);
+ assertEquals("Check i 0", i[0], 1);
+ assertEquals("Check i 1", i[1], 2);
+ assertEquals("Check i 2", i[2], 3);
+ assertEquals("Check l 0", l[0], 1);
+ assertEquals("Check l 1", l[1], 2);
+ assertEquals("Check l 2", l[2], 3);
+ assertEquals("Check d 0", d[0], 1);
+ assertEquals("Check d 1", d[1], 2);
+ assertEquals("Check d 2", d[2], 3);
+ assertEquals("Check f 0", f[0], 1);
+ assertEquals("Check f 1", f[1], 2);
+ assertEquals("Check f 2", f[2], 3);
+ assertEquals("Check c 0", c[0], 'a');
+ assertEquals("Check c 1", c[1], 'b');
+ assertEquals("Check c 2", c[2], 'c');
+ assertTrue("Check bool 0", bool[0]);
+ assertTrue("Check bool 1", bool[0]);
+ assertTrue("Check bool 2", bool[0]);
+
+ reconfigure();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (byte[]) props.get("bs");
+ s = (short[]) props.get("ss");
+ i = (int[]) props.get("is");
+ l = (long[]) props.get("ls");
+ d = (double[]) props.get("ds");
+ f = (float[]) props.get("fs");
+ c = (char[]) props.get("cs");
+ bool = (boolean[]) props.get("bools");
+
+ assertEquals("2) Check b 0", b[0], 3);
+ assertEquals("2) Check b 1", b[1], 2);
+ assertEquals("2) Check b 2", b[2], 1);
+ assertEquals("2) Check s 0", s[0], 3);
+ assertEquals("2) Check s 1", s[1], 2);
+ assertEquals("2) Check s 2", s[2], 1);
+ assertEquals("2) Check i 0", i[0], 3);
+ assertEquals("2) Check i 1", i[1], 2);
+ assertEquals("2) Check i 2", i[2], 1);
+ assertEquals("2) Check l 0", l[0], 3);
+ assertEquals("2) Check l 1", l[1], 2);
+ assertEquals("2) Check l 2", l[2], 1);
+ assertEquals("2) Check d 0", d[0], 3);
+ assertEquals("2) Check d 1", d[1], 2);
+ assertEquals("2) Check d 2", d[2], 1);
+ assertEquals("2) Check f 0", f[0], 3);
+ assertEquals("2) Check f 1", f[1], 2);
+ assertEquals("2) Check f 2", f[2], 1);
+ assertEquals("2) Check c 0", c[0], 'c');
+ assertEquals("2) Check c 1", c[1], 'b');
+ assertEquals("2) Check c 2", c[2], 'a');
+ assertFalse("2) Check bool 0", bool[0]);
+ assertFalse("2) Check bool 1", bool[0]);
+ assertFalse("2) Check bool 2", bool[0]);
+
+ }
+
+ public void testConfigurationPrimitiveArraysString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ byte[] b = (byte[]) props.get("bs");
+ short[] s = (short[]) props.get("ss");
+ int[] i = (int[]) props.get("is");
+ long[] l = (long[]) props.get("ls");
+ double[] d = (double[]) props.get("ds");
+ float[] f = (float[]) props.get("fs");
+ char[] c = (char[]) props.get("cs");
+ boolean[] bool = (boolean[]) props.get("bools");
+
+ assertEquals("Check b 0", b[0], 1);
+ assertEquals("Check b 1", b[1], 2);
+ assertEquals("Check b 2", b[2], 3);
+ assertEquals("Check s 0", s[0], 1);
+ assertEquals("Check s 1", s[1], 2);
+ assertEquals("Check s 2", s[2], 3);
+ assertEquals("Check i 0", i[0], 1);
+ assertEquals("Check i 1", i[1], 2);
+ assertEquals("Check i 2", i[2], 3);
+ assertEquals("Check l 0", l[0], 1);
+ assertEquals("Check l 1", l[1], 2);
+ assertEquals("Check l 2", l[2], 3);
+ assertEquals("Check d 0", d[0], 1);
+ assertEquals("Check d 1", d[1], 2);
+ assertEquals("Check d 2", d[2], 3);
+ assertEquals("Check f 0", f[0], 1);
+ assertEquals("Check f 1", f[1], 2);
+ assertEquals("Check f 2", f[2], 3);
+ assertEquals("Check c 0", c[0], 'a');
+ assertEquals("Check c 1", c[1], 'b');
+ assertEquals("Check c 2", c[2], 'c');
+ assertTrue("Check bool 0", bool[0]);
+ assertTrue("Check bool 1", bool[0]);
+ assertTrue("Check bool 2", bool[0]);
+
+ reconfigureString();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (byte[]) props.get("bs");
+ s = (short[]) props.get("ss");
+ i = (int[]) props.get("is");
+ l = (long[]) props.get("ls");
+ d = (double[]) props.get("ds");
+ f = (float[]) props.get("fs");
+ c = (char[]) props.get("cs");
+ bool = (boolean[]) props.get("bools");
+
+ assertEquals("2) Check b 0", b[0], 3);
+ assertEquals("2) Check b 1", b[1], 2);
+ assertEquals("2) Check b 2", b[2], 1);
+ assertEquals("2) Check s 0", s[0], 3);
+ assertEquals("2) Check s 1", s[1], 2);
+ assertEquals("2) Check s 2", s[2], 1);
+ assertEquals("2) Check i 0", i[0], 3);
+ assertEquals("2) Check i 1", i[1], 2);
+ assertEquals("2) Check i 2", i[2], 1);
+ assertEquals("2) Check l 0", l[0], 3);
+ assertEquals("2) Check l 1", l[1], 2);
+ assertEquals("2) Check l 2", l[2], 1);
+ assertEquals("2) Check d 0", d[0], 3);
+ assertEquals("2) Check d 1", d[1], 2);
+ assertEquals("2) Check d 2", d[2], 1);
+ assertEquals("2) Check f 0", f[0], 3);
+ assertEquals("2) Check f 1", f[1], 2);
+ assertEquals("2) Check f 2", f[2], 1);
+ assertEquals("2) Check c 0", c[0], 'c');
+ assertEquals("2) Check c 1", c[1], 'b');
+ assertEquals("2) Check c 2", c[2], 'a');
+ assertFalse("2) Check bool 0", bool[0]);
+ assertFalse("2) Check bool 1", bool[0]);
+ assertFalse("2) Check bool 2", bool[0]);
+
+ }
+
+ public void testConfigurationObj() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ String s = (String) props.get("string");
+ String[] ss = (String[]) props.get("strings");
+
+ assertEquals("Check string", s, "foo");
+ assertEquals("Check strings 0", ss[0], "foo");
+ assertEquals("Check strings 1", ss[1], "bar");
+ assertEquals("Check strings 2", ss[2], "baz");
+
+ reconfigure();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ s = (String) props.get("string");
+ ss = (String[]) props.get("strings");
+
+ assertEquals("2) Check string", s, "bar");
+ assertEquals("2) Check strings 0", ss[0], "baz");
+ assertEquals("2) Check strings 1", ss[1], "bar");
+ assertEquals("2) Check strings 2", ss[2], "foo");
+ }
+
+ public void testConfigurationObjString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ String s = (String) props.get("string");
+ String[] ss = (String[]) props.get("strings");
+
+ assertEquals("Check string", s, "foo");
+ assertEquals("Check strings 0", ss[0], "foo");
+ assertEquals("Check strings 1", ss[1], "bar");
+ assertEquals("Check strings 2", ss[2], "baz");
+
+ reconfigureString();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ s = (String) props.get("string");
+ ss = (String[]) props.get("strings");
+
+ assertEquals("2) Check string", s, "bar");
+ assertEquals("2) Check strings 0", ss[0], "baz");
+ assertEquals("2) Check strings 1", ss[1], "bar");
+ assertEquals("2) Check strings 2", ss[2], "foo");
+ }
+
+ private void reconfigure() {
+ Properties props2 = new Properties();
+ props2.put("name", "under-test");
+ props2.put("b", new Byte("2"));
+ props2.put("s", new Short("2"));
+ props2.put("i", new Integer("2"));
+ props2.put("l", new Long("2"));
+ props2.put("d", new Double("2"));
+ props2.put("f", new Float("2"));
+ props2.put("c", new Character('b'));
+ props2.put("bool", new Boolean(false));
+ props2.put("bs", new byte[]{(byte)3,(byte)2,(byte)1});
+ props2.put("ss", new short[]{(short)3,(short)2,(short)1});
+ props2.put("is", new int[]{3,2,1});
+ props2.put("ls", new long[]{3,2,1});
+ props2.put("ds", new double[]{3,2,1});
+ props2.put("fs", new float[]{3,2,1});
+ props2.put("cs", new char[]{'c','b','a'});
+ props2.put("bools", new boolean[]{false,false,false});
+ props2.put("string", "bar");
+ props2.put("strings", new String[]{"baz", "bar", "foo"});
+
+ instance.reconfigure(props2);
+ }
+
+ private void reconfigureString() {
+ Properties props2 = new Properties();
+ props2.put("name", "under-test");
+ props2.put("b", "2");
+ props2.put("s", "2");
+ props2.put("i", "2");
+ props2.put("l", "2");
+ props2.put("d", "2");
+ props2.put("f", "2");
+ props2.put("c", "b");
+ props2.put("bool", "false");
+ props2.put("bs", "{3, 2,1}");
+ props2.put("ss", "{3, 2,1}");
+ props2.put("is", "{3, 2,1}");
+ props2.put("ls", "{3, 2,1}");
+ props2.put("ds", "{3, 2,1}");
+ props2.put("fs", "{3, 2,1}");
+ props2.put("cs", "{c, b , a}");
+ props2.put("bools", "{false,false,false}");
+ props2.put("string", "bar");
+ props2.put("strings", "{baz, bar, foo}");
+
+ instance.reconfigure(props2);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestMethodProperties.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestMethodProperties.java
new file mode 100644
index 0000000..7e1dcea
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestMethodProperties.java
@@ -0,0 +1,1145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class TestMethodProperties extends OSGiTestCase {
+
+ ComponentInstance instance;
+
+ ComponentInstance instance2;
+
+ public void setUp() {
+ Factory fact = Utils.getFactoryByName(context, "MethodConfigurableCheckService");
+ Properties props = new Properties();
+ props.put("name", "under-test");
+ props.put("b", "1");
+ props.put("s", "1");
+ props.put("i", "1");
+ props.put("l", "1");
+ props.put("d", "1");
+ props.put("f", "1");
+ props.put("c", "a");
+ props.put("bool", "true");
+ props.put("bs", "{1,2,3}");
+ props.put("ss", "{1,2,3}");
+ props.put("is", "{1,2,3}");
+ props.put("ls", "{1,2,3}");
+ props.put("ds", "{1,2,3}");
+ props.put("fs", "{1,2,3}");
+ props.put("cs", "{a,b,c}");
+ props.put("bools", "{true,true,true}");
+ props.put("string", "foo");
+ props.put("strings", "{foo, bar, baz}");
+
+ try {
+ instance = fact.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Cannot create the under-test instance : " + e.getMessage());
+ }
+
+ Properties props2 = new Properties();
+ props2.put("name", "under-test-2");
+ props2.put("b", new Byte("1"));
+ props2.put("s", new Short("1"));
+ props2.put("i", new Integer("1"));
+ props2.put("l", new Long("1"));
+ props2.put("d", new Double("1"));
+ props2.put("f", new Float("1"));
+ props2.put("c", new Character('a'));
+ props2.put("bool", new Boolean(true));
+ props2.put("bs", new byte[] {1,2,3});
+ props2.put("ss", new short[] {1,2,3});
+ props2.put("is", new int[] {1,2,3});
+ props2.put("ls", new long[] {1,2,3});
+ props2.put("ds", new double[] {1,2,3});
+ props2.put("fs", new float[] {1,2,3});
+ props2.put("cs", new char[] {'a','b','c'});
+ props2.put("bools", new boolean[] {true,true,true});
+ props2.put("string", "foo");
+ props2.put("strings", new String[] {"foo", "bar", "baz"});
+
+ try {
+ instance2 = fact.createComponentInstance(props2);
+ } catch(Exception e) {
+ e.printStackTrace();
+ fail("Cannot create the under-test instance 2 : " + e.getMessage());
+ }
+
+
+ }
+
+ public void tearDown() {
+ instance.dispose();
+ instance2.dispose();
+ instance = null;
+ instance2 = null;
+ }
+
+ public void testConfigurationPrimitive() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ Byte b = (Byte) props.get("b");
+ Short s = (Short) props.get("s");
+ Integer i = (Integer) props.get("i");
+ Long l = (Long) props.get("l");
+ Double d = (Double) props.get("d");
+ Float f = (Float) props.get("f");
+ Character c = (Character) props.get("c");
+ Boolean bool = (Boolean) props.get("bool");
+
+ assertEquals("Check b", b, new Byte("1"));
+ assertEquals("Check s", s, new Short("1"));
+ assertEquals("Check i", i, new Integer("1"));
+ assertEquals("Check l", l, new Long("1"));
+ assertEquals("Check d", d, new Double("1"));
+ assertEquals("Check f", f, new Float("1"));
+ assertEquals("Check c", c, new Character('a'));
+ assertEquals("Check bool", bool, new Boolean("true"));
+
+ Integer upb = (Integer) props.get("upb");
+ Integer ups = (Integer) props.get("ups");
+ Integer upi = (Integer) props.get("upi");
+ Integer upl = (Integer) props.get("upl");
+ Integer upd = (Integer) props.get("upd");
+ Integer upf = (Integer) props.get("upf");
+ Integer upc = (Integer) props.get("upc");
+ Integer upbool = (Integer) props.get("upbool");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigure(instance);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (Byte) props.get("b");
+ s = (Short) props.get("s");
+ i = (Integer) props.get("i");
+ l = (Long) props.get("l");
+ d = (Double) props.get("d");
+ f = (Float) props.get("f");
+ c = (Character) props.get("c");
+ bool = (Boolean) props.get("bool");
+
+ assertEquals("2) Check b ("+b+")", b, new Byte("2"));
+ assertEquals("2) Check s", s, new Short("2"));
+ assertEquals("2) Check i", i, new Integer("2"));
+ assertEquals("2) Check l", l, new Long("2"));
+ assertEquals("2) Check d", d, new Double("2"));
+ assertEquals("2) Check f", f, new Float("2"));
+ assertEquals("2) Check c", c, new Character('b'));
+ assertEquals("2) Check bool", bool, new Boolean("false"));
+
+ upb = (Integer) props.get("upb");
+ ups = (Integer) props.get("ups");
+ upi = (Integer) props.get("upi");
+ upl = (Integer) props.get("upl");
+ upd = (Integer) props.get("upd");
+ upf = (Integer) props.get("upf");
+ upc = (Integer) props.get("upc");
+ upbool = (Integer) props.get("upbool");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitiveString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ Byte b = (Byte) props.get("b");
+ Short s = (Short) props.get("s");
+ Integer i = (Integer) props.get("i");
+ Long l = (Long) props.get("l");
+ Double d = (Double) props.get("d");
+ Float f = (Float) props.get("f");
+ Character c = (Character) props.get("c");
+ Boolean bool = (Boolean) props.get("bool");
+
+ assertEquals("Check b", b, new Byte("1"));
+ assertEquals("Check s", s, new Short("1"));
+ assertEquals("Check i", i, new Integer("1"));
+ assertEquals("Check l", l, new Long("1"));
+ assertEquals("Check d", d, new Double("1"));
+ assertEquals("Check f", f, new Float("1"));
+ assertEquals("Check c", c, new Character('a'));
+ assertEquals("Check bool", bool, new Boolean("true"));
+
+ Integer upb = (Integer) props.get("upb");
+ Integer ups = (Integer) props.get("ups");
+ Integer upi = (Integer) props.get("upi");
+ Integer upl = (Integer) props.get("upl");
+ Integer upd = (Integer) props.get("upd");
+ Integer upf = (Integer) props.get("upf");
+ Integer upc = (Integer) props.get("upc");
+ Integer upbool = (Integer) props.get("upbool");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigureString(instance);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (Byte) props.get("b");
+ s = (Short) props.get("s");
+ i = (Integer) props.get("i");
+ l = (Long) props.get("l");
+ d = (Double) props.get("d");
+ f = (Float) props.get("f");
+ c = (Character) props.get("c");
+ bool = (Boolean) props.get("bool");
+
+ assertEquals("2) Check b ("+b+")", b, new Byte("2"));
+ assertEquals("2) Check s", s, new Short("2"));
+ assertEquals("2) Check i", i, new Integer("2"));
+ assertEquals("2) Check l", l, new Long("2"));
+ assertEquals("2) Check d", d, new Double("2"));
+ assertEquals("2) Check f", f, new Float("2"));
+ assertEquals("2) Check c", c, new Character('b'));
+ assertEquals("2) Check bool", bool, new Boolean("false"));
+
+ upb = (Integer) props.get("upb");
+ ups = (Integer) props.get("ups");
+ upi = (Integer) props.get("upi");
+ upl = (Integer) props.get("upl");
+ upd = (Integer) props.get("upd");
+ upf = (Integer) props.get("upf");
+ upc = (Integer) props.get("upc");
+ upbool = (Integer) props.get("upbool");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitiveArrays() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ byte[] b = (byte[]) props.get("bs");
+ short[] s = (short[]) props.get("ss");
+ int[] i = (int[]) props.get("is");
+ long[] l = (long[]) props.get("ls");
+ double[] d = (double[]) props.get("ds");
+ float[] f = (float[]) props.get("fs");
+ char[] c = (char[]) props.get("cs");
+ boolean[] bool = (boolean[]) props.get("bools");
+
+ assertEquals("Check b 0", b[0], 1);
+ assertEquals("Check b 1", b[1], 2);
+ assertEquals("Check b 2", b[2], 3);
+ assertEquals("Check s 0", s[0], 1);
+ assertEquals("Check s 1", s[1], 2);
+ assertEquals("Check s 2", s[2], 3);
+ assertEquals("Check i 0", i[0], 1);
+ assertEquals("Check i 1", i[1], 2);
+ assertEquals("Check i 2", i[2], 3);
+ assertEquals("Check l 0", l[0], 1);
+ assertEquals("Check l 1", l[1], 2);
+ assertEquals("Check l 2", l[2], 3);
+ assertEquals("Check d 0", d[0], 1);
+ assertEquals("Check d 1", d[1], 2);
+ assertEquals("Check d 2", d[2], 3);
+ assertEquals("Check f 0", f[0], 1);
+ assertEquals("Check f 1", f[1], 2);
+ assertEquals("Check f 2", f[2], 3);
+ assertEquals("Check c 0", c[0], 'a');
+ assertEquals("Check c 1", c[1], 'b');
+ assertEquals("Check c 2", c[2], 'c');
+ assertTrue("Check bool 0", bool[0]);
+ assertTrue("Check bool 1", bool[0]);
+ assertTrue("Check bool 2", bool[0]);
+
+ Integer upb = (Integer) props.get("upbs");
+ Integer ups = (Integer) props.get("upss");
+ Integer upi = (Integer) props.get("upis");
+ Integer upl = (Integer) props.get("upls");
+ Integer upd = (Integer) props.get("upds");
+ Integer upf = (Integer) props.get("upfs");
+ Integer upc = (Integer) props.get("upcs");
+ Integer upbool = (Integer) props.get("upbools");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigure(instance);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (byte[]) props.get("bs");
+ s = (short[]) props.get("ss");
+ i = (int[]) props.get("is");
+ l = (long[]) props.get("ls");
+ d = (double[]) props.get("ds");
+ f = (float[]) props.get("fs");
+ c = (char[]) props.get("cs");
+ bool = (boolean[]) props.get("bools");
+
+ assertEquals("2) Check b 0", b[0], 3);
+ assertEquals("2) Check b 1", b[1], 2);
+ assertEquals("2) Check b 2", b[2], 1);
+ assertEquals("2) Check s 0", s[0], 3);
+ assertEquals("2) Check s 1", s[1], 2);
+ assertEquals("2) Check s 2", s[2], 1);
+ assertEquals("2) Check i 0", i[0], 3);
+ assertEquals("2) Check i 1", i[1], 2);
+ assertEquals("2) Check i 2", i[2], 1);
+ assertEquals("2) Check l 0", l[0], 3);
+ assertEquals("2) Check l 1", l[1], 2);
+ assertEquals("2) Check l 2", l[2], 1);
+ assertEquals("2) Check d 0", d[0], 3);
+ assertEquals("2) Check d 1", d[1], 2);
+ assertEquals("2) Check d 2", d[2], 1);
+ assertEquals("2) Check f 0", f[0], 3);
+ assertEquals("2) Check f 1", f[1], 2);
+ assertEquals("2) Check f 2", f[2], 1);
+ assertEquals("2) Check c 0", c[0], 'c');
+ assertEquals("2) Check c 1", c[1], 'b');
+ assertEquals("2) Check c 2", c[2], 'a');
+ assertFalse("2) Check bool 0", bool[0]);
+ assertFalse("2) Check bool 1", bool[0]);
+ assertFalse("2) Check bool 2", bool[0]);
+
+ upb = (Integer) props.get("upbs");
+ ups = (Integer) props.get("upss");
+ upi = (Integer) props.get("upis");
+ upl = (Integer) props.get("upls");
+ upd = (Integer) props.get("upds");
+ upf = (Integer) props.get("upfs");
+ upc = (Integer) props.get("upcs");
+ upbool = (Integer) props.get("upbools");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitiveArraysString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ byte[] b = (byte[]) props.get("bs");
+ short[] s = (short[]) props.get("ss");
+ int[] i = (int[]) props.get("is");
+ long[] l = (long[]) props.get("ls");
+ double[] d = (double[]) props.get("ds");
+ float[] f = (float[]) props.get("fs");
+ char[] c = (char[]) props.get("cs");
+ boolean[] bool = (boolean[]) props.get("bools");
+
+ assertEquals("Check b 0", b[0], 1);
+ assertEquals("Check b 1", b[1], 2);
+ assertEquals("Check b 2", b[2], 3);
+ assertEquals("Check s 0", s[0], 1);
+ assertEquals("Check s 1", s[1], 2);
+ assertEquals("Check s 2", s[2], 3);
+ assertEquals("Check i 0", i[0], 1);
+ assertEquals("Check i 1", i[1], 2);
+ assertEquals("Check i 2", i[2], 3);
+ assertEquals("Check l 0", l[0], 1);
+ assertEquals("Check l 1", l[1], 2);
+ assertEquals("Check l 2", l[2], 3);
+ assertEquals("Check d 0", d[0], 1);
+ assertEquals("Check d 1", d[1], 2);
+ assertEquals("Check d 2", d[2], 3);
+ assertEquals("Check f 0", f[0], 1);
+ assertEquals("Check f 1", f[1], 2);
+ assertEquals("Check f 2", f[2], 3);
+ assertEquals("Check c 0", c[0], 'a');
+ assertEquals("Check c 1", c[1], 'b');
+ assertEquals("Check c 2", c[2], 'c');
+ assertTrue("Check bool 0", bool[0]);
+ assertTrue("Check bool 1", bool[0]);
+ assertTrue("Check bool 2", bool[0]);
+
+ Integer upb = (Integer) props.get("upbs");
+ Integer ups = (Integer) props.get("upss");
+ Integer upi = (Integer) props.get("upis");
+ Integer upl = (Integer) props.get("upls");
+ Integer upd = (Integer) props.get("upds");
+ Integer upf = (Integer) props.get("upfs");
+ Integer upc = (Integer) props.get("upcs");
+ Integer upbool = (Integer) props.get("upbools");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigureString(instance);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (byte[]) props.get("bs");
+ s = (short[]) props.get("ss");
+ i = (int[]) props.get("is");
+ l = (long[]) props.get("ls");
+ d = (double[]) props.get("ds");
+ f = (float[]) props.get("fs");
+ c = (char[]) props.get("cs");
+ bool = (boolean[]) props.get("bools");
+
+ assertEquals("2) Check b 0", b[0], 3);
+ assertEquals("2) Check b 1", b[1], 2);
+ assertEquals("2) Check b 2", b[2], 1);
+ assertEquals("2) Check s 0", s[0], 3);
+ assertEquals("2) Check s 1", s[1], 2);
+ assertEquals("2) Check s 2", s[2], 1);
+ assertEquals("2) Check i 0", i[0], 3);
+ assertEquals("2) Check i 1", i[1], 2);
+ assertEquals("2) Check i 2", i[2], 1);
+ assertEquals("2) Check l 0", l[0], 3);
+ assertEquals("2) Check l 1", l[1], 2);
+ assertEquals("2) Check l 2", l[2], 1);
+ assertEquals("2) Check d 0", d[0], 3);
+ assertEquals("2) Check d 1", d[1], 2);
+ assertEquals("2) Check d 2", d[2], 1);
+ assertEquals("2) Check f 0", f[0], 3);
+ assertEquals("2) Check f 1", f[1], 2);
+ assertEquals("2) Check f 2", f[2], 1);
+ assertEquals("2) Check c 0", c[0], 'c');
+ assertEquals("2) Check c 1", c[1], 'b');
+ assertEquals("2) Check c 2", c[2], 'a');
+ assertFalse("2) Check bool 0", bool[0]);
+ assertFalse("2) Check bool 1", bool[0]);
+ assertFalse("2) Check bool 2", bool[0]);
+
+ upb = (Integer) props.get("upbs");
+ ups = (Integer) props.get("upss");
+ upi = (Integer) props.get("upis");
+ upl = (Integer) props.get("upls");
+ upd = (Integer) props.get("upds");
+ upf = (Integer) props.get("upfs");
+ upc = (Integer) props.get("upcs");
+ upbool = (Integer) props.get("upbools");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationObj() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ String s = (String) props.get("string");
+ String[] ss = (String[]) props.get("strings");
+
+ assertEquals("Check string", s, "foo");
+ assertEquals("Check strings 0", ss[0], "foo");
+ assertEquals("Check strings 1", ss[1], "bar");
+ assertEquals("Check strings 2", ss[2], "baz");
+
+ Integer upString = (Integer) props.get("upstring");
+ Integer upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("Check upString", upString, new Integer(1));
+ assertEquals("Check upStrings", upStrings, new Integer(1));
+
+ reconfigure(instance);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ s = (String) props.get("string");
+ ss = (String[]) props.get("strings");
+
+ assertEquals("2) Check string", s, "bar");
+ assertEquals("2) Check strings 0", ss[0], "baz");
+ assertEquals("2) Check strings 1", ss[1], "bar");
+ assertEquals("2) Check strings 2", ss[2], "foo");
+
+ upString = (Integer) props.get("upstring");
+ upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("2) Check upString", upString, new Integer(2));
+ assertEquals("2) Check upStrings", upStrings, new Integer(2));
+ }
+
+ public void testConfigurationObjString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ String s = (String) props.get("string");
+ String[] ss = (String[]) props.get("strings");
+
+ assertEquals("Check string", s, "foo");
+ assertEquals("Check strings 0", ss[0], "foo");
+ assertEquals("Check strings 1", ss[1], "bar");
+ assertEquals("Check strings 2", ss[2], "baz");
+
+ Integer upString = (Integer) props.get("upstring");
+ Integer upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("Check upString", upString, new Integer(1));
+ assertEquals("Check upStrings", upStrings, new Integer(1));
+
+ reconfigureString(instance);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ s = (String) props.get("string");
+ ss = (String[]) props.get("strings");
+
+ assertEquals("2) Check string", s, "bar");
+ assertEquals("2) Check strings 0", ss[0], "baz");
+ assertEquals("2) Check strings 1", ss[1], "bar");
+ assertEquals("2) Check strings 2", ss[2], "foo");
+
+ upString = (Integer) props.get("upstring");
+ upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("2) Check upString", upString, new Integer(2));
+ assertEquals("2) Check upStrings", upStrings, new Integer(2));
+ }
+
+ public void testConfigurationPrimitive2() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ Byte b = (Byte) props.get("b");
+ Short s = (Short) props.get("s");
+ Integer i = (Integer) props.get("i");
+ Long l = (Long) props.get("l");
+ Double d = (Double) props.get("d");
+ Float f = (Float) props.get("f");
+ Character c = (Character) props.get("c");
+ Boolean bool = (Boolean) props.get("bool");
+
+ assertEquals("Check b", b, new Byte("1"));
+ assertEquals("Check s", s, new Short("1"));
+ assertEquals("Check i", i, new Integer("1"));
+ assertEquals("Check l", l, new Long("1"));
+ assertEquals("Check d", d, new Double("1"));
+ assertEquals("Check f", f, new Float("1"));
+ assertEquals("Check c", c, new Character('a'));
+ assertEquals("Check bool", bool, new Boolean("true"));
+
+ Integer upb = (Integer) props.get("upb");
+ Integer ups = (Integer) props.get("ups");
+ Integer upi = (Integer) props.get("upi");
+ Integer upl = (Integer) props.get("upl");
+ Integer upd = (Integer) props.get("upd");
+ Integer upf = (Integer) props.get("upf");
+ Integer upc = (Integer) props.get("upc");
+ Integer upbool = (Integer) props.get("upbool");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigure(instance2);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (Byte) props.get("b");
+ s = (Short) props.get("s");
+ i = (Integer) props.get("i");
+ l = (Long) props.get("l");
+ d = (Double) props.get("d");
+ f = (Float) props.get("f");
+ c = (Character) props.get("c");
+ bool = (Boolean) props.get("bool");
+
+ assertEquals("2) Check b ("+b+")", b, new Byte("2"));
+ assertEquals("2) Check s", s, new Short("2"));
+ assertEquals("2) Check i", i, new Integer("2"));
+ assertEquals("2) Check l", l, new Long("2"));
+ assertEquals("2) Check d", d, new Double("2"));
+ assertEquals("2) Check f", f, new Float("2"));
+ assertEquals("2) Check c", c, new Character('b'));
+ assertEquals("2) Check bool", bool, new Boolean("false"));
+
+ upb = (Integer) props.get("upb");
+ ups = (Integer) props.get("ups");
+ upi = (Integer) props.get("upi");
+ upl = (Integer) props.get("upl");
+ upd = (Integer) props.get("upd");
+ upf = (Integer) props.get("upf");
+ upc = (Integer) props.get("upc");
+ upbool = (Integer) props.get("upbool");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitive2String() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ Byte b = (Byte) props.get("b");
+ Short s = (Short) props.get("s");
+ Integer i = (Integer) props.get("i");
+ Long l = (Long) props.get("l");
+ Double d = (Double) props.get("d");
+ Float f = (Float) props.get("f");
+ Character c = (Character) props.get("c");
+ Boolean bool = (Boolean) props.get("bool");
+
+ assertEquals("Check b", b, new Byte("1"));
+ assertEquals("Check s", s, new Short("1"));
+ assertEquals("Check i", i, new Integer("1"));
+ assertEquals("Check l", l, new Long("1"));
+ assertEquals("Check d", d, new Double("1"));
+ assertEquals("Check f", f, new Float("1"));
+ assertEquals("Check c", c, new Character('a'));
+ assertEquals("Check bool", bool, new Boolean("true"));
+
+ Integer upb = (Integer) props.get("upb");
+ Integer ups = (Integer) props.get("ups");
+ Integer upi = (Integer) props.get("upi");
+ Integer upl = (Integer) props.get("upl");
+ Integer upd = (Integer) props.get("upd");
+ Integer upf = (Integer) props.get("upf");
+ Integer upc = (Integer) props.get("upc");
+ Integer upbool = (Integer) props.get("upbool");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigureString(instance2);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (Byte) props.get("b");
+ s = (Short) props.get("s");
+ i = (Integer) props.get("i");
+ l = (Long) props.get("l");
+ d = (Double) props.get("d");
+ f = (Float) props.get("f");
+ c = (Character) props.get("c");
+ bool = (Boolean) props.get("bool");
+
+ assertEquals("2) Check b ("+b+")", b, new Byte("2"));
+ assertEquals("2) Check s", s, new Short("2"));
+ assertEquals("2) Check i", i, new Integer("2"));
+ assertEquals("2) Check l", l, new Long("2"));
+ assertEquals("2) Check d", d, new Double("2"));
+ assertEquals("2) Check f", f, new Float("2"));
+ assertEquals("2) Check c", c, new Character('b'));
+ assertEquals("2) Check bool", bool, new Boolean("false"));
+
+ upb = (Integer) props.get("upb");
+ ups = (Integer) props.get("ups");
+ upi = (Integer) props.get("upi");
+ upl = (Integer) props.get("upl");
+ upd = (Integer) props.get("upd");
+ upf = (Integer) props.get("upf");
+ upc = (Integer) props.get("upc");
+ upbool = (Integer) props.get("upbool");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitiveArrays2() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ byte[] b = (byte[]) props.get("bs");
+ short[] s = (short[]) props.get("ss");
+ int[] i = (int[]) props.get("is");
+ long[] l = (long[]) props.get("ls");
+ double[] d = (double[]) props.get("ds");
+ float[] f = (float[]) props.get("fs");
+ char[] c = (char[]) props.get("cs");
+ boolean[] bool = (boolean[]) props.get("bools");
+
+ assertEquals("Check b 0", b[0], 1);
+ assertEquals("Check b 1", b[1], 2);
+ assertEquals("Check b 2", b[2], 3);
+ assertEquals("Check s 0", s[0], 1);
+ assertEquals("Check s 1", s[1], 2);
+ assertEquals("Check s 2", s[2], 3);
+ assertEquals("Check i 0", i[0], 1);
+ assertEquals("Check i 1", i[1], 2);
+ assertEquals("Check i 2", i[2], 3);
+ assertEquals("Check l 0", l[0], 1);
+ assertEquals("Check l 1", l[1], 2);
+ assertEquals("Check l 2", l[2], 3);
+ assertEquals("Check d 0", d[0], 1);
+ assertEquals("Check d 1", d[1], 2);
+ assertEquals("Check d 2", d[2], 3);
+ assertEquals("Check f 0", f[0], 1);
+ assertEquals("Check f 1", f[1], 2);
+ assertEquals("Check f 2", f[2], 3);
+ assertEquals("Check c 0", c[0], 'a');
+ assertEquals("Check c 1", c[1], 'b');
+ assertEquals("Check c 2", c[2], 'c');
+ assertTrue("Check bool 0", bool[0]);
+ assertTrue("Check bool 1", bool[0]);
+ assertTrue("Check bool 2", bool[0]);
+
+ Integer upb = (Integer) props.get("upbs");
+ Integer ups = (Integer) props.get("upss");
+ Integer upi = (Integer) props.get("upis");
+ Integer upl = (Integer) props.get("upls");
+ Integer upd = (Integer) props.get("upds");
+ Integer upf = (Integer) props.get("upfs");
+ Integer upc = (Integer) props.get("upcs");
+ Integer upbool = (Integer) props.get("upbools");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigure(instance2);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (byte[]) props.get("bs");
+ s = (short[]) props.get("ss");
+ i = (int[]) props.get("is");
+ l = (long[]) props.get("ls");
+ d = (double[]) props.get("ds");
+ f = (float[]) props.get("fs");
+ c = (char[]) props.get("cs");
+ bool = (boolean[]) props.get("bools");
+
+ assertEquals("2) Check b 0", b[0], 3);
+ assertEquals("2) Check b 1", b[1], 2);
+ assertEquals("2) Check b 2", b[2], 1);
+ assertEquals("2) Check s 0", s[0], 3);
+ assertEquals("2) Check s 1", s[1], 2);
+ assertEquals("2) Check s 2", s[2], 1);
+ assertEquals("2) Check i 0", i[0], 3);
+ assertEquals("2) Check i 1", i[1], 2);
+ assertEquals("2) Check i 2", i[2], 1);
+ assertEquals("2) Check l 0", l[0], 3);
+ assertEquals("2) Check l 1", l[1], 2);
+ assertEquals("2) Check l 2", l[2], 1);
+ assertEquals("2) Check d 0", d[0], 3);
+ assertEquals("2) Check d 1", d[1], 2);
+ assertEquals("2) Check d 2", d[2], 1);
+ assertEquals("2) Check f 0", f[0], 3);
+ assertEquals("2) Check f 1", f[1], 2);
+ assertEquals("2) Check f 2", f[2], 1);
+ assertEquals("2) Check c 0", c[0], 'c');
+ assertEquals("2) Check c 1", c[1], 'b');
+ assertEquals("2) Check c 2", c[2], 'a');
+ assertFalse("2) Check bool 0", bool[0]);
+ assertFalse("2) Check bool 1", bool[0]);
+ assertFalse("2) Check bool 2", bool[0]);
+
+ upb = (Integer) props.get("upbs");
+ ups = (Integer) props.get("upss");
+ upi = (Integer) props.get("upis");
+ upl = (Integer) props.get("upls");
+ upd = (Integer) props.get("upds");
+ upf = (Integer) props.get("upfs");
+ upc = (Integer) props.get("upcs");
+ upbool = (Integer) props.get("upbools");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitiveArrays2String() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ byte[] b = (byte[]) props.get("bs");
+ short[] s = (short[]) props.get("ss");
+ int[] i = (int[]) props.get("is");
+ long[] l = (long[]) props.get("ls");
+ double[] d = (double[]) props.get("ds");
+ float[] f = (float[]) props.get("fs");
+ char[] c = (char[]) props.get("cs");
+ boolean[] bool = (boolean[]) props.get("bools");
+
+ assertEquals("Check b 0", b[0], 1);
+ assertEquals("Check b 1", b[1], 2);
+ assertEquals("Check b 2", b[2], 3);
+ assertEquals("Check s 0", s[0], 1);
+ assertEquals("Check s 1", s[1], 2);
+ assertEquals("Check s 2", s[2], 3);
+ assertEquals("Check i 0", i[0], 1);
+ assertEquals("Check i 1", i[1], 2);
+ assertEquals("Check i 2", i[2], 3);
+ assertEquals("Check l 0", l[0], 1);
+ assertEquals("Check l 1", l[1], 2);
+ assertEquals("Check l 2", l[2], 3);
+ assertEquals("Check d 0", d[0], 1);
+ assertEquals("Check d 1", d[1], 2);
+ assertEquals("Check d 2", d[2], 3);
+ assertEquals("Check f 0", f[0], 1);
+ assertEquals("Check f 1", f[1], 2);
+ assertEquals("Check f 2", f[2], 3);
+ assertEquals("Check c 0", c[0], 'a');
+ assertEquals("Check c 1", c[1], 'b');
+ assertEquals("Check c 2", c[2], 'c');
+ assertTrue("Check bool 0", bool[0]);
+ assertTrue("Check bool 1", bool[0]);
+ assertTrue("Check bool 2", bool[0]);
+
+ Integer upb = (Integer) props.get("upbs");
+ Integer ups = (Integer) props.get("upss");
+ Integer upi = (Integer) props.get("upis");
+ Integer upl = (Integer) props.get("upls");
+ Integer upd = (Integer) props.get("upds");
+ Integer upf = (Integer) props.get("upfs");
+ Integer upc = (Integer) props.get("upcs");
+ Integer upbool = (Integer) props.get("upbools");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigureString(instance2);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (byte[]) props.get("bs");
+ s = (short[]) props.get("ss");
+ i = (int[]) props.get("is");
+ l = (long[]) props.get("ls");
+ d = (double[]) props.get("ds");
+ f = (float[]) props.get("fs");
+ c = (char[]) props.get("cs");
+ bool = (boolean[]) props.get("bools");
+
+ assertEquals("2) Check b 0", b[0], 3);
+ assertEquals("2) Check b 1", b[1], 2);
+ assertEquals("2) Check b 2", b[2], 1);
+ assertEquals("2) Check s 0", s[0], 3);
+ assertEquals("2) Check s 1", s[1], 2);
+ assertEquals("2) Check s 2", s[2], 1);
+ assertEquals("2) Check i 0", i[0], 3);
+ assertEquals("2) Check i 1", i[1], 2);
+ assertEquals("2) Check i 2", i[2], 1);
+ assertEquals("2) Check l 0", l[0], 3);
+ assertEquals("2) Check l 1", l[1], 2);
+ assertEquals("2) Check l 2", l[2], 1);
+ assertEquals("2) Check d 0", d[0], 3);
+ assertEquals("2) Check d 1", d[1], 2);
+ assertEquals("2) Check d 2", d[2], 1);
+ assertEquals("2) Check f 0", f[0], 3);
+ assertEquals("2) Check f 1", f[1], 2);
+ assertEquals("2) Check f 2", f[2], 1);
+ assertEquals("2) Check c 0", c[0], 'c');
+ assertEquals("2) Check c 1", c[1], 'b');
+ assertEquals("2) Check c 2", c[2], 'a');
+ assertFalse("2) Check bool 0", bool[0]);
+ assertFalse("2) Check bool 1", bool[0]);
+ assertFalse("2) Check bool 2", bool[0]);
+
+ upb = (Integer) props.get("upbs");
+ ups = (Integer) props.get("upss");
+ upi = (Integer) props.get("upis");
+ upl = (Integer) props.get("upls");
+ upd = (Integer) props.get("upds");
+ upf = (Integer) props.get("upfs");
+ upc = (Integer) props.get("upcs");
+ upbool = (Integer) props.get("upbools");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationObj2() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ String s = (String) props.get("string");
+ String[] ss = (String[]) props.get("strings");
+
+ assertEquals("Check string", s, "foo");
+ assertEquals("Check strings 0", ss[0], "foo");
+ assertEquals("Check strings 1", ss[1], "bar");
+ assertEquals("Check strings 2", ss[2], "baz");
+
+ Integer upString = (Integer) props.get("upstring");
+ Integer upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("Check upString", upString, new Integer(1));
+ assertEquals("Check upStrings", upStrings, new Integer(1));
+
+ reconfigure(instance2);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ s = (String) props.get("string");
+ ss = (String[]) props.get("strings");
+
+ assertEquals("2) Check string", s, "bar");
+ assertEquals("2) Check strings 0", ss[0], "baz");
+ assertEquals("2) Check strings 1", ss[1], "bar");
+ assertEquals("2) Check strings 2", ss[2], "foo");
+
+ upString = (Integer) props.get("upstring");
+ upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("2) Check upString", upString, new Integer(2));
+ assertEquals("2) Check upStrings", upStrings, new Integer(2));
+ }
+
+ public void testConfigurationObj2String() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ String s = (String) props.get("string");
+ String[] ss = (String[]) props.get("strings");
+
+ assertEquals("Check string", s, "foo");
+ assertEquals("Check strings 0", ss[0], "foo");
+ assertEquals("Check strings 1", ss[1], "bar");
+ assertEquals("Check strings 2", ss[2], "baz");
+
+ Integer upString = (Integer) props.get("upstring");
+ Integer upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("Check upString", upString, new Integer(1));
+ assertEquals("Check upStrings", upStrings, new Integer(1));
+
+ reconfigureString(instance2);
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ s = (String) props.get("string");
+ ss = (String[]) props.get("strings");
+
+ assertEquals("2) Check string", s, "bar");
+ assertEquals("2) Check strings 0", ss[0], "baz");
+ assertEquals("2) Check strings 1", ss[1], "bar");
+ assertEquals("2) Check strings 2", ss[2], "foo");
+
+ upString = (Integer) props.get("upstring");
+ upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("2) Check upString", upString, new Integer(2));
+ assertEquals("2) Check upStrings", upStrings, new Integer(2));
+ }
+
+ private void reconfigure(ComponentInstance ci) {
+ Properties props2 = new Properties();
+ props2.put("name", "under-test");
+ props2.put("b", new Byte("2"));
+ props2.put("s", new Short("2"));
+ props2.put("i", new Integer("2"));
+ props2.put("l", new Long("2"));
+ props2.put("d", new Double("2"));
+ props2.put("f", new Float("2"));
+ props2.put("c", new Character('b'));
+ props2.put("bool", new Boolean(false));
+ props2.put("bs", new byte[]{(byte)3,(byte)2,(byte)1});
+ props2.put("ss", new short[]{(short)3,(short)2,(short)1});
+ props2.put("is", new int[]{3,2,1});
+ props2.put("ls", new long[]{3,2,1});
+ props2.put("ds", new double[]{3,2,1});
+ props2.put("fs", new float[]{3,2,1});
+ props2.put("cs", new char[]{'c','b','a'});
+ props2.put("bools", new boolean[]{false,false,false});
+ props2.put("string", "bar");
+ props2.put("strings", new String[]{"baz", "bar", "foo"});
+
+ ci.reconfigure(props2);
+ }
+
+ private void reconfigureString(ComponentInstance ci) {
+ Properties props2 = new Properties();
+ props2.put("name", "under-test");
+ props2.put("b", "2");
+ props2.put("s", "2");
+ props2.put("i", "2");
+ props2.put("l", "2");
+ props2.put("d", "2");
+ props2.put("f", "2");
+ props2.put("c", "b");
+ props2.put("bool", "false");
+ props2.put("bs", "{3, 2,1}");
+ props2.put("ss", "{3, 2,1}");
+ props2.put("is", "{3, 2,1}");
+ props2.put("ls", "{3, 2,1}");
+ props2.put("ds", "{3, 2,1}");
+ props2.put("fs", "{3, 2,1}");
+ props2.put("cs", "{c, b , a}");
+ props2.put("bools", "{false,false,false}");
+ props2.put("string", "bar");
+ props2.put("strings", "{baz, bar, foo}");
+
+ ci.reconfigure(props2);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestSuperMethodProperties.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestSuperMethodProperties.java
new file mode 100644
index 0000000..c7b322b
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestSuperMethodProperties.java
@@ -0,0 +1,617 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class TestSuperMethodProperties extends OSGiTestCase {
+
+ ComponentInstance instance;
+
+ public void setUp() {
+ Factory fact = Utils.getFactoryByName(context, "ParentMethodConfigurableCheckService");
+ Properties props = new Properties();
+ props.put("name", "under-test");
+ props.put("b", "1");
+ props.put("s", "1");
+ props.put("i", "1");
+ props.put("l", "1");
+ props.put("d", "1");
+ props.put("f", "1");
+ props.put("c", "a");
+ props.put("bool", "true");
+ props.put("bs", "{1,2,3}");
+ props.put("ss", "{1,2,3}");
+ props.put("is", "{1,2,3}");
+ props.put("ls", "{1,2,3}");
+ props.put("ds", "{1,2,3}");
+ props.put("fs", "{1,2,3}");
+ props.put("cs", "{a,b,c}");
+ props.put("bools", "{true,true,true}");
+ props.put("string", "foo");
+ props.put("strings", "{foo, bar, baz}");
+
+ try {
+ instance = fact.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot create the under-test instance : " + e.getMessage());
+ }
+
+
+ }
+
+ public void tearDown() {
+ instance.dispose();
+ instance = null;
+ }
+
+ public void testConfigurationPrimitive() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ Byte b = (Byte) props.get("b");
+ Short s = (Short) props.get("s");
+ Integer i = (Integer) props.get("i");
+ Long l = (Long) props.get("l");
+ Double d = (Double) props.get("d");
+ Float f = (Float) props.get("f");
+ Character c = (Character) props.get("c");
+ Boolean bool = (Boolean) props.get("bool");
+
+ assertEquals("Check b", b, new Byte("1"));
+ assertEquals("Check s", s, new Short("1"));
+ assertEquals("Check i", i, new Integer("1"));
+ assertEquals("Check l", l, new Long("1"));
+ assertEquals("Check d", d, new Double("1"));
+ assertEquals("Check f", f, new Float("1"));
+ assertEquals("Check c", c, new Character('a'));
+ assertEquals("Check bool", bool, new Boolean("true"));
+
+ Integer upb = (Integer) props.get("upb");
+ Integer ups = (Integer) props.get("ups");
+ Integer upi = (Integer) props.get("upi");
+ Integer upl = (Integer) props.get("upl");
+ Integer upd = (Integer) props.get("upd");
+ Integer upf = (Integer) props.get("upf");
+ Integer upc = (Integer) props.get("upc");
+ Integer upbool = (Integer) props.get("upbool");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigure();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (Byte) props.get("b");
+ s = (Short) props.get("s");
+ i = (Integer) props.get("i");
+ l = (Long) props.get("l");
+ d = (Double) props.get("d");
+ f = (Float) props.get("f");
+ c = (Character) props.get("c");
+ bool = (Boolean) props.get("bool");
+
+ assertEquals("2) Check b ("+b+")", b, new Byte("2"));
+ assertEquals("2) Check s", s, new Short("2"));
+ assertEquals("2) Check i", i, new Integer("2"));
+ assertEquals("2) Check l", l, new Long("2"));
+ assertEquals("2) Check d", d, new Double("2"));
+ assertEquals("2) Check f", f, new Float("2"));
+ assertEquals("2) Check c", c, new Character('b'));
+ assertEquals("2) Check bool", bool, new Boolean("false"));
+
+ upb = (Integer) props.get("upb");
+ ups = (Integer) props.get("ups");
+ upi = (Integer) props.get("upi");
+ upl = (Integer) props.get("upl");
+ upd = (Integer) props.get("upd");
+ upf = (Integer) props.get("upf");
+ upc = (Integer) props.get("upc");
+ upbool = (Integer) props.get("upbool");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitiveString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ Byte b = (Byte) props.get("b");
+ Short s = (Short) props.get("s");
+ Integer i = (Integer) props.get("i");
+ Long l = (Long) props.get("l");
+ Double d = (Double) props.get("d");
+ Float f = (Float) props.get("f");
+ Character c = (Character) props.get("c");
+ Boolean bool = (Boolean) props.get("bool");
+
+ assertEquals("Check b", b, new Byte("1"));
+ assertEquals("Check s", s, new Short("1"));
+ assertEquals("Check i", i, new Integer("1"));
+ assertEquals("Check l", l, new Long("1"));
+ assertEquals("Check d", d, new Double("1"));
+ assertEquals("Check f", f, new Float("1"));
+ assertEquals("Check c", c, new Character('a'));
+ assertEquals("Check bool", bool, new Boolean("true"));
+
+ Integer upb = (Integer) props.get("upb");
+ Integer ups = (Integer) props.get("ups");
+ Integer upi = (Integer) props.get("upi");
+ Integer upl = (Integer) props.get("upl");
+ Integer upd = (Integer) props.get("upd");
+ Integer upf = (Integer) props.get("upf");
+ Integer upc = (Integer) props.get("upc");
+ Integer upbool = (Integer) props.get("upbool");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigureString();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (Byte) props.get("b");
+ s = (Short) props.get("s");
+ i = (Integer) props.get("i");
+ l = (Long) props.get("l");
+ d = (Double) props.get("d");
+ f = (Float) props.get("f");
+ c = (Character) props.get("c");
+ bool = (Boolean) props.get("bool");
+
+ assertEquals("2) Check b ("+b+")", b, new Byte("2"));
+ assertEquals("2) Check s", s, new Short("2"));
+ assertEquals("2) Check i", i, new Integer("2"));
+ assertEquals("2) Check l", l, new Long("2"));
+ assertEquals("2) Check d", d, new Double("2"));
+ assertEquals("2) Check f", f, new Float("2"));
+ assertEquals("2) Check c", c, new Character('b'));
+ assertEquals("2) Check bool", bool, new Boolean("false"));
+
+ upb = (Integer) props.get("upb");
+ ups = (Integer) props.get("ups");
+ upi = (Integer) props.get("upi");
+ upl = (Integer) props.get("upl");
+ upd = (Integer) props.get("upd");
+ upf = (Integer) props.get("upf");
+ upc = (Integer) props.get("upc");
+ upbool = (Integer) props.get("upbool");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitiveArrays() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ byte[] b = (byte[]) props.get("bs");
+ short[] s = (short[]) props.get("ss");
+ int[] i = (int[]) props.get("is");
+ long[] l = (long[]) props.get("ls");
+ double[] d = (double[]) props.get("ds");
+ float[] f = (float[]) props.get("fs");
+ char[] c = (char[]) props.get("cs");
+ boolean[] bool = (boolean[]) props.get("bools");
+
+ assertEquals("Check b 0", b[0], 1);
+ assertEquals("Check b 1", b[1], 2);
+ assertEquals("Check b 2", b[2], 3);
+ assertEquals("Check s 0", s[0], 1);
+ assertEquals("Check s 1", s[1], 2);
+ assertEquals("Check s 2", s[2], 3);
+ assertEquals("Check i 0", i[0], 1);
+ assertEquals("Check i 1", i[1], 2);
+ assertEquals("Check i 2", i[2], 3);
+ assertEquals("Check l 0", l[0], 1);
+ assertEquals("Check l 1", l[1], 2);
+ assertEquals("Check l 2", l[2], 3);
+ assertEquals("Check d 0", d[0], 1);
+ assertEquals("Check d 1", d[1], 2);
+ assertEquals("Check d 2", d[2], 3);
+ assertEquals("Check f 0", f[0], 1);
+ assertEquals("Check f 1", f[1], 2);
+ assertEquals("Check f 2", f[2], 3);
+ assertEquals("Check c 0", c[0], 'a');
+ assertEquals("Check c 1", c[1], 'b');
+ assertEquals("Check c 2", c[2], 'c');
+ assertTrue("Check bool 0", bool[0]);
+ assertTrue("Check bool 1", bool[0]);
+ assertTrue("Check bool 2", bool[0]);
+
+ Integer upb = (Integer) props.get("upbs");
+ Integer ups = (Integer) props.get("upss");
+ Integer upi = (Integer) props.get("upis");
+ Integer upl = (Integer) props.get("upls");
+ Integer upd = (Integer) props.get("upds");
+ Integer upf = (Integer) props.get("upfs");
+ Integer upc = (Integer) props.get("upcs");
+ Integer upbool = (Integer) props.get("upbools");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigure();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (byte[]) props.get("bs");
+ s = (short[]) props.get("ss");
+ i = (int[]) props.get("is");
+ l = (long[]) props.get("ls");
+ d = (double[]) props.get("ds");
+ f = (float[]) props.get("fs");
+ c = (char[]) props.get("cs");
+ bool = (boolean[]) props.get("bools");
+
+ assertEquals("2) Check b 0", b[0], 3);
+ assertEquals("2) Check b 1", b[1], 2);
+ assertEquals("2) Check b 2", b[2], 1);
+ assertEquals("2) Check s 0", s[0], 3);
+ assertEquals("2) Check s 1", s[1], 2);
+ assertEquals("2) Check s 2", s[2], 1);
+ assertEquals("2) Check i 0", i[0], 3);
+ assertEquals("2) Check i 1", i[1], 2);
+ assertEquals("2) Check i 2", i[2], 1);
+ assertEquals("2) Check l 0", l[0], 3);
+ assertEquals("2) Check l 1", l[1], 2);
+ assertEquals("2) Check l 2", l[2], 1);
+ assertEquals("2) Check d 0", d[0], 3);
+ assertEquals("2) Check d 1", d[1], 2);
+ assertEquals("2) Check d 2", d[2], 1);
+ assertEquals("2) Check f 0", f[0], 3);
+ assertEquals("2) Check f 1", f[1], 2);
+ assertEquals("2) Check f 2", f[2], 1);
+ assertEquals("2) Check c 0", c[0], 'c');
+ assertEquals("2) Check c 1", c[1], 'b');
+ assertEquals("2) Check c 2", c[2], 'a');
+ assertFalse("2) Check bool 0", bool[0]);
+ assertFalse("2) Check bool 1", bool[0]);
+ assertFalse("2) Check bool 2", bool[0]);
+
+ upb = (Integer) props.get("upbs");
+ ups = (Integer) props.get("upss");
+ upi = (Integer) props.get("upis");
+ upl = (Integer) props.get("upls");
+ upd = (Integer) props.get("upds");
+ upf = (Integer) props.get("upfs");
+ upc = (Integer) props.get("upcs");
+ upbool = (Integer) props.get("upbools");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationPrimitiveArraysString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ byte[] b = (byte[]) props.get("bs");
+ short[] s = (short[]) props.get("ss");
+ int[] i = (int[]) props.get("is");
+ long[] l = (long[]) props.get("ls");
+ double[] d = (double[]) props.get("ds");
+ float[] f = (float[]) props.get("fs");
+ char[] c = (char[]) props.get("cs");
+ boolean[] bool = (boolean[]) props.get("bools");
+
+ assertEquals("Check b 0", b[0], 1);
+ assertEquals("Check b 1", b[1], 2);
+ assertEquals("Check b 2", b[2], 3);
+ assertEquals("Check s 0", s[0], 1);
+ assertEquals("Check s 1", s[1], 2);
+ assertEquals("Check s 2", s[2], 3);
+ assertEquals("Check i 0", i[0], 1);
+ assertEquals("Check i 1", i[1], 2);
+ assertEquals("Check i 2", i[2], 3);
+ assertEquals("Check l 0", l[0], 1);
+ assertEquals("Check l 1", l[1], 2);
+ assertEquals("Check l 2", l[2], 3);
+ assertEquals("Check d 0", d[0], 1);
+ assertEquals("Check d 1", d[1], 2);
+ assertEquals("Check d 2", d[2], 3);
+ assertEquals("Check f 0", f[0], 1);
+ assertEquals("Check f 1", f[1], 2);
+ assertEquals("Check f 2", f[2], 3);
+ assertEquals("Check c 0", c[0], 'a');
+ assertEquals("Check c 1", c[1], 'b');
+ assertEquals("Check c 2", c[2], 'c');
+ assertTrue("Check bool 0", bool[0]);
+ assertTrue("Check bool 1", bool[0]);
+ assertTrue("Check bool 2", bool[0]);
+
+ Integer upb = (Integer) props.get("upbs");
+ Integer ups = (Integer) props.get("upss");
+ Integer upi = (Integer) props.get("upis");
+ Integer upl = (Integer) props.get("upls");
+ Integer upd = (Integer) props.get("upds");
+ Integer upf = (Integer) props.get("upfs");
+ Integer upc = (Integer) props.get("upcs");
+ Integer upbool = (Integer) props.get("upbools");
+
+ assertEquals("Check upb", upb, new Integer(1));
+ assertEquals("Check ups", ups, new Integer(1));
+ assertEquals("Check upi", upi, new Integer(1));
+ assertEquals("Check upl", upl, new Integer(1));
+ assertEquals("Check upd", upd, new Integer(1));
+ assertEquals("Check upf", upf, new Integer(1));
+ assertEquals("Check upc", upc, new Integer(1));
+ assertEquals("Check upbool", upbool, new Integer(1));
+
+ reconfigureString();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ b = (byte[]) props.get("bs");
+ s = (short[]) props.get("ss");
+ i = (int[]) props.get("is");
+ l = (long[]) props.get("ls");
+ d = (double[]) props.get("ds");
+ f = (float[]) props.get("fs");
+ c = (char[]) props.get("cs");
+ bool = (boolean[]) props.get("bools");
+
+ assertEquals("2) Check b 0", b[0], 3);
+ assertEquals("2) Check b 1", b[1], 2);
+ assertEquals("2) Check b 2", b[2], 1);
+ assertEquals("2) Check s 0", s[0], 3);
+ assertEquals("2) Check s 1", s[1], 2);
+ assertEquals("2) Check s 2", s[2], 1);
+ assertEquals("2) Check i 0", i[0], 3);
+ assertEquals("2) Check i 1", i[1], 2);
+ assertEquals("2) Check i 2", i[2], 1);
+ assertEquals("2) Check l 0", l[0], 3);
+ assertEquals("2) Check l 1", l[1], 2);
+ assertEquals("2) Check l 2", l[2], 1);
+ assertEquals("2) Check d 0", d[0], 3);
+ assertEquals("2) Check d 1", d[1], 2);
+ assertEquals("2) Check d 2", d[2], 1);
+ assertEquals("2) Check f 0", f[0], 3);
+ assertEquals("2) Check f 1", f[1], 2);
+ assertEquals("2) Check f 2", f[2], 1);
+ assertEquals("2) Check c 0", c[0], 'c');
+ assertEquals("2) Check c 1", c[1], 'b');
+ assertEquals("2) Check c 2", c[2], 'a');
+ assertFalse("2) Check bool 0", bool[0]);
+ assertFalse("2) Check bool 1", bool[0]);
+ assertFalse("2) Check bool 2", bool[0]);
+
+ upb = (Integer) props.get("upbs");
+ ups = (Integer) props.get("upss");
+ upi = (Integer) props.get("upis");
+ upl = (Integer) props.get("upls");
+ upd = (Integer) props.get("upds");
+ upf = (Integer) props.get("upfs");
+ upc = (Integer) props.get("upcs");
+ upbool = (Integer) props.get("upbools");
+
+ assertEquals("2) Check upb", upb, new Integer(2));
+ assertEquals("2) Check ups", ups, new Integer(2));
+ assertEquals("2) Check upi", upi, new Integer(2));
+ assertEquals("2) Check upl", upl, new Integer(2));
+ assertEquals("2) Check upd", upd, new Integer(2));
+ assertEquals("2) Check upf", upf, new Integer(2));
+ assertEquals("2) Check upc", upc, new Integer(2));
+ assertEquals("2) Check upbool", upbool, new Integer(2));
+
+ }
+
+ public void testConfigurationObj() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ String s = (String) props.get("string");
+ String[] ss = (String[]) props.get("strings");
+
+ assertEquals("Check string", s, "foo");
+ assertEquals("Check strings 0", ss[0], "foo");
+ assertEquals("Check strings 1", ss[1], "bar");
+ assertEquals("Check strings 2", ss[2], "baz");
+
+ Integer upString = (Integer) props.get("upstring");
+ Integer upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("Check upString", upString, new Integer(1));
+ assertEquals("Check upStrings", upStrings, new Integer(1));
+
+ reconfigure();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ s = (String) props.get("string");
+ ss = (String[]) props.get("strings");
+
+ assertEquals("2) Check string", s, "bar");
+ assertEquals("2) Check strings 0", ss[0], "baz");
+ assertEquals("2) Check strings 1", ss[1], "bar");
+ assertEquals("2) Check strings 2", ss[2], "foo");
+
+ upString = (Integer) props.get("upstring");
+ upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("2) Check upString", upString, new Integer(2));
+ assertEquals("2) Check upStrings", upStrings, new Integer(2));
+ }
+
+ public void testConfigurationObjString() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ CheckService check = (CheckService) context.getService(ref);
+ Properties props = check.getProps();
+
+ String s = (String) props.get("string");
+ String[] ss = (String[]) props.get("strings");
+
+ assertEquals("Check string", s, "foo");
+ assertEquals("Check strings 0", ss[0], "foo");
+ assertEquals("Check strings 1", ss[1], "bar");
+ assertEquals("Check strings 2", ss[2], "baz");
+
+ Integer upString = (Integer) props.get("upstring");
+ Integer upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("Check upString", upString, new Integer(1));
+ assertEquals("Check upStrings", upStrings, new Integer(1));
+
+ reconfigureString();
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Test check service availability", ref);
+ check = (CheckService) context.getService(ref);
+ props = check.getProps();
+
+ s = (String) props.get("string");
+ ss = (String[]) props.get("strings");
+
+ assertEquals("2) Check string", s, "bar");
+ assertEquals("2) Check strings 0", ss[0], "baz");
+ assertEquals("2) Check strings 1", ss[1], "bar");
+ assertEquals("2) Check strings 2", ss[2], "foo");
+
+ upString = (Integer) props.get("upstring");
+ upStrings = (Integer) props.get("upstrings");
+
+ assertEquals("2) Check upString", upString, new Integer(2));
+ assertEquals("2) Check upStrings", upStrings, new Integer(2));
+ }
+
+ private void reconfigure() {
+ Properties props2 = new Properties();
+ props2.put("name", "under-test");
+ props2.put("b", new Byte("2"));
+ props2.put("s", new Short("2"));
+ props2.put("i", new Integer("2"));
+ props2.put("l", new Long("2"));
+ props2.put("d", new Double("2"));
+ props2.put("f", new Float("2"));
+ props2.put("c", new Character('b'));
+ props2.put("bool", new Boolean(false));
+ props2.put("bs", new byte[]{(byte)3,(byte)2,(byte)1});
+ props2.put("ss", new short[]{(short)3,(short)2,(short)1});
+ props2.put("is", new int[]{3,2,1});
+ props2.put("ls", new long[]{3,2,1});
+ props2.put("ds", new double[]{3,2,1});
+ props2.put("fs", new float[]{3,2,1});
+ props2.put("cs", new char[]{'c','b','a'});
+ props2.put("bools", new boolean[]{false,false,false});
+ props2.put("string", "bar");
+ props2.put("strings", new String[]{"baz", "bar", "foo"});
+
+ instance.reconfigure(props2);
+ }
+
+ private void reconfigureString() {
+ Properties props2 = new Properties();
+ props2.put("name", "under-test");
+ props2.put("b", "2");
+ props2.put("s", "2");
+ props2.put("i", "2");
+ props2.put("l", "2");
+ props2.put("d", "2");
+ props2.put("f", "2");
+ props2.put("c", "b");
+ props2.put("bool", "false");
+ props2.put("bs", "{3, 2,1}");
+ props2.put("ss", "{3, 2,1}");
+ props2.put("is", "{3, 2,1}");
+ props2.put("ls", "{3, 2,1}");
+ props2.put("ds", "{3, 2,1}");
+ props2.put("fs", "{3, 2,1}");
+ props2.put("cs", "{c, b , a}");
+ props2.put("bools", "{false,false,false}");
+ props2.put("string", "bar");
+ props2.put("strings", "{baz, bar, foo}");
+
+ instance.reconfigure(props2);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/controller/ImmediateLifeCycleControllerTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/controller/ImmediateLifeCycleControllerTest.java
new file mode 100644
index 0000000..c5f5e20
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/controller/ImmediateLifeCycleControllerTest.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.controller;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class ImmediateLifeCycleControllerTest extends OSGiTestCase {
+
+ private ComponentInstance under;
+ private Factory factory;
+
+ public void setUp() {
+ factory = Utils.getFactoryByName(context, "lcTest2");
+ }
+
+ public void testOne() {
+ Properties props = new Properties();
+ props.put("conf", "foo");
+ props.put("name", "under");
+ under = Utils.getComponentInstance(context, "lcTest2", props);
+
+ // The conf is correct, the PS must be provided
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");
+ assertNotNull("Check service availability -1", ref);
+ CheckService cs = (CheckService) context.getService(ref);
+ assertTrue("Check state 1", cs.check());
+ context.ungetService(ref);
+ cs = null;
+
+ // Reconfigure the instance with a bad configuration
+ props.put("conf", "bar"); // Bar is a bad conf
+ try {
+ factory.reconfigure(props);
+ } catch(Exception e) {
+ fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
+ }
+
+ // The instance should now be invalid
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");
+ assertNull("Check service availability -2", ref);
+
+ // Reconfigure the instance with a valid configuration
+ props.put("conf", "foo"); // Bar is a bad conf
+ try {
+ factory.reconfigure(props);
+ } catch(Exception e) {
+ fail("The reconfiguration is not unacceptable and seems unacceptable (2) : " + props);
+ }
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");
+ assertNotNull("Check service availability -3", ref);
+ cs = (CheckService) context.getService(ref);
+ assertTrue("Check state 2", cs.check());
+ context.ungetService(ref);
+ cs = null;
+
+ under.dispose();
+ }
+
+ public void testTwo() {
+ Properties props = new Properties();
+ props.put("conf", "bar");
+ props.put("name", "under");
+ under = Utils.getComponentInstance(context, "lcTest2", props);
+
+ assertEquals("check under state", under.getState(), ComponentInstance.INVALID);
+
+ // The conf is incorrect, the PS must not be provided
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");
+ assertNull("Check service availability -1", ref);
+
+ // Reconfigure the instance with a correct configuration
+ props.put("conf", "foo");
+ try {
+ factory.reconfigure(props);
+ } catch(Exception e) {
+ fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
+ }
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");
+ assertNotNull("Check service availability -2", ref);
+ CheckService cs = (CheckService) context.getService(ref);
+ assertTrue("Check state ", cs.check());
+ context.ungetService(ref);
+ cs = null;
+
+ under.dispose();
+ }
+
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/controller/LifeCycleControllerTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/controller/LifeCycleControllerTest.java
new file mode 100644
index 0000000..d86b997
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/controller/LifeCycleControllerTest.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.test.scenarios.controller;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * @author clement
+ *
+ */
+public class LifeCycleControllerTest extends OSGiTestCase {
+
+ private ComponentInstance under;
+
+ private Factory factory;
+
+ public void setUp() {
+ factory = Utils.getFactoryByName(context, "lcTest");
+ }
+
+ public void testOne() {
+ Properties props = new Properties();
+ props.put("conf", "foo");
+ props.put("name", "under");
+ under = Utils.getComponentInstance(context, "lcTest", props);
+
+ // The conf is correct, the PS must be provided
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");
+ assertNotNull("Check service availability -1", ref);
+ CheckService cs = (CheckService) context.getService(ref);
+ assertTrue("Check state 1", cs.check());
+ context.ungetService(ref);
+ cs = null;
+
+ // Reconfigure the instance with a bad configuration
+ props.put("conf", "bar"); // Bar is a bad conf
+ try {
+ factory.reconfigure(props);
+ } catch (Exception e) {
+ fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
+ }
+
+ // The instance should now be invalid
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");
+ assertNull("Check service availability -2", ref);
+
+ // Reconfigure the instance with a valid configuration
+ props.put("conf", "foo"); // Bar is a bad conf
+ try {
+ factory.reconfigure(props);
+ } catch (Exception e) {
+ fail("The reconfiguration is not unacceptable and seems unacceptable (2) : " + props);
+ }
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");
+ assertNotNull("Check service availability -3", ref);
+ cs = (CheckService) context.getService(ref);
+ assertTrue("Check state 2", cs.check());
+ context.ungetService(ref);
+ cs = null;
+
+ under.dispose();
+ }
+
+ /**
+ * This test must be removed as it is not compliant with OSGi. It unregisters a service during the creation of the
+ * service instance, so the returned object is null.
+ */
+ public void notestTwo() {
+ Properties props = new Properties();
+ props.put("conf", "bar");
+ props.put("name", "under");
+ under = Utils.getComponentInstance(context, "lcTest", props);
+
+ // The conf is incorrect, but the test can appears only when the object is created : the PS must be provided
+ ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");
+ assertNotNull("Check service availability -1", ref);
+
+ System.out.println("CS received : " + context.getService(ref));
+ CheckService cs = (CheckService) context.getService(ref);
+ assertNotNull("Assert CS not null", cs);
+ try {
+ assertFalse("Check state (false)", cs.check());
+ } catch (Throwable e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ // As soon as the instance is created, the service has to disappear :
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");
+ assertNull("Check service availability -2", ref);
+
+ // Reconfigure the instance with a correct configuration
+ props.put("conf", "foo");
+ try {
+ factory.reconfigure(props);
+ } catch (Exception e) {
+ fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
+ }
+
+ ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");
+ assertNotNull("Check service availability -3", ref);
+ cs = (CheckService) context.getService(ref);
+ assertTrue("Check state ", cs.check());
+ context.ungetService(ref);
+ cs = null;
+
+ under.dispose();
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/controller/LifeCycleControllerTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/controller/LifeCycleControllerTestSuite.java
new file mode 100644
index 0000000..423088f
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/controller/LifeCycleControllerTestSuite.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.controller;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class LifeCycleControllerTestSuite {
+
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Lifecycle Controller Test Suite", bc);
+ ots.addTestSuite( LifeCycleControllerTest.class);
+ ots.addTestSuite( ImmediateLifeCycleControllerTest.class);
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/ComponentDesc.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/ComponentDesc.java
new file mode 100644
index 0000000..df3d25a
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/ComponentDesc.java
@@ -0,0 +1,336 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.core;
+
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.test.scenarios.service.BarService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class ComponentDesc extends OSGiTestCase {
+
+ ServiceReference sr_fooProvider1;
+ ServiceReference sr_fooProvider2;
+ ServiceReference sr_fooProviderDyn2;
+ ServiceReference sr_fooProvider3;
+ ServiceReference sr_foobarProvider;
+// ServiceReference sr_simple;
+// ServiceReference sr_optional;
+// ServiceReference sr_multiple;
+// ServiceReference sr_multiple_optional;
+
+ Factory fooProvider1;
+ Factory fooProvider2;
+ Factory fooProviderDyn2;
+ Factory fooProvider3;
+ Factory foobarProvider;
+// Factory simple;
+// Factory optional;
+// Factory multiple;
+// Factory multiple_optional;
+
+ public void setUp() {
+ sr_fooProvider1 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-1");
+ sr_fooProvider2 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-2");
+ sr_fooProviderDyn2 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-Dyn2");
+ sr_fooProvider3 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-3");
+ sr_foobarProvider = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooBarProviderType-1");
+// sr_simple = Utils.getServiceReferenceByName(context, Factory.class.getName(), "SimpleCheckServiceProvider");
+// sr_optional = Utils.getServiceReferenceByName(context, Factory.class.getName(), "SimpleOptionalCheckServiceProvider");
+// sr_multiple = Utils.getServiceReferenceByName(context, Factory.class.getName(), "SimpleMultipleCheckServiceProvider");
+// sr_multiple_optional = Utils.getServiceReferenceByName(context, Factory.class.getName(), "SimpleOptionalMultipleCheckServiceProvider");
+
+ fooProvider1 = (Factory) context.getService(sr_fooProvider1);
+ fooProvider2 = (Factory) context.getService(sr_fooProvider2);
+ fooProviderDyn2 = (Factory) context.getService(sr_fooProviderDyn2);
+ fooProvider3 = (Factory) context.getService(sr_fooProvider3);
+ foobarProvider = (Factory) context.getService(sr_foobarProvider);
+// simple = (Factory) context.getService(sr_simple);
+// optional = (Factory) context.getService(sr_optional);
+// multiple = (Factory) context.getService(sr_multiple);
+// multiple_optional = (Factory) context.getService(sr_multiple_optional);
+
+ }
+
+ public void tearDown() {
+ fooProvider1 = null;
+ fooProvider2 = null;
+ fooProviderDyn2 = null;
+ fooProvider3 = null;
+ foobarProvider = null;
+// simple = null;
+// multiple = null;
+// optional = null;
+// multiple_optional = null;
+
+ context.ungetService(sr_fooProvider1);
+ context.ungetService(sr_fooProvider2);
+ context.ungetService(sr_fooProviderDyn2);
+ context.ungetService(sr_fooProvider3);
+ context.ungetService(sr_foobarProvider);
+// context.ungetService(sr_simple);
+// context.ungetService(sr_optional);
+// context.ungetService(sr_multiple);
+// context.ungetService(sr_multiple_optional);
+ }
+
+ public void testFooProvider1() {
+ // Test SR properties
+// String impl = (String) sr_fooProvider1.getProperty("component.class");
+// assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderType1");
+
+ String[] specs = (String[]) sr_fooProvider1.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
+ assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
+
+ PropertyDescription[] pd = (PropertyDescription[]) sr_fooProvider1.getProperty("component.properties");
+ assertEquals("Check component.properties length", pd.length, 0);
+
+ // Test factory
+ assertEquals("Check factory name", fooProvider1.getName(), "FooProviderType-1");
+ Element cd = fooProvider1.getDescription();
+
+// assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
+
+ Element[] specs2 = cd.getElements("provides");
+ assertEquals("Check specs length", specs2.length, 1);
+ assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
+
+ Element[] pd2 = cd.getElements("property");
+ assertNull("Check props null", pd2);
+
+ // Check Description equality
+ ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProvider1.getProperty("component.description");
+ assertNotNull("check description equality", desc);
+ }
+
+ public void testFooProvider2() {
+ // Test SR properties
+// String impl = (String) sr_fooProvider2.getProperty("component.class");
+// assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderType1");
+
+ String[] specs = (String[]) sr_fooProvider2.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
+ assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
+
+ PropertyDescription[] pd = (PropertyDescription[]) sr_fooProvider2.getProperty("component.properties");
+ assertEquals("Check component.properties length", pd.length, 5);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "int", pd[0].getName());
+ assertEquals("Check component.properties type [" + 0 + "]", "int", pd[0].getType());
+ assertEquals("Check component.properties value [" + 0 + "]", "2", pd[0].getValue());
+
+ assertEquals("Check component.properties name [" + 1 + "]", "long", pd[1].getName());
+ assertEquals("Check component.properties type [" + 1 + "]", "long", pd[1].getType());
+ assertEquals("Check component.properties value [" + 1 + "]", "40", pd[1].getValue());
+
+ assertEquals("Check component.properties name [" + 2 + "]", "string", pd[2].getName());
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd[2].getType());
+ assertEquals("Check component.properties value [" + 2 + "]", "foo", pd[2].getValue());
+
+ assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd[3].getName());
+ assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd[3].getType());
+
+ assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd[4].getName());
+ assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd[4].getType());
+
+ // Test factory
+ assertEquals("Check factory name", fooProvider2.getName(), "FooProviderType-2");
+ Element cd = fooProvider2.getDescription();
+
+// assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
+
+ Element[] specs2 = cd.getElements("provides");
+ assertEquals("Check specs length", specs2.length, 1);
+ assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
+
+ Element[] pd2 = cd.getElements("property");
+ assertEquals("Check props length", pd2.length, 5);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "int", pd2[0].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 0 + "]", "int", pd2[0].getAttribute("type"));
+ assertEquals("Check component.properties value [" + 0 + "]", "2", pd2[0].getAttribute("value"));
+
+ assertEquals("Check component.properties name [" + 1 + "]", "long", pd2[1].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 1 + "]", "long", pd2[1].getAttribute("type"));
+ assertEquals("Check component.properties value [" + 1 + "]", "40", pd2[1].getAttribute("value"));
+
+ assertEquals("Check component.properties name [" + 2 + "]", "string", pd2[2].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd2[2].getAttribute("type"));
+ assertEquals("Check component.properties value [" + 2 + "]", "foo", pd2[2].getAttribute("value"));
+
+ assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd2[3].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd2[3].getAttribute("type"));
+
+ assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd2[4].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd2[4].getAttribute("type"));
+
+ // Check Description equality
+ ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProvider2.getProperty("component.description");
+ assertNotNull("check description equality", desc);
+ }
+
+ public void testFooProviderDyn2() {
+ // Test SR properties
+// String impl = (String) sr_fooProviderDyn2.getProperty("component.class");
+// assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn2");
+
+ String[] specs = (String[]) sr_fooProviderDyn2.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
+ assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
+
+ PropertyDescription[] pd = (PropertyDescription[]) sr_fooProviderDyn2.getProperty("component.properties");
+ assertEquals("Check component.properties length", pd.length, 5);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "int", pd[0].getName());
+ assertEquals("Check component.properties type [" + 0 + "]", "int", pd[0].getType());
+ assertEquals("Check component.properties value [" + 0 + "]", "4", pd[0].getValue());
+
+ assertEquals("Check component.properties name [" + 1 + "]", "boolean", pd[1].getName());
+ assertEquals("Check component.properties type [" + 1 + "]", "boolean", pd[1].getType());
+
+ assertEquals("Check component.properties name [" + 2 + "]", "string", pd[2].getName());
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd[2].getType());
+
+ assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd[3].getName());
+ assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd[3].getType());
+
+ assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd[4].getName());
+ assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd[4].getType());
+
+ // Test factory
+ assertEquals("Check factory name", fooProviderDyn2.getName(), "FooProviderType-Dyn2");
+ Element cd = fooProviderDyn2.getDescription();
+
+// assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
+
+ Element[] specs2 = cd.getElements("provides");
+ assertEquals("Check specs length", specs2.length, 1);
+ assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
+
+ Element[] pd2 = cd.getElements("property");
+ assertEquals("Check props length", pd2.length, 5);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "int", pd2[0].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 0 + "]", "int", pd2[0].getAttribute("type"));
+ assertEquals("Check component.properties value [" + 0 + "]", "4", pd2[0].getAttribute("value"));
+
+ assertEquals("Check component.properties name [" + 1 + "]", "boolean", pd2[1].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 1 + "]", "boolean", pd2[1].getAttribute("type"));
+
+ assertEquals("Check component.properties name [" + 2 + "]", "string", pd2[2].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd2[2].getAttribute("type"));
+
+ assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd2[3].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd2[3].getAttribute("type"));
+
+ assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd2[4].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd2[4].getAttribute("type"));
+
+ // Check Description equality
+ ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProviderDyn2.getProperty("component.description");
+ assertNotNull("check description equality", desc);
+ }
+
+ public void testFooProvider3() {
+ // Test SR properties
+// String impl = (String) sr_fooProvider3.getProperty("component.class");
+// assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderType1");
+
+ String[] specs = (String[]) sr_fooProvider3.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
+ assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
+
+ PropertyDescription[] pd = (PropertyDescription[]) sr_fooProvider3.getProperty("component.properties");
+ assertEquals("Check component.properties length (" + pd.length +")", pd.length, 3);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "foo", pd[0].getName());
+
+ assertEquals("Check component.properties name [" + 1 + "]", "bar", pd[1].getName());
+
+ assertEquals("Check component.properties name [" + 2 + "]", "baz", pd[2].getName());
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd[2].getType());
+
+ // Test factory
+ assertEquals("Check factory name", fooProvider3.getName(), "FooProviderType-3");
+ Element cd = fooProvider3.getDescription();
+
+// assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
+
+ Element[] specs2 = cd.getElements("provides");
+ assertEquals("Check specs length", specs2.length, 1);
+ assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
+
+ Element[] pd2 = cd.getElements("property");
+ assertEquals("Check props length", pd2.length, 3);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "foo", pd2[0].getAttribute("name"));
+
+ assertEquals("Check component.properties name [" + 1 + "]", "bar", pd2[1].getAttribute("name"));
+
+ assertEquals("Check component.properties name [" + 2 + "]", "baz", pd2[2].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd2[2].getAttribute("type"));
+
+ // Check Description equality
+ ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProvider3.getProperty("component.description");
+ assertNotNull("check description equality", desc);
+ }
+
+ public void testFooBar() {
+ // Test SR properties
+// String impl = (String) sr_foobarProvider.getProperty("component.class");
+// assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1");
+
+ String[] specs = (String[]) sr_foobarProvider.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check component.providedServiceSpecifications length", specs.length, 2);
+ assertEquals("Check component.providedServiceSpecifications 1", FooService.class.getName(), specs[1]);
+ assertEquals("Check component.providedServiceSpecifications 2", BarService.class.getName(), specs[0]);
+
+ PropertyDescription[] pd = (PropertyDescription[]) sr_foobarProvider.getProperty("component.properties");
+ assertEquals("Check component.properties length", pd.length, 0);
+
+ // Test factory
+ assertEquals("Check factory name", foobarProvider.getName(), "FooBarProviderType-1");
+ Element cd = foobarProvider.getDescription();
+
+// assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
+
+ Element[] specs2 = cd.getElements("provides");
+ assertEquals("Check specs length", specs2.length, 2);
+ assertEquals("Check specs", FooService.class.getName(), specs2[1].getAttribute("specification"));
+ assertEquals("Check specs", BarService.class.getName(), specs2[0].getAttribute("specification"));
+
+ Element[] pd2 = cd.getElements("property");
+ assertNull("Check props null", pd2);
+
+ // Check Description equality
+ ComponentTypeDescription desc = (ComponentTypeDescription) sr_foobarProvider.getProperty("component.description");
+ assertNotNull("check description equality", desc);
+
+ }
+
+
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/CoreTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/CoreTestSuite.java
new file mode 100644
index 0000000..bc87ae4
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/CoreTestSuite.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.core;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class CoreTestSuite extends TestSuite {
+
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Contre Test Suite", bc);
+ ots.addTestSuite(POJOCreation.class);
+ ots.addTestSuite(ComponentDesc.class);
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/POJOCreation.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/POJOCreation.java
new file mode 100644
index 0000000..7c76bbf
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/POJOCreation.java
@@ -0,0 +1,264 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.core;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.component.FooProviderType1;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class POJOCreation extends OSGiTestCase {
+
+ private ComponentInstance ci_lazzy;
+ private ComponentInstance ci_immediate;
+ private ComponentInstance ci_immediate_singleton;
+
+ private Architecture lazzyArch;
+ private Architecture immeArch;
+ private Architecture immeArchSing;
+
+ private ServiceReference lazzyRef;
+ private ServiceReference immRef;
+ private ServiceReference immRefSing;
+ private ComponentInstance ci_lazzy_sing;
+ private ComponentInstance ci_lazzy_sev;
+ private ServiceReference lazzyRefSing;
+ private ServiceReference lazzyRefSev;
+ private Architecture lazzyArchSing;
+ private Architecture lazzyArchSev;
+ private ComponentInstance ci_lazzy_singM;
+ private ComponentInstance ci_lazzy_sevM;
+ private ServiceReference lazzyRefSingM;
+ private ServiceReference lazzyRefSevM;
+ private Architecture lazzyArchSingM;
+ private Architecture lazzyArchSevM;
+
+ public void setUp() {
+ String factName = "FooProviderType-1";
+ String compName = "FooProvider-1";
+ Properties p = new Properties();
+ p.put("name", compName);
+ ci_lazzy = Utils.getComponentInstance(context, factName ,p);
+
+ String factName2 = "ImmediateFooProviderType";
+ String compName2 = "FooProvider-2";
+ Properties p2 = new Properties();
+ p2.put("name", compName2);
+ ci_immediate = Utils.getComponentInstance(context, factName2, p2);
+
+ String factName3 = "ImmediateFooProviderTypeSingleton";
+ String compName3 = "FooProvider-3";
+ Properties p3 = new Properties();
+ p3.put("name", compName3);
+ ci_immediate_singleton = Utils.getComponentInstance(context, factName3, p3);
+
+ String factName4 = "FooProviderType-1-Sing";
+ String compName4 = "FooProvider-1-Sing";
+ Properties p4 = new Properties();
+ p4.put("name", compName4);
+ ci_lazzy_sing = Utils.getComponentInstance(context, factName4 ,p4);
+
+ String factName5 = "FooProviderType-1-Sev";
+ String compName5 = "FooProvider-1-Sev";
+ Properties p5 = new Properties();
+ p5.put("name", compName5);
+ ci_lazzy_sev = Utils.getComponentInstance(context, factName5 ,p5);
+
+ String factName6 = "FooProviderType-1-SingM";
+ String compName6 = "FooProvider-1-SingM";
+ Properties p6 = new Properties();
+ p6.put("name", compName6);
+ ci_lazzy_singM = Utils.getComponentInstance(context, factName6 ,p6);
+
+ String factName7 = "FooProviderType-1-SevM";
+ String compName7 = "FooProvider-1-SevM";
+ Properties p7 = new Properties();
+ p7.put("name", compName7);
+ ci_lazzy_sevM = Utils.getComponentInstance(context, factName7 ,p7);
+
+ lazzyRef = Utils.getServiceReference(context, Architecture.class.getName(), "(instance.name="+compName+")");
+ immRef = Utils.getServiceReference(context, Architecture.class.getName(), "(instance.name="+compName2+")");
+ immRefSing = Utils.getServiceReference(context, Architecture.class.getName(), "(instance.name="+compName3+")");
+ lazzyRefSing = Utils.getServiceReference(context, Architecture.class.getName(), "(instance.name="+compName4+")");
+ lazzyRefSev = Utils.getServiceReference(context, Architecture.class.getName(), "(instance.name="+compName5+")");
+ lazzyRefSingM = Utils.getServiceReference(context, Architecture.class.getName(), "(instance.name="+compName6+")");
+ lazzyRefSevM = Utils.getServiceReference(context, Architecture.class.getName(), "(instance.name="+compName7+")");
+
+ lazzyArch = (Architecture) context.getService(lazzyRef);
+ immeArch = (Architecture) context.getService(immRef);
+ immeArchSing = (Architecture) context.getService(immRefSing);
+ lazzyArchSing = (Architecture) context.getService(lazzyRefSing);
+ lazzyArchSev = (Architecture) context.getService(lazzyRefSev);
+ lazzyArchSingM = (Architecture) context.getService(lazzyRefSingM);
+ lazzyArchSevM = (Architecture) context.getService(lazzyRefSevM);
+ }
+
+ public void tearDown() {
+ context.ungetService(lazzyRef);
+ context.ungetService(immRef);
+ context.ungetService(immRefSing);
+ context.ungetService(lazzyRefSing);
+ context.ungetService(lazzyRefSev);
+ context.ungetService(lazzyRefSingM);
+ context.ungetService(lazzyRefSevM);
+ lazzyArch = null;
+ immeArch = null;
+ immeArchSing = null;
+ lazzyArchSing = null;
+ lazzyArchSev = null;
+ lazzyArchSingM = null;
+ lazzyArchSevM = null;
+ ci_lazzy.dispose();
+ ci_immediate.dispose();
+ ci_immediate_singleton.dispose();
+ ci_lazzy_sing.dispose();
+ ci_lazzy_sev.dispose();
+ ci_lazzy_singM.dispose();
+ ci_lazzy_sevM.dispose();
+ }
+
+ public void testLazyCreation() {
+ assertEquals("Check that no objects are created ", 0, lazzyArch.getInstanceDescription().getCreatedObjects().length);
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy.getInstanceName()+")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",refs);
+ FooService fs = (FooService) context.getService(refs[0]);
+ assertTrue("Check the FooService invocation", fs.foo());
+ assertEquals("Check the creation of 1 object",1, lazzyArch.getInstanceDescription().getCreatedObjects().length);
+ context.ungetService(refs[0]);
+ }
+
+ public void testLazyCreationSingleton() {
+ assertEquals("Check that no objects are created ", 0, lazzyArchSing.getInstanceDescription().getCreatedObjects().length);
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy_sing.getInstanceName()+")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ assertNotNull("Check that a FooService from " + ci_lazzy_sing.getInstanceName() + " is available",refs);
+ FooService fs = (FooService) context.getService(refs[0]);
+ assertTrue("Check the FooService invocation", fs.foo());
+ assertEquals("Check the creation of 1 object",1, lazzyArchSing.getInstanceDescription().getCreatedObjects().length);
+ context.ungetService(refs[0]);
+ }
+
+ public void testLazyCreationSeveral() {
+ assertEquals("Check that no objects are created ", 0, lazzyArchSev.getInstanceDescription().getCreatedObjects().length);
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy_sev.getInstanceName()+")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ assertNotNull("Check that a FooService from " + ci_lazzy_sev.getInstanceName() + " is available",refs);
+ FooService fs = (FooService) context.getService(refs[0]);
+ FooService fs2 = (FooService) context.getService(refs[0]);
+ assertTrue("Check the FooService invocation", fs.foo());
+ assertTrue("Check the FooService invocation-2", fs2.foo());
+ assertEquals("Check the creation of 1 object",1, lazzyArchSev.getInstanceDescription().getCreatedObjects().length);
+ context.ungetService(refs[0]);
+ }
+
+ public void testImmediateCreation() {
+ assertEquals("Check that one object is created ", 1, immeArch.getInstanceDescription().getCreatedObjects().length);
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_immediate.getInstanceName()+")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ assertNotNull("Check that a FooService from " + ci_immediate.getInstanceName() + " is available",refs);
+ FooService fs = (FooService) context.getService(refs[0]);
+ assertTrue("Check the FooService invocation", fs.foo());
+ assertEquals("Check the creation of 1 object", 1, immeArch.getInstanceDescription().getCreatedObjects().length);
+ context.ungetService(refs[0]);
+ }
+
+ public void testBundleContext() {
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy.getInstanceName()+")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",refs);
+ FooService fs = (FooService) context.getService(refs[0]);
+ Properties p = fs.fooProps();
+ assertNotNull("Check the bundle context", p.get("context"));
+ assertEquals("Check the creation of 1 object",1, lazzyArch.getInstanceDescription().getCreatedObjects().length);
+ context.ungetService(refs[0]);
+ }
+
+ public void testImmediateSingletonCreation() {
+ assertEquals("Check that one object is created ", 1, immeArchSing.getInstanceDescription().getCreatedObjects().length);
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_immediate_singleton.getInstanceName()+")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ assertNotNull("Check that a FooService from " + ci_immediate_singleton.getInstanceName() + " is available",refs);
+ FooService fs = (FooService) context.getService(refs[0]);
+ assertTrue("Check the FooService invocation", fs.foo());
+ assertEquals("Check the creation of 1 object", 1, immeArchSing.getInstanceDescription().getCreatedObjects().length);
+ context.ungetService(refs[0]);
+ }
+
+ public void testLazyCreationSingletonM() {
+ assertEquals("Check that no objects are created ", 0, lazzyArchSingM.getInstanceDescription().getCreatedObjects().length);
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy_singM.getInstanceName()+")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ assertNotNull("Check that a FooService from " + ci_lazzy_singM.getInstanceName() + " is available",refs);
+ FooService fs = (FooService) context.getService(refs[0]);
+ FooService fs2 = (FooService) context.getService(refs[0]);
+ assertTrue("Check the FooService invocation", fs.foo());
+ assertTrue("Check the FooService invocation", fs2.foo());
+ assertEquals("Check the creation of 1 object",1, lazzyArchSingM.getInstanceDescription().getCreatedObjects().length);
+ context.ungetService(refs[0]);
+ }
+
+ public void testLazyCreationSeveralM() {
+ assertEquals("Check that no objects are created ", 0, lazzyArchSevM.getInstanceDescription().getCreatedObjects().length);
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy_sevM.getInstanceName()+")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ assertNotNull("Check that a FooService from " + ci_lazzy_sevM.getInstanceName() + " is available",refs);
+ FooService fs = (FooService) context.getService(refs[0]);
+ assertTrue("Check the FooService invocation", fs.foo());
+ assertEquals("Check the creation of 1 object",1, lazzyArchSevM.getInstanceDescription().getCreatedObjects().length);
+ FooService fs2 = (FooService) context.getService(refs[0]);
+ assertTrue("Check the FooService invocation-2", fs2.foo());
+ // Only one object as the getService method is called only once (service factory) despite the policy="method".
+ assertEquals("Check the creation of 1 object",1, lazzyArchSevM.getInstanceDescription().getCreatedObjects().length);
+ context.ungetService(refs[0]);
+ }
+
+ public void testCustomConstuctor() {
+ FooService fs = new FooProviderType1(0, "foo", context);
+ Properties props = fs.fooProps();
+ assertEquals("Check bar", 0, ((Integer) props.get("bar")).intValue());
+ assertEquals("Check foo", "foo", props.get("foo"));
+ assertEquals("Check context", context, props.get("context"));
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedMultipleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedMultipleDependencies.java
new file mode 100644
index 0000000..edc0b2f
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedMultipleDependencies.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.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedMultipleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "SimpleMultipleCheckServiceProvider").createComponentInstance(i1);
+ instance1.stop();
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "VoidMultipleCheckServiceProvider").createComponentInstance(i2);
+ instance2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "ObjectMultipleCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "RefMultipleCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "BothMultipleCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+
+ Properties prov2 = new Properties();
+ prov2.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+ } catch(Exception e) { fail(e.getMessage()); }
+ }
+
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ public void testSimple() {
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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(), 2);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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(), 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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance1.stop();
+ }
+
+ public void testVoid() {
+ instance2.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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(), 2);
+ 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(), 2);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ instance2.stop();
+ }
+
+ public void testObject() {
+ instance3.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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(), 2);
+ 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(), 2);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ instance3.stop();
+ }
+
+ public void testRef() {
+ instance4.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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(), 2);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ instance4.stop();
+ context.ungetService(cs_ref);
+ }
+
+ public void testBoth() {
+ instance5.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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 both bind callback invocation - 1", ((Integer)props.get("bothB")).intValue(), 2);
+ assertEquals("check both unbind callback invocation - 1", ((Integer)props.get("bothU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 2.0, 0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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 both bind callback invocation - 3", ((Integer)props.get("bothB")).intValue(), 2);
+ assertEquals("check both unbind callback invocation - 3", ((Integer)props.get("bothU")).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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ instance5.stop();
+ context.ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedOptionalDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedOptionalDependencies.java
new file mode 100644
index 0000000..763ebca
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedOptionalDependencies.java
@@ -0,0 +1,353 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedOptionalDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5;
+
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "SimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+ instance1.stop();
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "VoidOptionalCheckServiceProvider").createComponentInstance(i2);
+ instance2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "ObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "RefOptionalCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "BothOptionalCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ 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;
+ }
+
+ public void testSimple() {
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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(), 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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance1.stop();
+ }
+
+ public void testVoid() {
+ instance2.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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(), 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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance2.stop();
+ }
+
+ public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance3.stop();
+ }
+
+ public void testRef() {
+ instance4.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+ public void testBoth() {
+ instance5.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedOptionalMultipleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedOptionalMultipleDependencies.java
new file mode 100644
index 0000000..2546039
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedOptionalMultipleDependencies.java
@@ -0,0 +1,356 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedOptionalMultipleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "SimpleOptionalMultipleCheckServiceProvider").createComponentInstance(i1);
+ instance1.stop();
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "VoidOptionalMultipleCheckServiceProvider").createComponentInstance(i2);
+ instance2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "ObjectOptionalMultipleCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "RefOptionalMultipleCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+
+ Properties prov2 = new Properties();
+ prov2.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+ } catch(Exception e) { fail(e.getMessage()); }
+ }
+
+ 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;
+ }
+
+ public void testSimple() {
+ instance1.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ instance1.stop();
+ }
+
+ public void testVoid() {
+ instance2.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ instance2.stop();
+ }
+
+ public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ instance3.stop();
+ }
+
+ public void testRef() {
+ instance4.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ instance4.stop();
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedSimpleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedSimpleDependencies.java
new file mode 100644
index 0000000..489c161
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DelayedSimpleDependencies.java
@@ -0,0 +1,262 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedSimpleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5;
+ ComponentInstance fooProvider;
+
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "SimpleCheckServiceProvider").createComponentInstance(i1);
+ instance1.stop();
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "VoidCheckServiceProvider").createComponentInstance(i2);
+ instance2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "ObjectCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "RefCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "BothCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+ } catch(Exception e) { fail(e.getMessage()); }
+
+ }
+
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+ public void testSimple() {
+ instance1.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+ fooProvider.stop();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+ fooProvider.start();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+ fooProvider.stop();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ instance1.stop();
+ }
+
+ public void testVoid() {
+ instance2.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance2.stop();
+ }
+
+ public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance3.stop();
+ }
+
+ public void testRef() {
+ instance4.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+ public void testBoth() {
+ instance5.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance5.stop();
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DependencyTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DependencyTestSuite.java
new file mode 100644
index 0000000..8943880
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/DependencyTestSuite.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.test.scenarios.dependency;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.apache.felix.ipojo.test.scenarios.dependency.di.DefaultImplementationTestSuite;
+import org.apache.felix.ipojo.test.scenarios.dependency.statics.StaticDependencyTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class DependencyTestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Service Dependencies Test Suite", bc);
+ ots.addTestSuite(SimpleDependencies.class);
+ ots.addTestSuite(OptionalDependencies.class);
+ ots.addTestSuite(MultipleDependencies.class);
+ ots.addTestSuite(OptionalMultipleDependencies.class);
+ ots.addTestSuite(DelayedSimpleDependencies.class);
+ ots.addTestSuite(DelayedOptionalDependencies.class);
+ ots.addTestSuite(DelayedMultipleDependencies.class);
+ ots.addTestSuite(DelayedOptionalMultipleDependencies.class);
+ ots.addTestSuite(MethodSimpleDependencies.class);
+ ots.addTestSuite(MethodOptionalDependencies.class);
+ ots.addTestSuite(MethodMultipleDependencies.class);
+ ots.addTestSuite(MethodOptionalMultipleDependencies.class);
+ ots.addTestSuite(MethodDelayedSimpleDependencies.class);
+ ots.addTestSuite(MethodDelayedOptionalDependencies.class);
+ ots.addTestSuite(MethodDelayedMultipleDependencies.class);
+ ots.addTestSuite(MethodDelayedOptionalMultipleDependencies.class);
+ ots.addTestSuite(SimpleFilterDependencies.class);
+ ots.addTestSuite(OptionalSimpleFilterDependencies.class);
+ ots.addTestSuite(MultipleFilterDependencies.class);
+ ots.addTestSuite(OptionalMultipleFilterDependencies.class);
+ ots.addTest(StaticDependencyTestSuite.suite(bc));
+ ots.addTest(DefaultImplementationTestSuite.suite(bc));
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedMultipleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedMultipleDependencies.java
new file mode 100644
index 0000000..822be4b
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedMultipleDependencies.java
@@ -0,0 +1,244 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodDelayedMultipleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4, instance5;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "MObjectMultipleCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "MRefMultipleCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "MBothMultipleCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+
+ Properties prov2 = new Properties();
+ prov2.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+ } catch(Exception e) { fail(e.getMessage()); }
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ public void testObject() {
+ instance3.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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(), 2);
+ 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(), 2);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 2.0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ instance3.stop();
+ }
+
+ public void testRef() {
+ instance4.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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(), 2);
+ assertEquals("check ref unbind callback invocation - 1", ((Integer)props.get("refU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 2.0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ instance4.stop();
+ context.ungetService(cs_ref);
+ }
+
+ public void testBoth() {
+ instance5.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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 both bind callback invocation - 1", ((Integer)props.get("bothB")).intValue(), 2);
+ assertEquals("check both unbind callback invocation - 1", ((Integer)props.get("bothU")).intValue(), 0);
+ assertEquals("Check FS invocation (int) - 1", ((Integer)props.get("int")).intValue(), 2);
+ assertEquals("Check FS invocation (long) - 1", ((Long)props.get("long")).longValue(), 2);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 2.0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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 both bind callback invocation - 3", ((Integer)props.get("bothB")).intValue(), 2);
+ assertEquals("check both unbind callback invocation - 3", ((Integer)props.get("bothU")).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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ instance5.stop();
+ context.ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedOptionalDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedOptionalDependencies.java
new file mode 100644
index 0000000..72f9271
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedOptionalDependencies.java
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodDelayedOptionalDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4, instance5;
+
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "MObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "MRefOptionalCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "MBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+ public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance3.stop();
+ }
+
+ public void testRef() {
+ instance4.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+ public void testBoth() {
+ instance5.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedOptionalMultipleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedOptionalMultipleDependencies.java
new file mode 100644
index 0000000..f08366b
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedOptionalMultipleDependencies.java
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodDelayedOptionalMultipleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4;
+ ComponentInstance fooProvider1, fooProvider2;
+
+
+ public void setUp() {
+ try {
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "MObjectOptionalMultipleCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "MRefOptionalMultipleCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+
+ Properties prov2 = new Properties();
+ prov2.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+ } catch(Exception e) { fail(e.getMessage()); }
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance3 = null;
+ instance4 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ instance3.stop();
+ }
+
+ public void testRef() {
+ instance4.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ instance4.stop();
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedSimpleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedSimpleDependencies.java
new file mode 100644
index 0000000..bc7af12
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodDelayedSimpleDependencies.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodDelayedSimpleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4, instance5;
+ ComponentInstance fooProvider;
+
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "MObjectCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "MRefCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "MBothCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+ } catch(Exception e) { fail(e.getMessage()); }
+
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+ public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance3.stop();
+ }
+
+ public void testRef() {
+ instance4.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+ public void testBoth() {
+ instance5.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodMultipleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodMultipleDependencies.java
new file mode 100644
index 0000000..20cca5b
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodMultipleDependencies.java
@@ -0,0 +1,305 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodMultipleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4, instance5;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ Properties prov2 = new Properties();
+ prov2.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+ fooProvider2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "MObjectMultipleCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "MRefMultipleCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "MBothMultipleCheckServiceProvider").createComponentInstance(i5);
+ } catch(Exception e) { fail(e.getMessage()); }
+
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ public void testObject() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testBoth() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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 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 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);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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 both bind callback invocation - 2", ((Integer)props.get("bothB")).intValue(), 2);
+ assertEquals("check both unbind callback invocation - 2", ((Integer)props.get("bothU")).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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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 both bind callback invocation - 3", ((Integer)props.get("bothB")).intValue(), 2);
+ assertEquals("check both unbind callback invocation - 3", ((Integer)props.get("bothU")).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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodOptionalDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodOptionalDependencies.java
new file mode 100644
index 0000000..e7e075f
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodOptionalDependencies.java
@@ -0,0 +1,266 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodOptionalDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4, instance5;
+
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "MObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "MRefOptionalCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "MBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+ public void testObject() {
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testBoth() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodOptionalMultipleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodOptionalMultipleDependencies.java
new file mode 100644
index 0000000..fa571eb
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodOptionalMultipleDependencies.java
@@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodOptionalMultipleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ Properties prov2 = new Properties();
+ prov2.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+ fooProvider2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "MObjectOptionalMultipleCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "MRefOptionalMultipleCheckServiceProvider").createComponentInstance(i4);
+ } catch(Exception e) { fail(e.getMessage()); }
+
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance3 = null;
+ instance4 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ public void testObject() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodSimpleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodSimpleDependencies.java
new file mode 100644
index 0000000..bf314a4
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MethodSimpleDependencies.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.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodSimpleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4, instance5;
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "MObjectCheckServiceProvider").createComponentInstance(i3);
+ assertNotNull("check instance 3", instance3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "MRefCheckServiceProvider").createComponentInstance(i4);
+ assertNotNull("check instance 4", instance4);
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "MBothCheckServiceProvider").createComponentInstance(i5);
+ assertNotNull("check instance 5", instance5);
+ } catch(Exception e) { fail(e.getMessage()); }
+
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+
+ public void testObject() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testBoth() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MultipleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MultipleDependencies.java
new file mode 100644
index 0000000..aaa401c
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MultipleDependencies.java
@@ -0,0 +1,385 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MultipleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ Properties prov2 = new Properties();
+ prov2.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+ fooProvider2.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "SimpleMultipleCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "VoidMultipleCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "ObjectMultipleCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "RefMultipleCheckServiceProvider").createComponentInstance(i4);
+ } catch(Exception e) { fail(e.getMessage()); }
+
+ }
+
+ 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;
+ }
+
+ public void testSimple() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 1.0);
+
+ fooProvider2.start();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+ assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 2.0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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(), 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);
+
+ fooProvider2.stop();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testVoid() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 1.0);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+ assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 2.0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testObject() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MultipleFilterDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MultipleFilterDependencies.java
new file mode 100644
index 0000000..8c55bb1
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/MultipleFilterDependencies.java
@@ -0,0 +1,570 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MultipleFilterDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "SimpleFilterCheckServiceProvider").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ prov = new Properties();
+ prov.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "SimpleFilterCheckServiceProvider").createComponentInstance(prov);
+ fooProvider2.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Subscriber1");
+ instance1 = Utils.getFactoryByName(context, "MultipleFilterCheckServiceSubscriber").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Subscriber2");
+ Properties ii2 = new Properties();
+ ii2.put("id2", "(toto=A)");
+ i2.put("requires.filters", ii2);
+ instance2 = Utils.getFactoryByName(context, "MultipleFilterCheckServiceSubscriber2").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Subscriber3");
+ Properties ii3 = new Properties();
+ ii3.put("id1", "(toto=A)");
+ i3.put("requires.filters", ii3);
+ instance3 = Utils.getFactoryByName(context, "MultipleFilterCheckServiceSubscriber").createComponentInstance(i3);
+
+ } catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage()); }
+
+ }
+
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ public void testMultipleNotMatch() {
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 3", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+
+ fooProvider2.start();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+ CheckService cs2 = (CheckService) context.getService(cs_ref2);
+ // change the value of the property toto
+ cs2.check();
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 6", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 6", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 7", id.getState() == ComponentInstance.INVALID);
+
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 8", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service Binding - 8", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 8", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 9", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ cs2 = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+ public void testMultipleMatch() {
+
+ fooProvider1.start();
+ fooProvider2.start();
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+ CheckService cs2 = (CheckService) context.getService(cs_ref2);
+ // change the value of the property toto
+ cs2.check();
+
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 1", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 2", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 3", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ id = null;
+ cs = null;
+ cs2 = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+ public void testMultipleNotMatchInstance() {
+ instance3.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+
+ fooProvider1.start();
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 1", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.start();
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+ CheckService cs2 = (CheckService) context.getService(cs_ref2);
+ // change the value of the property toto
+ cs2.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+
+ // change the value of the property toto
+ cs2.check();
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 6", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 6", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 7", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 8", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 8", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 8", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 9", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ cs2 = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+ public void testMultipleMatchInstance() {
+
+ fooProvider1.start();
+ fooProvider2.start();
+ instance3.start();
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 1", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 2", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 3", id.getState() == ComponentInstance.INVALID);
+
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+ public void testMultipleNotMatchInstanceWithoutFilter() {
+ instance2.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+
+ fooProvider1.start();
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 1", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.start();
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+ CheckService cs2 = (CheckService) context.getService(cs_ref2);
+ // change the value of the property toto
+ cs2.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+
+ // change the value of the property toto
+ cs2.check();
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 6", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 6", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 7", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 8", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 8", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 8", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 9", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ cs2 = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+ public void testMultipleMatchInstanceWithoutFilter() {
+ fooProvider1.start();
+ fooProvider2.start();
+ instance2.start();
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 1", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 2", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 3", id.getState() == ComponentInstance.INVALID);
+
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalDependencies.java
new file mode 100644
index 0000000..773ea6c
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalDependencies.java
@@ -0,0 +1,386 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5;
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "SimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "VoidOptionalCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "ObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "RefOptionalCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "BothOptionalCheckServiceProvider").createComponentInstance(i5);
+ } catch(Exception e) { fail(e.getMessage()); }
+ }
+
+ 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;
+ }
+
+ public void testSimple() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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")+")", 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);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testVoid() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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(), 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);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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(), 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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testObject() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testBoth() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalMultipleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalMultipleDependencies.java
new file mode 100644
index 0000000..91e222d
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalMultipleDependencies.java
@@ -0,0 +1,499 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalMultipleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ Properties prov2 = new Properties();
+ prov2.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+ fooProvider2.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "SimpleOptionalMultipleCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "VoidOptionalMultipleCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "ObjectOptionalMultipleCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "RefOptionalMultipleCheckServiceProvider").createComponentInstance(i4);
+ } catch(Exception e) { fail(e.getMessage()); }
+
+ }
+
+ 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;
+ }
+
+ public void testSimple() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 1.0);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+ assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 2.0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testVoid() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 1.0);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+ assertEquals("Check FS invocation (double) - 2", ((Double)props.get("double")).doubleValue(), 2.0);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testObject() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(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);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalMultipleFilterDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalMultipleFilterDependencies.java
new file mode 100644
index 0000000..5d0ae74
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalMultipleFilterDependencies.java
@@ -0,0 +1,592 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalMultipleFilterDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "SimpleFilterCheckServiceProvider").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ prov = new Properties();
+ prov.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "SimpleFilterCheckServiceProvider").createComponentInstance(prov);
+ fooProvider2.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Subscriber1");
+ instance1 = Utils.getFactoryByName(context, "OptionalMultipleFilterCheckServiceSubscriber").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Subscriber2");
+ Properties ii2 = new Properties();
+ ii2.put("id2", "(toto=A)");
+ i2.put("requires.filters", ii2);
+ instance2 = Utils.getFactoryByName(context, "OptionalMultipleFilterCheckServiceSubscriber2").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Subscriber3");
+ Properties ii3 = new Properties();
+ ii3.put("id1", "(toto=A)");
+ i3.put("requires.filters", ii3);
+ instance3 = Utils.getFactoryByName(context, "OptionalMultipleFilterCheckServiceSubscriber").createComponentInstance(i3);
+
+ } catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage()); }
+
+ }
+
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ public void testMultipleNotMatch() {
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 1", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 2", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 3", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+
+ fooProvider2.start();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+ CheckService cs2 = (CheckService) context.getService(cs_ref2);
+ // change the value of the property toto
+ cs2.check();
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 6", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 6", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 7", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 7", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 7", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 8", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 8", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 8", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 9", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 9", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 9", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ id = null;
+ cs = null;
+ cs2 = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+ public void testMultipleMatch() {
+
+ fooProvider1.start();
+ fooProvider2.start();
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+ CheckService cs2 = (CheckService) context.getService(cs_ref2);
+ // change the value of the property toto
+ cs2.check();
+
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 1", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 2", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 3", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ id = null;
+ cs = null;
+ cs2 = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+ public void testMultipleNotMatchInstance() {
+ instance3.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 1", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ fooProvider1.start();
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 2", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 3", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+
+ fooProvider2.start();
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+ CheckService cs2 = (CheckService) context.getService(cs_ref2);
+ // change the value of the property toto
+ cs2.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+
+ // change the value of the property toto
+ cs2.check();
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 6", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 6", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 7", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 7", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 7", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 8", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 8", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 8", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 9", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 9", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 9", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ id = null;
+ cs = null;
+ cs2 = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+ public void testMultipleMatchInstance() {
+
+ fooProvider1.start();
+ fooProvider2.start();
+ instance3.start();
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 1", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 2", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 3", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+ public void testMultipleNotMatchInstanceWithoutFilter() {
+ instance2.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 1", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ fooProvider1.start();
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 2", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 3", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+
+ fooProvider2.start();
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+ CheckService cs2 = (CheckService) context.getService(cs_ref2);
+ // change the value of the property toto
+ cs2.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+
+ // change the value of the property toto
+ cs2.check();
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 6", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 6", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 7", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 7", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 7", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 8", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 8", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 8", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 9", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 9", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 9", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ id = null;
+ cs = null;
+ cs2 = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+ public void testMultipleMatchInstanceWithoutFilter() {
+
+
+ fooProvider1.start();
+ fooProvider2.start();
+ instance2.start();
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+
+ ServiceReference cs_ref2 = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref2);
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 1", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 2", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ fooProvider2.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Array size - 3", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(0)));
+
+ fooProvider2.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertTrue("Check Array size - 4", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(1)));
+
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(2)));
+ assertTrue("Check Array size - 5", ((Integer)cs_instance.getProps().get("Size")).equals(new Integer(2)));
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ context.ungetService(cs_ref2);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalSimpleFilterDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalSimpleFilterDependencies.java
new file mode 100644
index 0000000..061d08e
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/OptionalSimpleFilterDependencies.java
@@ -0,0 +1,558 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalSimpleFilterDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "SimpleFilterCheckServiceProvider").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ prov = new Properties();
+ prov.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "SimpleFilterCheckServiceProvider").createComponentInstance(prov);
+ fooProvider2.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Subscriber1");
+ instance1 = Utils.getFactoryByName(context, "OptionalSimpleFilterCheckServiceSubscriber").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Subscriber2");
+ Properties ii2 = new Properties();
+ ii2.put("id2", "(toto=A)");
+ i2.put("requires.filters", ii2);
+ instance2 = Utils.getFactoryByName(context, "OptionalSimpleFilterCheckServiceSubscriber2").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Subscriber3");
+ Properties ii3 = new Properties();
+ ii3.put("id1", "(toto=A)");
+ i3.put("requires.filters", ii3);
+ instance3 = Utils.getFactoryByName(context, "OptionalSimpleFilterCheckServiceSubscriber").createComponentInstance(i3);
+
+ } catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage()); }
+
+ }
+
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ public void testSimpleNotMatch() {
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 1", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 2", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertFalse("Check Nullable - 3", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 4", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 5", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 6", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+ assertTrue("Check service Binding - 7", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 7", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service Binding - 8", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 8", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testSimpleMatch() {
+
+ fooProvider1.start();
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 1", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 2", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 3", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 4", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 5", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 6", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 6", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testSimpleNotMatchInstance() {
+ instance3.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 1", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.start();
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 2", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 3", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 4", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 5", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 6", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 6", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 7", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 7", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 7", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 8", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 8", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 8", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testSimpleMatchInstance() {
+
+ fooProvider1.start();
+ instance3.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 1", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 2", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 3", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 4", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 5", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 6", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 6", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testSimpleNotMatchInstanceWithoutFilter() {
+ instance2.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 1", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.start();
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 2", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 3", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 4", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 5", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 6", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 6", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 7", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 7", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 7", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 8", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 8", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 8", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testSimpleMatchInstanceWithoutFilter() {
+
+ fooProvider1.start();
+ instance2.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 1", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 1", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 2", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 2", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 3", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 3", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 4", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 4", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 4", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 5", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(1)));
+ assertFalse("Check Nullable - 5", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 6", id.getState() == ComponentInstance.VALID);
+ assertTrue("Check service invocation", cs_instance.check());
+ assertTrue("Check service Binding - 6", ((Integer)cs_instance.getProps().get("Bind")).equals(new Integer(0)));
+ assertTrue("Check Nullable - 6", ((Boolean)cs_instance.getProps().get("Nullable")).booleanValue());
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/SimpleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/SimpleDependencies.java
new file mode 100644
index 0000000..ad02a8f
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/SimpleDependencies.java
@@ -0,0 +1,319 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class SimpleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5, instance6;
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "SimpleCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "VoidCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "ObjectCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "RefCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "BothCheckServiceProvider").createComponentInstance(i5);
+
+ Properties i6 = new Properties();
+ i6.put("name", "Double");
+ instance6 = Utils.getFactoryByName(context, "DoubleCheckServiceProvider").createComponentInstance(i6);
+ } catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage()); }
+
+ }
+
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ instance6.dispose();
+ fooProvider.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ instance6 = null;
+ fooProvider = null;
+ }
+
+ public void testSimple() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testVoid() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ Object o = context.getService(cs_ref);
+ CheckService cs = (CheckService) o;
+ 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()+")", ((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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testObject() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testBoth() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testDouble() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance6.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertNotNull("Check cs", cs);
+ cs.check();
+ 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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/SimpleFilterDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/SimpleFilterDependencies.java
new file mode 100644
index 0000000..c6a2333
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/SimpleFilterDependencies.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.test.scenarios.dependency;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class SimpleFilterDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "SimpleFilterCheckServiceProvider").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ prov = new Properties();
+ prov.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "SimpleFilterCheckServiceProvider").createComponentInstance(prov);
+ fooProvider2.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Subscriber1");
+ instance1 = Utils.getFactoryByName(context, "SimpleFilterCheckServiceSubscriber").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Subscriber2");
+ Properties ii2 = new Properties();
+ ii2.put("id2", "(toto=A)");
+ i2.put("requires.filters", ii2);
+ instance2 = Utils.getFactoryByName(context, "SimpleFilterCheckServiceSubscriber2").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Subscriber3");
+ Properties ii3 = new Properties();
+ ii3.put("id1", "(toto=A)");
+ i3.put("requires.filters", ii3);
+ instance3 = Utils.getFactoryByName(context, "SimpleFilterCheckServiceSubscriber").createComponentInstance(i3);
+
+ } catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage()); }
+
+ }
+
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ fooProvider1.dispose();
+ fooProvider2.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ fooProvider1 = null;
+ fooProvider2 = null;
+ }
+
+ public void testSimpleNotMatch() {
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 3", id.getState() == ComponentInstance.INVALID);
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 4", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testSimpleMatch() {
+
+ fooProvider1.start();
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 3", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testSimpleNotMatchInstance() {
+ instance3.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 3", id.getState() == ComponentInstance.INVALID);
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 4", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testSimpleMatchInstance() {
+
+ fooProvider1.start();
+ instance3.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 3", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testSimpleNotMatchInstanceWithoutFilter() {
+ instance2.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 3", id.getState() == ComponentInstance.INVALID);
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 4", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testSimpleMatchInstanceWithoutFilter() {
+
+ fooProvider1.start();
+ instance2.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ CheckService cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("Check service invocation", cs_instance.check());
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), fooProvider1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ // change the value of the property toto
+ cs.check();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider1.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs_instance_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_instance_ref);
+ cs_instance = (CheckService) context.getService(cs_instance_ref);
+ assertTrue("check CheckService invocation", cs_instance.check());
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 3", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ cs_instance = null;
+ context.ungetService(cs_instance_ref);
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/DefaultImplementationTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/DefaultImplementationTestSuite.java
new file mode 100644
index 0000000..fa045d7
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/DefaultImplementationTestSuite.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency.di;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class DefaultImplementationTestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Default Implementation Test Suite", bc);
+ ots.addTestSuite( OptionalDependencies.class);
+ ots.addTestSuite( MethodOptionalDependencies.class);
+ ots.addTestSuite( DelayedOptionalDependencies.class);
+ ots.addTestSuite( MethodDelayedOptionalDependencies.class);
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/DelayedOptionalDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/DelayedOptionalDependencies.java
new file mode 100644
index 0000000..29a3efe
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/DelayedOptionalDependencies.java
@@ -0,0 +1,353 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency.di;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedOptionalDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5;
+
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "DISimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+ instance1.stop();
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "DIVoidOptionalCheckServiceProvider").createComponentInstance(i2);
+ instance2.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "DIObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "DIRefOptionalCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "DIBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ 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;
+ }
+
+ public void testSimple() {
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance1.stop();
+ }
+
+ public void testVoid() {
+ instance2.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance2.stop();
+ }
+
+ public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance3.stop();
+ }
+
+ public void testRef() {
+ instance4.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+ public void testBoth() {
+ instance5.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/MethodDelayedOptionalDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/MethodDelayedOptionalDependencies.java
new file mode 100644
index 0000000..4d404c7
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/MethodDelayedOptionalDependencies.java
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency.di;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodDelayedOptionalDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4, instance5;
+
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "DIMObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+ instance3.stop();
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "DIMRefOptionalCheckServiceProvider").createComponentInstance(i4);
+ instance4.stop();
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "DIMBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ instance5.stop();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+ public void testObject() {
+ instance3.start();
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance3.stop();
+ }
+
+ public void testRef() {
+ instance4.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+ public void testBoth() {
+ instance5.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+
+ instance4.stop();
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/MethodOptionalDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/MethodOptionalDependencies.java
new file mode 100644
index 0000000..2713fbe
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/MethodOptionalDependencies.java
@@ -0,0 +1,266 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency.di;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodOptionalDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4, instance5;
+
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "DIMObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "DIMRefOptionalCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "DIMBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+ public void testObject() {
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testBoth() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/OptionalDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/OptionalDependencies.java
new file mode 100644
index 0000000..1a1d359
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/di/OptionalDependencies.java
@@ -0,0 +1,386 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency.di;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5;
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "DISimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "DIVoidOptionalCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "DIObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "DIRefOptionalCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "DIBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ } catch(Exception e) { fail(e.getMessage()); }
+ }
+
+ 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;
+ }
+
+ public void testSimple() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testVoid() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testObject() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testBoth() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/MethodOptionalDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/MethodOptionalDependencies.java
new file mode 100644
index 0000000..310f131
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/MethodOptionalDependencies.java
@@ -0,0 +1,266 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency.statics;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodOptionalDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4, instance5;
+
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "StaticMObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "StaticMRefOptionalCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "StaticMBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+ public void testObject() {
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testBoth() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/MethodSimpleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/MethodSimpleDependencies.java
new file mode 100644
index 0000000..70fef81
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/MethodSimpleDependencies.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.test.scenarios.dependency.statics;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MethodSimpleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance3, instance4, instance5;
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "StaticMObjectCheckServiceProvider").createComponentInstance(i3);
+ assertNotNull("check instance 3", instance3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "StaticMRefCheckServiceProvider").createComponentInstance(i4);
+ assertNotNull("check instance 4", instance4);
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "StaticMBothCheckServiceProvider").createComponentInstance(i5);
+ assertNotNull("check instance 5", instance5);
+ } catch(Exception e) { fail(e.getMessage()); }
+
+ }
+
+ public void tearDown() {
+ instance3.dispose();
+ instance4.dispose();
+ instance5.dispose();
+ fooProvider.dispose();
+ instance3 = null;
+ instance4 = null;
+ instance5 = null;
+ fooProvider = null;
+ }
+
+
+ public void testObject() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testBoth() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/MultipleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/MultipleDependencies.java
new file mode 100644
index 0000000..251adc7
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/MultipleDependencies.java
@@ -0,0 +1,307 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency.statics;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MultipleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4;
+ ComponentInstance fooProvider1, fooProvider2;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider1");
+ fooProvider1 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider1.stop();
+
+ Properties prov2 = new Properties();
+ prov2.put("name", "FooProvider2");
+ fooProvider2 = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov2);
+ fooProvider2.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "StaticSimpleMultipleCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "StaticVoidMultipleCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "StaticObjectMultipleCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "StaticRefMultipleCheckServiceProvider").createComponentInstance(i4);
+ } catch(Exception e) { fail(e.getMessage()); }
+
+ }
+
+ 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;
+ }
+
+ public void testSimple() {
+ instance1.stop();
+ fooProvider1.start();
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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);
+ assertEquals("Check FS invocation (double) - 1", ((Double)props.get("double")).doubleValue(), 1.0);
+
+ fooProvider2.start();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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(), 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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testVoid() {
+ instance2.stop();
+ fooProvider1.start();
+ instance2.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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);
+ assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 1.0);
+
+ fooProvider2.start();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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(), 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);
+ 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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testObject() {
+ instance3.stop();
+ fooProvider1.start();
+ instance3.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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);
+
+ fooProvider2.start();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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(), 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 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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testRef() {
+ instance4.stop();
+ fooProvider1.start();
+ instance4.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties 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);
+
+ fooProvider2.start();
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.getService(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(), 1);
+ assertEquals("check ref unbind callback invocation - 2", ((Integer) props.get("refU")).intValue(), 0);
+ 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);
+
+ fooProvider1.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 5", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/OptionalDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/OptionalDependencies.java
new file mode 100644
index 0000000..601cd08
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/OptionalDependencies.java
@@ -0,0 +1,506 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency.statics;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.MissingHandlerException;
+import org.apache.felix.ipojo.UnacceptableConfiguration;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5;
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "StaticSimpleOptionalCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "StaticVoidOptionalCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "StaticObjectOptionalCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "StaticRefOptionalCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "StaticBothOptionalCheckServiceProvider").createComponentInstance(i5);
+ } catch(Exception e) { fail(e.getMessage()); }
+ }
+
+ 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;
+ }
+
+ public void atestSimple() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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(), 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);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ props = cs.getProps();
+
+ //Check properties
+ assertFalse("check CheckService invocation - 2", ((Boolean)props.get("result")).booleanValue()); // False, the provider was not bound
+ 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);
+ 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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void atestDelayedSimple() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+ instance1.stop();
+ fooProvider.start();
+ instance1.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties props = cs.getProps();
+
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean)props.get("result")).booleanValue()); // True, the provider was bound
+ 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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.INVALID); // Dependency broken
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void atestVoid() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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(), 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);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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);
+ 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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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")) + ")", ((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);
+ 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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void testDelayedVoid() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+ instance2.stop();
+ fooProvider.start();
+ instance2.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties props = cs.getProps();
+
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean)props.get("result")).booleanValue()); // True, the provider was bound
+ 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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3 (" + id.getState() + ")", id.getState() == ComponentInstance.INVALID); // Dependency broken
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void atestObject() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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() + ")", ((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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void atestDelayedObject() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+ instance3.stop();
+ fooProvider.start();
+ instance3.start();
+
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ Properties props = cs.getProps();
+
+ //Check properties
+ assertTrue("check CheckService invocation - 2", ((Boolean)props.get("result")).booleanValue()); // True, the provider was bound
+ 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);
+ 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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.INVALID); // Dependency broken
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void atestRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+ public void atestBoth() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.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(), 0);
+ assertEquals("check both unbind callback invocation -2", ((Integer)props.get("bothU")).intValue(), 0);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 3 (" + id.getState() + ")", id.getState() == ComponentInstance.VALID);
+
+ cs = (CheckService) context.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(), 0);
+ assertEquals("check both unbind callback invocation -3", ((Integer)props.get("bothU")).intValue(), 0);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/SimpleDependencies.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/SimpleDependencies.java
new file mode 100644
index 0000000..8623784
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/SimpleDependencies.java
@@ -0,0 +1,319 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency.statics;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class SimpleDependencies extends OSGiTestCase {
+
+ ComponentInstance instance1, instance2, instance3, instance4, instance5;
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ try {
+ Properties prov = new Properties();
+ prov.put("name", "FooProvider");
+ fooProvider = Utils.getFactoryByName(context, "FooProviderType-1").createComponentInstance(prov);
+ fooProvider.stop();
+
+ Properties i1 = new Properties();
+ i1.put("name", "Simple");
+ instance1 = Utils.getFactoryByName(context, "StaticSimpleCheckServiceProvider").createComponentInstance(i1);
+
+ Properties i2 = new Properties();
+ i2.put("name", "Void");
+ instance2 = Utils.getFactoryByName(context, "StaticVoidCheckServiceProvider").createComponentInstance(i2);
+
+ Properties i3 = new Properties();
+ i3.put("name", "Object");
+ instance3 = Utils.getFactoryByName(context, "StaticObjectCheckServiceProvider").createComponentInstance(i3);
+
+ Properties i4 = new Properties();
+ i4.put("name", "Ref");
+ instance4 = Utils.getFactoryByName(context, "StaticRefCheckServiceProvider").createComponentInstance(i4);
+
+ Properties i5 = new Properties();
+ i5.put("name", "Both");
+ instance5 = Utils.getFactoryByName(context, "StaticBothCheckServiceProvider").createComponentInstance(i5);
+ } catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage()); }
+
+ }
+
+ 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;
+ }
+
+ public void testSimple() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.INVALID);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance1.getInstanceName());
+ assertNull("Check CheckService availability", cs_ref);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ }
+
+ public void testVoid() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ Object o = context.getService(cs_ref);
+ CheckService cs = (CheckService) o;
+ 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()+")", ((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);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.INVALID);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance2.getInstanceName());
+ assertNull("Check CheckService availability - 2", cs_ref);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ }
+
+ public void testObject() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.INVALID);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance3.getInstanceName());
+ assertNull("Check CheckService availability - 2", cs_ref);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ }
+
+ public void testRef() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.INVALID);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance4.getInstanceName());
+ assertNull("Check CheckService availability - 2", cs_ref);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ }
+
+ public void testBoth() {
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity", id.getState() == ComponentInstance.VALID);
+
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.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) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.INVALID);
+
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance5.getInstanceName());
+ assertNull("Check CheckService availability - 2", cs_ref);
+
+ fooProvider.stop();
+
+ id = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id.getState() == ComponentInstance.INVALID);
+
+ id = null;
+ cs = null;
+ context.ungetService(arch_ref);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/StaticDependencyTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/StaticDependencyTestSuite.java
new file mode 100644
index 0000000..656c635
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/dependency/statics/StaticDependencyTestSuite.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.dependency.statics;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class StaticDependencyTestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Static Dependency Test Suite", bc);
+ ots.addTestSuite( SimpleDependencies.class);
+ ots.addTestSuite( OptionalDependencies.class);
+ ots.addTestSuite( MultipleDependencies.class);
+ ots.addTestSuite( MethodSimpleDependencies.class);
+ ots.addTestSuite( MethodOptionalDependencies.class);
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/ConfigAdminTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/ConfigAdminTest.java
new file mode 100644
index 0000000..34f5b5d
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/ConfigAdminTest.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.factory;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class ConfigAdminTest extends OSGiTestCase {
+
+ private ManagedServiceFactory getFactoryByName(String pid) {
+ ServiceReference[] refs;
+ try {
+ refs = context.getServiceReferences(ManagedServiceFactory.class.getName(), "(service.pid="+pid+")");
+ if(refs == null) { return null; }
+ return ((org.osgi.service.cm.ManagedServiceFactory) context.getService(refs[0]));
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Cannot get the factory " + pid + " : " + e.getMessage());
+ return null;
+ }
+ }
+
+ public void testCreation() {
+ ManagedServiceFactory f = getFactoryByName("FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("int", new Integer(3));
+ p.put("long", new Long(42));
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+ p.put("intAProp", new int[] {1,2});
+
+ try {
+ f.updated("ok2", p);
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), "ok2");
+ assertNotNull("Check instance creation", ref);
+ f.deleted("ok2");
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), "ok2");
+ assertNull("Check instance deletion", ref);
+ } catch (ConfigurationException e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ public void testCreationString() {
+ ManagedServiceFactory f = getFactoryByName("FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("int", "3");
+ p.put("long", "42");
+ p.put("string", "absdir");
+ p.put("strAProp", "{a}");
+ p.put("intAProp", "{1,2}");
+
+ try {
+ f.updated("ok2", p);
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), "ok2");
+ assertNotNull("Check instance creation", ref);
+ f.deleted("ok2");
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), "ok2");
+ assertNull("Check instance deletion", ref);
+ } catch (ConfigurationException e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ public void testUpdate() {
+ ManagedServiceFactory f = getFactoryByName("FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("int", new Integer(3));
+ p.put("long", new Long(42));
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+ p.put("intAProp", new int[] {1,2});
+
+ try {
+ f.updated("okkkk", p);
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), "okkkk");
+ assertNotNull("Check instance creation", ref);
+ p.put("int", new Integer("4"));
+ f.updated("okkkk", p);
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), "okkkk");
+ Integer test = (Integer) ref.getProperty("int");
+ assertEquals("Check instance modification", 4, test.intValue());
+ f.deleted("okkkk");
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), "okkkk");
+ assertNull("Check instance deletion", ref);
+ } catch (ConfigurationException e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ public void testUpdateString() {
+ ManagedServiceFactory f = getFactoryByName("FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("int", "3");
+ p.put("long", "42");
+ p.put("string", "absdir");
+ p.put("strAProp", "{a}");
+ p.put("intAProp", "{1,2}");
+
+ try {
+ f.updated("okkkk", p);
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), "okkkk");
+ assertNotNull("Check instance creation", ref);
+ p.put("int", new Integer("4"));
+ f.updated("okkkk", p);
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), "okkkk");
+ Integer test = (Integer) ref.getProperty("int");
+ assertEquals("Check instance modification", 4, test.intValue());
+ f.deleted("okkkk");
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), "okkkk");
+ assertNull("Check instance deletion", ref);
+ } catch (ConfigurationException e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/FactoryTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/FactoryTestSuite.java
new file mode 100644
index 0000000..4c45c4c
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/FactoryTestSuite.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.factory;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class FactoryTestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Factories Test Suite", bc);
+
+ ots.addTestSuite( UnacceptableConfigurationTest.class);
+ ots.addTestSuite( ConfigAdminTest.class);
+ ots.addTestSuite( ObedienceTest.class);
+
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/ObedienceTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/ObedienceTest.java
new file mode 100644
index 0000000..da818e4
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/ObedienceTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.factory;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+
+public class ObedienceTest extends OSGiTestCase {
+
+ public void testObedience1() {
+ assertNull("Check no foo service", context.getServiceReference(FooService.class.getName()));
+ ComponentFactory factory = (ComponentFactory) Utils.getFactoryByName(context, "FooProviderType-1");
+ assertNotNull("Check factory existing", factory);
+
+ Properties props1 = new Properties();
+ props1.put("name", "foo1");
+ Properties props2 = new Properties();
+ props2.put("name", "foo2");
+
+ ComponentInstance ci1 = null, ci2 = null;
+ try {
+ ci1 = factory.createComponentInstance(props1);
+ ci2 = factory.createComponentInstance(props2);
+ } catch(Exception e) {
+ fail("Cannot instantiate foo providers : " + e.getMessage());
+ }
+
+ assertTrue("Check foo1 validity", ci1.getState() == ComponentInstance.VALID);
+ assertTrue("Check foo2 validity", ci2.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check foo service", context.getServiceReference(FooService.class.getName()));
+ assertEquals("Check the number of Foo", Utils.getServiceReferences(context, FooService.class.getName(), null).length, 2);
+
+ factory.stop();
+
+ assertTrue("Check foo1 invalidity ("+ci1.getState()+")", ci1.getState() == ComponentInstance.DISPOSED);
+ assertTrue("Check foo2 invalidity ("+ci1.getState()+")", ci2.getState() == ComponentInstance.DISPOSED);
+
+ assertNull("Check no foo service", context.getServiceReference(FooService.class.getName()));
+
+ factory.start();
+ assertNull("Check no foo service", context.getServiceReference(FooService.class.getName()));
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/UnacceptableConfigurationTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/UnacceptableConfigurationTest.java
new file mode 100644
index 0000000..797b5db
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/factory/UnacceptableConfigurationTest.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.test.scenarios.factory;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+
+public class UnacceptableConfigurationTest extends OSGiTestCase {
+
+ public void testWithoutName() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("int", new Integer(3));
+ p.put("long", new Long(42));
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+ p.put("intAProp", new int[] {1,2});
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) { fail("an acceptable configuration is refused : " + e.getMessage()); }
+
+ }
+
+ public void testEmptyConfiguration() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-2");
+ Properties p = new Properties();
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) { fail("An acceptable configuration is refused"); }
+ }
+
+ public void testEmptyConfiguration2() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-Dyn2");
+ Properties p = new Properties();
+ p.put("name", "ko");
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) { return; }
+
+ fail("An unacceptable configuration is accepted");
+ }
+
+ public void testNull() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-2");
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(null);
+ ci.dispose();
+ } catch(Exception e) { fail("An acceptable configuration is refused"); }
+ }
+
+ public void testNull2() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-Dyn2");
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(null);
+ ci.dispose();
+ } catch(Exception e) { return; }
+
+ fail("An unacceptable configuration is accepted");
+ }
+
+ public void testStaticOK() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("name", "ok");
+ p.put("int", new Integer(3));
+ p.put("long", new Long(42));
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+ p.put("intAProp", new int[] {1,2});
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ public void testDynamicOK() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-Dyn");
+
+ Properties p = new Properties();
+ p.put("name", "ok");
+ p.put("int", new Integer(3));
+ p.put("boolean", new Boolean(true));
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+ p.put("intAProp", new int[] {1,2});
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) {
+ e.printStackTrace();
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ public void testDynamicBadType() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-Dyn");
+
+ Properties p = new Properties();
+ p.put("name", "ok");
+ p.put("int", new Integer(3));
+ p.put("long", new Long(42));
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+ p.put("intAProp", new int[] {1,2});
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ public void testDynamicComplete() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("name", "ok");
+ p.put("int", new Integer(3));
+ p.put("boolean", new Boolean(true));
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+ p.put("intAProp", new int[] {1,2});
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ public void testDynamicJustEnough() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("name", "ok");
+ p.put("boolean", new Boolean(true));
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ public void testDynamicMix() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("name", "ok");
+ p.put("boolean", new Boolean(true));
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+ p.put("intAProp", new int[] {1,2});
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ public void testDynamicUncomplete() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("name", "ok");
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+ p.put("intAProp", new int[] {1,2});
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) { return; }
+
+ fail("An unacceptable configuration is accepted");
+ }
+
+ public void testDynamicMore() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("name", "ok");
+ p.put("int", new Integer(3));
+ p.put("boolean", new Boolean(true));
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+ p.put("intAProp", new int[] {1,2});
+ p.put("tralala", "foo");
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ public void testDoubleProps() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("name", "ok");
+ p.put("int", new Integer(3));
+ p.put("boolean", new Boolean(true));
+ p.put("string", "absdir");
+ p.put("strAProp", new String[] {"a"});
+ p.put("intAProp", new int[] {1,2});
+ p.put("boolean", new Boolean(false));
+ p.put("string", "toto");
+
+ ComponentInstance ci = null;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch(Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ public void testUnicity1() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-2");
+
+ ComponentInstance ci1,ci2, ci3 = null;
+ try {
+ ci1 = f.createComponentInstance(null);
+ ci2 = f.createComponentInstance(null);
+ ci3 = f.createComponentInstance(null);
+ assertNotEquals("Check name ci1, ci2", ci1.getInstanceName(), ci2.getInstanceName());
+ assertNotEquals("Check name ci1, ci3", ci1.getInstanceName(), ci3.getInstanceName());
+ assertNotEquals("Check name ci3, ci2", ci3.getInstanceName(), ci2.getInstanceName());
+ ci1.dispose();
+ ci2.dispose();
+ ci3.dispose();
+ } catch(Exception e) { fail("An acceptable configuration is refused"); }
+ }
+
+ public void testUnicity2() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-2");
+
+ ComponentInstance ci1,ci2, ci3 = null;
+ try {
+ Properties p1 = new Properties();
+ p1.put("name", "name1");
+ ci1 = f.createComponentInstance(p1);
+ Properties p2 = new Properties();
+ p2.put("name", "name2");
+ ci2 = f.createComponentInstance(p2);
+ Properties p3 = new Properties();
+ p3.put("name", "name3");
+ ci3 = f.createComponentInstance(p3);
+ assertNotEquals("Check name ci1, ci2", ci1.getInstanceName(), ci2.getInstanceName());
+ assertNotEquals("Check name ci1, ci3", ci1.getInstanceName(), ci3.getInstanceName());
+ assertNotEquals("Check name ci3, ci2", ci3.getInstanceName(), ci2.getInstanceName());
+ ci1.dispose();
+ ci2.dispose();
+ ci3.dispose();
+ } catch(Exception e) { fail("An acceptable configuration is refused"); }
+ }
+
+ public void testUnicity3() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-2");
+
+ ComponentInstance ci1 = null,ci2 = null, ci3 = null;
+ try {
+ Properties p1 = new Properties();
+ p1.put("name", "name1");
+ ci1 = f.createComponentInstance(p1);
+ Properties p2 = new Properties();
+ p2.put("name", "name1");
+ ci2 = f.createComponentInstance(p2);
+ assertNotEquals("Check name ci1, ci2", ci1.getInstanceName(), ci2.getInstanceName());
+ assertNotEquals("Check name ci1, ci3", ci1.getInstanceName(), ci3.getInstanceName());
+ assertNotEquals("Check name ci3, ci2", ci3.getInstanceName(), ci3.getInstanceName());
+ ci1.dispose();
+ ci2.dispose();
+ ci3.dispose();
+ } catch(Exception e) {
+ ci1.dispose();
+ return; }
+
+ fail("An unacceptable configuration is acceptable");
+ }
+
+ public void testUnicity4() {
+ Factory f = Utils.getFactoryByName(context, "FooProviderType-2");
+ Factory f2 = Utils.getFactoryByName(context, "FooProviderType-1");
+
+ ComponentInstance ci1 = null,ci2 = null, ci3 = null;
+ try {
+ Properties p1 = new Properties();
+ p1.put("name", "name1");
+ ci1 = f.createComponentInstance(p1);
+ Properties p2 = new Properties();
+ p2.put("name", "name1");
+ ci2 = f2.createComponentInstance(p2);
+ System.err.println("==== " + ci1.getInstanceName() + " === " + ci2.getInstanceName());
+ assertNotEquals("Check name ci1, ci2", ci1.getInstanceName(), ci2.getInstanceName());
+ assertNotEquals("Check name ci1, ci3", ci1.getInstanceName(), ci3.getInstanceName());
+ assertNotEquals("Check name ci3, ci2", ci3.getInstanceName(), ci3.getInstanceName());
+ ci1.dispose();
+ ci2.dispose();
+ ci3.dispose();
+ } catch(Exception e) {
+ ci1.dispose();
+ return; }
+
+ fail("An unacceptable configuration is acceptable");
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/handler/ExternalHandlerTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/handler/ExternalHandlerTestSuite.java
new file mode 100644
index 0000000..f37d2ec
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/handler/ExternalHandlerTestSuite.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.handler;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class ExternalHandlerTestSuite extends TestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("External Handler Test Suite", bc);
+ ots.addTestSuite(HandlerTest.class);
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/handler/HandlerTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/handler/HandlerTest.java
new file mode 100644
index 0000000..a9d2718
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/handler/HandlerTest.java
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.handler;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.HandlerFactory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class HandlerTest extends OSGiTestCase {
+
+ ComponentInstance instance;
+
+ public void setUp() {
+ Properties props = new Properties();
+ props.put("name", "HandlerTest-1");
+ props.put("csh.simple", "simple");
+ Properties p = new Properties();
+ p.put("a", "a");
+ p.put("b", "b");
+ p.put("c", "c");
+ props.put("csh.map", p);
+ instance = Utils.getComponentInstance(context, "HandlerTester", props);
+ }
+
+ public void tearDown() {
+ instance.dispose();
+ instance = null;
+ }
+
+ public void testConfiguration1() {
+ // Check the availability of CheckService
+ String name = "HandlerTest-1";
+ ServiceReference sr = null;
+ ServiceReference[] refs = null;
+ String filter = "("+"instance.name"+"="+name+")";
+ try {
+ refs = context.getServiceReferences(CheckService.class.getName(), filter);
+ } catch (InvalidSyntaxException e) { System.err.println("Invalid Filter : " + filter);}
+ if(refs != null) { sr = refs[0]; }
+
+ assertNotNull("Check the check service availability", sr);
+
+ CheckService cs = (CheckService) context.getService(sr);
+ Properties p = cs.getProps();
+ assertEquals("Assert 'simple' equality", p.get("Simple"), "simple");
+ assertEquals("Assert 'a' equality", p.get("Map1"), "a");
+ assertEquals("Assert 'b' equality", p.get("Map2"), "b");
+ assertEquals("Assert 'c' equality", p.get("Map3"), "c");
+
+ cs = null;
+ context.ungetService(sr);
+ }
+
+ public void testConfiguration2() {
+ // Check the availability of CheckService
+ String name = "HandlerTest-2";
+ ServiceReference sr = null;
+ ServiceReference[] refs = null;
+ String filter = "("+"instance.name"+"="+name+")";
+ try {
+ refs = context.getServiceReferences(CheckService.class.getName(), filter);
+ } catch (InvalidSyntaxException e) { System.err.println("Invalid Filter : " + filter);}
+ if(refs != null) { sr = refs[0]; }
+ assertNotNull("Check the check service availability", sr);
+
+ CheckService cs = (CheckService) context.getService(sr);
+ Properties p = cs.getProps();
+ assertEquals("Assert 'simple' equality", p.get("Simple"), "Simple");
+ assertEquals("Assert 'a' equality", p.get("Map1"), "a");
+ assertEquals("Assert 'b' equality", p.get("Map2"), "b");
+ assertEquals("Assert 'c' equality", p.get("Map3"), "c");
+
+ cs = null;
+ context.ungetService(sr);
+ }
+
+ public void testLifecycle() {
+ // Check the availability of CheckService
+ String name = "HandlerTest-1";
+ ServiceReference sr = null;
+ ServiceReference[] refs = null;
+ String filter = "("+"instance.name"+"="+name+")";
+ try {
+ refs = context.getServiceReferences(CheckService.class.getName(), filter);
+ } catch (InvalidSyntaxException e) { System.err.println("Invalid Filter : " + filter);}
+ if(refs != null) { sr = refs[0]; }
+ assertNotNull("Check the check service availability", sr);
+
+ ServiceReference sr_arch = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "HandlerTest-1");
+ Architecture arch = (Architecture) context.getService(sr_arch);
+
+ assertEquals("Check instance validity - 0", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+
+ CheckService cs = (CheckService) context.getService(sr);
+ Properties p = cs.getProps();
+ Integer changes = (Integer) p.get("changes");
+ assertNotNull("Check changes no null", changes);
+ assertEquals("Changes changes 1 ("+changes+")", changes.intValue(), 1);
+ assertEquals("Check instance validity - 1", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+ cs.check();
+ p = cs.getProps();
+ changes = (Integer) p.get("changes");
+ assertEquals("Changes changes 2 ("+changes+")", changes.intValue(), 2);
+ assertEquals("Check instance validity - 2", arch.getInstanceDescription().getState(), ComponentInstance.INVALID);
+ cs.check();
+ p = cs.getProps();
+ changes = (Integer) p.get("changes");
+ assertEquals("Changes changes 3 ("+changes+")", changes.intValue(), 3);
+ assertEquals("Check instance validity - 3", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+ cs.check();
+ p = cs.getProps();
+ changes = (Integer) p.get("changes");
+ assertEquals("Changes changes 4 ("+changes+")", changes.intValue(), 4);
+ assertEquals("Check instance validity - 4", arch.getInstanceDescription().getState(), ComponentInstance.INVALID);
+
+ cs = null;
+ arch = null;
+ context.ungetService(sr_arch);
+ context.ungetService(sr);
+ }
+
+ public void testAvailability() {
+ String name = "HandlerTest-1";
+ ServiceReference sr = null;
+ ServiceReference[] refs = null;
+ String filter = "("+"instance.name"+"="+name+")";
+ try {
+ refs = context.getServiceReferences(CheckService.class.getName(), filter);
+ } catch (InvalidSyntaxException e) { System.err.println("Invalid Filter : " + filter);}
+ if(refs != null) { sr = refs[0]; }
+ assertNotNull("Check the check service availability", sr);
+
+ ServiceReference sr_arch = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "HandlerTest-1");
+ Architecture arch = (Architecture) context.getService(sr_arch);
+ assertEquals("Check validity", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+
+ // Kill the handler factory
+ HandlerFactory f = (HandlerFactory) Utils.getHandlerFactoryByName(context, "check");
+ f.stop();
+
+ sr = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "HandlerTest-1");
+ assertNull("Check the check service unavailability", sr);
+
+ sr_arch = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "HandlerTest-1");
+ assertNull("Check the architecture unavailability", sr_arch);
+
+ // The instance is disposed, restart the handler
+ f.start();
+
+ Properties props = new Properties();
+ props.put("name", "HandlerTest-1");
+ props.put("csh.simple", "simple");
+ Properties p = new Properties();
+ p.put("a", "a");
+ p.put("b", "b");
+ p.put("c", "c");
+ props.put("csh.map", p);
+ instance = Utils.getComponentInstance(context, "HandlerTester", props);
+
+ sr = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "HandlerTest-1");
+ assertNotNull("Check the check service availability - 2", sr);
+
+ sr_arch = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "HandlerTest-1");
+ arch = (Architecture) context.getService(sr_arch);
+ assertEquals("Check validity - 2", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/CallbackTestCase.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/CallbackTestCase.java
new file mode 100644
index 0000000..019bec5
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/CallbackTestCase.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.lifecycle;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class CallbackTestCase extends OSGiTestCase {
+
+ ComponentInstance instance; // Instance under test
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ Properties p2 = new Properties();
+ p2.put("name", "fooProvider");
+ fooProvider = Utils.getComponentInstance(context, "FooProviderType-1", p2);
+ fooProvider.stop();
+
+ Properties p1 = new Properties();
+ p1.put("name", "callback");
+ instance = Utils.getComponentInstance(context, "CallbackCheckService", p1);
+
+ }
+
+ public void tearDown() {
+ instance.dispose();
+ fooProvider.dispose();
+ instance= null;
+ fooProvider = null;
+ }
+
+ public void testCallback() {
+ // Check instance is invalid
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
+ assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);
+
+ // Start fooprovider
+ fooProvider.start();
+
+ // Check instance validity
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check service providing
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check int property
+ Integer index = (Integer) (cs.getProps().get("int"));
+ assertEquals("Check int property - 1", index.intValue(), 1);
+
+ assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
+
+ fooProvider.stop();
+
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
+
+ assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);
+
+ fooProvider.start();
+
+ // Check instance validity
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check service providing
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check int property
+ index = (Integer) (cs.getProps().get("int"));
+ assertEquals("Check int property - 2 ("+index.intValue()+")", index.intValue(), 3);
+
+ assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);
+
+ // Clean up
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ cs = null;
+ id_dep = null;
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ImmediateCallbackSeveralFactoryTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ImmediateCallbackSeveralFactoryTest.java
new file mode 100644
index 0000000..19b7df9
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ImmediateCallbackSeveralFactoryTest.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.lifecycle;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class ImmediateCallbackSeveralFactoryTest extends OSGiTestCase {
+
+ ComponentInstance instance; // Instance under test
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ Properties p2 = new Properties();
+ p2.put("name", "fooProvider");
+ fooProvider = Utils.getComponentInstance(context, "FooProviderType-1", p2);
+ fooProvider.stop();
+
+ Properties p1 = new Properties();
+ p1.put("name", "callback");
+ instance = Utils.getComponentInstance(context, "ImmediateCallbackCheckServiceSeveral", p1);
+
+ }
+
+ public void tearDown() {
+ instance.dispose();
+ fooProvider.dispose();
+ instance= null;
+ fooProvider = null;
+ CallbackCheckService.count = 0;
+ }
+
+ public void testCallback() {
+ // Check instance is invalid
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
+ assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);
+
+ // Start fooprovider
+ fooProvider.start();
+
+ // Check instance validity
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check service providing
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
+ // Check int property
+ Integer index = (Integer) (cs.getProps().get("int"));
+ Integer count = (Integer) (cs.getProps().get("count"));
+ assertEquals("Check int property - 1 (" + index.intValue() +")", index.intValue(), 1);
+ assertEquals("Check count property - 1 (" + count.intValue() +")", count.intValue(), 1);
+
+ fooProvider.stop();
+
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
+
+ assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);
+
+ fooProvider.start();
+
+ // Check instance validity
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check service providing
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check int property
+ index = (Integer) (cs.getProps().get("int"));
+ count = (Integer) (cs.getProps().get("count"));
+ assertEquals("Check int property - 2 ("+index.intValue()+")", index.intValue(), 3);
+ assertEquals("Check count property - 2 ("+count.intValue()+")", count.intValue(), 1);
+
+ assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);
+
+ // Clean up
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ cs = null;
+ id_dep = null;
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ImmediateCallbackSingletonFactoryTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ImmediateCallbackSingletonFactoryTest.java
new file mode 100644
index 0000000..a86911f
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ImmediateCallbackSingletonFactoryTest.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.lifecycle;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class ImmediateCallbackSingletonFactoryTest extends OSGiTestCase {
+
+ ComponentInstance instance; // Instance under test
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ Properties p2 = new Properties();
+ p2.put("name", "fooProvider");
+ fooProvider = Utils.getComponentInstance(context, "FooProviderType-1", p2);
+ fooProvider.stop();
+
+ Properties p1 = new Properties();
+ p1.put("name", "callback");
+ instance = Utils.getComponentInstance(context, "ImmediateCallbackCheckServiceSingleton", p1);
+
+ }
+
+ public void tearDown() {
+ instance.dispose();
+ fooProvider.dispose();
+ instance= null;
+ fooProvider = null;
+ CallbackCheckService.count = 0;
+ CallbackCheckService.singleton = null;
+ }
+
+ public void testCallback() {
+ // Check instance is invalid
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
+ assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);
+
+ // Start fooprovider
+ fooProvider.start();
+
+ // Check instance validity
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check service providing
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
+ // Check int property
+ Integer index = (Integer) (cs.getProps().get("int"));
+ assertEquals("Check int property - 1 (" + index.intValue() +")", index.intValue(), 1);
+
+ fooProvider.stop();
+
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
+
+ assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);
+
+ fooProvider.start();
+
+ // Check instance validity
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check service providing
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check int property
+ index = (Integer) (cs.getProps().get("int"));
+ assertEquals("Check int property - 2 ("+index.intValue()+")", index.intValue(), 3);
+
+ assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);
+
+ // Clean up
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ cs = null;
+ id_dep = null;
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ImmediateCallbackTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ImmediateCallbackTest.java
new file mode 100644
index 0000000..dad0c1d
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ImmediateCallbackTest.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.lifecycle;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class ImmediateCallbackTest extends OSGiTestCase {
+
+ ComponentInstance instance; // Instance under test
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ Properties p2 = new Properties();
+ p2.put("name", "fooProvider");
+ fooProvider = Utils.getComponentInstance(context, "FooProviderType-1", p2);
+ fooProvider.stop();
+
+ Properties p1 = new Properties();
+ p1.put("name", "callback");
+ instance = Utils.getComponentInstance(context, "ImmediateCallbackCheckService", p1);
+
+ }
+
+ public void tearDown() {
+ instance.dispose();
+ fooProvider.dispose();
+ instance= null;
+ fooProvider = null;
+ }
+
+ public void testCallback() {
+ // Check instance is invalid
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
+ assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);
+
+ // Start fooprovider
+ fooProvider.start();
+
+ // Check instance validity
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check service providing
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
+ // Check int property
+ Integer index = (Integer) (cs.getProps().get("int"));
+ assertEquals("Check int property - 1 (" + index.intValue() +")", index.intValue(), 1);
+
+ fooProvider.stop();
+
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
+
+ assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);
+
+ fooProvider.start();
+
+ // Check instance validity
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check service providing
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Check int property
+ index = (Integer) (cs.getProps().get("int"));
+ assertEquals("Check int property - 2 ("+index.intValue()+")", index.intValue(), 3);
+
+ assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);
+
+ // Clean up
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ cs = null;
+ id_dep = null;
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/LifeCycleCallbackTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/LifeCycleCallbackTest.java
new file mode 100644
index 0000000..69b171a
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/LifeCycleCallbackTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.lifecycle;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class LifeCycleCallbackTest extends TestSuite {
+
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Lifecycle callbacks Test Suite", bc);
+ ots.addTestSuite(CallbackTestCase.class);
+ ots.addTestSuite(ParentCallbackTestCase.class);
+ ots.addTestSuite(ImmediateCallbackTest.class);
+ ots.addTestSuite(ImmediateCallbackSingletonFactoryTest.class);
+ ots.addTestSuite(ImmediateCallbackSeveralFactoryTest.class);
+ return ots;
+ }
+
+}
+
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ParentCallbackTestCase.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ParentCallbackTestCase.java
new file mode 100644
index 0000000..1f4901c
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/ParentCallbackTestCase.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.lifecycle;
+
+import java.util.Properties;
+
+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.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class ParentCallbackTestCase extends OSGiTestCase {
+
+ ComponentInstance instance; // Instance under test
+ ComponentInstance fooProvider;
+
+ public void setUp() {
+ Properties p2 = new Properties();
+ p2.put("name", "fooProvider");
+ fooProvider = Utils.getComponentInstance(context, "FooProviderType-1", p2);
+ fooProvider.stop();
+
+ Properties p1 = new Properties();
+ p1.put("name", "callback");
+ instance = Utils.getComponentInstance(context, "ParentCallbackCheckService", p1);
+
+ }
+
+ public void tearDown() {
+ instance.dispose();
+ fooProvider.dispose();
+ instance= null;
+ fooProvider = null;
+ }
+
+ public void testCallback() {
+ // Check instance is invalid
+ ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance.getInstanceName());
+ assertNotNull("Check architecture availability", arch_ref);
+ InstanceDescription id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
+
+ // Start fooprovider
+ fooProvider.start();
+
+ // Check instance validity
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check service providing
+ ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ CheckService cs = (CheckService) context.getService(cs_ref);
+
+ // Check int property
+ assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
+
+ fooProvider.stop();
+
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
+
+ fooProvider.start();
+
+ // Check instance validity
+ id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();
+ assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
+
+ // Check service providing
+ cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check CheckService availability", cs_ref);
+ cs = (CheckService) context.getService(cs_ref);
+ assertTrue("check CheckService invocation", cs.check());
+
+ // Clean up
+ context.ungetService(arch_ref);
+ context.ungetService(cs_ref);
+ cs = null;
+ id_dep = null;
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ExceptionTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ExceptionTest.java
new file mode 100644
index 0000000..975e2a6
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ExceptionTest.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.manipulation;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.component.FooProviderType1;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class ExceptionTest extends OSGiTestCase {
+
+ private ComponentInstance ci_lazzy;
+ private ComponentInstance ci_immediate;
+
+ private ServiceReference lazzyRef;
+ private ServiceReference immRef;
+
+ public void setUp() {
+ String factName = "FooProviderType-1";
+ String compName = "FooProvider-1";
+
+ Properties p = new Properties();
+ p.put("name", compName);
+ ci_lazzy = Utils.getComponentInstance(context, factName, p);
+
+ String factName2 = "ImmediateFooProviderType";
+ String compName2 = "FooProvider-2";
+
+ Properties p2 = new Properties();
+ p2.put("name", compName2);
+ ci_immediate = Utils.getComponentInstance(context, factName2, p2);
+
+ lazzyRef = Utils.getServiceReference(context, Architecture.class.getName(), "(instance.name="+compName+")");
+ immRef = Utils.getServiceReference(context, Architecture.class.getName(), "(instance.name="+compName2+")");
+ assertNotNull("LazzyRef", lazzyRef);
+ assertNotNull("ImmRef", immRef);
+ }
+
+ public void tearDown() {
+ context.ungetService(lazzyRef);
+ context.ungetService(immRef);
+ ci_lazzy.dispose();
+ ci_immediate.dispose();
+ }
+
+
+ public void testException() {
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy.getInstanceName()+")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",refs);
+ FooProviderType1 fs = (FooProviderType1) context.getService(refs[0]);
+ try {
+ fs.testException();
+ context.ungetService(refs[0]);
+ fail("The method must returns an exception");
+ } catch(Exception e) {
+ context.ungetService(refs[0]);
+ }
+ }
+
+ public void testTry() {
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy.getInstanceName()+")");
+ } catch (InvalidSyntaxException e) { e.printStackTrace(); }
+ assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",refs);
+ FooProviderType1 fs = (FooProviderType1) context.getService(refs[0]);
+ try {
+ fs.testTry();
+ context.ungetService(refs[0]);
+ } catch(Exception e) {
+ context.ungetService(refs[0]);
+ fail("The method has returned an exception");
+ }
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/GetComponentInstanceTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/GetComponentInstanceTest.java
new file mode 100644
index 0000000..e82a011
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/GetComponentInstanceTest.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.test.scenarios.manipulation;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.Pojo;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class GetComponentInstanceTest extends OSGiTestCase {
+
+ public void testGetComponentInstance() {
+ String factName = "FooProviderType-1";
+ String compName = "FooProvider-1";
+ ServiceReference[] refs = null;
+
+ // Get the facotry to create a component instance
+ Factory fact = Utils.getFactoryByName(context, factName);
+ assertNotNull("Cannot find the factory FooProvider-1", fact);
+
+ Properties props = new Properties();
+ props.put("name", compName);
+ ComponentInstance ci = null;
+ try {
+ ci = fact.createComponentInstance(props);
+ } catch (Exception e1) { fail(e1.getMessage()); }
+
+ // Get a FooService provider
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(instance.name=" + compName + ")");
+ } catch (InvalidSyntaxException e) { fail("Service query failed (2) " + e); }
+
+ assertNotNull("FS not available", refs);
+
+ // Get foo object
+ FooService fs = (FooService) context.getService(refs[0]);
+
+ // Cast to POJO
+ Pojo pojo = (Pojo) fs;
+
+ // GetComponentInstance
+ ComponentInstance instance = pojo.getComponentInstance();
+ assertEquals("Check component instance name", instance.getInstanceName(), compName);
+ assertEquals("Check component factory name", instance.getFactory().getName(), factName);
+ assertNotNull("Instance description not null", instance.getInstanceDescription());
+ InstanceDescription id = instance.getInstanceDescription();
+ assertTrue("Check instance state", id.getState() == ComponentInstance.VALID);
+ assertEquals("Check created pojo count", id.getCreatedObjects().length, 1);
+ assertEquals("Check instance description name", id.getName(), compName);
+
+ // Unget the service
+ context.ungetService(refs[0]);
+
+ ci.dispose();
+
+ // Check that there is no more FooService
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), null);
+ } catch (InvalidSyntaxException e) { fail("Service query failed (3) : " + e.getMessage()); }
+
+ assertNull("FS available, but component instance stopped", refs);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationMetadata.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationMetadata.java
new file mode 100644
index 0000000..69c788e
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationMetadata.java
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.manipulation;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.parser.ManifestMetadataParser;
+import org.apache.felix.ipojo.parser.ParseException;
+import org.apache.felix.ipojo.parser.ParseUtils;
+import org.apache.felix.ipojo.test.scenarios.service.BarService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+
+public class ManipulationMetadata extends OSGiTestCase {
+
+ public void testGetMetadata() {
+ String header = (String) context.getBundle().getHeaders().get("iPOJO-Components");
+ Element elem = null;
+ try {
+ elem = ManifestMetadataParser.parse(header);
+ } catch (ParseException e) {
+ fail("Parse Exception when parsing iPOJO-Component");
+ }
+
+ assertNotNull("Check elem not null", elem);
+
+ Element manip = getManipulationForComponent(elem, "FooProviderType-1");
+ assertNotNull("Check manipulation metadata not null for " + "FooProviderType-1", manip);
+ }
+
+ public void testInterface() {
+ String comp_name = "FooProviderType-1";
+ Element manip = getManipulationForComponent(comp_name);
+ Element[] itf = manip.getElements("Interface");
+ assertEquals("Check interfaces number", itf.length, 1);
+ assertEquals("Check itf name", itf[0].getAttribute("name"), FooService.class.getName());
+ }
+
+ public void testInterfaces() {
+ String comp_name = "FooBarProviderType-1";
+ Element manip = getManipulationForComponent(comp_name);
+ Element[] itf = manip.getElements("Interface");
+ assertEquals("Check interfaces number", itf.length, 2);
+ assertEquals("Check itf name", itf[0].getAttribute("name"), FooService.class.getName());
+ assertEquals("Check itf name", itf[1].getAttribute("name"), BarService.class.getName());
+ }
+
+ public void testFields() {
+ String comp_name = "FooProviderType-Dyn";
+ Element manip = getManipulationForComponent(comp_name);
+ Element[] fields = manip.getElements("field");
+ assertEquals("Check field count " + fields.length, fields.length, 5);
+ /*
+ private int intProp;
+ private String strProp;
+ private String[] strAProp;
+ private int[] intAProp;
+ private boolean boolProp;
+ */
+
+ Element field;
+
+ field = getFieldFromName(manip, "intProp");
+ assertEquals("Check field name : " + field.getAttribute("name"), field.getAttribute("name"), "intProp");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "int");
+
+ field = getFieldFromName(manip, "strProp");
+ assertEquals("Check field name : " + field.getAttribute("name"), field.getAttribute("name"), "strProp");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "java.lang.String");
+
+ field = getFieldFromName(manip, "strAProp");
+ assertEquals("Check field name : " + field.getAttribute("name"), field.getAttribute("name"), "strAProp");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "java.lang.String[]");
+
+ field = getFieldFromName(manip, "intAProp");
+ assertEquals("Check field name : " + field.getAttribute("name"), field.getAttribute("name"), "intAProp");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "int[]");
+
+ field = getFieldFromName(manip, "boolProp");
+ assertEquals("Check field name : " + field.getAttribute("name"), field.getAttribute("name"), "boolProp");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "boolean");
+ }
+
+ public void testPrimitivesFields() {
+ String comp_name = "PrimitiveManipulationTester";
+ Element manip = getManipulationForComponent(comp_name);
+ Element[] fields = manip.getElements("Field");
+ assertEquals("Check field count", fields.length, 16);
+ /*
+ byte b = 1;
+ short s = 1;
+ int i = 1;
+ long l = 1;
+ double d = 1.1;
+ float f = 1.1f;
+ char c = 'a';
+ boolean bool = false;
+ byte[] bs = new byte[] {0,1,2};
+ short[] ss = new short[] {0,1,2};
+ int[] is = new int[] {0,1,2};
+ long[] ls = new long[] {0,1,2};
+ double[] ds = new double[] {0.0, 1.1, 2.2};
+ float[] fs = new float[] {0.0f, 1.1f, 2.2f};
+ char[] cs = new char[] {'a', 'b', 'c'};
+ boolean[] bools = new boolean[] {false, true, false};
+ */
+ Element field;
+
+ field = getFieldFromName(manip, "b");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "byte");
+ field = getFieldFromName(manip, "s");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "short");
+ field = getFieldFromName(manip, "i");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "int");
+ field = getFieldFromName(manip, "l");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "long");
+ field = getFieldFromName(manip, "d");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "double");
+ field = getFieldFromName(manip, "f");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "float");
+ field = getFieldFromName(manip, "c");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "char");
+ field = getFieldFromName(manip, "bool");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "boolean");
+
+ field = getFieldFromName(manip, "bs");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "byte[]");
+ field = getFieldFromName(manip, "ss");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "short[]");
+ field = getFieldFromName(manip, "is");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "int[]");
+ field = getFieldFromName(manip, "ls");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "long[]");
+ field = getFieldFromName(manip, "ds");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "double[]");
+ field = getFieldFromName(manip, "fs");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "float[]");
+ field = getFieldFromName(manip, "cs");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "char[]");
+ field = getFieldFromName(manip, "bools");
+ assertEquals("Check field type : " + field.getAttribute("name"), field.getAttribute("type"), "boolean[]");
+ }
+
+ public void testNoArgMethod() {
+ String comp_name = "SimpleMultipleCheckServiceProvider";
+ Element manip = getManipulationForComponent(comp_name);
+ Element method = getMethodFromName(manip, "check");
+ assertFalse("Check no args", method.containsAttribute("arguments"));
+ assertEquals("Check return", method.getAttribute("return"), "boolean");
+ }
+
+ public void testOneArgsMethod() {
+ String comp_name = "SimpleMultipleCheckServiceProvider";
+ Element manip = getManipulationForComponent(comp_name);
+ Element method = getMethodFromName(manip, "refBind");
+ assertEquals("Check args", method.getAttribute("arguments"), "{org.osgi.framework.ServiceReference}");
+ assertEquals("Check args count", 1, ParseUtils.parseArrays("{org.osgi.framework.ServiceReference}").length);
+ assertFalse("Check return", method.containsAttribute("return"));
+ }
+
+ public void testTwoArgsMethod() {
+ String comp_name = "SimpleMultipleCheckServiceProvider";
+ Element manip = getManipulationForComponent(comp_name);
+ Element method = getMethodFromName(manip, "doNothing");
+ assertEquals("Check args", method.getAttribute("arguments"), "{java.lang.Object,java.lang.String}");
+ assertEquals("Check args count", 2, ParseUtils.parseArrays("{java.lang.Object,java.lang.String}").length);
+ assertEquals("Check return", method.getAttribute("return"), "java.lang.Object");
+ }
+
+ private Element getManipulationForComponent(Element metadata, String comp_name) {
+ Element[] comps = metadata.getElements("component");
+ for(int i = 0; i < comps.length; i++) {
+ if(comps[i].containsAttribute("factory") && comps[i].getAttribute("factory").equals(comp_name)) {
+ return comps[i].getElements("manipulation")[0];
+ }
+ if(comps[i].containsAttribute("name") && comps[i].getAttribute("name").equals(comp_name)) {
+ return comps[i].getElements("manipulation")[0];
+ }
+ }
+ return null;
+ }
+
+ private Element getManipulationForComponent(String comp_name) {
+ String header = (String) context.getBundle().getHeaders().get("iPOJO-Components");
+ Element elem = null;
+ try {
+ elem = ManifestMetadataParser.parse(header);
+ } catch (ParseException e) {
+ fail("Parse Exception when parsing iPOJO-Component");
+ }
+
+ assertNotNull("Check elem not null", elem);
+
+ Element manip = getManipulationForComponent(elem, comp_name);
+ assertNotNull("Check manipulation metadata not null for " + comp_name, manip);
+ return manip;
+ }
+
+ private Element getMethodFromName(Element manip, String name) {
+ Element methods[] = manip.getElements("Method");
+ for(int i = 0; i < methods.length; i++) {
+ if(methods[i].containsAttribute("name") && methods[i].getAttribute("name").equals(name)) {
+ return methods[i];
+ }
+ }
+ fail("Method " + name + " not found");
+ return null;
+ }
+
+ private Element getFieldFromName(Element manip, String name) {
+ Element fields[] = manip.getElements("Field");
+ for(int i = 0; i < fields.length; i++) {
+ if(fields[i].containsAttribute("name") && fields[i].getAttribute("name").equals(name)) {
+ return fields[i];
+ }
+ }
+ fail("Field " + name + " not found");
+ return null;
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationMetadataAPI.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationMetadataAPI.java
new file mode 100644
index 0000000..598267e
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationMetadataAPI.java
@@ -0,0 +1,278 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.manipulation;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.parser.FieldMetadata;
+import org.apache.felix.ipojo.parser.ManifestMetadataParser;
+import org.apache.felix.ipojo.parser.MethodMetadata;
+import org.apache.felix.ipojo.parser.ParseException;
+import org.apache.felix.ipojo.parser.PojoMetadata;
+import org.apache.felix.ipojo.test.scenarios.service.BarService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+
+public class ManipulationMetadataAPI extends OSGiTestCase {
+
+ PojoMetadata FooProviderType1, FooBarProviderType1, FooProviderTypeDyn, PrimitiveManipulationTester, SimpleMultipleCheckServiceProvider;
+
+ public void setUp() {
+ String comp_name = "FooProviderType-1";
+ FooProviderType1 = getManipulationMetadataForComponent(comp_name);
+
+ comp_name = "FooBarProviderType-1";
+ FooBarProviderType1 = getManipulationMetadataForComponent(comp_name);
+
+ comp_name = "FooProviderType-Dyn";
+ FooProviderTypeDyn = getManipulationMetadataForComponent(comp_name);
+
+ comp_name = "PrimitiveManipulationTester";
+ PrimitiveManipulationTester = getManipulationMetadataForComponent(comp_name);
+
+ comp_name = "SimpleMultipleCheckServiceProvider";
+ SimpleMultipleCheckServiceProvider = getManipulationMetadataForComponent(comp_name);
+ }
+
+ public void testGetMetadata() {
+ String header = (String) context.getBundle().getHeaders().get("iPOJO-Components");
+ Element elem = null;
+ try {
+ elem = ManifestMetadataParser.parse(header);
+ } catch (ParseException e) {
+ fail("Parse Exception when parsing iPOJO-Component");
+ }
+
+ assertNotNull("Check elem not null", elem);
+
+ Element manip = getMetadataForComponent(elem, "FooProviderType-1");
+ assertNotNull("Check manipulation metadata not null for " + "FooProviderType-1", manip);
+ PojoMetadata mm = new PojoMetadata(manip);
+ assertNotNull("Check mm not null", mm);
+ }
+
+ public void testInterface() {
+ PojoMetadata manip = FooProviderType1;
+
+ String[] itf = manip.getInterfaces();
+ assertEquals("Check interfaces number", itf.length, 1);
+ assertEquals("Check itf name", itf[0], FooService.class.getName());
+
+ assertTrue("Check Foo Service implementation", manip.isInterfaceImplemented(FooService.class.getName()));
+ assertFalse("Check Bar Service implementation", manip.isInterfaceImplemented(BarService.class.getName()));
+ }
+
+ public void testInterfaces() {
+ PojoMetadata manip = FooBarProviderType1;
+ String[] itf = manip.getInterfaces();
+ assertEquals("Check interfaces number", itf.length, 2);
+ assertEquals("Check itf name", itf[0], FooService.class.getName());
+ assertEquals("Check itf name", itf[1], BarService.class.getName());
+
+ assertTrue("Check Foo Service implementation", manip.isInterfaceImplemented(FooService.class.getName()));
+ assertTrue("Check Bar Service implementation", manip.isInterfaceImplemented(BarService.class.getName()));
+ }
+
+ public void testFields() {
+ PojoMetadata manip = FooProviderTypeDyn;
+
+ FieldMetadata[] fields = manip.getFields();
+ assertEquals("Check field count + " + fields.length, fields.length, 5);
+ /*
+ private int intProp;
+ private String strProp;
+ private String[] strAProp;
+ private int[] intAProp;
+ private boolean boolProp;
+ */
+
+ FieldMetadata field;
+
+ field = manip.getField("intProp");
+ assertEquals("Check field name : " + field.getFieldName(), field.getFieldName(), "intProp");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "int");
+ assertEquals("Check field reflective type : " + field.getFieldName(), FieldMetadata.getReflectionType(field.getFieldType()), "int");
+
+ field = manip.getField("intProp", "int");
+ assertEquals("Check field name : " + field.getFieldName(), field.getFieldName(), "intProp");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "int");
+
+ field = manip.getField("intProp", "long");
+ assertNull("Check bad field", field);
+
+ field = manip.getField("strProp");
+ assertEquals("Check field name : " + field.getFieldName(), field.getFieldName(), "strProp");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "java.lang.String");
+ assertEquals("Check field reflective type : " + field.getFieldName(), FieldMetadata.getReflectionType(field.getFieldType()), "java.lang.String");
+
+ field = manip.getField("strProp", "String");
+ assertNull("Check bad field", field);
+
+ field = manip.getField("strProp", "java.lang.String");
+ assertEquals("Check field name : " + field.getFieldName(), field.getFieldName(), "strProp");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "java.lang.String");
+
+ field = manip.getField("strAProp");
+ assertEquals("Check field name : " + field.getFieldName(), field.getFieldName(), "strAProp");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "java.lang.String[]");
+ assertEquals("Check field reflective type : " + field.getFieldName() + " -> " + FieldMetadata.getReflectionType(field.getFieldType()), FieldMetadata.getReflectionType(field.getFieldType()), "[Ljava.lang.String;");
+
+ field = manip.getField("strAProp", "java.lang.String[]");
+ assertEquals("Check field name : " + field.getFieldName(), field.getFieldName(), "strAProp");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "java.lang.String[]");
+
+ field = manip.getField("strAProp", "String[]");
+ assertNull("Check bad field", field);
+
+ field = manip.getField("intAProp");
+ assertEquals("Check field name : " + field.getFieldName(), field.getFieldName(), "intAProp");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "int[]");
+ assertEquals("Check field reflective type : " + field.getFieldName() + " -> " + FieldMetadata.getReflectionType(field.getFieldType()), FieldMetadata.getReflectionType(field.getFieldType()), "[I");
+
+ field = manip.getField("intAProp", "int[]");
+ assertEquals("Check field name : " + field.getFieldName(), field.getFieldName(), "intAProp");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "int[]");
+
+ field = manip.getField("intAProp", "String[]");
+ assertNull("Check bad field", field);
+
+ field = manip.getField("boolProp");
+ assertEquals("Check field name : " + field.getFieldName(), field.getFieldName(), "boolProp");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "boolean");
+ assertEquals("Check field reflective type : " + field.getFieldName(), FieldMetadata.getReflectionType(field.getFieldType()), "boolean");
+
+ field = manip.getField("boolProp", "boolean");
+ assertEquals("Check field name : " + field.getFieldName(), field.getFieldName(), "boolProp");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "boolean");
+
+ field = manip.getField("boolProp", "bool");
+ assertNull("Check bad field", field);
+ }
+
+ public void testPrimitivesFields() {
+ PojoMetadata manip = PrimitiveManipulationTester;
+ FieldMetadata[] fields = manip.getFields();
+ assertEquals("Check field count", fields.length, 16);
+
+ FieldMetadata field;
+
+ field = manip.getField("b");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "byte");
+ field = manip.getField("s");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "short");
+ field = manip.getField("i");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "int");
+ field = manip.getField("l");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "long");
+ field = manip.getField("d");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "double");
+ field = manip.getField("f");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "float");
+ field = manip.getField("c");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "char");
+ field = manip.getField("bool");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "boolean");
+
+ field = manip.getField("bs");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "byte[]");
+ field = manip.getField("ss");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "short[]");
+ field = manip.getField("is");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "int[]");
+ field = manip.getField("ls");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "long[]");
+ field = manip.getField("ds");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "double[]");
+ field = manip.getField("fs");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "float[]");
+ field = manip.getField("cs");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "char[]");
+ field = manip.getField("bools");
+ assertEquals("Check field type : " + field.getFieldName(), field.getFieldType(), "boolean[]");
+ }
+
+ public void testNoArgMethod() {
+ PojoMetadata manip = SimpleMultipleCheckServiceProvider;
+ MethodMetadata method = manip.getMethod("check");
+ assertEquals("Check no args", method.getMethodArguments().length, 0);
+ assertEquals("Check return", method.getMethodReturn(), "boolean");
+
+ method = manip.getMethod("check", new String[0]);
+ assertEquals("Check no args", method.getMethodArguments().length, 0);
+ assertEquals("Check return", method.getMethodReturn(), "boolean");
+ }
+
+ public void testOneArgsMethod() {
+ PojoMetadata manip = SimpleMultipleCheckServiceProvider;
+ MethodMetadata method = manip.getMethods("refBind")[0];
+ assertEquals("Check args count", method.getMethodArguments().length, 1);
+ assertEquals("Check args", method.getMethodArguments()[0], "org.osgi.framework.ServiceReference");
+ assertEquals("Check return", method.getMethodReturn(), "void");
+
+ method = manip.getMethod("refBind", new String[] {"org.osgi.framework.ServiceReference"});
+ assertEquals("Check args count", method.getMethodArguments().length, 1);
+ assertEquals("Check args", method.getMethodArguments()[0], "org.osgi.framework.ServiceReference");
+ assertEquals("Check return", method.getMethodReturn(), "void");
+ }
+
+ public void testTwoArgsMethod() {
+ PojoMetadata manip = SimpleMultipleCheckServiceProvider;
+ MethodMetadata method = manip.getMethods("doNothing")[0];
+ assertEquals("Check args count", 2, method.getMethodArguments().length);
+ assertEquals("Check args - 1", method.getMethodArguments()[0], "java.lang.Object");
+ assertEquals("Check args - 2", method.getMethodArguments()[1], "java.lang.String");
+ assertEquals("Check return", method.getMethodReturn(), "java.lang.Object");
+
+ method = manip.getMethod("doNothing", new String[] {"java.lang.Object", "java.lang.String"});
+ assertEquals("Check args count", 2, method.getMethodArguments().length);
+ assertEquals("Check args - 1", method.getMethodArguments()[0], "java.lang.Object");
+ assertEquals("Check args - 2", method.getMethodArguments()[1], "java.lang.String");
+ assertEquals("Check return", method.getMethodReturn(), "java.lang.Object");
+ }
+
+ private Element getMetadataForComponent(Element metadata, String comp_name) {
+ Element[] comps = metadata.getElements("component");
+ for(int i = 0; i < comps.length; i++) {
+ if(comps[i].containsAttribute("factory") && comps[i].getAttribute("factory").equals(comp_name)) {
+ return comps[i];
+ }
+ if(comps[i].containsAttribute("name") && comps[i].getAttribute("name").equals(comp_name)) {
+ return comps[i];
+ }
+ }
+ return null;
+ }
+
+
+ private PojoMetadata getManipulationMetadataForComponent(String comp_name) {
+ String header = (String) context.getBundle().getHeaders().get("iPOJO-Components");
+ Element elem = null;
+ try {
+ elem = ManifestMetadataParser.parse(header);
+ } catch (ParseException e) {
+ fail("Parse Exception when parsing iPOJO-Component");
+ }
+
+ assertNotNull("Check elem not null", elem);
+
+ Element manip = getMetadataForComponent(elem, comp_name);
+ assertNotNull("Check manipulation metadata not null for " + comp_name, manip);
+ return new PojoMetadata(manip);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java
new file mode 100644
index 0000000..7bae413
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.manipulation;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class ManipulationTestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Manipulation Test Suite", bc);
+ ots.addTestSuite(ManipulationMetadata.class);
+ ots.addTestSuite(PrimitiveTypeTest.class);
+ ots.addTestSuite(PrimitiveTypeTest2.class);
+ ots.addTestSuite(GetComponentInstanceTest.class);
+ ots.addTestSuite(ManipulationMetadataAPI.class);
+ ots.addTestSuite(ExceptionTest.class);
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest.java
new file mode 100644
index 0000000..defd46e
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.manipulation;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.PrimitiveManipulationTestService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class PrimitiveTypeTest extends OSGiTestCase {
+
+ ComponentInstance instance; // Instance under test
+ PrimitiveManipulationTestService prim;
+ ServiceReference prim_ref;
+
+ public void setUp() {
+ Properties p1 = new Properties();
+ p1.put("name", "primitives");
+ instance = Utils.getComponentInstance(context, "PrimitiveManipulationTester", p1);
+ assertTrue("check instance state", instance.getState() == ComponentInstance.VALID);
+ prim_ref = Utils.getServiceReferenceByName(context, PrimitiveManipulationTestService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check prim availability", prim_ref);
+ prim = (PrimitiveManipulationTestService) context.getService(prim_ref);
+ }
+
+ public void tearDown() {
+ context.ungetService(prim_ref);
+ prim = null;
+ instance.dispose();
+ instance = null;
+ }
+
+ public void testByte() {
+ assertEquals("Check - 1", prim.getByte(), 1);
+ prim.setByte((byte) 2);
+ assertEquals("Check - 2", prim.getByte(), 2);
+ }
+
+ public void testShort() {
+ assertEquals("Check - 1", prim.getShort(), 1);
+ prim.setShort((short) 2);
+ assertEquals("Check - 2", prim.getShort(), 2);
+ }
+
+ public void testInt() {
+ assertEquals("Check - 1", prim.getInt(), 1);
+ prim.setInt((int) 2);
+ assertEquals("Check - 2", prim.getInt(), 2);
+ }
+
+ public void testLong() {
+ assertEquals("Check - 1", prim.getLong(), 1);
+ prim.setLong((long) 2);
+ assertEquals("Check - 2", prim.getLong(), 2);
+ }
+
+ public void testFloat() {
+ assertEquals("Check - 1", prim.getFloat(), 1.1f);
+ prim.setFloat(2.2f);
+ assertEquals("Check - 2", prim.getFloat(), 2.2f);
+ }
+
+ public void testDouble() {
+ assertEquals("Check - 1", prim.getDouble(), 1.1);
+ prim.setDouble(2.2);
+ assertEquals("Check - 2", prim.getDouble(), 2.2);
+ }
+
+ public void testBoolean() {
+ assertFalse("Check - 1", prim.getBoolean());
+ prim.setBoolean(true);
+ assertTrue("Check - 2", prim.getBoolean());
+ }
+
+ public void testChar() {
+ assertEquals("Check - 1", prim.getChar(), 'a');
+ prim.setChar('b');
+ assertEquals("Check - 2", prim.getChar(), 'b');
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest2.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest2.java
new file mode 100644
index 0000000..a3e7dd3
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest2.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.manipulation;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.PrimitiveManipulationTestService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class PrimitiveTypeTest2 extends OSGiTestCase {
+
+ ComponentInstance instance; // Instance under test
+
+ PrimitiveManipulationTestService prim;
+
+ ServiceReference prim_ref;
+
+ public void setUp() {
+ Properties p1 = new Properties();
+ p1.put("name", "primitives");
+ instance = Utils.getComponentInstance(context, "PrimitiveManipulationTesterA", p1);
+ assertTrue("check instance state", instance.getState() == ComponentInstance.VALID);
+ prim_ref = Utils.getServiceReferenceByName(context, PrimitiveManipulationTestService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check prim availability", prim_ref);
+ prim = (PrimitiveManipulationTestService) context.getService(prim_ref);
+ }
+
+ public void tearDown() {
+ context.ungetService(prim_ref);
+ prim = null;
+ instance.dispose();
+ instance = null;
+ }
+
+ public void testByte() {
+ assertEquals("Check - 1", prim.getByte(), 1);
+ prim.setByte((byte) 2);
+ assertEquals("Check - 2", prim.getByte(), 2);
+ }
+
+ public void testShort() {
+ assertEquals("Check - 1", prim.getShort(), 1);
+ prim.setShort((short) 2);
+ assertEquals("Check - 2", prim.getShort(), 2);
+ }
+
+ public void testInt() {
+ assertEquals("Check - 1", prim.getInt(), 1);
+ prim.setInt((int) 2);
+ assertEquals("Check - 2", prim.getInt(), 2);
+ }
+
+ public void testLong() {
+ assertEquals("Check - 1", prim.getLong(), 1);
+ prim.setLong((long) 2);
+ assertEquals("Check - 2", prim.getLong(), 2);
+ }
+
+ public void testLong2() {
+ assertEquals("Check - 1", prim.getLong(), 1);
+ prim.setLong(2, "ss");
+ assertEquals("Check - 2", prim.getLong(), 2);
+ }
+
+ public void testLongFromObject() {
+ assertEquals("Check - 1", prim.getLong(), 1);
+ Long l = new Long(2);
+ prim.setLong(l);
+ assertEquals("Check - 2", prim.getLong(), 2);
+ }
+
+ public void testLongFromObject2() {
+ assertEquals("Check - 1", prim.getLong(), 1);
+ Long l = new Long(2);
+ prim.setLong(l, "ss");
+ assertEquals("Check - 2", prim.getLong(), 2);
+ }
+
+ public void testFloat() {
+ assertEquals("Check - 1", prim.getFloat(), 1.1f);
+ prim.setFloat(2.2f);
+ assertEquals("Check - 2", prim.getFloat(), 2.2f);
+ }
+
+ public void testDouble() {
+ assertEquals("Check - 1", prim.getDouble(), 1.1);
+ prim.setDouble(2.2);
+ assertEquals("Check - 2", prim.getDouble(), 2.2);
+ }
+
+ public void testBoolean() {
+ assertFalse("Check - 1", prim.getBoolean());
+ prim.setBoolean(true);
+ assertTrue("Check - 2", prim.getBoolean());
+ }
+
+ public void testChar() {
+ assertEquals("Check - 1", prim.getChar(), 'a');
+ prim.setChar('b');
+ assertEquals("Check - 2", prim.getChar(), 'b');
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/A123/CheckService2.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/A123/CheckService2.java
new file mode 100644
index 0000000..6b0aafc
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/A123/CheckService2.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.A123;
+
+public interface CheckService2 {
+
+ public boolean check();
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/BarService.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/BarService.java
new file mode 100644
index 0000000..727e845
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/BarService.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service;
+
+import java.util.Properties;
+
+public interface BarService {
+
+ public boolean bar();
+
+ public Properties getProps();
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/BazService.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/BazService.java
new file mode 100644
index 0000000..115b5de
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/BazService.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service;
+
+import java.util.Properties;
+
+public interface BazService {
+
+ boolean foo();
+
+ Properties fooProps();
+
+ Boolean getObject();
+
+ boolean getBoolean();
+
+ int getInt();
+
+ long getLong();
+
+ double getDouble();
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/CheckService.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/CheckService.java
new file mode 100644
index 0000000..62f254c
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/CheckService.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service;
+
+import java.util.Properties;
+
+public interface CheckService {
+
+ public static final String foo = "foo";
+
+ public boolean check();
+
+ public Properties getProps();
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ChildInterface.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ChildInterface.java
new file mode 100644
index 0000000..cb7c6c1
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ChildInterface.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service;
+
+public interface ChildInterface extends ParentInterface1, ParentInterface2 {
+
+ public void processChild();
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/FooService.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/FooService.java
new file mode 100644
index 0000000..78693cf
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/FooService.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service;
+
+import java.util.Properties;
+
+public interface FooService {
+
+ boolean foo();
+
+ Properties fooProps();
+
+ Boolean getObject();
+
+ boolean getBoolean();
+
+ int getInt();
+
+ long getLong();
+
+ double getDouble();
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ParentInterface1.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ParentInterface1.java
new file mode 100644
index 0000000..f70daf3
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ParentInterface1.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service;
+
+public interface ParentInterface1 extends ParentParentInterface {
+
+ public void processParent1();
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ParentInterface2.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ParentInterface2.java
new file mode 100644
index 0000000..78c3d35
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ParentInterface2.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service;
+
+public interface ParentInterface2 {
+
+ public void processParent2();
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ParentParentInterface.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ParentParentInterface.java
new file mode 100644
index 0000000..29767d4
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/ParentParentInterface.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service;
+
+public interface ParentParentInterface {
+
+ public void processParentParent();
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/PrimitiveManipulationTestService.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/PrimitiveManipulationTestService.java
new file mode 100644
index 0000000..d87118b
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/PrimitiveManipulationTestService.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service;
+
+public interface PrimitiveManipulationTestService {
+
+ byte getByte();
+ void setByte(byte b);
+
+ short getShort();
+ void setShort(short s);
+
+ int getInt();
+ void setInt(int i);
+
+ long getLong();
+ void setLong(long l);
+
+ float getFloat();
+ void setFloat(float f);
+
+ double getDouble();
+ void setDouble(double d);
+
+ char getChar();
+ void setChar(char c);
+
+ boolean getBoolean();
+ void setBoolean(boolean b);
+
+ // Array types
+ byte[] getBytes();
+ void setBytes(byte[] bs);
+
+ short[] getShorts();
+ void setShorts(short[] ss);
+
+ int[] getInts();
+ void setInts(int is[]);
+
+ long[] getLongs();
+ void setLongs(long[] ls);
+
+ float[] getFloats();
+ void setFloats(float[] fs);
+
+ double[] getDoubles();
+ void setDoubles(double[] ds);
+
+ char[] getChars();
+ void setChars(char[] cs);
+
+ boolean[] getBooleans();
+ void setBooleans(boolean[] bs);
+
+ // This method has been added to test an issue when autoboxing.
+ void setLong(long l, String s);
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/DynamicProps.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/DynamicProps.java
new file mode 100644
index 0000000..6f615ae
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/DynamicProps.java
@@ -0,0 +1,231 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DynamicProps extends OSGiTestCase {
+
+ ComponentInstance fooProvider1;
+ ComponentInstance fooProvider2;
+ ComponentInstance fooProvider3;
+
+ public void setUp() {
+ String type = "FooProviderType-Dyn";
+
+ Properties p1 = new Properties();
+ p1.put("name", "FooProvider-1");
+ fooProvider1 = Utils.getComponentInstance(context, type, p1);
+
+ Properties p2 = new Properties();
+ p2.put("name", "FooProvider-2");
+ p2.put("int", new Integer(4));
+ p2.put("boolean", new Boolean(false));
+ p2.put("string", new String("bar"));
+ p2.put("strAProp", new String[] {"bar", "foo"});
+ p2.put("intAProp", new int[] {1, 2, 3});
+ fooProvider2 = Utils.getComponentInstance(context, type, p2);
+
+ String type2 = "FooProviderType-Dyn2";
+ Properties p3 = new Properties();
+ p3.put("name", "FooProvider-3");
+ p3.put("int", new Integer(0));
+ p3.put("boolean", new Boolean(true));
+ p3.put("string", new String(""));
+ p3.put("strAProp", new String[0]);
+ p3.put("intAProp", new int[0]);
+ fooProvider3 = Utils.getComponentInstance(context, type2, p3);
+
+ }
+
+ public void tearDown() {
+ fooProvider1.dispose();
+ fooProvider1 = null;
+ fooProvider2.dispose();
+ fooProvider2 = null;
+ fooProvider3.dispose();
+ fooProvider3 = null;
+ }
+
+ public void testProperties1() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Boolean boolProp = (Boolean) sr.getProperty("boolean");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality (1)", intProp, new Integer(2));
+ assertEquals("Check longProp equality (1)", boolProp, new Boolean(false));
+ assertEquals("Check strProp equality (1)", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity (1)", strAProp);
+ String[] v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality (1)"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality (1)"); }
+ }
+
+ // Invoke
+ FooService fs = (FooService) context.getService(sr);
+ assertTrue("invoke fs", fs.foo());
+
+ // Re-check the property (change)
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality (2)", intProp, new Integer(3));
+ assertEquals("Check longProp equality (2)", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality (2)", strProp, new String("bar"));
+ assertNotNull("Check strAProp not nullity (2)", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality (2)"); }
+ }
+ assertNotNull("Check intAProp not nullity (2)", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality (2)"); }
+ }
+
+ fs = null;
+ context.ungetService(sr);
+ }
+
+ public void testProperties2() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Boolean boolProp = (Boolean) sr.getProperty("boolean");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(4));
+ assertEquals("Check longProp equality", boolProp, new Boolean(false));
+ assertEquals("Check strProp equality", strProp, new String("bar"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"bar", "foo"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Invoke
+ FooService fs = (FooService) context.getService(sr);
+ assertTrue("invoke fs", fs.foo());
+
+ // Re-check the property (change)
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(3));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ fs = null;
+ context.ungetService(sr);
+ }
+
+ public void testProperties3() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Boolean boolProp = (Boolean) sr.getProperty("boolean");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(0));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String(""));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[0];
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[0];
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Invoke
+ FooService fs = (FooService) context.getService(sr);
+ assertTrue("invoke fs", fs.foo());
+
+ // Re-check the property (change)
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNull("Check intAProp hidding (no value)", intAProp);
+
+ fs = null;
+ context.ungetService(sr);
+
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/DynamicPropsReconfiguration.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/DynamicPropsReconfiguration.java
new file mode 100644
index 0000000..baeaa9d
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/DynamicPropsReconfiguration.java
@@ -0,0 +1,577 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class DynamicPropsReconfiguration extends OSGiTestCase {
+ ComponentInstance fooProvider3;
+
+ public void setUp() {
+ String type2 = "FooProviderType-Dyn2";
+ Properties p3 = new Properties();
+ p3.put("name", "FooProvider-3");
+ p3.put("int", new Integer(0));
+ p3.put("boolean", new Boolean(true));
+ p3.put("string", new String(""));
+ p3.put("strAProp", new String[0]);
+ p3.put("intAProp", new int[0]);
+ fooProvider3 = Utils.getComponentInstance(context, type2, p3);
+ }
+
+ public void tearDown() {
+ fooProvider3.dispose();
+ fooProvider3 = null;
+ }
+
+ public void testFactoryReconf() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Boolean boolProp = (Boolean) sr.getProperty("boolean");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(0));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String(""));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[0];
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[0];
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "FooProviderType-Dyn2");
+ Factory fact = (Factory) context.getService(fact_ref);
+ Properties p3 = new Properties();
+ p3.put("name", "FooProvider-3");
+ p3.put("int", new Integer(1));
+ p3.put("boolean", new Boolean(true));
+ p3.put("string", new String("foo"));
+ p3.put("strAProp", new String[] {"foo", "bar", "baz"});
+ p3.put("intAProp", new int[] { 1, 2, 3});
+ try {
+ fact.reconfigure(p3);
+ } catch(Exception e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Invoke
+ FooService fs = (FooService) context.getService(sr);
+ assertTrue("invoke fs", fs.foo());
+
+ // Re-check the property (change)
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNull("Check intAProp hidding (no value)", intAProp);
+
+ // Reconfiguration
+ fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "FooProviderType-Dyn2");
+ fact = (Factory) context.getService(fact_ref);
+ p3 = new Properties();
+ p3.put("name", "FooProvider-3");
+ p3.put("int", new Integer(1));
+ p3.put("boolean", new Boolean(true));
+ p3.put("string", new String("foo"));
+ p3.put("strAProp", new String[] {"foo", "bar", "baz"});
+ p3.put("intAProp", new int[] { 1, 2, 3});
+ try {
+ fact.reconfigure(p3);
+ } catch(Exception e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ fact = null;
+ context.ungetService(fact_ref);
+ fs = null;
+ context.ungetService(sr);
+ }
+
+ public void testFactoryReconfString() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Boolean boolProp = (Boolean) sr.getProperty("boolean");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(0));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String(""));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[0];
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[0];
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "FooProviderType-Dyn2");
+ Factory fact = (Factory) context.getService(fact_ref);
+ Properties p3 = new Properties();
+ p3.put("name", "FooProvider-3");
+ p3.put("int", "1");
+ p3.put("boolean", "true");
+ p3.put("string", "foo");
+ p3.put("strAProp", "{foo, bar, baz}");
+ p3.put("intAProp", "{1, 2, 3}");
+ try {
+ fact.reconfigure(p3);
+ } catch(Exception e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Invoke
+ FooService fs = (FooService) context.getService(sr);
+ assertTrue("invoke fs", fs.foo());
+
+ // Re-check the property (change)
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNull("Check intAProp hidding (no value)", intAProp);
+
+ // Reconfiguration
+ fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "FooProviderType-Dyn2");
+ fact = (Factory) context.getService(fact_ref);
+ p3 = new Properties();
+ p3.put("name", "FooProvider-3");
+ p3.put("int", "1");
+ p3.put("boolean", "true");
+ p3.put("string", "foo");
+ p3.put("strAProp", "{foo, bar, baz}");
+ p3.put("intAProp", "{ 1, 2, 3}");
+ try {
+ fact.reconfigure(p3);
+ } catch(Exception e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ fact = null;
+ context.ungetService(fact_ref);
+ fs = null;
+ context.ungetService(sr);
+ }
+
+ public void testMSFReconf() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Boolean boolProp = (Boolean) sr.getProperty("boolean");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(0));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String(""));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[0];
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[0];
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "FooProviderType-Dyn2");
+ ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ Properties p3 = new Properties();
+ p3.put("int", new Integer(1));
+ p3.put("boolean", new Boolean(true));
+ p3.put("string", new String("foo"));
+ p3.put("strAProp", new String[] {"foo", "bar", "baz"});
+ p3.put("intAProp", new int[] { 1, 2, 3});
+ try {
+ fact.updated("FooProvider-3", p3);
+ } catch (ConfigurationException e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Invoke
+ FooService fs = (FooService) context.getService(sr);
+ assertTrue("invoke fs", fs.foo());
+
+ // Re-check the property (change)
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNull("Check intAProp hidding (no value)", intAProp);
+
+ // Reconfiguration
+ fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "FooProviderType-Dyn2");
+ fact = (ManagedServiceFactory) context.getService(fact_ref);
+ p3 = new Properties();
+ p3.put("int", new Integer(1));
+ p3.put("boolean", new Boolean(true));
+ p3.put("string", new String("foo"));
+ p3.put("strAProp", new String[] {"foo", "bar", "baz"});
+ p3.put("intAProp", new int[] { 1, 2, 3});
+ try {
+ fact.updated("FooProvider-3", p3);
+ } catch (ConfigurationException e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ fact = null;
+ context.ungetService(fact_ref);
+ fs = null;
+ context.ungetService(sr);
+ }
+
+ public void testMSFReconfString() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Boolean boolProp = (Boolean) sr.getProperty("boolean");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(0));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String(""));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[0];
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[0];
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "FooProviderType-Dyn2");
+ ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ Properties p3 = new Properties();
+ p3.put("int", "1");
+ p3.put("boolean", "true");
+ p3.put("string", "foo");
+ p3.put("strAProp", "{foo, bar, baz}");
+ p3.put("intAProp", "{ 1, 2, 3}");
+ try {
+ fact.updated("FooProvider-3", p3);
+ } catch (ConfigurationException e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Invoke
+ FooService fs = (FooService) context.getService(sr);
+ assertTrue("invoke fs", fs.foo());
+
+ // Re-check the property (change)
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNull("Check intAProp hidding (no value)", intAProp);
+
+ // Reconfiguration
+ fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "FooProviderType-Dyn2");
+ fact = (ManagedServiceFactory) context.getService(fact_ref);
+ p3 = new Properties();
+ p3.put("int", "1");
+ p3.put("boolean", "true");
+ p3.put("string", "foo");
+ p3.put("strAProp", "{foo, bar, baz}");
+ p3.put("intAProp", "{ 1, 2, 3}");
+ try {
+ fact.updated("FooProvider-3", p3);
+ } catch (ConfigurationException e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ fact = null;
+ context.ungetService(fact_ref);
+ fs = null;
+ context.ungetService(sr);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/Exposition.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/Exposition.java
new file mode 100644
index 0000000..ee7aca2
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/Exposition.java
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.BarService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class Exposition extends OSGiTestCase {
+
+ private ComponentInstance fooProviderSimple;
+ private ComponentInstance fooProviderItf;
+ private ComponentInstance fooBarProvider;
+ private ComponentInstance fooBarProvider2;
+ private ComponentInstance fooBarProvider3;
+
+ public void setUp(){
+ Properties p1 = new Properties();
+ p1.put("name", "fooProviderSimple");
+ fooProviderSimple = Utils.getComponentInstance(context, "FooProviderType-1", p1);
+
+ Properties p2 = new Properties();
+ p2.put("name", "fooProviderItf");
+ fooProviderItf = Utils.getComponentInstance(context, "FooProviderType-itf", p2);
+
+ Properties p3 = new Properties();
+ p3.put("name", "fooProviderItfs");
+ fooBarProvider = Utils.getComponentInstance(context, "FooBarProviderType-1", p3);
+
+ Properties p4 = new Properties();
+ p4.put("name", "fooProviderItfs2");
+ fooBarProvider2 = Utils.getComponentInstance(context, "FooBarProviderType-2", p4);
+
+ Properties p5 = new Properties();
+ p5.put("name", "fooProviderItfs3");
+ fooBarProvider3 = Utils.getComponentInstance(context, "FooBarProviderType-3", p5);
+
+ assertNotNull("Check the instance creation of fooProviderSimple", fooProviderSimple);
+ assertNotNull("Check the instance creation of fooProviderItf", fooProviderItf);
+ assertNotNull("Check the instance creation of fooProviderItfs", fooBarProvider);
+ assertNotNull("Check the instance creation of fooProviderItfs2", fooBarProvider2);
+ assertNotNull("Check the instance creation of fooProviderItfs3", fooBarProvider3);
+
+ }
+
+ public void tearDown() {
+ fooProviderSimple.dispose();
+ fooProviderItf.dispose();
+ fooBarProvider.dispose();
+ fooBarProvider2.dispose();
+ fooBarProvider3.dispose();
+ fooProviderSimple = null;
+ fooProviderItf = null;
+ fooBarProvider = null;
+ fooBarProvider2 = null;
+ fooBarProvider3 = null;
+ }
+
+ public void testSimpleExposition() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderSimple.getInstanceName());
+ assertNotNull("Check the availability of the FS from "+fooProviderSimple.getInstanceName(), ref);
+ FooService fs = (FooService) context.getService(ref);
+ assertTrue("Check fs invocation", fs.foo());
+ fs = null;
+ context.ungetService(ref);
+ fooProviderSimple.stop();
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderSimple.getInstanceName());
+ assertNull("Check the absence of the FS from "+fooProviderSimple.getInstanceName(), ref);
+
+ }
+
+ public void testItfExposition() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderItf.getInstanceName());
+ assertNotNull("Check the availability of the FS from "+fooProviderItf.getInstanceName(), ref);
+ FooService fs = (FooService) context.getService(ref);
+ assertTrue("Check fs invocation", fs.foo());
+ fs = null;
+ context.ungetService(ref);
+ fooProviderItf.stop();
+
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderItf.getInstanceName());
+ assertNull("Check the absence of the FS from "+fooProviderItf.getInstanceName(), ref);
+ }
+
+ public void testItfsExposition() {
+ ServiceReference refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider.getInstanceName());
+ assertNotNull("Check the availability of the FS from "+fooBarProvider.getInstanceName(), refFoo);
+ ServiceReference refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider.getInstanceName());
+ assertNotNull("Check the availability of the BS from "+fooBarProvider.getInstanceName(), refBar);
+
+ assertSame("Check service reference equality", refFoo, refBar);
+
+ FooService fs = (FooService) context.getService(refFoo);
+ assertTrue("Check fs invocation", fs.foo());
+ fs = null;
+ context.ungetService(refFoo);
+
+ BarService bs = (BarService) context.getService(refBar);
+ assertTrue("Check bs invocation", bs.bar());
+ bs = null;
+ context.ungetService(refBar);
+
+ fooBarProvider.stop();
+
+ refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider.getInstanceName());
+ refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider.getInstanceName());
+ assertNull("Check the absence of the FS from "+fooBarProvider.getInstanceName(), refFoo);
+ assertNull("Check the absence of the BS from "+fooBarProvider.getInstanceName(), refBar);
+ }
+
+ public void testItfsExposition2() {
+ ServiceReference refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider2.getInstanceName());
+ assertNotNull("Check the availability of the FS from "+fooBarProvider2.getInstanceName(), refFoo);
+ ServiceReference refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider2.getInstanceName());
+ assertNotNull("Check the availability of the BS from "+fooBarProvider2.getInstanceName(), refBar);
+
+ assertSame("Check service reference equality", refFoo, refBar);
+
+ FooService fs = (FooService) context.getService(refFoo);
+ assertTrue("Check fs invocation", fs.foo());
+ fs = null;
+ context.ungetService(refFoo);
+
+ BarService bs = (BarService) context.getService(refBar);
+ assertTrue("Check bs invocation", bs.bar());
+ bs = null;
+ context.ungetService(refBar);
+
+ fooBarProvider2.stop();
+
+ refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider2.getInstanceName());
+ refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider2.getInstanceName());
+ assertNull("Check the absence of the FS from "+fooBarProvider.getInstanceName(), refFoo);
+ assertNull("Check the absence of the BS from "+fooBarProvider.getInstanceName(), refBar);
+ }
+
+ public void testItfsExposition3() {
+ ServiceReference refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider3.getInstanceName());
+ assertNotNull("Check the availability of the FS from "+fooBarProvider3.getInstanceName(), refFoo);
+ ServiceReference refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider3.getInstanceName());
+ assertNotNull("Check the availability of the BS from "+fooBarProvider3.getInstanceName(), refBar);
+
+ assertNotSame("Check service reference inequality", refFoo, refBar);
+
+ FooService fs = (FooService) context.getService(refFoo);
+ assertTrue("Check fs invocation", fs.foo());
+ fs = null;
+ context.ungetService(refFoo);
+
+ BarService bs = (BarService) context.getService(refBar);
+ assertTrue("Check bs invocation", bs.bar());
+ bs = null;
+ context.ungetService(refBar);
+
+ // Check properties
+ String baz1 = (String) refFoo.getProperty("baz");
+ String baz2 = (String) refBar.getProperty("baz");
+
+ assertEquals("Check Baz Property 1", baz1, "foo");
+ assertEquals("Check Baz Property 2", baz2, "bar");
+
+ fooBarProvider3.stop();
+
+ refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider3.getInstanceName());
+ refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider3.getInstanceName());
+ assertNull("Check the absence of the FS from "+fooBarProvider.getInstanceName(), refFoo);
+ assertNull("Check the absence of the BS from "+fooBarProvider.getInstanceName(), refBar);
+ }
+
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/FactoryProps.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/FactoryProps.java
new file mode 100644
index 0000000..0be3205
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/FactoryProps.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.test.scenarios.service.providing;
+
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.BarService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class FactoryProps extends OSGiTestCase {
+
+// public void testImplementationClass() {
+// ServiceReference ref1 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-1");
+// assertNotNull("The factory is available", ref1);
+// String clazz = (String) ref1.getProperty("component.class");
+// assertEquals("Check the implementation class", clazz, FooProviderType1.class.getName());
+// }
+
+ public void testSimpleExposition() {
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-1");
+ assertNotNull("The factory is available", ref1);
+ String[] spec = (String[]) ref1.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check array length", spec.length, 1);
+ assertEquals("Check spec", spec[0], FooService.class.getName());
+ }
+
+ public void testDoubleExposition() {
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooBarProviderType-1");
+ assertNotNull("The factory is available", ref1);
+ String[] spec = (String[]) ref1.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check array length", spec.length, 2);
+ assertContains("Check spec 1", spec, FooService.class.getName());
+ assertContains("Check spec 2", spec, BarService.class.getName());
+ }
+
+ public void testProps() {
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-Dyn2");
+ assertNotNull("The factory is available", ref1);
+ PropertyDescription[] pd = (PropertyDescription[]) ref1.getProperty("component.properties");
+ assertEquals("Check property list size", pd.length, 5);
+
+ //P0
+ assertEquals("0) Check name", "int", pd[0].getName());
+ assertEquals("0) Check type", "int", pd[0].getType());
+ assertEquals("0) Check value", "4", pd[0].getValue());
+
+ //P1
+ assertEquals("1) Check name", "boolean", pd[1].getName());
+ assertEquals("1) Check type", "boolean", pd[1].getType());
+ assertNull("1) Check value", pd[1].getValue());
+
+ //P2
+ assertEquals("2) Check name", "string", pd[2].getName());
+ assertEquals("2) Check type", String.class.getName(), pd[2].getType());
+ assertNull("2) Check value", pd[2].getValue());
+
+ //P3
+ assertEquals("3) Check name", "strAProp", pd[3].getName());
+ assertEquals("3) Check type", "java.lang.String[]", pd[3].getType());
+ assertNull("3) Check value", pd[3].getValue());
+
+ //P4
+ assertEquals("4) Check name", "intAProp", pd[4].getName());
+ assertEquals("4) Check type", "int[]", pd[4].getType());
+ }
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/ProvidedServiceTestSuite.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/ProvidedServiceTestSuite.java
new file mode 100644
index 0000000..d12c206
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/ProvidedServiceTestSuite.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.apache.felix.ipojo.test.scenarios.service.providing.inherited.InheritedTest;
+import org.osgi.framework.BundleContext;
+
+public class ProvidedServiceTestSuite extends TestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Provided Service Test Suite", bc);
+ ots.addTestSuite(Exposition.class);
+ ots.addTestSuite(SimplePS.class);
+ ots.addTestSuite(StaticProps.class);
+ ots.addTestSuite(DynamicProps.class);
+ ots.addTestSuite(FactoryProps.class);
+ ots.addTestSuite(StaticPropsReconfiguration.class);
+ ots.addTestSuite(DynamicPropsReconfiguration.class);
+ ots.addTestSuite(InheritedTest.class);
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/SimplePS.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/SimplePS.java
new file mode 100644
index 0000000..8e52b1c
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/SimplePS.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class SimplePS extends OSGiTestCase {
+
+ public void testPS() {
+ String factName = "FooProviderType-1";
+ String compName = "FooProvider-1";
+ ServiceReference[] refs = null;
+
+ // Check that no Foo Service are available
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), null);
+ } catch (InvalidSyntaxException e) { fail("Service query failed : " + e); }
+
+ assertNull("FS already available", refs);
+
+ // Get the factory to create a component instance
+ Factory fact = Utils.getFactoryByName(context, factName);
+ assertNotNull("Cannot find the factory FooProvider-1", fact);
+
+ Properties props = new Properties();
+ props.put("name", compName);
+ ComponentInstance ci = null;
+ try {
+ ci = fact.createComponentInstance(props);
+ } catch (Exception e1) { fail(e1.getMessage()); }
+
+ // Get a FooService provider
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
+ } catch (InvalidSyntaxException e) { fail("Service query failed (2) " + e); }
+
+ assertNotNull("FS not available", refs);
+
+ // Test foo invocation
+ FooService fs = (FooService) context.getService(refs[0]);
+ assertTrue("FooService invocation failed", fs.foo());
+
+ // Unget the service
+ context.ungetService(refs[0]);
+
+ ci.dispose();
+
+ // Check that there is no more FooService
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), null);
+ } catch (InvalidSyntaxException e) { fail("Service query failed (3) : " + e.getMessage()); }
+
+ assertNull("FS available, but component instance stopped", refs);
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticProps.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticProps.java
new file mode 100644
index 0000000..4894900
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticProps.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class StaticProps extends OSGiTestCase {
+
+ ComponentInstance fooProvider1;
+ ComponentInstance fooProvider2;
+
+ public void setUp() {
+ String type = "FooProviderType-2";
+
+ Properties p1 = new Properties();
+ p1.put("name", "FooProvider-1");
+ fooProvider1 = Utils.getComponentInstance(context, type, p1);
+
+ Properties p2 = new Properties();
+ p2.put("name", "FooProvider-2");
+ p2.put("int", new Integer(4));
+ p2.put("long", new Long(42));
+ p2.put("string", new String("bar"));
+ p2.put("strAProp", new String[] {"bar", "foo"});
+ p2.put("intAProp", new int[] {1, 2, 3});
+ fooProvider2 = Utils.getComponentInstance(context, type, p2);
+
+ }
+
+ public void tearDown() {
+ fooProvider1.dispose();
+ fooProvider1 = null;
+ fooProvider2.dispose();
+ fooProvider2 = null;
+ }
+
+ public void testProperties1() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", longProp, new Long(40));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ }
+
+ public void testProperties2() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(4));
+ assertEquals("Check longProp equality", longProp, new Long(42));
+ assertEquals("Check strProp equality", strProp, new String("bar"));
+
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"bar", "foo"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+ }
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticPropsReconfiguration.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticPropsReconfiguration.java
new file mode 100644
index 0000000..215d41e
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticPropsReconfiguration.java
@@ -0,0 +1,337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class StaticPropsReconfiguration extends OSGiTestCase {
+
+ ComponentInstance fooProvider1;
+ ComponentInstance fooProvider2;
+
+ public void setUp() {
+ String type = "FooProviderType-2";
+
+ Properties p1 = new Properties();
+ p1.put("name", "FooProvider-1");
+ fooProvider1 = Utils.getComponentInstance(context, type, p1);
+
+ Properties p2 = new Properties();
+ p2.put("name", "FooProvider-2");
+ p2.put("int", new Integer(4));
+ p2.put("long", new Long(42));
+ p2.put("string", new String("bar"));
+ p2.put("strAProp", new String[] {"bar", "foo"});
+ p2.put("intAProp", new int[] {1, 2, 3});
+ fooProvider2 = Utils.getComponentInstance(context, type, p2);
+
+ }
+
+ public void tearDown() {
+ fooProvider1.dispose();
+ fooProvider1 = null;
+ fooProvider2.dispose();
+ fooProvider2 = null;
+ }
+
+ public void testReconfFactory1() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", longProp, new Long(40));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("name", "FooProvider-1");
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[] {"foo", "baz"});
+ reconf.put("intAProp", new int[] {3, 2, 1});
+ Factory fact = (Factory) context.getService(fact_ref);
+ try {
+ fact.reconfigure(reconf);
+ } catch(Exception e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[] {"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ context.ungetService(fact_ref);
+ fact = null;
+
+ }
+
+ public void testReconfFactory2() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(4));
+ assertEquals("Check longProp equality", longProp, new Long(42));
+ assertEquals("Check strProp equality", strProp, new String("bar"));
+
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"bar", "foo"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("name", "FooProvider-2");
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[] {"foo", "baz"});
+ reconf.put("intAProp", new int[] {3, 2, 1});
+ Factory fact = (Factory) context.getService(fact_ref);
+ try {
+ fact.reconfigure(reconf);
+ } catch(Exception e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[] {"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ context.ungetService(fact_ref);
+ fact = null;
+ }
+
+ public void testMSFFactory1() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", longProp, new Long(40));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), "FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[] {"foo", "baz"});
+ reconf.put("intAProp", new int[] {3, 2, 1});
+ ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ try {
+ fact.updated("FooProvider-1", reconf);
+ } catch (ConfigurationException e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[] {"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ context.ungetService(fact_ref);
+ fact = null;
+
+ }
+
+ public void testReconfMSF2() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(4));
+ assertEquals("Check longProp equality", longProp, new Long(42));
+ assertEquals("Check strProp equality", strProp, new String("bar"));
+
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"bar", "foo"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), "FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[] {"foo", "baz"});
+ reconf.put("intAProp", new int[] {3, 2, 1});
+ ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ try {
+ fact.updated("FooProvider-2", reconf);
+ } catch (ConfigurationException e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[] {"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ context.ungetService(fact_ref);
+ fact = null;
+ }
+
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/inherited/InheritedTest.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/inherited/InheritedTest.java
new file mode 100644
index 0000000..a2c52f3
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/inherited/InheritedTest.java
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.service.providing.inherited;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.ChildInterface;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.service.ParentInterface1;
+import org.apache.felix.ipojo.test.scenarios.service.ParentInterface2;
+import org.apache.felix.ipojo.test.scenarios.service.ParentParentInterface;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class InheritedTest extends OSGiTestCase {
+
+ private Factory pi1, pi11, pi12, pi2, pi21, pi3;
+
+ public void setUp() {
+ pi1 = Utils.getFactoryByName(context, "PI1");
+ pi11 = Utils.getFactoryByName(context, "PI1-1");
+ pi12 = Utils.getFactoryByName(context, "PI1-2");
+
+ pi2 = Utils.getFactoryByName(context, "PI2");
+ pi21 = Utils.getFactoryByName(context, "PI2-1");
+
+ pi3 = Utils.getFactoryByName(context, "PI3");
+ }
+
+ private boolean contains(String[] arr, String txt) {
+ for (int i = 0; i < arr.length; i++) {
+ if (arr[i].equals(txt)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void testPI1Factory() {
+ String[] specs = pi1.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count", specs.length, 4);
+ assertTrue("Check Child", contains(specs, ChildInterface.class.getName()));
+ assertTrue("Check Parent1", contains(specs, ParentInterface1.class.getName()));
+ assertTrue("Check Parent2", contains(specs, ParentInterface2.class.getName()));
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ }
+
+ public void testPI11Factory() {
+ String[] specs = pi11.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count", specs.length, 1);
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ }
+
+ public void testPI12Factory() {
+ String[] specs = pi12.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count", specs.length, 2);
+ assertTrue("Check Parent2", contains(specs, ParentInterface2.class.getName()));
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ }
+
+ public void testPI2Factory() {
+ String[] specs = pi2.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count ("+specs.length+")", specs.length, 4);
+ assertTrue("Check Child", contains(specs, ChildInterface.class.getName()));
+ assertTrue("Check Parent1", contains(specs, ParentInterface1.class.getName()));
+ assertTrue("Check Parent2", contains(specs, ParentInterface2.class.getName()));
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ }
+
+ public void testPI21Factory() {
+ String[] specs = pi21.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count", specs.length, 1);
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ }
+
+ public void testPI3Factory() {
+ String[] specs = pi3.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count", specs.length, 5);
+ assertTrue("Check Child", contains(specs, ChildInterface.class.getName()));
+ assertTrue("Check Parent1", contains(specs, ParentInterface1.class.getName()));
+ assertTrue("Check Parent2", contains(specs, ParentInterface2.class.getName()));
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ assertTrue("Check FS", contains(specs, FooService.class.getName()));
+ }
+
+ public void testIP1() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi1.getName(), "ci");
+
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, ChildInterface.class.getName(), "ci");
+ assertNotNull("Check Child", ref1);
+
+ ServiceReference ref2 = Utils.getServiceReferenceByName(context, ParentInterface1.class.getName(), "ci");
+ assertNotNull("Check Parent1", ref2);
+
+ ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ assertNotNull("Check Parent2", ref3);
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ci.dispose();
+ }
+
+ public void testIP11() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi11.getName(), "ci");
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ci.dispose();
+ }
+
+ public void testIP12() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi12.getName(), "ci");
+
+ ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ assertNotNull("Check Parent2", ref3);
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ci.dispose();
+ }
+
+ public void testIP2() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi2.getName(), "ci");
+
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, ChildInterface.class.getName(), "ci");
+ assertNotNull("Check Child", ref1);
+
+ ServiceReference ref2 = Utils.getServiceReferenceByName(context, ParentInterface1.class.getName(), "ci");
+ assertNotNull("Check Parent1", ref2);
+
+ ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ assertNotNull("Check Parent2", ref3);
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ci.dispose();
+ }
+
+ public void testIP21() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi21.getName(), "ci");
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ci.dispose();
+ }
+
+ public void testIP3() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi3.getName(), "ci");
+
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, ChildInterface.class.getName(), "ci");
+ assertNotNull("Check Child", ref1);
+
+ ServiceReference ref2 = Utils.getServiceReferenceByName(context, ParentInterface1.class.getName(), "ci");
+ assertNotNull("Check Parent1", ref2);
+
+ ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ assertNotNull("Check Parent2", ref3);
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ServiceReference ref5 = Utils.getServiceReferenceByName(context, FooService.class.getName(), "ci");
+ assertNotNull("Check FS", ref5);
+
+ ci.dispose();
+ }
+
+
+
+
+}
diff --git a/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
new file mode 100644
index 0000000..9b0b8db
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.util;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.HandlerFactory;
+import org.apache.felix.ipojo.ServiceContext;
+//import org.apache.felix.ipojo.composite.CompositeManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class Utils {
+
+ public static Factory getFactoryByName(BundleContext bc, String factoryName) {
+ ServiceReference[] refs;
+ try {
+ refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
+ if (refs == null) {
+ System.err.println("Cannot get the factory " + factoryName);
+ return null;
+ }
+ return ((Factory) bc.getService(refs[0]));
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+ return null;
+ }
+ }
+
+ public static HandlerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {
+ ServiceReference[] refs;
+ try {
+ refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");
+ if (refs == null) {
+ System.err.println("Cannot get the factory " + factoryName);
+ return null;
+ }
+ return (HandlerFactory) bc.getService(refs[0]);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+ return null;
+ }
+ }
+
+ public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {
+ Factory fact = getFactoryByName(bc, factoryName);
+
+ if (fact == null) {
+ System.err.println("Factory " + factoryName + " not found");
+ return null;
+ }
+
+ // if(fact.isAcceptable(configuration)) {
+ try {
+ return fact.createComponentInstance(configuration);
+ } catch (Exception e) {
+ Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());
+ return null;
+ }
+ // }
+ // else {
+ // System.err.println("Configuration not accepted by : " + factoryName);
+ // return null;
+ // }
+ }
+
+ public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {
+ Factory fact = getFactoryByName(bc, factoryName);
+
+ if (fact == null) {
+ System.err.println("Factory " + factoryName + " not found");
+ return null;
+ }
+
+ try {
+ Properties props = new Properties();
+ props.put("name", name);
+ return fact.createComponentInstance(props);
+ } catch (Exception e) {
+ System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {
+ ServiceReference[] refs = null;
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return new ServiceReference[0];
+ } else {
+ return refs;
+ }
+ }
+
+ public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {
+ ServiceReference[] refs = null;
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return null;
+ } else {
+ return refs[0];
+ }
+ }
+
+ public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {
+ ServiceReference[] refs = null;
+ String filter = null;
+ if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
+ filter = "(" + "factory.name" + "=" + name + ")";
+ } else {
+ filter = "(" + "instance.name" + "=" + name + ")";
+ }
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return null;
+ } else {
+ return refs[0];
+ }
+ }
+
+ public static Object getServiceObject(BundleContext bc, String itf, String filter) {
+ ServiceReference ref = getServiceReference(bc, itf, filter);
+ if (ref != null) {
+ return bc.getService(ref);
+ } else {
+ return null;
+ }
+ }
+
+ public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {
+ ServiceReference[] refs = getServiceReferences(bc, itf, filter);
+ if (refs != null) {
+ Object[] list = new Object[refs.length];
+ for (int i = 0; i < refs.length; i++) {
+ list[i] = bc.getService(refs[i]);
+ }
+ return list;
+ } else {
+ return new Object[0];
+ }
+ }
+
+// public static ServiceContext getServiceContext(ComponentInstance ci) {
+// if (ci instanceof CompositeManager) {
+// return ((CompositeManager) ci).getServiceContext();
+// } else {
+// throw new RuntimeException("Cannot get the service context form an non composite instance");
+// }
+// }
+
+ public static Factory getFactoryByName(ServiceContext bc, String factoryName) {
+ ServiceReference[] refs;
+ try {
+ refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
+ if (refs == null) { return null; }
+ return ((Factory) bc.getService(refs[0]));
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+ return null;
+ }
+ }
+
+ public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {
+ Factory fact = getFactoryByName(bc, factoryName);
+
+ if (fact == null) { return null; }
+
+ if (fact.isAcceptable(configuration)) {
+ try {
+ return fact.createComponentInstance(configuration);
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ e.printStackTrace();
+ return null;
+ }
+ } else {
+ System.err.println("Configuration not accepted by : " + factoryName);
+ return null;
+ }
+ }
+
+ public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {
+ ServiceReference[] refs = null;
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return new ServiceReference[0];
+ } else {
+ return refs;
+ }
+ }
+
+ public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {
+ ServiceReference[] refs = null;
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return null;
+ } else {
+ return refs[0];
+ }
+ }
+
+ public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {
+ ServiceReference[] refs = null;
+ String filter = null;
+ if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
+ filter = "(" + "factory.name" + "=" + name + ")";
+ } else {
+ filter = "(" + "instance.name" + "=" + name + ")";
+ }
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return null;
+ } else {
+ return refs[0];
+ }
+ }
+
+ public static Object getServiceObject(ServiceContext bc, String itf, String filter) {
+ ServiceReference ref = getServiceReference(bc, itf, filter);
+ if (ref != null) {
+ return bc.getService(ref);
+ } else {
+ return null;
+ }
+ }
+
+ public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {
+ ServiceReference[] refs = getServiceReferences(bc, itf, filter);
+ if (refs != null) {
+ Object[] list = new Object[refs.length];
+ for (int i = 0; i < refs.length; i++) {
+ list[i] = bc.getService(refs[i]);
+ }
+ return list;
+ } else {
+ return new Object[0];
+ }
+ }
+
+}
diff --git a/ipojo/tests/tests.core/src/main/resources/metadata.xml b/ipojo/tests/tests.core/src/main/resources/metadata.xml
new file mode 100644
index 0000000..4d6ff5e
--- /dev/null
+++ b/ipojo/tests/tests.core/src/main/resources/metadata.xml
@@ -0,0 +1,1105 @@
+<ipojo
+ xmlns:cs="org.apache.felix.ipojo.test.handler.CheckServiceHandler">
+ <component classname="org.apache.felix.ipojo.test.log.LogImpl"
+ factory="true" name="log">
+ <provides />
+ </component>
+
+ <!-- Component Types used inside tests -->
+ <!-- Service Providing -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ factory="FooProviderType-1" architecture="true">
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ factory="FooProviderType-1-Sing" factory-method="singleton"
+ architecture="true">
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ factory="FooProviderType-1-Sev" factory-method="several"
+ architecture="true">
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ factory="FooProviderType-1-SingM" factory-method="singleton"
+ architecture="true">
+ <provides factory="method" />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ factory="FooProviderType-1-SevM" factory-method="several"
+ architecture="true">
+ <provides factory="method" />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ name="FooProviderType-2" architecture="true">
+ <provides>
+ <property name="int" type="int" value="2" />
+ <property name="long" type="long" value="40" />
+ <property name="string" type="java.lang.String" value="foo" />
+ <property name="strAProp" type="java.lang.String[]"
+ value="{foo, bar}" />
+ <property name="intAProp" type="int[]" value="{1,2,3}" />
+ </provides>
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn"
+ name="FooProviderType-Dyn" architecture="true">
+ <provides>
+ <property name="int" field="intProp" value="2" />
+ <property name="boolean" field="boolProp" value="false" />
+ <property name="string" field="strProp" value="foo" />
+ <property name="strAProp" field="strAProp"
+ value="{foo, bar}" />
+ <property name="intAProp" field="intAProp" value="{ 1,2,3}" />
+ </provides>
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn2"
+ name="FooProviderType-Dyn2" factory="true" architecture="true">
+ <provides>
+ <property name="int" field="intProp" value="4" />
+ <property name="boolean" field="boolProp" />
+ <property name="string" field="strProp" />
+ <property name="strAProp" field="strAProp" />
+ <property name="intAProp" field="intAProp"
+ value="{1, 2,3 }" />
+ </provides>
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn"
+ factory="FooProviderType-Conf" architecture="true">
+ <provides />
+ <properties propagation="false">
+ <property name="int" field="intProp" value="2" />
+ <property name="boolean" field="boolProp" value="false" />
+ <property name="string" field="strProp" value="foo" />
+ <property name="strAProp" field="strAProp"
+ value="{foo, bar}" />
+ <property name="intAProp" field="intAProp" value="{1,2, 3}" />
+ </properties>
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ factory="FooProviderType-3" architecture="true">
+ <provides>
+ <property name="foo" field="m_foo" />
+ <property name="bar" field="m_bar" />
+ <property name="baz" type="java.lang.String" />
+ </provides>
+ <properties propagation="true">
+ <property name="foo" field="m_foo" />
+ <property name="bar" field="m_bar" />
+ </properties>
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ factory="FooProviderType-itf" architecture="true">
+ <provides
+ interface="org.apache.felix.ipojo.test.scenarios.service.FooService" />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1"
+ factory="FooBarProviderType-1" architecture="true">
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1"
+ factory="FooBarProviderType-2" architecture="true">
+ <provides
+ interface="{org.apache.felix.ipojo.test.scenarios.service.FooService, org.apache.felix.ipojo.test.scenarios.service.BarService }" />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1"
+ factory="FooBarProviderType-3" architecture="true">
+ <provides
+ interface="{org.apache.felix.ipojo.test.scenarios.service.FooService}">
+ <property name="baz" type="java.lang.String" value="foo" />
+ </provides>
+ <provides
+ interface="{org.apache.felix.ipojo.test.scenarios.service.BarService}">
+ <property name="baz" type="java.lang.String" value="bar" />
+ </provides>
+ </component>
+
+ <!-- Immediate Component -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ factory="ImmediateFooProviderType" immediate="true"
+ architecture="true">
+ <provides />
+ </component>
+
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ factory="ImmediateFooProviderTypeSingleton" immediate="true"
+ factory-method="singleton" architecture="true">
+ <provides />
+ </component>
+
+ <!-- Simple Filter Dependencies -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FilterCheckProvider"
+ factory="SimpleFilterCheckServiceProvider" architecture="true">
+ <provides>
+ <property field="m_toto" name="toto" value="A" />
+ </provides>
+ </component>
+
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FilterCheckSubscriber"
+ factory="SimpleFilterCheckServiceSubscriber" architecture="true">
+ <requires field="m_foo" filter="(toto=B)" id="id1">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FilterCheckSubscriber"
+ factory="SimpleFilterCheckServiceSubscriber2" architecture="true">
+ <requires field="m_foo" id="id2">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Optional Simple Filter Dependencies -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FilterCheckSubscriber"
+ factory="OptionalSimpleFilterCheckServiceSubscriber"
+ architecture="true">
+ <requires field="m_foo" filter="(toto=B)" id="id1"
+ optional="true">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FilterCheckSubscriber"
+ factory="OptionalSimpleFilterCheckServiceSubscriber2"
+ architecture="true">
+ <requires field="m_foo" id="id2" optional="true">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Aggregate filter Dependencies-->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleFilterCheckSubscriber"
+ factory="MultipleFilterCheckServiceSubscriber" architecture="true">
+ <requires field="m_foo" filter="(toto=B)" id="id1">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleFilterCheckSubscriber"
+ factory="MultipleFilterCheckServiceSubscriber2" architecture="true">
+ <requires field="m_foo" id="id2">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Optional Aggregate Filter Dependencies -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleFilterCheckSubscriber"
+ factory="OptionalMultipleFilterCheckServiceSubscriber"
+ architecture="true">
+ <requires field="m_foo" filter="(toto=B)" id="id1"
+ optional="true">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleFilterCheckSubscriber"
+ factory="OptionalMultipleFilterCheckServiceSubscriber2"
+ architecture="true">
+ <requires field="m_foo" id="id2" optional="true">
+ <callback type="bind" method="Bind" />
+ <callback type="unbind" method="Unbind" />
+ </requires>
+ <provides />
+ </component>
+
+
+ <!-- Simple Dependencies -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="SimpleCheckServiceProvider" architecture="true">
+ <requires field="fs" />
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="VoidCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="ObjectCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="RefCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="BothCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="DoubleCheckServiceProvider" 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.test.scenarios.component.MethodCheckServiceProvider"
+ factory="MObjectCheckServiceProvider" architecture="true">
+ <requires>
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MethodCheckServiceProvider"
+ factory="MRefCheckServiceProvider" architecture="true">
+ <requires
+ interface="org.apache.felix.ipojo.test.scenarios.service.FooService">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MethodCheckServiceProvider"
+ factory="MBothCheckServiceProvider" architecture="true">
+ <requires>
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Simple & Optional Dependencies -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="SimpleOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true" />
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="VoidOptionalCheckServiceProvider" 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.test.scenarios.component.CheckServiceProvider"
+ factory="ObjectOptionalCheckServiceProvider" 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.test.scenarios.component.CheckServiceProvider"
+ factory="RefOptionalCheckServiceProvider" 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.test.scenarios.component.CheckServiceProvider"
+ factory="BothOptionalCheckServiceProvider" 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.test.scenarios.component.MethodCheckServiceProvider"
+ factory="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.test.scenarios.component.MethodCheckServiceProvider"
+ factory="MRefOptionalCheckServiceProvider" architecture="true">
+ <requires
+ interface="org.apache.felix.ipojo.test.scenarios.service.FooService"
+ optional="true">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MethodCheckServiceProvider"
+ factory="MBothOptionalCheckServiceProvider" architecture="true">
+ <requires
+ interface="org.apache.felix.ipojo.test.scenarios.service.FooService"
+ optional="true">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Simple & Optional Dependencies with default-implementation -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="DISimpleOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.test.scenarios.component.FooServiceDefaultImpl" />
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="DIVoidOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.test.scenarios.component.FooServiceDefaultImpl">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="DIObjectOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.test.scenarios.component.FooServiceDefaultImpl">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="DIRefOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.test.scenarios.component.FooServiceDefaultImpl">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="DIBothOptionalCheckServiceProvider" architecture="true">
+ <requires field="fs" optional="true"
+ default-implementation="org.apache.felix.ipojo.test.scenarios.component.FooServiceDefaultImpl">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MethodCheckServiceProvider"
+ factory="DIMObjectOptionalCheckServiceProvider" architecture="true">
+ <requires optional="true"
+ default-implementation="org.apache.felix.ipojo.test.scenarios.component.FooServiceDefaultImpl">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MethodCheckServiceProvider"
+ factory="DIMRefOptionalCheckServiceProvider" architecture="true">
+ <requires
+ interface="org.apache.felix.ipojo.test.scenarios.service.FooService"
+ optional="true"
+ default-implementation="org.apache.felix.ipojo.test.scenarios.component.FooServiceDefaultImpl">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MethodCheckServiceProvider"
+ factory="DIMBothOptionalCheckServiceProvider" architecture="true">
+ <requires
+ interface="org.apache.felix.ipojo.test.scenarios.service.FooService"
+ optional="true"
+ default-implementation="org.apache.felix.ipojo.test.scenarios.component.FooServiceDefaultImpl">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Multiple Dependencies -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckService"
+ factory="SimpleMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs" />
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckService"
+ factory="VoidMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="voidBind" />
+ <callback type="unbind" method="voidUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckService"
+ factory="ObjectMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="objectBind" />
+ <callback type="unbind" method="objectUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckService"
+ factory="RefMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckService"
+ factory="BothMultipleCheckServiceProvider" architecture="true">
+ <requires field="fs">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MethodMultipleCheckService"
+ factory="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.test.scenarios.component.MethodMultipleCheckService"
+ factory="MRefMultipleCheckServiceProvider" architecture="true">
+ <requires
+ interface="org.apache.felix.ipojo.test.scenarios.service.FooService"
+ aggregate="true">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MethodMultipleCheckService"
+ factory="MBothMultipleCheckServiceProvider" architecture="true">
+ <requires aggregate="true">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Multiple & Optional Dependencies -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckService"
+ factory="SimpleOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true" />
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckService"
+ factory="VoidOptionalMultipleCheckServiceProvider"
+ 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.test.scenarios.component.MultipleCheckService"
+ factory="ObjectOptionalMultipleCheckServiceProvider"
+ 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.test.scenarios.component.MultipleCheckService"
+ factory="RefOptionalMultipleCheckServiceProvider"
+ 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.test.scenarios.component.MethodMultipleCheckService"
+ factory="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.test.scenarios.component.MethodMultipleCheckService"
+ factory="MRefOptionalMultipleCheckServiceProvider"
+ architecture="true">
+ <requires
+ interface="org.apache.felix.ipojo.test.scenarios.service.FooService"
+ aggregate="true" optional="true">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+ <!-- Static Dependencies -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="StaticSimpleCheckServiceProvider" architecture="true">
+ <requires field="fs" policy="static" />
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="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.test.scenarios.component.CheckServiceProvider"
+ factory="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.test.scenarios.component.CheckServiceProvider"
+ factory="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.test.scenarios.component.CheckServiceProvider"
+ factory="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.test.scenarios.component.MethodCheckServiceProvider"
+ factory="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.test.scenarios.component.MethodCheckServiceProvider"
+ factory="StaticMRefCheckServiceProvider" architecture="true">
+ <requires
+ interface="org.apache.felix.ipojo.test.scenarios.service.FooService"
+ policy="static">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MethodCheckServiceProvider"
+ factory="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.test.scenarios.component.CheckServiceProvider"
+ factory="StaticSimpleOptionalCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" optional="true" policy="static" />
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CheckServiceProvider"
+ factory="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.test.scenarios.component.CheckServiceProvider"
+ factory="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.test.scenarios.component.CheckServiceProvider"
+ factory="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.test.scenarios.component.CheckServiceProvider"
+ factory="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.test.scenarios.component.MethodCheckServiceProvider"
+ factory="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.test.scenarios.component.MethodCheckServiceProvider"
+ factory="StaticMRefOptionalCheckServiceProvider"
+ architecture="true">
+ <requires
+ interface="org.apache.felix.ipojo.test.scenarios.service.FooService"
+ optional="true" policy="static">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MethodCheckServiceProvider"
+ factory="StaticMBothOptionalCheckServiceProvider"
+ architecture="true">
+ <requires
+ interface="org.apache.felix.ipojo.test.scenarios.service.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.test.scenarios.component.MultipleCheckService"
+ factory="StaticSimpleMultipleCheckServiceProvider"
+ architecture="true">
+ <requires field="fs" policy="static" />
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MultipleCheckService"
+ factory="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.test.scenarios.component.MultipleCheckService"
+ factory="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.test.scenarios.component.MultipleCheckService"
+ factory="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.test.scenarios.component.MultipleCheckService"
+ factory="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.test.scenarios.component.MethodMultipleCheckService"
+ factory="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.test.scenarios.component.MethodMultipleCheckService"
+ factory="StaticMRefMultipleCheckServiceProvider"
+ architecture="true">
+ <requires
+ interface="org.apache.felix.ipojo.test.scenarios.service.FooService"
+ aggregate="true" policy="static">
+ <callback type="bind" method="refBind" />
+ <callback type="unbind" method="refUnbind" />
+ </requires>
+ <provides />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.MethodMultipleCheckService"
+ factory="StaticMBothMultipleCheckServiceProvider"
+ architecture="true">
+ <requires aggregate="true" policy="static">
+ <callback type="bind" method="bothBind" />
+ <callback type="unbind" method="bothUnbind" />
+ </requires>
+ <provides />
+ </component>
+
+
+ <!-- Lifecycle Callback -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService"
+ factory="CallbackCheckService" architecture="true">
+ <requires field="fs" />
+ <provides />
+ <callback transition="validate" method="start" />
+ <callback transition="invalidate" method="stop" />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService"
+ factory="ParentCallbackCheckService" architecture="true">
+ <requires field="fs" />
+ <provides />
+ <callback transition="validate" method="parentStart" />
+ <callback transition="invalidate" method="parentStop" />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService"
+ immediate="true" factory="ImmediateCallbackCheckService"
+ architecture="true">
+ <requires field="fs" />
+ <provides />
+ <callback transition="validate" method="start" />
+ <callback transition="invalidate" method="stop" />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService"
+ immediate="true" factory="ImmediateCallbackCheckServiceSingleton"
+ factory-method="singleton" architecture="true">
+ <requires field="fs" />
+ <provides />
+ <callback transition="validate" method="start" />
+ <callback transition="invalidate" method="stop" />
+ </component>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService"
+ immediate="true" factory="ImmediateCallbackCheckServiceSeveral"
+ factory-method="several" architecture="true">
+ <requires field="fs" />
+ <provides />
+ <callback transition="validate" method="start" />
+ <callback transition="invalidate" method="stop" />
+ </component>
+
+ <!-- Manipulation -->
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.Manipulation23Tester"
+ factory="PrimitiveManipulationTester" architecture="true">
+ <provides />
+ </component>
+
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.A123.Manipulation23Tester"
+ factory="PrimitiveManipulationTesterA" architecture="true">
+ <provides />
+ </component>
+
+ <!-- Configuration Management Test -->
+ <component factory="FieldConfigurableCheckService"
+ className="org.apache.felix.ipojo.test.scenarios.component.ConfigurableCheckServiceProvider"
+ architecture="true">
+ <provides />
+ <properties propagation="true">
+ <property field="b" />
+ <property field="s" />
+ <property field="i" />
+ <property field="l" />
+ <property field="d" />
+ <property field="f" />
+ <property field="c" />
+ <property field="bool" />
+ <property field="bs" />
+ <property field="ss" />
+ <property field="is" />
+ <property field="ls" />
+ <property field="ds" />
+ <property field="fs" />
+ <property field="cs" />
+ <property field="bools" />
+ <property field="string" />
+ <property field="strings" />
+ </properties>
+ </component>
+
+ <component factory="BothConfigurableCheckService"
+ className="org.apache.felix.ipojo.test.scenarios.component.ConfigurableCheckServiceProvider"
+ architecture="true">
+ <provides />
+ <properties propagation="true">
+ <property field="b" method="updateB" />
+ <property field="s" method="updateS" />
+ <property field="i" method="updateI" />
+ <property field="l" method="updateL" />
+ <property field="d" method="updateD" />
+ <property field="f" method="updateF" />
+ <property field="c" method="updateC" />
+ <property field="bool" method="updateBool" />
+ <property field="bs" method="updateBs" />
+ <property field="ss" method="updateSs" />
+ <property field="is" method="updateIs" />
+ <property field="ls" method="updateLs" />
+ <property field="ds" method="updateDs" />
+ <property field="fs" method="updateFs" />
+ <property field="cs" method="updateCs" />
+ <property field="bools" method="updateBools" />
+ <property field="string" method="updateString" />
+ <property field="strings" method="updateStrings" />
+ </properties>
+ </component>
+
+ <component factory="MethodConfigurableCheckService"
+ className="org.apache.felix.ipojo.test.scenarios.component.ConfigurableCheckServiceProvider"
+ architecture="true">
+ <provides />
+ <properties propagation="true">
+ <property method="updateB" name="b" />
+ <property method="updateS" name="s" />
+ <property method="updateI" name="i" />
+ <property method="updateL" name="l" />
+ <property method="updateD" name="d" />
+ <property method="updateF" name="f" />
+ <property method="updateC" name="c" />
+ <property method="updateBool" name="bool" />
+ <property method="updateBs" name="bs" />
+ <property method="updateSs" name="ss" />
+ <property method="updateIs" name="is" />
+ <property method="updateLs" name="ls" />
+ <property method="updateDs" name="ds" />
+ <property method="updateFs" name="fs" />
+ <property method="updateCs" name="cs" />
+ <property method="updateBools" name="bools" />
+ <property method="updateString" name="string" />
+ <property method="updateStrings" name="strings" />
+ </properties>
+ </component>
+
+ <component factory="ParentMethodConfigurableCheckService"
+ className="org.apache.felix.ipojo.test.scenarios.component.ParentConfigurableCheckServiceProvider"
+ architecture="true">
+ <provides />
+ <properties propagation="true">
+ <property method="updateB" name="b" />
+ <property method="updateS" name="s" />
+ <property method="updateI" name="i" />
+ <property method="updateL" name="l" />
+ <property method="updateD" name="d" />
+ <property method="updateF" name="f" />
+ <property method="updateC" name="c" />
+ <property method="updateBool" name="bool" />
+ <property method="updateBs" name="bs" />
+ <property method="updateSs" name="ss" />
+ <property method="updateIs" name="is" />
+ <property method="updateLs" name="ls" />
+ <property method="updateDs" name="ds" />
+ <property method="updateFs" name="fs" />
+ <property method="updateCs" name="cs" />
+ <property method="updateBools" name="bools" />
+ <property method="updateString" name="string" type="string" />
+ <property method="updateStrings" name="strings"
+ type="java.lang.String[]" />
+ </properties>
+ </component>
+
+ <!-- Handler test -->
+ <handler
+ classname="org.apache.felix.ipojo.test.handler.CheckServiceHandler"
+ name="check"
+ namespace="org.apache.felix.ipojo.test.handler.CheckServiceHandler"
+ architecture="false">
+ <controller field="isValid" />
+ </handler>
+ <component
+ className="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
+ factory="HandlerTester" architecture="true">
+ <cs:check />
+ </component>
+ <instance name="HandlerTest-2" component="HandlerTester">
+ <property name="csh.simple" value="Simple" />
+ <property name="csh.map">
+ <property name="a" value="a" />
+ <property name="b" value="b" />
+ <property name="c" value="c" />
+ </property>
+ </instance>
+
+ <!-- Test lifecycle controller -->
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.LifecycleControllerTest"
+ name="lcTest">
+ <provides />
+ <controller field="m_state" />
+ <properties>
+ <property name="conf" field="m_conf" method="setConf" />
+ </properties>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.LifecycleControllerTest"
+ name="lcTest2" immediate="true" architecture="true">
+ <provides />
+ <controller field="m_state" />
+ <properties>
+ <property name="conf" field="m_conf" method="setConf" />
+ </properties>
+ </component>
+
+ <!-- Inherited Provides -->
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation1"
+ name="PI1" architecture="true">
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation1"
+ name="PI1-1" architecture="true">
+ <provides
+ interface="org.apache.felix.ipojo.test.scenarios.service.ParentParentInterface" />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation1"
+ name="PI1-2" architecture="true">
+ <provides
+ interface="{org.apache.felix.ipojo.test.scenarios.service.ParentParentInterface, org.apache.felix.ipojo.test.scenarios.service.ParentInterface2}" />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation2"
+ name="PI2" architecture="true">
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation2"
+ name="PI2-1" architecture="true">
+ <provides
+ interface="org.apache.felix.ipojo.test.scenarios.service.ParentParentInterface" />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.inherited.ProcessImplementation3"
+ name="PI3" architecture="true">
+ <provides />
+ </component>
+
+ <instance component="log" name="MyLogger" />
+</ipojo>