You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2013/02/21 21:52:27 UTC
svn commit: r1448797 [4/4] - in
/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test:
./ src/ src/main/ src/main/java/ src/main/java/org/
src/main/java/org/apache/ src/main/java/org/apache/felix/
src/main/java/org/apache/felix/ip...
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestServiceController.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestServiceController.java?rev=1448797&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestServiceController.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestServiceController.java Thu Feb 21 20:52:25 2013
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription;
+import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TestServiceController extends Common {
+
+ @Test
+ public void testComponentWithAController() {
+ ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-1-default");
+ // Controller set to true.
+ osgiHelper.waitForService(FooService.class.getName(), null, 5000);
+ osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
+
+ CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
+ assertNotNull(check);
+
+ assertFalse(check.check());
+
+ // FooService should not be there anymore
+ assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
+
+ assertTrue(check.check());
+
+ assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
+
+ ci.dispose();
+ }
+
+ @Test
+ public void testComponentWithAControllerSetToFalse() {
+ ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-1-false");
+ // Controller set to false.
+ osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
+ assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
+
+ CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
+ assertNotNull(check);
+
+ assertTrue(check.check());
+ assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
+
+ assertFalse(check.check());
+ // FooService should not be there anymore
+ assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
+
+ ci.dispose();
+ }
+
+ @Test
+ public void testComponentWithTwoControllersSetToTrue() {
+ ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-truetrue");
+
+ osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
+ osgiHelper.waitForService(FooService.class.getName(), null, 5000);
+
+ CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
+ assertNotNull(check);
+
+ check.check();
+
+ assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
+ assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
+
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
+ fs.foo();
+
+ assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
+ assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
+
+ ci.dispose();
+ }
+
+ @Test
+ public void testComponentWithTwoControllersSetToTrueAndFalse() {
+ ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-truefalse");
+
+ osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
+
+ assertFalse(osgiHelper.isServiceAvailable(FooService.class.getName()));
+
+ CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
+ assertNotNull(check);
+
+ check.getProps();
+
+ assertFalse(osgiHelper.isServiceAvailable(CheckService.class.getName()));
+ assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
+
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
+ fs.fooProps();
+
+ assertTrue(osgiHelper.isServiceAvailable(CheckService.class.getName()));
+ assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
+
+ ci.dispose();
+ }
+
+ @Test
+ public void testComponentWithTwoControllersUsingBothSpecificationsTrueFalse() {
+ ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec1");
+
+ osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
+
+ assertFalse(osgiHelper.isServiceAvailable(FooService.class.getName()));
+
+ CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
+ assertNotNull(check);
+
+ check.getProps();
+
+ assertFalse(osgiHelper.isServiceAvailable(CheckService.class.getName()));
+ assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
+
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
+ fs.fooProps();
+
+ assertTrue(osgiHelper.isServiceAvailable(CheckService.class.getName()));
+ assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
+
+ ci.dispose();
+ }
+
+ @Test
+ public void testComponentWithTwoControllersUsingBothSpecificationsTrueTrue() {
+ ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec2");
+
+ osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
+ osgiHelper.waitForService(FooService.class.getName(), null, 5000);
+
+ CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
+ assertNotNull(check);
+
+ check.check();
+ // CheckService not available
+ assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
+ assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
+
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
+ fs.foo();
+
+ assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
+ assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
+
+ ci.dispose();
+ }
+
+ @Test
+ public void testComponentWithTwoControllersUsingSpecificationAndAllTrueTrue() {
+ ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec3");
+
+ osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
+ osgiHelper.waitForService(FooService.class.getName(), null, 5000);
+
+ CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
+ assertNotNull(check);
+
+ check.check();
+ // CheckService not available
+ assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
+ assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
+
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
+ fs.foo();
+
+ assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
+ assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
+
+ ci.dispose();
+ }
+
+ @Test
+ public void testComponentWithTwoControllersUsingSpecificationAndAllTrueFalse() {
+ ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec4");
+
+ osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
+
+ assertFalse(osgiHelper.isServiceAvailable(FooService.class.getName()));
+
+ CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
+ assertNotNull(check);
+
+ check.getProps();
+
+ assertFalse(osgiHelper.isServiceAvailable(CheckService.class.getName()));
+ assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
+
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
+ fs.fooProps();
+
+ assertTrue(osgiHelper.isServiceAvailable(CheckService.class.getName()));
+ assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
+
+ ci.dispose();
+ }
+
+ @Test
+ public void testArchitecture() {
+ ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-1-default");
+ // Controller set to true.
+ osgiHelper.waitForService(FooService.class.getName(), null, 5000);
+ osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
+
+ ProvidedServiceHandlerDescription pshd = null;
+ pshd = (ProvidedServiceHandlerDescription) ci.getInstanceDescription()
+ .getHandlerDescription("org.apache.felix.ipojo:provides");
+
+ ProvidedServiceDescription ps = getPS(FooService.class.getName(), pshd.getProvidedServices());
+ assertEquals("true", ps.getController());
+
+ CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
+ assertNotNull(check);
+
+ assertFalse(check.check());
+
+ ps = getPS(FooService.class.getName(), pshd.getProvidedServices());
+ assertEquals("false", ps.getController());
+
+ assertTrue(check.check());
+
+ ps = getPS(FooService.class.getName(), pshd.getProvidedServices());
+ assertEquals("true", ps.getController());
+
+ }
+
+ private ProvidedServiceDescription getPS(String itf, ProvidedServiceDescription[] svc) {
+ for (int i = 0; i < svc.length; i++) {
+ if (svc[i].getServiceSpecifications()[0].equals(itf)) {
+ return svc[i];
+ }
+ }
+
+ fail("Service : " + itf + " not found");
+ return null;
+ }
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSimplePS.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSimplePS.java?rev=1448797&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSimplePS.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSimplePS.java Thu Feb 21 20:52:25 2013
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.runtime.core.components.SimpleClass;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.*;
+
+public class TestSimplePS extends Common {
+
+ @Test
+ public void testPS() {
+ String factName = "PS-FooProviderType-1";
+ String compName = "FooProvider-1";
+ ServiceReference ref;
+
+ // Check that no Foo Service are available
+ ref = osgiHelper.getServiceReference(FooService.class.getName());
+
+ assertNull("FS already available", ref);
+
+ // Get the factory to create a component instance
+ Factory fact = ipojoHelper.getFactory(factName);
+ assertNotNull("Cannot find the factory FooProvider-1", fact);
+
+ ipojoHelper.createComponentInstance(factName, compName);
+
+ // Get a FooService provider
+ ref = osgiHelper.getServiceReference(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
+
+ assertNotNull("FS not available", ref);
+
+ // Test foo invocation
+ FooService fs = (FooService) osgiHelper.getServiceObject(ref);
+ assertTrue("FooService invocation failed", fs.foo());
+
+ ipojoHelper.dispose();
+
+
+ // Check that there is no more FooService
+ ref = osgiHelper.getServiceReference(FooService.class.getName(), null);
+
+
+ assertNull("FS available, but component instance stopped", ref);
+
+ }
+
+ @Test
+ public void testWhenNoInterface() {
+ String factoryName = "org.apache.felix.ipojo.runtime.core.components.SimpleClass";
+ ComponentInstance ci = ipojoHelper.createComponentInstance(factoryName);
+ osgiHelper.waitForService(SimpleClass.class.getName(), null, 5000);
+ SimpleClass simple = (SimpleClass) osgiHelper.getServiceObject(SimpleClass.class.getName(), null);
+ assertEquals("Hello", simple.hello());
+ ci.dispose();
+ }
+
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticProps.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticProps.java?rev=1448797&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticProps.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticProps.java Thu Feb 21 20:52:25 2013
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+public class TestStaticProps extends Common {
+
+ @Before
+ public void setUp() {
+ String type = "PS-FooProviderType-2";
+
+ ipojoHelper.createComponentInstance(type, "FooProvider-1");
+
+ Properties p2 = new Properties();
+ p2.put("instance.name", "FooProvider-2");
+ p2.put("int", new Integer(4));
+ p2.put("long", new Long(42));
+ p2.put("string", new String("bar"));
+ p2.put("strAProp", new String[]{"bar", "foo"});
+ p2.put("intAProp", new int[]{1, 2, 3});
+ ipojoHelper.createComponentInstance(type, p2);
+
+ }
+
+
+ @Test
+ public void testProperties1() {
+ ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", longProp, new Long(40));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[]{"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if (!strAProp[i].equals(v[i])) {
+ fail("Check the strAProp Equality");
+ }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[]{1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if (intAProp[i] != v2[i]) {
+ fail("Check the intAProp Equality");
+ }
+ }
+
+ }
+
+ @Test
+ public void testProperties2() {
+ ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-2");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(4));
+ assertEquals("Check longProp equality", longProp, new Long(42));
+ assertEquals("Check strProp equality", strProp, new String("bar"));
+
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[]{"bar", "foo"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if (!strAProp[i].equals(v[i])) {
+ fail("Check the strAProp Equality");
+ }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[]{1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if (intAProp[i] != v2[i]) {
+ fail("Check the intAProp Equality");
+ }
+ }
+ }
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticPropsReconfiguration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticPropsReconfiguration.java?rev=1448797&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticPropsReconfiguration.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticPropsReconfiguration.java Thu Feb 21 20:52:25 2013
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+public class TestStaticPropsReconfiguration extends Common {
+
+ @Before
+ public void setUp() {
+ String type = "PS-FooProviderType-2";
+ ipojoHelper.createComponentInstance(type, "FooProvider-1");
+
+ Properties p2 = new Properties();
+ p2.put("instance.name", "FooProvider-2");
+ p2.put("int", new Integer(4));
+ p2.put("long", new Long(42));
+ p2.put("string", new String("bar"));
+ p2.put("strAProp", new String[]{"bar", "foo"});
+ p2.put("intAProp", new int[]{1, 2, 3});
+ ipojoHelper.createComponentInstance(type, p2);
+ }
+
+ @Test
+ public void testReconfFactory1() {
+ ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", longProp, new Long(40));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[]{"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if (!strAProp[i].equals(v[i])) {
+ fail("Check the strAProp Equality");
+ }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[]{1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if (intAProp[i] != v2[i]) {
+ fail("Check the intAProp Equality");
+ }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "PS-FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("instance.name", "FooProvider-1");
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[]{"foo", "baz"});
+ reconf.put("intAProp", new int[]{3, 2, 1});
+ Factory fact = (Factory) osgiHelper.getServiceObject(fact_ref);
+ try {
+ fact.reconfigure(reconf);
+ } catch (Exception e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[]{"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if (!strAProp[i].equals(v[i])) {
+ fail("Check the strAProp Equality");
+ }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[]{3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if (intAProp[i] != v2[i]) {
+ fail("Check the intAProp Equality");
+ }
+ }
+
+ fact = null;
+
+ }
+
+ @Test
+ public void testReconfFactory2() {
+ ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-2");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(4));
+ assertEquals("Check longProp equality", longProp, new Long(42));
+ assertEquals("Check strProp equality", strProp, new String("bar"));
+
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[]{"bar", "foo"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if (!strAProp[i].equals(v[i])) {
+ fail("Check the strAProp Equality");
+ }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[]{1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if (intAProp[i] != v2[i]) {
+ fail("Check the intAProp Equality");
+ }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "PS-FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("instance.name", "FooProvider-2");
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[]{"foo", "baz"});
+ reconf.put("intAProp", new int[]{3, 2, 1});
+ Factory fact = (Factory) osgiHelper.getServiceObject(fact_ref);
+ try {
+ fact.reconfigure(reconf);
+ } catch (Exception e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[]{"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if (!strAProp[i].equals(v[i])) {
+ fail("Check the strAProp Equality");
+ }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[]{3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if (intAProp[i] != v2[i]) {
+ fail("Check the intAProp Equality");
+ }
+ }
+ fact = null;
+ }
+
+ @Test
+ public void testMSFFactory1() {
+ ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", longProp, new Long(40));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[]{"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if (!strAProp[i].equals(v[i])) {
+ fail("Check the strAProp Equality");
+ }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[]{1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if (intAProp[i] != v2[i]) {
+ fail("Check the intAProp Equality");
+ }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = ipojoHelper.getServiceReferenceByName(ManagedServiceFactory.class.getName(), "PS-FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[]{"foo", "baz"});
+ reconf.put("intAProp", new int[]{3, 2, 1});
+ ManagedServiceFactory fact = (ManagedServiceFactory) osgiHelper.getServiceObject(fact_ref);
+ try {
+ fact.updated("FooProvider-1", reconf);
+ } catch (ConfigurationException e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[]{"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if (!strAProp[i].equals(v[i])) {
+ fail("Check the strAProp Equality");
+ }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[]{3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if (intAProp[i] != v2[i]) {
+ fail("Check the intAProp Equality");
+ }
+ }
+
+ fact = null;
+
+ }
+
+ @Test
+ public void testReconfMSF2() {
+ ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-2");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(4));
+ assertEquals("Check longProp equality", longProp, new Long(42));
+ assertEquals("Check strProp equality", strProp, new String("bar"));
+
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[]{"bar", "foo"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if (!strAProp[i].equals(v[i])) {
+ fail("Check the strAProp Equality");
+ }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[]{1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if (intAProp[i] != v2[i]) {
+ fail("Check the intAProp Equality");
+ }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = ipojoHelper.getServiceReferenceByName(ManagedServiceFactory.class.getName(), "PS-FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[]{"foo", "baz"});
+ reconf.put("intAProp", new int[]{3, 2, 1});
+ ManagedServiceFactory fact = (ManagedServiceFactory) osgiHelper.getServiceObject(fact_ref);
+ try {
+ fact.updated("FooProvider-2", reconf);
+ } catch (ConfigurationException e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[]{"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if (!strAProp[i].equals(v[i])) {
+ fail("Check the strAProp Equality");
+ }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[]{3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if (intAProp[i] != v2[i]) {
+ fail("Check the intAProp Equality");
+ }
+ }
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/inheritence/InheritanceTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/inheritence/InheritanceTest.java?rev=1448797&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/inheritence/InheritanceTest.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/inheritence/InheritanceTest.java Thu Feb 21 20:52:25 2013
@@ -0,0 +1,134 @@
+package org.apache.felix.ipojo.runtime.core.inheritence;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.handlers.dependency.DependencyDescription;
+import org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.components.inheritance.a.IA;
+import org.apache.felix.ipojo.runtime.core.components.inheritance.b.IB;
+import org.apache.felix.ipojo.runtime.core.components.inheritance.c.C;
+import org.apache.felix.ipojo.runtime.core.components.inheritance.d.D;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
+
+public class InheritanceTest extends Common {
+
+ @Configuration
+ public Option[] config() throws IOException {
+ deployTestedBundle = false;
+ Option[] options = super.config();
+
+ return OptionUtils.combine(
+ options,
+ streamBundle(
+ // Bundle A
+ TinyBundles.bundle()
+ .add(IA.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "A")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.runtime.core.components.inheritance.a")
+ .build(withBnd())
+ ),
+ streamBundle(
+ // Bundle B
+ TinyBundles.bundle()
+ .add(IB.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "B")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.runtime.core.components.inheritance.a")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.runtime.core.components" +
+ ".inheritance.b")
+ .build(withBnd())
+ ),
+ streamBundle(
+ // Bundle C
+ TinyBundles.bundle()
+ .add(C.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "C")
+ .set(Constants.IMPORT_PACKAGE,
+ "org.apache.felix.ipojo.runtime.core.components.inheritance.a, " +
+ "org.apache.felix.ipojo.runtime.core.components.inheritance.b")
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources/inheritance/provider" +
+ ".xml")))
+ ),
+ streamBundle(
+ // Bundle D
+ TinyBundles.bundle()
+ .add(D.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "D")
+ .set(Constants.IMPORT_PACKAGE,
+ "org.apache.felix.ipojo.runtime.core.components.inheritance.a, " +
+ "org.apache.felix.ipojo.runtime.core.components.inheritance.b")
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources/inheritance/cons" +
+ ".xml")))
+ )
+
+
+ );
+ }
+
+ @Test
+ public void testDeploy() {
+ Bundle[] bundles = bc.getBundles();
+ for (int i = 0; i < bundles.length; i++) {
+ Assert.assertEquals(bundles[i].getSymbolicName() + " is not active", Bundle.ACTIVE, bundles[i].getState());
+ }
+
+ osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=c)", 2000);
+ osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=d)", 2000);
+
+ Object[] arch = osgiHelper.getServiceObjects(Architecture.class.getName(), null);
+ for (Object o : arch) {
+ Architecture a = (Architecture) o;
+ if (a.getInstanceDescription().getState() != ComponentInstance.VALID) {
+ Assert.fail("Instance " + a.getInstanceDescription().getName() + " not valid : " + a.getInstanceDescription().getDescription());
+ }
+ }
+ }
+
+ @Test
+ public void testArchitecture() {
+ osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=d)", 2000);
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "d");
+ Assert.assertNotNull(ref);
+
+ Architecture arch = (Architecture) osgiHelper.getServiceObject(ref);
+
+ System.out.println(arch.getInstanceDescription().getDescription());
+
+ Assert.assertEquals(ComponentInstance.VALID, arch.getInstanceDescription().getState());
+ DependencyDescription dd = getDependency(arch, "org.apache.felix.ipojo.runtime.core.components.inheritance.b.IB");
+
+ Assert.assertTrue(!dd.getServiceReferences().isEmpty());
+
+ ServiceReference dref = (ServiceReference) dd.getServiceReferences().get(0);
+ Assert.assertEquals(dref.getBundle().getSymbolicName(), "C");
+
+ }
+
+ private DependencyDescription getDependency(Architecture arch, String id) {
+ DependencyHandlerDescription hd = (DependencyHandlerDescription) arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
+ Assert.assertNotNull(hd);
+ for (DependencyDescription dd : hd.getDependencies()) {
+ if (dd.getId().equals(id)) {
+ return dd;
+ }
+ }
+ Assert.fail("Dependency " + id + " not found");
+ return null;
+ }
+
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/CustomStrategy2Test.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/CustomStrategy2Test.java?rev=1448797&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/CustomStrategy2Test.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/CustomStrategy2Test.java Thu Feb 21 20:52:25 2013
@@ -0,0 +1,209 @@
+package org.apache.felix.ipojo.runtime.core.strategies;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.PrimitiveInstanceDescription;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.components.strategies.FooBarProviderType1;
+import org.apache.felix.ipojo.runtime.core.components.strategies.FooProviderType1;
+import org.apache.felix.ipojo.runtime.core.services.BarService;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+
+public class CustomStrategy2Test extends Common {
+
+
+ private ComponentInstance cons1, cons2, prov;
+ private ComponentInstance cons3, prov2;
+
+ @Before
+ public void setUp() {
+ cons1 = ipojoHelper.createComponentInstance("PSS-Cons");
+ assertEquals("cons1 invalid", ComponentInstance.INVALID, cons1.getState());
+ cons2 = ipojoHelper.createComponentInstance("PSS-Cons");
+ assertEquals("cons2 invalid", ComponentInstance.INVALID, cons2.getState());
+ prov = ipojoHelper.createComponentInstance("PSS-FooProviderType-Custom2");
+ prov2 = ipojoHelper.createComponentInstance("PSS-FooBarProviderType-Custom2");
+ cons3 = ipojoHelper.createComponentInstance("PSS-ConsBar");
+ prov2.stop();
+ prov.stop();
+ }
+
+ @After
+ public void tearDown() {
+ reset();
+ }
+
+
+ private void reset() {
+ FooProviderType1.resetIds();
+ FooBarProviderType1.resetIds();
+ }
+
+ private void checkCreatedObjects(ComponentInstance ci, int expected) {
+ assertEquals("Number of created objects", expected, ((PrimitiveInstanceDescription) ci.getInstanceDescription()).getCreatedObjects().length);
+ }
+
+ @Test
+ public void testOneService() {
+ prov.start();
+ cons2.stop();
+ cons1.stop();
+ assertEquals("Prov valid", ComponentInstance.VALID, prov.getState());
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov.getInstanceName());
+ assertNotNull("Service available", ref);
+ checkCreatedObjects(prov, 0);
+
+ // Step 1 : create start one consumer
+ cons1.start();
+ ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+
+ CheckService cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ Properties props = cs_cons1.getProps();
+ Long id = (Long) props.get("id");
+ FooService fscons1 = (FooService) props.get("object");
+ assertEquals("id 1", 1, id.intValue());
+ checkCreatedObjects(prov, 1);
+
+
+ // Step 2 : create a second consumer
+ cons2.start();
+ ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+
+ CheckService cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ Properties props2 = cs_cons2.getProps();
+ Long id2 = (Long) props2.get("id");
+ FooService fscons2 = (FooService) props2.get("object");
+ assertEquals("id 2", 2, id2.intValue());
+ checkCreatedObjects(prov, 2);
+
+ assertNotSame("Two objects", fscons1, fscons2);
+
+ // Step 3 : stop the second provider
+ System.out.println("cons2 stopping");
+ cons2.stop();
+ System.out.println("cons2 stopped");
+ checkCreatedObjects(prov, 1);
+
+ // Step 4 : stop the first consumer
+ cons1.stop();
+ checkCreatedObjects(prov, 0);
+ }
+
+ @Test
+ public void testObjectCreation() {
+ prov.start();
+
+ // The two consumers are started and use their own objects.
+ ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+ CheckService cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ Properties props = cs_cons1.getProps();
+ FooService fscons1 = (FooService) props.get("object");
+
+ ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+ CheckService cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ Properties props2 = cs_cons2.getProps();
+ FooService fscons2 = (FooService) props2.get("object");
+
+ checkCreatedObjects(prov, 2);
+ assertNotSame("Two objects", fscons1, fscons2);
+
+ // Stop the provider
+ prov.stop();
+ // Cons1 and 2 are invalid.
+ assertEquals("Cons1 invalidity", ComponentInstance.INVALID, cons1.getState());
+ assertEquals("Cons2 invalidity", ComponentInstance.INVALID, cons2.getState());
+
+ // No object created in prov
+ checkCreatedObjects(prov, 0);
+
+ // Restart the provider
+ prov.start();
+
+ // Consumers are valid.
+ assertEquals("Cons1 validity", ComponentInstance.VALID, cons1.getState());
+ assertEquals("Cons2 validity", ComponentInstance.VALID, cons2.getState());
+
+ // Check objects
+ refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+ cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ props = cs_cons1.getProps();
+ Object fscons3 = (FooService) props.get("object");
+
+ refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+ cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ props2 = cs_cons2.getProps();
+ Object fscons4 = (FooService) props2.get("object");
+
+ checkCreatedObjects(prov, 2);
+ assertNotSame("Two objects", fscons3, fscons4);
+ assertNotSame("Two new objects - 1", fscons3, fscons1);
+ assertNotSame("Two new objects - 2", fscons4, fscons2);
+
+ }
+
+ @Test
+ public void testTwoServices() {
+ cons3.stop();
+ prov2.start();
+ cons1.stop();
+ assertEquals("Prov valid", ComponentInstance.VALID, prov2.getState());
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov2.getInstanceName());
+ assertNotNull("Service available", ref);
+ ServiceReference refBar = ipojoHelper.getServiceReferenceByName(BarService.class.getName(), prov2.getInstanceName());
+ assertNotNull("Service available", refBar);
+ checkCreatedObjects(prov2, 0);
+
+ // Step 1 : create start one consumer
+ cons1.start();
+ ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+
+ CheckService cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ Properties props = cs_cons1.getProps();
+ Long id = (Long) props.get("id");
+ FooService fscons1 = (FooService) props.get("object");
+ assertEquals("id 1", 1, id.intValue());
+ checkCreatedObjects(prov2, 1);
+
+
+ // Step 2 : create a second consumer
+ cons3.start();
+ ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons3.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+
+ CheckService cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ Properties props2 = cs_cons2.getProps();
+ Long id2 = (Long) props2.get("id");
+ FooService fscons2 = (FooService) props2.get("object");
+ assertEquals("id 2", 2, id2.intValue());
+ checkCreatedObjects(prov2, 2);
+
+
+ assertNotSame("Two objects", fscons1, fscons2);
+
+ // Step 3 : stop the second provider
+ cons3.stop();
+ checkCreatedObjects(prov2, 1);
+
+ // Step 4 : stop the first consumer
+ cons1.stop();
+ checkCreatedObjects(prov, 0);
+ }
+
+}
\ No newline at end of file
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/CustomStrategyTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/CustomStrategyTest.java?rev=1448797&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/CustomStrategyTest.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/CustomStrategyTest.java Thu Feb 21 20:52:25 2013
@@ -0,0 +1,210 @@
+package org.apache.felix.ipojo.runtime.core.strategies;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.PrimitiveInstanceDescription;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.components.strategies.FooBarProviderType1;
+import org.apache.felix.ipojo.runtime.core.components.strategies.FooProviderType1;
+import org.apache.felix.ipojo.runtime.core.services.BarService;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+
+public class CustomStrategyTest extends Common {
+
+
+ private ComponentInstance cons1, cons2, prov;
+ private ComponentInstance cons3, prov2;
+
+ @Before
+ public void setUp() {
+ cons1 = ipojoHelper.createComponentInstance("PSS-Cons");
+ assertEquals("cons1 invalid", ComponentInstance.INVALID, cons1.getState());
+ cons2 = ipojoHelper.createComponentInstance("PSS-Cons");
+ assertEquals("cons2 invalid", ComponentInstance.INVALID, cons2.getState());
+ prov = ipojoHelper.createComponentInstance("PSS-FooProviderType-Custom");
+ prov2 = ipojoHelper.createComponentInstance("PSS-FooBarProviderType-Custom");
+ cons3 = ipojoHelper.createComponentInstance("PSS-ConsBar");
+ prov2.stop();
+ prov.stop();
+ }
+
+ @After
+ public void tearDown() {
+ reset();
+ }
+
+
+ private void reset() {
+ FooProviderType1.resetIds();
+ FooBarProviderType1.resetIds();
+ }
+
+ private void checkCreatedObjects(ComponentInstance ci, int expected) {
+ assertEquals("Number of created objects", expected, ((PrimitiveInstanceDescription) ci.getInstanceDescription()).getCreatedObjects().length);
+ }
+
+ @Test
+ public void testOneService() {
+ prov.start();
+ cons2.stop();
+ cons1.stop();
+ assertEquals("Prov valid", ComponentInstance.VALID, prov.getState());
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov.getInstanceName());
+ assertNotNull("Service available", ref);
+ checkCreatedObjects(prov, 0);
+
+ // Step 1 : create start one consumer
+ cons1.start();
+ ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+
+ CheckService cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ Properties props = cs_cons1.getProps();
+ Long id = (Long) props.get("id");
+ FooService fscons1 = (FooService) props.get("object");
+ assertEquals("id 1", 1, id.intValue());
+ checkCreatedObjects(prov, 1);
+
+
+ // Step 2 : create a second consumer
+ cons2.start();
+ ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+
+ CheckService cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ Properties props2 = cs_cons2.getProps();
+ Long id2 = (Long) props2.get("id");
+ FooService fscons2 = (FooService) props2.get("object");
+ assertEquals("id 2", 2, id2.intValue());
+ checkCreatedObjects(prov, 2);
+
+ assertNotSame("Two objects", fscons1, fscons2);
+
+ // Step 3 : stop the second provider
+ System.out.println("cons2 stopping");
+ cons2.stop();
+ System.out.println("cons2 stopped");
+ checkCreatedObjects(prov, 1);
+
+ // Step 4 : stop the first consumer
+ cons1.stop();
+ checkCreatedObjects(prov, 0);
+ }
+
+ @Test
+ public void testObjectCreation() {
+ prov.start();
+
+ // The two consumers are started and use their own objects.
+ ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+ CheckService cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ Properties props = cs_cons1.getProps();
+ FooService fscons1 = (FooService) props.get("object");
+
+ ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+ CheckService cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ Properties props2 = cs_cons2.getProps();
+ FooService fscons2 = (FooService) props2.get("object");
+
+ checkCreatedObjects(prov, 2);
+ assertNotSame("Two objects", fscons1, fscons2);
+
+ // Stop the provider
+ prov.stop();
+ // Cons1 and 2 are invalid.
+ assertEquals("Cons1 invalidity", ComponentInstance.INVALID, cons1.getState());
+ assertEquals("Cons2 invalidity", ComponentInstance.INVALID, cons2.getState());
+
+ // No object created in prov
+ checkCreatedObjects(prov, 0);
+
+ // Restart the provider
+ prov.start();
+
+ // Consumers are valid.
+ assertEquals("Cons1 validity", ComponentInstance.VALID, cons1.getState());
+ assertEquals("Cons2 validity", ComponentInstance.VALID, cons2.getState());
+
+ // Check objects
+ refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+ cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ props = cs_cons1.getProps();
+ Object fscons3 = (FooService) props.get("object");
+
+ refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+ cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ props2 = cs_cons2.getProps();
+ Object fscons4 = (FooService) props2.get("object");
+
+ checkCreatedObjects(prov, 2);
+ assertNotSame("Two objects", fscons3, fscons4);
+ assertNotSame("Two new objects - 1", fscons3, fscons1);
+ assertNotSame("Two new objects - 2", fscons4, fscons2);
+
+ }
+
+ @Test
+ public void testTwoServices() {
+ cons3.stop();
+ prov2.start();
+ cons1.stop();
+ assertEquals("Prov valid", ComponentInstance.VALID, prov2.getState());
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov2.getInstanceName());
+ assertNotNull("Service available", ref);
+ ServiceReference refBar;
+ refBar = ipojoHelper.getServiceReferenceByName(BarService.class.getName(), prov2.getInstanceName());
+ assertNotNull("Service available", refBar);
+ checkCreatedObjects(prov2, 0);
+
+ // Step 1 : create start one consumer
+ cons1.start();
+ ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+
+ CheckService cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ Properties props = cs_cons1.getProps();
+ Long id = (Long) props.get("id");
+ FooService fscons1 = (FooService) props.get("object");
+ assertEquals("id 1", 1, id.intValue());
+ checkCreatedObjects(prov2, 1);
+
+
+ // Step 2 : create a second consumer
+ cons3.start();
+ ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons3.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+
+ CheckService cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ Properties props2 = cs_cons2.getProps();
+ Long id2 = (Long) props2.get("id");
+ FooService fscons2 = (FooService) props2.get("object");
+ assertEquals("id 2", 2, id2.intValue());
+ checkCreatedObjects(prov2, 2);
+
+
+ assertNotSame("Two objects", fscons1, fscons2);
+
+ // Step 3 : stop the second provider
+ cons3.stop();
+ checkCreatedObjects(prov2, 1);
+
+ // Step 4 : stop the first consumer
+ cons1.stop();
+ checkCreatedObjects(prov, 0);
+ }
+
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/PerInstanceStrategyTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/PerInstanceStrategyTest.java?rev=1448797&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/PerInstanceStrategyTest.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/strategies/PerInstanceStrategyTest.java Thu Feb 21 20:52:25 2013
@@ -0,0 +1,208 @@
+package org.apache.felix.ipojo.runtime.core.strategies;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.PrimitiveInstanceDescription;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.components.strategies.FooBarProviderType1;
+import org.apache.felix.ipojo.runtime.core.components.strategies.FooProviderType1;
+import org.apache.felix.ipojo.runtime.core.services.BarService;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+
+public class PerInstanceStrategyTest extends Common {
+
+ private ComponentInstance cons1, cons2, prov;
+ private ComponentInstance cons3, prov2;
+
+ @Before
+ public void setUp() {
+ cons1 = ipojoHelper.createComponentInstance("PSS-Cons");
+ assertEquals("cons1 invalid", ComponentInstance.INVALID, cons1.getState());
+ cons2 = ipojoHelper.createComponentInstance("PSS-Cons");
+ assertEquals("cons2 invalid", ComponentInstance.INVALID, cons2.getState());
+ prov = ipojoHelper.createComponentInstance("PSS-FooProviderType-Instance");
+ prov2 = ipojoHelper.createComponentInstance("PSS-FooBarProviderType-Instance");
+ cons3 = ipojoHelper.createComponentInstance("PSS-ConsBar");
+ prov2.stop();
+ prov.stop();
+ }
+
+ @After
+ public void tearDown() {
+ reset();
+ }
+
+
+ private void reset() {
+ FooProviderType1.resetIds();
+ FooBarProviderType1.resetIds();
+ }
+
+ private void checkCreatedObjects(ComponentInstance ci, int expected) {
+ assertEquals("Number of created objects", expected, ((PrimitiveInstanceDescription) ci.getInstanceDescription()).getCreatedObjects().length);
+ }
+
+ @Test
+ public void testOneService() {
+ prov.start();
+ cons2.stop();
+ cons1.stop();
+ assertEquals("Prov valid", ComponentInstance.VALID, prov.getState());
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov.getInstanceName());
+ assertNotNull("Service available", ref);
+ checkCreatedObjects(prov, 0);
+
+ // Step 1 : create start one consumer
+ cons1.start();
+ ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+
+ CheckService cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ Properties props = cs_cons1.getProps();
+ Long id = (Long) props.get("id");
+ FooService fscons1 = (FooService) props.get("object");
+ assertEquals("id 1", 1, id.intValue());
+ checkCreatedObjects(prov, 1);
+
+
+ // Step 2 : create a second consumer
+ cons2.start();
+ ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+
+ CheckService cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ Properties props2 = cs_cons2.getProps();
+ Long id2 = (Long) props2.get("id");
+ FooService fscons2 = (FooService) props2.get("object");
+ assertEquals("id 2", 2, id2.intValue());
+ checkCreatedObjects(prov, 2);
+
+ assertNotSame("Two objects", fscons1, fscons2);
+
+ // Step 3 : stop the second provider
+ System.out.println("cons2 stopping");
+ cons2.stop();
+ System.out.println("cons2 stopped");
+ checkCreatedObjects(prov, 1);
+
+ // Step 4 : stop the first consumer
+ cons1.stop();
+ checkCreatedObjects(prov, 0);
+ }
+
+ @Test
+ public void testObjectCreation() {
+ prov.start();
+
+ // The two consumers are started and use their own objects.
+ ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+ CheckService cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ Properties props = cs_cons1.getProps();
+ FooService fscons1 = (FooService) props.get("object");
+
+ ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+ CheckService cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ Properties props2 = cs_cons2.getProps();
+ FooService fscons2 = (FooService) props2.get("object");
+
+ checkCreatedObjects(prov, 2);
+ assertNotSame("Two objects", fscons1, fscons2);
+
+ // Stop the provider
+ prov.stop();
+ // Cons1 and 2 are invalid.
+ assertEquals("Cons1 invalidity", ComponentInstance.INVALID, cons1.getState());
+ assertEquals("Cons2 invalidity", ComponentInstance.INVALID, cons2.getState());
+
+ // No object created in prov
+ checkCreatedObjects(prov, 0);
+
+ // Restart the provider
+ prov.start();
+
+ // Consumers are valid.
+ assertEquals("Cons1 validity", ComponentInstance.VALID, cons1.getState());
+ assertEquals("Cons2 validity", ComponentInstance.VALID, cons2.getState());
+
+ // Check objects
+ refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+ cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ props = cs_cons1.getProps();
+ Object fscons3 = (FooService) props.get("object");
+
+ refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+ cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ props2 = cs_cons2.getProps();
+ Object fscons4 = (FooService) props2.get("object");
+
+ checkCreatedObjects(prov, 2);
+ assertNotSame("Two objects", fscons3, fscons4);
+ assertNotSame("Two new objects - 1", fscons3, fscons1);
+ assertNotSame("Two new objects - 2", fscons4, fscons2);
+
+ }
+
+ @Test
+ public void testTwoServices() {
+ cons3.stop();
+ prov2.start();
+ cons1.stop();
+ assertEquals("Prov valid", ComponentInstance.VALID, prov2.getState());
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov2.getInstanceName());
+ assertNotNull("Service available", ref);
+ ServiceReference refBar = ipojoHelper.getServiceReferenceByName(BarService.class.getName(), prov2.getInstanceName());
+ assertNotNull("Service available", refBar);
+ checkCreatedObjects(prov2, 0);
+
+ // Step 1 : create start one consumer
+ cons1.start();
+ ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
+ assertNotNull("Cons1 Service available", refcons1);
+
+ CheckService cs_cons1 = (CheckService) osgiHelper.getServiceObject(refcons1);
+ Properties props = cs_cons1.getProps();
+ Long id = (Long) props.get("id");
+ FooService fscons1 = (FooService) props.get("object");
+ assertEquals("id 1", 1, id.intValue());
+ checkCreatedObjects(prov2, 1);
+
+
+ // Step 2 : create a second consumer
+ cons3.start();
+ ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons3.getInstanceName());
+ assertNotNull("Cons2 Service available", refcons2);
+
+ CheckService cs_cons2 = (CheckService) osgiHelper.getServiceObject(refcons2);
+ Properties props2 = cs_cons2.getProps();
+ Long id2 = (Long) props2.get("id");
+ FooService fscons2 = (FooService) props2.get("object");
+ assertEquals("id 2", 2, id2.intValue());
+ checkCreatedObjects(prov2, 2);
+
+
+ assertNotSame("Two objects", fscons1, fscons2);
+
+ // Step 3 : stop the second provider
+ cons3.stop();
+ checkCreatedObjects(prov2, 1);
+
+ // Step 4 : stop the first consumer
+ cons1.stop();
+ checkCreatedObjects(prov, 0);
+ }
+
+}