Split the composite test suite
Add the annotation test suite (checking annotations processing)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@652169 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/tests.composite.service.import-export/pom.xml b/ipojo/tests/tests.composite.service.import-export/pom.xml
new file mode 100644
index 0000000..50fdc8d
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/pom.xml
@@ -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.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <name>iPOJO Composite (Service Import/Export) Test Suite</name>
+ <artifactId>tests.composite.service.import-export</artifactId>
+ <groupId>ipojo.tests</groupId>
+ <version>0.7.6-SNAPSHOT</version>
+ <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>
+ <dependency>
+ <groupId>ipojo.tests</groupId>
+ <artifactId>tests.composite</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>
+ <Bundle-SymbolicName>
+ ${pom.artifactId}
+ </Bundle-SymbolicName>
+ <Private-Package>
+ org.apache.felix.ipojo.test.composite.exporter, org.apache.felix.ipojo.test.composite.importer
+ </Private-Package>
+ <Test-Suite>
+ org.apache.felix.ipojo.test.composite.importer.ImportTestSuite, org.apache.felix.ipojo.test.composite.exporter.ExportTestSuite
+ </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>
+ </plugins>
+ </build>
+</project>
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/ExportTestSuite.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/ExportTestSuite.java
new file mode 100644
index 0000000..d9b84f1
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/ExportTestSuite.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.composite.exporter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class ExportTestSuite extends TestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Composite Service Exporters Test Suite", bc);
+ ots.addTestSuite(SimpleExport.class);
+ ots.addTestSuite(OptionalExport.class);
+ ots.addTestSuite(MultipleExport.class);
+ ots.addTestSuite(OptionalMultipleExport.class);
+ ots.addTestSuite(FilteredExport.class);
+ ots.setBundleContext(bc);
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/FilteredExport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/FilteredExport.java
new file mode 100644
index 0000000..8353c03
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/FilteredExport.java
@@ -0,0 +1,230 @@
+/*
+ * 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.composite.exporter;
+
+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.composite.service.BazService;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class FilteredExport extends OSGiTestCase {
+
+ ComponentInstance export1;
+ Factory fooProvider;
+ ComponentInstance foo1 = null, foo2 = null;
+
+ public void setUp() {
+ fooProvider = Utils.getFactoryByName(context, "BazProviderType");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to create foos : " + e.getMessage());
+ }
+
+ foo1.stop();
+ foo2.stop();
+
+ Factory factory = Utils.getFactoryByName(context, "composite.export.5");
+ Properties props = new Properties();
+ props.put("name", "export");
+ try {
+ export1 = factory.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Fail to instantiate exporter " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ export1.dispose();
+ foo1 = null;
+ foo2 = null;
+ export1 = null;
+ }
+
+ public void test1() {
+ export1.start();
+
+ // Check that no foo service are available
+ assertEquals("Check no foo service", Utils.getServiceReferences(context, FooService.class.getName(), null).length, 0);
+
+ // Test invalidity
+ assertTrue("Check invalidity - 0", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo1.stop();
+ assertTrue("Check invalidity - 3", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo2.stop();
+ assertTrue("Check invalidity - 4", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check invalidity - 5", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 0);
+ }
+
+ public void test2() {
+ export1.start();
+
+ // Test invalidity
+ assertTrue("Check invalidity - 0", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke());
+
+ foo1.stop();
+ assertTrue("Check invalidity - 4", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 5", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke());
+ }
+
+ public void test3() {
+ foo1.start();
+ foo2.start();
+
+ export1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo1.stop();
+ assertTrue("Check invalidity - 2", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 0);
+
+ foo2.stop();
+ assertTrue("Check invalidity - 3", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 4", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke());
+ }
+
+ public void test4() {
+ foo1.start();
+ foo2.start();
+
+ export1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo1.stop();
+ assertTrue("Check invalidity - 3", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check invalidity - 4", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+ }
+
+
+
+ private boolean isFooServiceProvided() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export1.getInstanceName());
+ return ref != null;
+ }
+
+ private int countFooServiceProvided() {
+ ServiceReference[] refs = Utils.getServiceReferences(context, BazService.class.getName(), "(instance.name="+export1.getInstanceName()+")");
+ return refs.length;
+ }
+
+ private boolean invoke() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export1.getInstanceName());
+ if(ref == null) { return false; }
+ BazService fs = (BazService) context.getService(ref);
+ return fs.foo();
+ }
+
+
+
+
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/MultipleExport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/MultipleExport.java
new file mode 100644
index 0000000..fed07ba
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/MultipleExport.java
@@ -0,0 +1,247 @@
+/*
+ * 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.composite.exporter;
+
+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.composite.service.BazService;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MultipleExport extends OSGiTestCase {
+
+ ComponentInstance export3;
+ Factory fooProvider;
+ ComponentInstance foo1 = null, foo2 = null;
+
+ public void setUp() {
+ fooProvider = Utils.getFactoryByName(context, "BazProviderType");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to create foos : " + e.getMessage());
+ }
+
+ foo1.stop();
+ foo2.stop();
+
+ Factory factory = Utils.getFactoryByName(context, "composite.export.3");
+ Properties props = new Properties();
+ props.put("name", "export");
+ try {
+ export3 = factory.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Fail to instantiate exporter " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ export3.dispose();
+ foo1 = null;
+ foo2 = null;
+ export3 = null;
+ }
+
+ public void test1() {
+ export3.start();
+
+ // Check that no foo service are available
+ assertEquals("Check no foo service", Utils.getServiceReferences(context, FooService.class.getName(), null).length, 0);
+
+ // Test invalidity
+ assertTrue("Check invalidity - 0", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke(1));
+
+ foo2.start();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 2", invoke(2));
+
+ foo1.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3 ("+countFooServiceProvided()+")", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke(1));
+
+ foo2.stop();
+ assertTrue("Check invalidity - 4", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 5", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke(1));
+ }
+
+ public void test2() {
+ export3.start();
+
+ // Test invalidity
+ assertTrue("Check invalidity - 0", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 2", invoke(2));
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke(1));
+
+ foo1.stop();
+ assertTrue("Check invalidity - 4", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 5", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke(1));
+ }
+
+ public void test3() {
+ foo1.start();
+ foo2.start();
+
+ export3.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 1", invoke(2));
+
+ foo1.stop();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke(1));
+
+ foo2.stop();
+ assertTrue("Check invalidity - 3", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke(1));
+ }
+
+ public void test4() {
+ foo1.start();
+ foo2.start();
+
+ export3.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 1", invoke(2));
+
+ foo2.stop();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke(1));
+
+ foo1.stop();
+ assertTrue("Check invalidity - 3", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke(1));
+ }
+
+
+
+ private boolean isFooServiceProvided() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export3.getInstanceName());
+ return ref != null;
+ }
+
+ private int countFooServiceProvided() {
+ ServiceReference[] refs = Utils.getServiceReferences(context, BazService.class.getName(), "(instance.name="+export3.getInstanceName()+")");
+ return refs.length;
+ }
+
+ private boolean invoke() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export3.getInstanceName());
+ if(ref == null) { return false; }
+ BazService fs = (BazService) context.getService(ref);
+ context.ungetService(ref);
+ return fs.foo();
+ }
+
+ private boolean invoke(int nb) {
+ ServiceReference[] refs = Utils.getServiceReferences(context, BazService.class.getName(), "(instance.name="+export3.getInstanceName()+")");
+ if(refs == null) { return false; }
+ if (nb > refs.length) { return false; }
+ for(int i = 0; i < nb; i++) {
+ BazService fs = (BazService) context.getService(refs[i]);
+ context.ungetService(refs[i]);
+ if(!fs.foo()) { return false; }
+ }
+ return true;
+ }
+
+
+
+
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/OptionalExport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/OptionalExport.java
new file mode 100644
index 0000000..4f78f49
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/OptionalExport.java
@@ -0,0 +1,234 @@
+/*
+ * 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.composite.exporter;
+
+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.composite.service.BazService;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalExport extends OSGiTestCase {
+
+ ComponentInstance export2;
+ Factory fooProvider;
+ ComponentInstance foo1 = null, foo2 = null;
+
+ public void setUp() {
+ fooProvider = Utils.getFactoryByName(context, "BazProviderType");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to create foos : " + e.getMessage());
+ }
+
+ foo1.stop();
+ foo2.stop();
+
+ Factory factory = Utils.getFactoryByName(context, "composite.export.2");
+ Properties props = new Properties();
+ props.put("name", "export");
+ try {
+ export2 = factory.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Fail to instantiate exporter " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ export2.dispose();
+ foo1 = null;
+ foo2 = null;
+ export2 = null;
+ }
+
+ public void test1() {
+ export2.start();
+
+ // Check that no foo service are available
+ assertEquals("Check no foo service", Utils.getServiceReferences(context, FooService.class.getName(), null).length, 0);
+
+ // Test validity
+ assertTrue("Check validity - 0", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo1.stop();
+ assertTrue("Check validity - 3", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3 ("+countFooServiceProvided()+")", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 4", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 5", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke());
+ }
+
+ public void test2() {
+ export2.start();
+
+ // Test invalidity
+ assertTrue("Check validity - 0", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke());
+
+ foo1.stop();
+ assertTrue("Check validity - 4", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 5", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke());
+ }
+
+ public void test3() {
+ foo1.start();
+ foo2.start();
+
+ export2.start();
+ assertTrue("Check validity - 1", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo1.stop();
+ assertTrue("Check validity - 2", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 4", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke());
+ }
+
+ public void test4() {
+ foo1.start();
+ foo2.start();
+
+ export2.start();
+ assertTrue("Check validity - 1", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 2", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo1.stop();
+ assertTrue("Check validity - 3", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 4", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke());
+ }
+
+
+
+ private boolean isFooServiceProvided() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export2.getInstanceName());
+ return ref != null;
+ }
+
+ private int countFooServiceProvided() {
+ ServiceReference[] refs = Utils.getServiceReferences(context, BazService.class.getName(), "(instance.name="+export2.getInstanceName()+")");
+ return refs.length;
+ }
+
+ private boolean invoke() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export2.getInstanceName());
+ if(ref == null) { return false; }
+ BazService fs = (BazService) context.getService(ref);
+ return fs.foo();
+ }
+
+
+
+
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/OptionalMultipleExport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/OptionalMultipleExport.java
new file mode 100644
index 0000000..a285ef0
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/OptionalMultipleExport.java
@@ -0,0 +1,247 @@
+/*
+ * 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.composite.exporter;
+
+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.composite.service.BazService;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalMultipleExport extends OSGiTestCase {
+
+ ComponentInstance export3;
+ Factory fooProvider;
+ ComponentInstance foo1 = null, foo2 = null;
+
+ public void setUp() {
+ fooProvider = Utils.getFactoryByName(context, "BazProviderType");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to create foos : " + e.getMessage());
+ }
+
+ foo1.stop();
+ foo2.stop();
+
+ Factory factory = Utils.getFactoryByName(context, "composite.export.4");
+ Properties props = new Properties();
+ props.put("name", "export");
+ try {
+ export3 = factory.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Fail to instantiate exporter " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ export3.dispose();
+ foo1 = null;
+ foo2 = null;
+ export3 = null;
+ }
+
+ public void test1() {
+ export3.start();
+
+ // Check that no foo service are available
+ assertEquals("Check no foo service", Utils.getServiceReferences(context, FooService.class.getName(), null).length, 0);
+
+ // Test invalidity
+ assertTrue("Check validity - 0", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke(1));
+
+ foo2.start();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 2", invoke(2));
+
+ foo1.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3 ("+countFooServiceProvided()+")", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke(1));
+
+ foo2.stop();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 5", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke(1));
+ }
+
+ public void test2() {
+ export3.start();
+
+ // Test invalidity
+ assertTrue("Check validity - 0", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 2", invoke(2));
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke(1));
+
+ foo1.stop();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 5", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke(1));
+ }
+
+ public void test3() {
+ foo1.start();
+ foo2.start();
+
+ export3.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 1", invoke(2));
+
+ foo1.stop();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke(1));
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke(1));
+ }
+
+ public void test4() {
+ foo1.start();
+ foo2.start();
+
+ export3.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 1", invoke(2));
+
+ foo2.stop();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke(1));
+
+ foo1.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke(1));
+ }
+
+
+
+ private boolean isFooServiceProvided() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export3.getInstanceName());
+ return ref != null;
+ }
+
+ private int countFooServiceProvided() {
+ ServiceReference[] refs = Utils.getServiceReferences(context, BazService.class.getName(), "(instance.name="+export3.getInstanceName()+")");
+ return refs.length;
+ }
+
+ private boolean invoke() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export3.getInstanceName());
+ if(ref == null) { return false; }
+ BazService fs = (BazService) context.getService(ref);
+ context.ungetService(ref);
+ return fs.foo();
+ }
+
+ private boolean invoke(int nb) {
+ ServiceReference[] refs = Utils.getServiceReferences(context, BazService.class.getName(), "(instance.name="+export3.getInstanceName()+")");
+ if(refs == null) { return false; }
+ if (nb > refs.length) { return false; }
+ for(int i = 0; i < nb; i++) {
+ BazService fs = (BazService) context.getService(refs[i]);
+ context.ungetService(refs[i]);
+ if(!fs.foo()) { return false; }
+ }
+ return true;
+ }
+
+
+
+
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/SimpleExport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/SimpleExport.java
new file mode 100644
index 0000000..b0bf922
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/exporter/SimpleExport.java
@@ -0,0 +1,234 @@
+/*
+ * 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.composite.exporter;
+
+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.composite.service.BazService;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class SimpleExport extends OSGiTestCase {
+
+ ComponentInstance export1;
+ Factory fooProvider;
+ ComponentInstance foo1 = null, foo2 = null;
+
+ public void setUp() {
+ fooProvider = Utils.getFactoryByName(context, "BazProviderType");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to create foos : " + e.getMessage());
+ }
+
+ foo1.stop();
+ foo2.stop();
+
+ Factory factory = Utils.getFactoryByName(context, "composite.export.1");
+ Properties props = new Properties();
+ props.put("name", "export");
+ try {
+ export1 = factory.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Fail to instantiate exporter " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ export1.dispose();
+ foo1 = null;
+ foo2 = null;
+ export1 = null;
+ }
+
+ public void test1() {
+ export1.start();
+
+ // Check that no foo service are available
+ assertEquals("Check no foo service", Utils.getServiceReferences(context, FooService.class.getName(), null).length, 0);
+
+ // Test invalidity
+ assertTrue("Check invalidity - 0", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo1.stop();
+ assertTrue("Check validity - 3", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3 ("+countFooServiceProvided()+")", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke());
+
+ foo2.stop();
+ assertTrue("Check invalidity - 4", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 5", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke());
+ }
+
+ public void test2() {
+ export1.start();
+
+ // Test invalidity
+ assertTrue("Check invalidity - 0", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke());
+
+ foo1.stop();
+ assertTrue("Check invalidity - 4", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 5", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke());
+ }
+
+ public void test3() {
+ foo1.start();
+ foo2.start();
+
+ export1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo1.stop();
+ assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo2.stop();
+ assertTrue("Check invalidity - 3", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 4", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke());
+ }
+
+ public void test4() {
+ foo1.start();
+ foo2.start();
+
+ export1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo1.stop();
+ assertTrue("Check invalidity - 3", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 4", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke());
+ }
+
+
+
+ private boolean isFooServiceProvided() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export1.getInstanceName());
+ return ref != null;
+ }
+
+ private int countFooServiceProvided() {
+ ServiceReference[] refs = Utils.getServiceReferences(context, BazService.class.getName(), "(instance.name="+export1.getInstanceName()+")");
+ return refs.length;
+ }
+
+ private boolean invoke() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), export1.getInstanceName());
+ if(ref == null) { return false; }
+ BazService fs = (BazService) context.getService(ref);
+ return fs.foo();
+ }
+
+
+
+
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedFilteredImport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedFilteredImport.java
new file mode 100644
index 0000000..1466677
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedFilteredImport.java
@@ -0,0 +1,150 @@
+/*
+ * 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.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedFilteredImport extends OSGiTestCase {
+
+ ComponentInstance import1;
+ Factory fooProvider;
+ ComponentInstance foo1, foo2;
+
+ public void setUp() {
+
+ Properties p = new Properties();
+ p.put("name", "importer");
+ Factory compFact = Utils.getFactoryByName(context, "composite.requires.1");
+ try {
+ import1 = compFact.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Cannot instantiate the component : " + e.getMessage());
+ }
+
+ import1.stop();
+
+ fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Cannot instantiate foo providers : " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ import1.dispose();
+ foo1 = null;
+ foo2 = null;
+ import1 = null;
+ }
+
+ public void testSimple() {
+ import1.start();
+ //Two providers
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import1);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo1.stop();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo2.stop();
+ assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+
+ foo2.start();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+ public void testSimple2() {
+ import1.start();
+ //Two providers
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import1);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo2.stop();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo1.stop();
+ assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+
+ foo1.start();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedMultipleImport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedMultipleImport.java
new file mode 100644
index 0000000..47688ee
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedMultipleImport.java
@@ -0,0 +1,156 @@
+/*
+ * 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.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedMultipleImport extends OSGiTestCase {
+
+ ComponentInstance import2;
+ Factory fooProvider;
+ ComponentInstance foo1, foo2;
+
+ public void setUp() {
+
+ Properties p = new Properties();
+ p.put("name", "importer");
+ Factory compFact = Utils.getFactoryByName(context, "composite.requires.2");
+ try {
+ import2 = compFact.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Cannot instantiate the component : " + e.getMessage());
+ }
+
+ import2.stop();
+
+ fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Cannot instantiate foo providers : " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ import2.dispose();
+ foo1 = null;
+ foo2 = null;
+ import2 = null;
+ }
+
+ public void testSimple() {
+ import2.start();
+ //Two providers
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import2);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 2);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ fs = (FooService) sc.getService(refs[1]);
+ assertTrue("Test foo invocation (2)", fs.foo());
+ sc.ungetService(refs[1]);
+
+ foo1.stop();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo2.stop();
+ assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);
+
+ foo2.start();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+ public void testSimple2() {
+ import2.start();
+ //Two providers
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import2);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 2);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ fs = (FooService) sc.getService(refs[1]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[1]);
+
+ foo2.stop();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo1.stop();
+ assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);
+
+ foo1.start();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalImport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalImport.java
new file mode 100644
index 0000000..6e36797
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalImport.java
@@ -0,0 +1,156 @@
+/*
+ * 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.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedOptionalImport extends OSGiTestCase {
+
+ ComponentInstance import3;
+ Factory fooProvider;
+ ComponentInstance foo1, foo2;
+
+ public void setUp() {
+
+ Properties p = new Properties();
+ p.put("name", "importer");
+ Factory compFact = Utils.getFactoryByName(context, "composite.requires.3");
+ try {
+ import3 = compFact.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Cannot instantiate the component : " + e.getMessage());
+ }
+
+ import3.stop();
+
+ fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Cannot instantiate foo providers : " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ import3.dispose();
+ foo1 = null;
+ foo2 = null;
+ import3 = null;
+ }
+
+ public void testSimple() {
+ import3.start();
+ //Two providers
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import3);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo1.stop();
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import3);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo2.stop();
+ assertTrue("Test component validity - 2", import3.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import3);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertEquals("Test foo non-availability inside the composite - 3.1", refs.length, 0);
+
+ foo2.start();
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import3);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+ public void testSimple2() {
+ import3.start();
+ //Two providers
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import3);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo2.stop();
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import3);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo1.stop();
+ assertTrue("Test component validity - 2", import3.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import3);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 0);
+
+ foo1.start();
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import3);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalMultipleImport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalMultipleImport.java
new file mode 100644
index 0000000..0dac390
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedOptionalMultipleImport.java
@@ -0,0 +1,162 @@
+/*
+ * 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.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedOptionalMultipleImport extends OSGiTestCase {
+
+ ComponentInstance import4;
+ Factory fooProvider;
+ ComponentInstance foo1, foo2;
+
+ public void setUp() {
+
+ Properties p = new Properties();
+ p.put("name", "importer");
+ Factory compFact = Utils.getFactoryByName(context, "composite.requires.4");
+ try {
+ import4 = compFact.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Cannot instantiate the component : " + e.getMessage());
+ }
+
+ import4.stop();
+
+ fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Cannot instantiate foo providers : " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ import4.dispose();
+ foo1 = null;
+ foo2 = null;
+ import4 = null;
+ }
+
+ public void testSimple() {
+ import4.start();
+ //Two providers
+ assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import4);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 2);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ fs = (FooService) sc.getService(refs[1]);
+ assertTrue("Test foo invocation (2)", fs.foo());
+ sc.ungetService(refs[1]);
+
+ foo1.stop();
+ assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import4);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo2.stop();
+ assertTrue("Test component validity - 2", import4.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import4);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertEquals("Test foo availability inside the composite - 1", refs.length, 0);
+
+ foo2.start();
+ assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import4);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+ public void testSimple2() {
+ import4.start();
+ //Two providers
+ assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import4);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 2);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ fs = (FooService) sc.getService(refs[1]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[1]);
+
+ foo2.stop();
+ assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import4);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo1.stop();
+ assertTrue("Test component validity - 2", import4.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import4);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertEquals("Test foo availability inside the composite - 1", refs.length, 0);
+
+ foo1.start();
+ assertTrue("Test component validity", import4.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import4);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedSimpleImport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedSimpleImport.java
new file mode 100644
index 0000000..2d89ee8
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/DelayedSimpleImport.java
@@ -0,0 +1,151 @@
+/*
+ * 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.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DelayedSimpleImport extends OSGiTestCase {
+
+ ComponentInstance import1;
+ Factory fooProvider;
+ ComponentInstance foo1, foo2;
+
+ public void setUp() {
+
+ Properties p = new Properties();
+ p.put("name", "importer");
+ Factory compFact = Utils.getFactoryByName(context, "composite.requires.1");
+ try {
+ import1 = compFact.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Cannot instantiate the component : " + e.getMessage());
+ }
+
+ import1.stop();
+
+ fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Cannot instantiate foo providers : " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ import1.dispose();
+ foo1 = null;
+ foo2 = null;
+ import1 = null;
+ }
+
+ public void testSimple() {
+ import1.start();
+
+ //Two providers
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import1);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo1.stop();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 2", refs);
+ assertEquals("Test foo availability inside the composite - 2.2", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo2.stop();
+ assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+
+ foo2.start();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+ public void testSimple2() {
+ import1.start();
+ //Two providers
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import1);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo2.stop();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo1.stop();
+ assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+
+ foo1.start();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/FilteredImport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/FilteredImport.java
new file mode 100644
index 0000000..221ecda
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/FilteredImport.java
@@ -0,0 +1,147 @@
+/*
+ * 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.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class FilteredImport extends OSGiTestCase {
+
+ ComponentInstance import1;
+ Factory fooProvider;
+ Factory fooProvider2;
+
+ ComponentInstance foo1, foo2;
+
+ public void setUp() {
+ Properties p = new Properties();
+ p.put("name", "importer");
+ Factory compFact = Utils.getFactoryByName(context, "composite.requires.5");
+ try {
+ import1 = compFact.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Cannot instantiate the component : " + e.getMessage());
+ }
+ import1.stop();
+
+ fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ fooProvider2 = Utils.getFactoryByName(context, "COMPO-FooProviderType-2");
+ assertNotNull("Check fooProvider availability", fooProvider2);
+
+ Properties p1 = new Properties();
+ p1.put("name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider2.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Cannot instantiate foo providers : " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ import1.dispose();
+ foo1 = null;
+ foo2 = null;
+ import1 = null;
+ }
+
+ public void testSimple() {
+ import1.start();
+ //Two providers
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import1);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo1.stop();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo2.stop();
+ assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+
+ foo2.start();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+ public void testSimple2() {
+ import1.start();
+ //Two providers
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import1);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo2.stop();
+ assertTrue("Test component invalidity - 1", import1.getState() == ComponentInstance.INVALID);
+
+ // Stop the second provider
+ foo1.stop();
+ assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+
+ foo1.start();
+ assertTrue("Test component invalidity - 3", import1.getState() == ComponentInstance.INVALID);
+
+ foo2.start();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+ }
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/ImportTestSuite.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/ImportTestSuite.java
new file mode 100644
index 0000000..2f25b2c
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/ImportTestSuite.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.composite.importer;
+
+import junit.framework.Test;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.osgi.framework.BundleContext;
+
+public class ImportTestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Composite Import Test Suite", bc);
+ ots.addTestSuite(SimpleImport.class);
+ ots.addTestSuite(DelayedSimpleImport.class);
+ ots.addTestSuite(OptionalImport.class);
+ ots.addTestSuite(DelayedOptionalImport.class);
+ ots.addTestSuite(MultipleImport.class);
+ ots.addTestSuite(DelayedMultipleImport.class);
+ ots.addTestSuite(OptionalMultipleImport.class);
+ ots.addTestSuite(DelayedOptionalMultipleImport.class);
+ ots.addTestSuite(FilteredImport.class);
+ ots.addTestSuite(DelayedFilteredImport.class);
+ return ots;
+ }
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/MultipleImport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/MultipleImport.java
new file mode 100644
index 0000000..c8eedce
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/MultipleImport.java
@@ -0,0 +1,190 @@
+/*
+ * 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.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class MultipleImport extends OSGiTestCase {
+
+ ComponentInstance import2;
+ Factory fooProvider;
+
+ public void setUp() {
+ fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p = new Properties();
+ p.put("name", "importer");
+ Factory compFact = Utils.getFactoryByName(context, "composite.requires.2");
+ try {
+ import2 = compFact.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Cannot instantiate the component : " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ import2.dispose();
+ import2 = null;
+ }
+
+ public void testSimple() {
+ // No provider -> Invalid
+ assertTrue("Test component invalidity", import2.getState() == ComponentInstance.INVALID);
+
+ ComponentInstance foo = null;
+ Properties p = new Properties();
+ p.put("name", "foo");
+ try {
+ foo = fooProvider.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo component " + e.getMessage());
+ }
+
+ ComponentInstance foo2 = null;
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo2 component " + e.getMessage());
+ }
+
+ // The foo service is available => import1 must be valid
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import2);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2 ("+refs.length+")", refs.length, 2);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ FooService fs2 = (FooService) sc.getService(refs[1]);
+ assertTrue("Test foo invocation", fs2.foo());
+ sc.ungetService(refs[0]);
+ sc.ungetService(refs[1]);
+
+ // Stop the second provider
+ foo2.dispose();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 2", refs);
+ assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // stop the foo provider
+ foo.stop();
+
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);
+
+ foo.start();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo.dispose();
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 3", import2.getState() == ComponentInstance.INVALID);
+ }
+
+ public void testSimple2() {
+ // No provider -> Invalid
+ assertTrue("Test component invalidity", import2.getState() == ComponentInstance.INVALID);
+
+ ComponentInstance foo1 = null;
+ Properties p = new Properties();
+ p.put("name", "foo");
+ try {
+ foo1 = fooProvider.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo component " + e.getMessage());
+ }
+
+ ComponentInstance foo2 = null;
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo2 component " + e.getMessage());
+ }
+
+ // The foo service is available => import1 must be valid
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import2);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2 ("+refs.length+")", refs.length, 2);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ FooService fs2 = (FooService) sc.getService(refs[1]);
+ assertTrue("Test foo invocation", fs2.foo());
+ sc.ungetService(refs[0]);
+ sc.ungetService(refs[1]);
+
+ // Stop the first provider
+ foo1.stop();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 2", refs);
+ assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // stop the second foo provider
+ foo2.dispose();
+
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);
+
+ foo1.start();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo1.dispose();
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 3", import2.getState() == ComponentInstance.INVALID);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalImport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalImport.java
new file mode 100644
index 0000000..0fb3f89
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalImport.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.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalImport extends OSGiTestCase {
+
+ ComponentInstance import3;
+ Factory fooProvider;
+
+ public void setUp() {
+ fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p = new Properties();
+ p.put("name", "importer");
+ Factory compFact = Utils.getFactoryByName(context, "composite.requires.3");
+ try {
+ import3 = compFact.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Cannot instantiate the component : " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ import3.dispose();
+ import3 = null;
+ }
+
+ public void testSimple() {
+ // No provider -> valid
+ assertTrue("Test component invalidity", import3.getState() == ComponentInstance.VALID);
+
+ ComponentInstance foo = null;
+ Properties p = new Properties();
+ p.put("name", "foo");
+ try {
+ foo = fooProvider.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo component " + e.getMessage());
+ }
+
+ ComponentInstance foo2 = null;
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo2 component " + e.getMessage());
+ }
+
+ // The foo service is available => import1 must be valid
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import3);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo2.dispose();
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import3);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 2", refs);
+ assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // stop the foo provider
+ foo.stop();
+
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 2", import3.getState() == ComponentInstance.VALID);
+
+ foo.start();
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import3);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo.dispose();
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 3", import3.getState() == ComponentInstance.VALID);
+ }
+
+ public void testSimple2() {
+ // No provider -> valid
+ assertTrue("Test component invalidity", import3.getState() == ComponentInstance.VALID);
+
+ ComponentInstance foo1 = null;
+ Properties p = new Properties();
+ p.put("name", "foo");
+ try {
+ foo1 = fooProvider.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo component " + e.getMessage());
+ }
+
+ ComponentInstance foo2 = null;
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo2 component " + e.getMessage());
+ }
+
+ // The foo service is available => import1 must be valid
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import3);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo1.stop();
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import3);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 2", refs);
+ assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // stop the foo provider
+ foo2.dispose();
+
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 2", import3.getState() == ComponentInstance.VALID);
+
+ foo1.start();
+ assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import3);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo1.dispose();
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 3", import3.getState() == ComponentInstance.VALID);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalMultipleImport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalMultipleImport.java
new file mode 100644
index 0000000..a7c71b0
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/OptionalMultipleImport.java
@@ -0,0 +1,201 @@
+/*
+ * 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.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class OptionalMultipleImport extends OSGiTestCase {
+
+ ComponentInstance import2;
+ Factory fooProvider;
+
+ public void setUp() {
+ fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p = new Properties();
+ p.put("name", "importer");
+ Factory compFact = Utils.getFactoryByName(context, "composite.requires.4");
+ try {
+ import2 = compFact.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Cannot instantiate the component : " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ import2.dispose();
+ import2 = null;
+ }
+
+ public void testSimple() {
+ // No provider -> valid
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+
+ ComponentInstance foo = null;
+ Properties p = new Properties();
+ p.put("name", "foo");
+ try {
+ foo = fooProvider.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo component " + e.getMessage());
+ }
+
+ ComponentInstance foo2 = null;
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo2 component " + e.getMessage());
+ }
+
+ // The foo service is available => import1 must be valid
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import2);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2 ("+refs.length+")", refs.length, 2);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ FooService fs2 = (FooService) sc.getService(refs[1]);
+ assertTrue("Test foo invocation", fs2.foo());
+ sc.ungetService(refs[0]);
+ sc.ungetService(refs[1]);
+
+ // Stop the second provider
+ foo2.dispose();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 2", refs);
+ assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // stop the foo provider
+ foo.stop();
+
+ // No provider -> valid
+ assertTrue("Test component validity - 2", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertEquals("Test foo non-availability inside the composite - 1", refs.length, 0);
+
+ foo.start();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo.dispose();
+ // No provider -> Invalid
+ assertTrue("Test component validity - 3", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertEquals("Test foo non-availability inside the composite - 2", refs.length, 0);
+ }
+
+ public void testSimple2() {
+ // No provider -> Invalid
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+
+ ComponentInstance foo1 = null;
+ Properties p = new Properties();
+ p.put("name", "foo");
+ try {
+ foo1 = fooProvider.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo component " + e.getMessage());
+ }
+
+ ComponentInstance foo2 = null;
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo2 component " + e.getMessage());
+ }
+
+ // The foo service is available => import1 must be valid
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import2);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2 ("+refs.length+")", refs.length, 2);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ FooService fs2 = (FooService) sc.getService(refs[1]);
+ assertTrue("Test foo invocation", fs2.foo());
+ sc.ungetService(refs[0]);
+ sc.ungetService(refs[1]);
+
+ // Stop the first provider
+ foo1.stop();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 2", refs);
+ assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // stop the second foo provider
+ foo2.dispose();
+
+ // No provider -> Invalid
+ assertTrue("Test component validity - 2", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertEquals("Test foo non-availability inside the composite - 1", refs.length, 0);
+
+ foo1.start();
+ assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo1.dispose();
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 3", import2.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import2);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertEquals("Test foo non-availability inside the composite - 2", refs.length, 0);
+ }
+
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/SimpleImport.java b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/SimpleImport.java
new file mode 100644
index 0000000..31f2b5a
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/java/org/apache/felix/ipojo/test/composite/importer/SimpleImport.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.composite.importer;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.composite.service.FooService;
+import org.apache.felix.ipojo.test.composite.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class SimpleImport extends OSGiTestCase {
+
+ ComponentInstance import1;
+ Factory fooProvider;
+
+ public void setUp() {
+ fooProvider = Utils.getFactoryByName(context, "COMPO-FooProviderType-1");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p = new Properties();
+ p.put("name", "importer");
+ Factory compFact = Utils.getFactoryByName(context, "composite.requires.1");
+ try {
+ import1 = compFact.createComponentInstance(p);
+ } catch(Exception e) {
+ e.printStackTrace();
+ fail("Cannot instantiate the component : " + e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ import1.dispose();
+ import1 = null;
+ }
+
+ public void testSimple() {
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 0 ("+import1.getState()+")", import1.getState() == ComponentInstance.INVALID);
+
+ ComponentInstance foo = null;
+ Properties p = new Properties();
+ p.put("name", "foo");
+ try {
+ foo = fooProvider.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo component " + e.getMessage());
+ }
+
+ ComponentInstance foo2 = null;
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo2 component " + e.getMessage());
+ }
+
+ // The foo service is available => import1 must be valid
+ assertTrue("Test component validity - 1", import1.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import1);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the second provider
+ foo2.dispose();
+ assertTrue("Test component validity - 2", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 2", refs);
+ assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // stop the foo provider
+ foo.stop();
+
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+
+ foo.start();
+ assertTrue("Test component validity - 3", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo.dispose();
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 3", import1.getState() == ComponentInstance.INVALID);
+ }
+
+ public void testSimple2() {
+ // No provider -> Invalid
+ assertTrue("Test component invalidity", import1.getState() == ComponentInstance.INVALID);
+
+ ComponentInstance foo1 = null;
+ Properties p = new Properties();
+ p.put("name", "foo");
+ try {
+ foo1 = fooProvider.createComponentInstance(p);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo component " + e.getMessage());
+ }
+
+ ComponentInstance foo2 = null;
+ Properties p2 = new Properties();
+ p2.put("name", "foo2");
+ try {
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch(Exception e) {
+ fail("Fail to instantiate the foo2 component " + e.getMessage());
+ }
+
+ // The foo service is available => import1 must be valid
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ ServiceContext sc = Utils.getServiceContext(import1);
+ ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 1", refs);
+ assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
+ FooService fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // Stop the first provider
+ foo1.stop();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 2", refs);
+ assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ // stop the second foo provider
+ foo2.dispose();
+
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
+
+ foo1.start();
+ assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
+ sc = Utils.getServiceContext(import1);
+ refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
+ assertNotNull("Test foo availability inside the composite - 3", refs);
+ assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
+ fs = (FooService) sc.getService(refs[0]);
+ assertTrue("Test foo invocation", fs.foo());
+ sc.ungetService(refs[0]);
+
+ foo1.dispose();
+ // No provider -> Invalid
+ assertTrue("Test component invalidity - 3", import1.getState() == ComponentInstance.INVALID);
+ }
+
+}
diff --git a/ipojo/tests/tests.composite.service.import-export/src/main/resources/metadata.xml b/ipojo/tests/tests.composite.service.import-export/src/main/resources/metadata.xml
new file mode 100644
index 0000000..cb1e07f
--- /dev/null
+++ b/ipojo/tests/tests.composite.service.import-export/src/main/resources/metadata.xml
@@ -0,0 +1,82 @@
+<ipojo
+ xmlns:cs="org.apache.felix.ipojo.test.composite.handler.CheckServiceHandler">
+ <composite name="composite.requires.1" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.test.composite.service.FooService"
+ scope="composite" />
+ </composite>
+
+ <composite name="composite.requires.2" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.test.composite.service.FooService"
+ aggregate="true" scope="composite" />
+ </composite>
+
+ <composite name="composite.requires.3" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.test.composite.service.FooService"
+ optional="true" scope="composite" />
+ </composite>
+
+ <composite name="composite.requires.4" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.test.composite.service.FooService"
+ optional="true" aggregate="true" scope="composite" />
+ </composite>
+
+ <composite name="composite.requires.5" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.test.composite.service.FooService"
+ filter="(&(int=2)(long=40))" scope="composite" />
+ </composite>
+
+ <composite name="composite.export.1" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.test.composite.service.BazService"
+ aggregate="true" optional="true" filter="(!(instance.name=export))"
+ scope="composite" />
+ <provides action="export"
+ specification="org.apache.felix.ipojo.test.composite.service.BazService" />
+ </composite>
+
+ <composite name="composite.export.2" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.test.composite.service.BazService"
+ scope="composite" aggregate="true" optional="true"
+ filter="(!(instance.name=export))" />
+ <provides action="export"
+ specification="org.apache.felix.ipojo.test.composite.service.BazService"
+ optional="true" />
+ </composite>
+
+ <composite name="composite.export.3" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.test.composite.service.BazService"
+ scope="composite" aggregate="true" optional="true"
+ filter="(!(instance.name=export))" />
+ <provides action="export"
+ specification="org.apache.felix.ipojo.test.composite.service.BazService"
+ aggregate="true" />
+ </composite>
+
+ <composite name="composite.export.4" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.test.composite.service.BazService"
+ aggregate="true" optional="true" filter="(!(instance.name=export))"
+ scope="composite" />
+ <provides action="export"
+ specification="org.apache.felix.ipojo.test.composite.service.BazService"
+ aggregate="true" optional="true" />
+ </composite>
+
+ <composite name="composite.export.5" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.test.composite.service.BazService"
+ aggregate="true" optional="true" filter="(!(instance.name=export))"
+ scope="composite" />
+ <provides action="export"
+ specification="org.apache.felix.ipojo.test.composite.service.BazService"
+ filter="(instance.name=foo1)" />
+ </composite>
+
+</ipojo>