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 2008/01/28 00:21:37 UTC
svn commit: r615675 [20/21] - in /felix/sandbox/clement/ipojo: ./
annotations/ ant/ arch/ core/
core/src/main/java/org/apache/felix/ipojo/handlers/configuration/
core/src/main/java/org/apache/felix/ipojo/handlers/dependency/
core/src/main/java/org/apac...
Added: felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/DynamicPropsReconfiguration.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/DynamicPropsReconfiguration.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/DynamicPropsReconfiguration.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/DynamicPropsReconfiguration.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,559 @@
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class DynamicPropsReconfiguration extends OSGiTestCase {
+ ComponentInstance fooProvider3;
+
+ public void setUp() {
+ String type2 = "FooProviderType-Dyn2";
+ Properties p3 = new Properties();
+ p3.put("name", "FooProvider-3");
+ p3.put("int", new Integer(0));
+ p3.put("boolean", new Boolean(true));
+ p3.put("string", new String(""));
+ p3.put("strAProp", new String[0]);
+ p3.put("intAProp", new int[0]);
+ fooProvider3 = Utils.getComponentInstance(context, type2, p3);
+ }
+
+ public void tearDown() {
+ fooProvider3.dispose();
+ fooProvider3 = null;
+ }
+
+ public void testFactoryReconf() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Boolean boolProp = (Boolean) sr.getProperty("boolean");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(0));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String(""));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[0];
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[0];
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "FooProviderType-Dyn2");
+ Factory fact = (Factory) context.getService(fact_ref);
+ Properties p3 = new Properties();
+ p3.put("name", "FooProvider-3");
+ p3.put("int", new Integer(1));
+ p3.put("boolean", new Boolean(true));
+ p3.put("string", new String("foo"));
+ p3.put("strAProp", new String[] {"foo", "bar", "baz"});
+ p3.put("intAProp", new int[] { 1, 2, 3});
+ try {
+ fact.reconfigure(p3);
+ } catch(Exception e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Invoke
+ FooService fs = (FooService) context.getService(sr);
+ assertTrue("invoke fs", fs.foo());
+
+ // Re-check the property (change)
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNull("Check intAProp hidding (no value)", intAProp);
+
+ // Reconfiguration
+ fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "FooProviderType-Dyn2");
+ fact = (Factory) context.getService(fact_ref);
+ p3 = new Properties();
+ p3.put("name", "FooProvider-3");
+ p3.put("int", new Integer(1));
+ p3.put("boolean", new Boolean(true));
+ p3.put("string", new String("foo"));
+ p3.put("strAProp", new String[] {"foo", "bar", "baz"});
+ p3.put("intAProp", new int[] { 1, 2, 3});
+ try {
+ fact.reconfigure(p3);
+ } catch(Exception e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ fact = null;
+ context.ungetService(fact_ref);
+ fs = null;
+ context.ungetService(sr);
+ }
+
+ public void testFactoryReconfString() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Boolean boolProp = (Boolean) sr.getProperty("boolean");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(0));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String(""));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[0];
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[0];
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "FooProviderType-Dyn2");
+ Factory fact = (Factory) context.getService(fact_ref);
+ Properties p3 = new Properties();
+ p3.put("name", "FooProvider-3");
+ p3.put("int", "1");
+ p3.put("boolean", "true");
+ p3.put("string", "foo");
+ p3.put("strAProp", "{foo, bar, baz}");
+ p3.put("intAProp", "{1, 2, 3}");
+ try {
+ fact.reconfigure(p3);
+ } catch(Exception e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Invoke
+ FooService fs = (FooService) context.getService(sr);
+ assertTrue("invoke fs", fs.foo());
+
+ // Re-check the property (change)
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNull("Check intAProp hidding (no value)", intAProp);
+
+ // Reconfiguration
+ fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "FooProviderType-Dyn2");
+ fact = (Factory) context.getService(fact_ref);
+ p3 = new Properties();
+ p3.put("name", "FooProvider-3");
+ p3.put("int", "1");
+ p3.put("boolean", "true");
+ p3.put("string", "foo");
+ p3.put("strAProp", "{foo, bar, baz}");
+ p3.put("intAProp", "{ 1, 2, 3}");
+ try {
+ fact.reconfigure(p3);
+ } catch(Exception e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ fact = null;
+ context.ungetService(fact_ref);
+ fs = null;
+ context.ungetService(sr);
+ }
+
+ public void testMSFReconf() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Boolean boolProp = (Boolean) sr.getProperty("boolean");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(0));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String(""));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[0];
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[0];
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "FooProviderType-Dyn2");
+ ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ Properties p3 = new Properties();
+ p3.put("int", new Integer(1));
+ p3.put("boolean", new Boolean(true));
+ p3.put("string", new String("foo"));
+ p3.put("strAProp", new String[] {"foo", "bar", "baz"});
+ p3.put("intAProp", new int[] { 1, 2, 3});
+ try {
+ fact.updated("FooProvider-3", p3);
+ } catch (ConfigurationException e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Invoke
+ FooService fs = (FooService) context.getService(sr);
+ assertTrue("invoke fs", fs.foo());
+
+ // Re-check the property (change)
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNull("Check intAProp hidding (no value)", intAProp);
+
+ // Reconfiguration
+ fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "FooProviderType-Dyn2");
+ fact = (ManagedServiceFactory) context.getService(fact_ref);
+ p3 = new Properties();
+ p3.put("int", new Integer(1));
+ p3.put("boolean", new Boolean(true));
+ p3.put("string", new String("foo"));
+ p3.put("strAProp", new String[] {"foo", "bar", "baz"});
+ p3.put("intAProp", new int[] { 1, 2, 3});
+ try {
+ fact.updated("FooProvider-3", p3);
+ } catch (ConfigurationException e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ fact = null;
+ context.ungetService(fact_ref);
+ fs = null;
+ context.ungetService(sr);
+ }
+
+ public void testMSFReconfString() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Boolean boolProp = (Boolean) sr.getProperty("boolean");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(0));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String(""));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[0];
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[0];
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "FooProviderType-Dyn2");
+ ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ Properties p3 = new Properties();
+ p3.put("int", "1");
+ p3.put("boolean", "true");
+ p3.put("string", "foo");
+ p3.put("strAProp", "{foo, bar, baz}");
+ p3.put("intAProp", "{ 1, 2, 3}");
+ try {
+ fact.updated("FooProvider-3", p3);
+ } catch (ConfigurationException e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Invoke
+ FooService fs = (FooService) context.getService(sr);
+ assertTrue("invoke fs", fs.foo());
+
+ // Re-check the property (change)
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNull("Check intAProp hidding (no value)", intAProp);
+
+ // Reconfiguration
+ fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "FooProviderType-Dyn2");
+ fact = (ManagedServiceFactory) context.getService(fact_ref);
+ p3 = new Properties();
+ p3.put("int", "1");
+ p3.put("boolean", "true");
+ p3.put("string", "foo");
+ p3.put("strAProp", "{foo, bar, baz}");
+ p3.put("intAProp", "{ 1, 2, 3}");
+ try {
+ fact.updated("FooProvider-3", p3);
+ } catch (ConfigurationException e) {
+ fail("Unable to reconfigure the instance with : " + p3);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ intProp = (Integer) sr.getProperty("int");
+ boolProp = (Boolean) sr.getProperty("boolean");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(1));
+ assertEquals("Check longProp equality", boolProp, new Boolean(true));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ v = new String[] {"foo", "bar", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] { 1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ fact = null;
+ context.ungetService(fact_ref);
+ fs = null;
+ context.ungetService(sr);
+ }
+
+
+}
Added: felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/Exposition.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/Exposition.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/Exposition.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/Exposition.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,175 @@
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.BarService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class Exposition extends OSGiTestCase {
+
+ private ComponentInstance fooProviderSimple;
+ private ComponentInstance fooProviderItf;
+ private ComponentInstance fooBarProvider;
+ private ComponentInstance fooBarProvider2;
+ private ComponentInstance fooBarProvider3;
+
+ public void setUp(){
+ Properties p1 = new Properties();
+ p1.put("name", "fooProviderSimple");
+ fooProviderSimple = Utils.getComponentInstance(context, "FooProviderType-1", p1);
+
+ Properties p2 = new Properties();
+ p2.put("name", "fooProviderItf");
+ fooProviderItf = Utils.getComponentInstance(context, "FooProviderType-itf", p2);
+
+ Properties p3 = new Properties();
+ p3.put("name", "fooProviderItfs");
+ fooBarProvider = Utils.getComponentInstance(context, "FooBarProviderType-1", p3);
+
+ Properties p4 = new Properties();
+ p4.put("name", "fooProviderItfs2");
+ fooBarProvider2 = Utils.getComponentInstance(context, "FooBarProviderType-2", p4);
+
+ Properties p5 = new Properties();
+ p5.put("name", "fooProviderItfs3");
+ fooBarProvider3 = Utils.getComponentInstance(context, "FooBarProviderType-3", p5);
+
+ assertNotNull("Check the instance creation of fooProviderSimple", fooProviderSimple);
+ assertNotNull("Check the instance creation of fooProviderItf", fooProviderItf);
+ assertNotNull("Check the instance creation of fooProviderItfs", fooBarProvider);
+ assertNotNull("Check the instance creation of fooProviderItfs2", fooBarProvider2);
+ assertNotNull("Check the instance creation of fooProviderItfs3", fooBarProvider3);
+
+ }
+
+ public void tearDown() {
+ fooProviderSimple.dispose();
+ fooProviderItf.dispose();
+ fooBarProvider.dispose();
+ fooBarProvider2.dispose();
+ fooBarProvider3.dispose();
+ fooProviderSimple = null;
+ fooProviderItf = null;
+ fooBarProvider = null;
+ fooBarProvider2 = null;
+ fooBarProvider3 = null;
+ }
+
+ public void testSimpleExposition() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderSimple.getInstanceName());
+ assertNotNull("Check the availability of the FS from "+fooProviderSimple.getInstanceName(), ref);
+ FooService fs = (FooService) context.getService(ref);
+ assertTrue("Check fs invocation", fs.foo());
+ fs = null;
+ context.ungetService(ref);
+ fooProviderSimple.stop();
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderSimple.getInstanceName());
+ assertNull("Check the absence of the FS from "+fooProviderSimple.getInstanceName(), ref);
+
+ }
+
+ public void testItfExposition() {
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderItf.getInstanceName());
+ assertNotNull("Check the availability of the FS from "+fooProviderItf.getInstanceName(), ref);
+ FooService fs = (FooService) context.getService(ref);
+ assertTrue("Check fs invocation", fs.foo());
+ fs = null;
+ context.ungetService(ref);
+ fooProviderItf.stop();
+
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderItf.getInstanceName());
+ assertNull("Check the absence of the FS from "+fooProviderItf.getInstanceName(), ref);
+ }
+
+ public void testItfsExposition() {
+ ServiceReference refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider.getInstanceName());
+ assertNotNull("Check the availability of the FS from "+fooBarProvider.getInstanceName(), refFoo);
+ ServiceReference refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider.getInstanceName());
+ assertNotNull("Check the availability of the BS from "+fooBarProvider.getInstanceName(), refBar);
+
+ assertSame("Check service reference equality", refFoo, refBar);
+
+ FooService fs = (FooService) context.getService(refFoo);
+ assertTrue("Check fs invocation", fs.foo());
+ fs = null;
+ context.ungetService(refFoo);
+
+ BarService bs = (BarService) context.getService(refBar);
+ assertTrue("Check bs invocation", bs.bar());
+ bs = null;
+ context.ungetService(refBar);
+
+ fooBarProvider.stop();
+
+ refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider.getInstanceName());
+ refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider.getInstanceName());
+ assertNull("Check the absence of the FS from "+fooBarProvider.getInstanceName(), refFoo);
+ assertNull("Check the absence of the BS from "+fooBarProvider.getInstanceName(), refBar);
+ }
+
+ public void testItfsExposition2() {
+ ServiceReference refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider2.getInstanceName());
+ assertNotNull("Check the availability of the FS from "+fooBarProvider2.getInstanceName(), refFoo);
+ ServiceReference refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider2.getInstanceName());
+ assertNotNull("Check the availability of the BS from "+fooBarProvider2.getInstanceName(), refBar);
+
+ assertSame("Check service reference equality", refFoo, refBar);
+
+ FooService fs = (FooService) context.getService(refFoo);
+ assertTrue("Check fs invocation", fs.foo());
+ fs = null;
+ context.ungetService(refFoo);
+
+ BarService bs = (BarService) context.getService(refBar);
+ assertTrue("Check bs invocation", bs.bar());
+ bs = null;
+ context.ungetService(refBar);
+
+ fooBarProvider2.stop();
+
+ refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider2.getInstanceName());
+ refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider2.getInstanceName());
+ assertNull("Check the absence of the FS from "+fooBarProvider.getInstanceName(), refFoo);
+ assertNull("Check the absence of the BS from "+fooBarProvider.getInstanceName(), refBar);
+ }
+
+ public void testItfsExposition3() {
+ ServiceReference refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider3.getInstanceName());
+ assertNotNull("Check the availability of the FS from "+fooBarProvider3.getInstanceName(), refFoo);
+ ServiceReference refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider3.getInstanceName());
+ assertNotNull("Check the availability of the BS from "+fooBarProvider3.getInstanceName(), refBar);
+
+ assertNotSame("Check service reference inequality", refFoo, refBar);
+
+ FooService fs = (FooService) context.getService(refFoo);
+ assertTrue("Check fs invocation", fs.foo());
+ fs = null;
+ context.ungetService(refFoo);
+
+ BarService bs = (BarService) context.getService(refBar);
+ assertTrue("Check bs invocation", bs.bar());
+ bs = null;
+ context.ungetService(refBar);
+
+ // Check properties
+ String baz1 = (String) refFoo.getProperty("baz");
+ String baz2 = (String) refBar.getProperty("baz");
+
+ assertEquals("Check Baz Property 1", baz1, "foo");
+ assertEquals("Check Baz Property 2", baz2, "bar");
+
+ fooBarProvider3.stop();
+
+ refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider3.getInstanceName());
+ refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider3.getInstanceName());
+ assertNull("Check the absence of the FS from "+fooBarProvider.getInstanceName(), refFoo);
+ assertNull("Check the absence of the BS from "+fooBarProvider.getInstanceName(), refBar);
+ }
+
+
+
+}
Added: felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/FactoryProps.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/FactoryProps.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/FactoryProps.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/FactoryProps.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,69 @@
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.BarService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class FactoryProps extends OSGiTestCase {
+
+// public void testImplementationClass() {
+// ServiceReference ref1 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-1");
+// assertNotNull("The factory is available", ref1);
+// String clazz = (String) ref1.getProperty("component.class");
+// assertEquals("Check the implementation class", clazz, FooProviderType1.class.getName());
+// }
+
+ public void testSimpleExposition() {
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-1");
+ assertNotNull("The factory is available", ref1);
+ String[] spec = (String[]) ref1.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check array length", spec.length, 1);
+ assertEquals("Check spec", spec[0], FooService.class.getName());
+ }
+
+ public void testDoubleExposition() {
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooBarProviderType-1");
+ assertNotNull("The factory is available", ref1);
+ String[] spec = (String[]) ref1.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check array length", spec.length, 2);
+ assertContains("Check spec 1", spec, FooService.class.getName());
+ assertContains("Check spec 2", spec, BarService.class.getName());
+ }
+
+ public void testProps() {
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-Dyn2");
+ assertNotNull("The factory is available", ref1);
+ PropertyDescription[] pd = (PropertyDescription[]) ref1.getProperty("component.properties");
+ assertEquals("Check property list size", pd.length, 5);
+
+ //P0
+ assertEquals("0) Check name", "int", pd[0].getName());
+ assertEquals("0) Check type", "int", pd[0].getType());
+ assertEquals("0) Check value", "4", pd[0].getValue());
+
+ //P1
+ assertEquals("1) Check name", "boolean", pd[1].getName());
+ assertEquals("1) Check type", "boolean", pd[1].getType());
+ assertNull("1) Check value", pd[1].getValue());
+
+ //P2
+ assertEquals("2) Check name", "string", pd[2].getName());
+ assertEquals("2) Check type", String.class.getName(), pd[2].getType());
+ assertNull("2) Check value", pd[2].getValue());
+
+ //P3
+ assertEquals("3) Check name", "strAProp", pd[3].getName());
+ assertEquals("3) Check type", "java.lang.String[]", pd[3].getType());
+ assertNull("3) Check value", pd[3].getValue());
+
+ //P4
+ assertEquals("4) Check name", "intAProp", pd[4].getName());
+ assertEquals("4) Check type", "int[]", pd[4].getType());
+ }
+
+
+}
Added: felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/ProvidedServiceTestSuite.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/ProvidedServiceTestSuite.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/ProvidedServiceTestSuite.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/ProvidedServiceTestSuite.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,25 @@
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;
+import org.apache.felix.ipojo.test.scenarios.service.providing.inherited.InheritedTest;
+import org.osgi.framework.BundleContext;
+
+public class ProvidedServiceTestSuite extends TestSuite {
+
+ public static Test suite(BundleContext bc) {
+ OSGiTestSuite ots = new OSGiTestSuite("Provided Service Test Suite", bc);
+ ots.addTestSuite(Exposition.class);
+ ots.addTestSuite(SimplePS.class);
+ ots.addTestSuite(StaticProps.class);
+ ots.addTestSuite(DynamicProps.class);
+ ots.addTestSuite(FactoryProps.class);
+ ots.addTestSuite(StaticPropsReconfiguration.class);
+ ots.addTestSuite(DynamicPropsReconfiguration.class);
+ ots.addTestSuite(InheritedTest.class);
+ return ots;
+ }
+
+}
Added: felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/SimplePS.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/SimplePS.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/SimplePS.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/SimplePS.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,62 @@
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class SimplePS extends OSGiTestCase {
+
+ public void testPS() {
+ String factName = "FooProviderType-1";
+ String compName = "FooProvider-1";
+ ServiceReference[] refs = null;
+
+ // Check that no Foo Service are available
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), null);
+ } catch (InvalidSyntaxException e) { fail("Service query failed : " + e); }
+
+ assertNull("FS already available", refs);
+
+ // Get the factory to create a component instance
+ Factory fact = Utils.getFactoryByName(context, factName);
+ assertNotNull("Cannot find the factory FooProvider-1", fact);
+
+ Properties props = new Properties();
+ props.put("name", compName);
+ ComponentInstance ci = null;
+ try {
+ ci = fact.createComponentInstance(props);
+ } catch (Exception e1) { fail(e1.getMessage()); }
+
+ // Get a FooService provider
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
+ } catch (InvalidSyntaxException e) { fail("Service query failed (2) " + e); }
+
+ assertNotNull("FS not available", refs);
+
+ // Test foo invocation
+ FooService fs = (FooService) context.getService(refs[0]);
+ assertTrue("FooService invocation failed", fs.foo());
+
+ // Unget the service
+ context.ungetService(refs[0]);
+
+ ci.dispose();
+
+ // Check that there is no more FooService
+ try {
+ refs = context.getServiceReferences(FooService.class.getName(), null);
+ } catch (InvalidSyntaxException e) { fail("Service query failed (3) : " + e.getMessage()); }
+
+ assertNull("FS available, but component instance stopped", refs);
+ }
+
+}
Added: felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticProps.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticProps.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticProps.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticProps.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,94 @@
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class StaticProps extends OSGiTestCase {
+
+ ComponentInstance fooProvider1;
+ ComponentInstance fooProvider2;
+
+ public void setUp() {
+ String type = "FooProviderType-2";
+
+ Properties p1 = new Properties();
+ p1.put("name", "FooProvider-1");
+ fooProvider1 = Utils.getComponentInstance(context, type, p1);
+
+ Properties p2 = new Properties();
+ p2.put("name", "FooProvider-2");
+ p2.put("int", new Integer(4));
+ p2.put("long", new Long(42));
+ p2.put("string", new String("bar"));
+ p2.put("strAProp", new String[] {"bar", "foo"});
+ p2.put("intAProp", new int[] {1, 2, 3});
+ fooProvider2 = Utils.getComponentInstance(context, type, p2);
+
+ }
+
+ public void tearDown() {
+ fooProvider1.dispose();
+ fooProvider1 = null;
+ fooProvider2.dispose();
+ fooProvider2 = null;
+ }
+
+ public void testProperties1() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", longProp, new Long(40));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ }
+
+ public void testProperties2() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(4));
+ assertEquals("Check longProp equality", longProp, new Long(42));
+ assertEquals("Check strProp equality", strProp, new String("bar"));
+
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"bar", "foo"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+ }
+}
Added: felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticPropsReconfiguration.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticPropsReconfiguration.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticPropsReconfiguration.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/StaticPropsReconfiguration.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,319 @@
+package org.apache.felix.ipojo.test.scenarios.service.providing;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class StaticPropsReconfiguration extends OSGiTestCase {
+
+ ComponentInstance fooProvider1;
+ ComponentInstance fooProvider2;
+
+ public void setUp() {
+ String type = "FooProviderType-2";
+
+ Properties p1 = new Properties();
+ p1.put("name", "FooProvider-1");
+ fooProvider1 = Utils.getComponentInstance(context, type, p1);
+
+ Properties p2 = new Properties();
+ p2.put("name", "FooProvider-2");
+ p2.put("int", new Integer(4));
+ p2.put("long", new Long(42));
+ p2.put("string", new String("bar"));
+ p2.put("strAProp", new String[] {"bar", "foo"});
+ p2.put("intAProp", new int[] {1, 2, 3});
+ fooProvider2 = Utils.getComponentInstance(context, type, p2);
+
+ }
+
+ public void tearDown() {
+ fooProvider1.dispose();
+ fooProvider1 = null;
+ fooProvider2.dispose();
+ fooProvider2 = null;
+ }
+
+ public void testReconfFactory1() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", longProp, new Long(40));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("name", "FooProvider-1");
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[] {"foo", "baz"});
+ reconf.put("intAProp", new int[] {3, 2, 1});
+ Factory fact = (Factory) context.getService(fact_ref);
+ try {
+ fact.reconfigure(reconf);
+ } catch(Exception e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[] {"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ context.ungetService(fact_ref);
+ fact = null;
+
+ }
+
+ public void testReconfFactory2() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(4));
+ assertEquals("Check longProp equality", longProp, new Long(42));
+ assertEquals("Check strProp equality", strProp, new String("bar"));
+
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"bar", "foo"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName(), "FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("name", "FooProvider-2");
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[] {"foo", "baz"});
+ reconf.put("intAProp", new int[] {3, 2, 1});
+ Factory fact = (Factory) context.getService(fact_ref);
+ try {
+ fact.reconfigure(reconf);
+ } catch(Exception e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[] {"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ context.ungetService(fact_ref);
+ fact = null;
+ }
+
+ public void testMSFFactory1() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(2));
+ assertEquals("Check longProp equality", longProp, new Long(40));
+ assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"foo", "bar"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), "FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[] {"foo", "baz"});
+ reconf.put("intAProp", new int[] {3, 2, 1});
+ ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ try {
+ fact.updated("FooProvider-1", reconf);
+ } catch (ConfigurationException e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[] {"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ context.ungetService(fact_ref);
+ fact = null;
+
+ }
+
+ public void testReconfMSF2() {
+ ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ assertNotNull("Check the availability of the FS service", sr);
+
+ // Check service properties
+ Integer intProp = (Integer) sr.getProperty("int");
+ Long longProp = (Long) sr.getProperty("long");
+ String strProp = (String) sr.getProperty("string");
+ String[] strAProp = (String[]) sr.getProperty("strAProp");
+ int[] intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality", intProp, new Integer(4));
+ assertEquals("Check longProp equality", longProp, new Long(42));
+ assertEquals("Check strProp equality", strProp, new String("bar"));
+
+ assertNotNull("Check strAProp not nullity", strAProp);
+ String[] v = new String[] {"bar", "foo"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ int[] v2 = new int[] {1, 2, 3};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ // Reconfiguration
+ ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), "FooProviderType-2");
+ Dictionary reconf = new Properties();
+ reconf.put("int", new Integer(5));
+ reconf.put("long", new Long(43));
+ reconf.put("string", new String("toto"));
+ reconf.put("strAProp", new String[] {"foo", "baz"});
+ reconf.put("intAProp", new int[] {3, 2, 1});
+ ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ try {
+ fact.updated("FooProvider-2", reconf);
+ } catch (ConfigurationException e) {
+ fail("Configuration non acceptable : " + reconf);
+ }
+
+ // Check service properties after the reconfiguration
+ intProp = (Integer) sr.getProperty("int");
+ longProp = (Long) sr.getProperty("long");
+ strProp = (String) sr.getProperty("string");
+ strAProp = (String[]) sr.getProperty("strAProp");
+ intAProp = (int[]) sr.getProperty("intAProp");
+
+ assertEquals("Check intProp equality after reconfiguration", intProp, new Integer(5));
+ assertEquals("Check longProp equality after reconfiguration", longProp, new Long(43));
+ assertEquals("Check strProp equality after reconfiguration", strProp, new String("toto"));
+ assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
+ v = new String[] {"foo", "baz"};
+ for (int i = 0; i < strAProp.length; i++) {
+ if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+ }
+ assertNotNull("Check intAProp not nullity", intAProp);
+ v2 = new int[] {3, 2, 1};
+ for (int i = 0; i < intAProp.length; i++) {
+ if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+ }
+
+ context.ungetService(fact_ref);
+ fact = null;
+ }
+
+
+
+}
Propchange: felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/inherited/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Jan 27 15:21:24 2008
@@ -0,0 +1,6 @@
+target*
+bin*
+.settings*
+.classpath
+.project
+.checkstyle
Added: felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/inherited/InheritedTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/inherited/InheritedTest.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/inherited/InheritedTest.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/service/providing/inherited/InheritedTest.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,175 @@
+package org.apache.felix.ipojo.test.scenarios.service.providing.inherited;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.service.ChildInterface;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.service.ParentInterface1;
+import org.apache.felix.ipojo.test.scenarios.service.ParentInterface2;
+import org.apache.felix.ipojo.test.scenarios.service.ParentParentInterface;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class InheritedTest extends OSGiTestCase {
+
+ private Factory pi1, pi11, pi12, pi2, pi21, pi3;
+
+ public void setUp() {
+ pi1 = Utils.getFactoryByName(context, "PI1");
+ pi11 = Utils.getFactoryByName(context, "PI1-1");
+ pi12 = Utils.getFactoryByName(context, "PI1-2");
+
+ pi2 = Utils.getFactoryByName(context, "PI2");
+ pi21 = Utils.getFactoryByName(context, "PI2-1");
+
+ pi3 = Utils.getFactoryByName(context, "PI3");
+ }
+
+ private boolean contains(String[] arr, String txt) {
+ for (int i = 0; i < arr.length; i++) {
+ if (arr[i].equals(txt)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void testPI1Factory() {
+ String[] specs = pi1.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count", specs.length, 4);
+ assertTrue("Check Child", contains(specs, ChildInterface.class.getName()));
+ assertTrue("Check Parent1", contains(specs, ParentInterface1.class.getName()));
+ assertTrue("Check Parent2", contains(specs, ParentInterface2.class.getName()));
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ }
+
+ public void testPI11Factory() {
+ String[] specs = pi11.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count", specs.length, 1);
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ }
+
+ public void testPI12Factory() {
+ String[] specs = pi12.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count", specs.length, 2);
+ assertTrue("Check Parent2", contains(specs, ParentInterface2.class.getName()));
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ }
+
+ public void testPI2Factory() {
+ String[] specs = pi2.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count ("+specs.length+")", specs.length, 4);
+ assertTrue("Check Child", contains(specs, ChildInterface.class.getName()));
+ assertTrue("Check Parent1", contains(specs, ParentInterface1.class.getName()));
+ assertTrue("Check Parent2", contains(specs, ParentInterface2.class.getName()));
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ }
+
+ public void testPI21Factory() {
+ String[] specs = pi21.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count", specs.length, 1);
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ }
+
+ public void testPI3Factory() {
+ String[] specs = pi3.getComponentDescription().getprovidedServiceSpecification();
+ assertEquals("Check provides count", specs.length, 5);
+ assertTrue("Check Child", contains(specs, ChildInterface.class.getName()));
+ assertTrue("Check Parent1", contains(specs, ParentInterface1.class.getName()));
+ assertTrue("Check Parent2", contains(specs, ParentInterface2.class.getName()));
+ assertTrue("Check ParentParent", contains(specs, ParentParentInterface.class.getName()));
+ assertTrue("Check FS", contains(specs, FooService.class.getName()));
+ }
+
+ public void testIP1() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi1.getName(), "ci");
+
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, ChildInterface.class.getName(), "ci");
+ assertNotNull("Check Child", ref1);
+
+ ServiceReference ref2 = Utils.getServiceReferenceByName(context, ParentInterface1.class.getName(), "ci");
+ assertNotNull("Check Parent1", ref2);
+
+ ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ assertNotNull("Check Parent2", ref3);
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ci.dispose();
+ }
+
+ public void testIP11() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi11.getName(), "ci");
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ci.dispose();
+ }
+
+ public void testIP12() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi12.getName(), "ci");
+
+ ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ assertNotNull("Check Parent2", ref3);
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ci.dispose();
+ }
+
+ public void testIP2() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi2.getName(), "ci");
+
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, ChildInterface.class.getName(), "ci");
+ assertNotNull("Check Child", ref1);
+
+ ServiceReference ref2 = Utils.getServiceReferenceByName(context, ParentInterface1.class.getName(), "ci");
+ assertNotNull("Check Parent1", ref2);
+
+ ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ assertNotNull("Check Parent2", ref3);
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ci.dispose();
+ }
+
+ public void testIP21() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi21.getName(), "ci");
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ci.dispose();
+ }
+
+ public void testIP3() {
+ ComponentInstance ci = Utils.getComponentInstanceByName(context, pi3.getName(), "ci");
+
+ ServiceReference ref1 = Utils.getServiceReferenceByName(context, ChildInterface.class.getName(), "ci");
+ assertNotNull("Check Child", ref1);
+
+ ServiceReference ref2 = Utils.getServiceReferenceByName(context, ParentInterface1.class.getName(), "ci");
+ assertNotNull("Check Parent1", ref2);
+
+ ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ assertNotNull("Check Parent2", ref3);
+
+ ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ assertNotNull("Check PP", ref4);
+
+ ServiceReference ref5 = Utils.getServiceReferenceByName(context, FooService.class.getName(), "ci");
+ assertNotNull("Check FS", ref5);
+
+ ci.dispose();
+ }
+
+
+
+
+}
Propchange: felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Jan 27 15:21:24 2008
@@ -0,0 +1,6 @@
+target*
+bin*
+.settings*
+.classpath
+.project
+.checkstyle
Added: felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java?rev=615675&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java (added)
+++ felix/sandbox/clement/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java Sun Jan 27 15:21:24 2008
@@ -0,0 +1,271 @@
+package org.apache.felix.ipojo.test.scenarios.util;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.HandlerFactory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.composite.CompositeManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class Utils {
+
+ public static Factory getFactoryByName(BundleContext bc, String factoryName) {
+ ServiceReference[] refs;
+ try {
+ refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
+ if (refs == null) {
+ System.err.println("Cannot get the factory " + factoryName);
+ return null;
+ }
+ return ((Factory) bc.getService(refs[0]));
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+ return null;
+ }
+ }
+
+ public static HandlerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {
+ ServiceReference[] refs;
+ try {
+ refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");
+ if (refs == null) {
+ System.err.println("Cannot get the factory " + factoryName);
+ return null;
+ }
+ return (HandlerFactory) bc.getService(refs[0]);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+ return null;
+ }
+ }
+
+ public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {
+ Factory fact = getFactoryByName(bc, factoryName);
+
+ if (fact == null) {
+ System.err.println("Factory " + factoryName + " not found");
+ return null;
+ }
+
+ // if(fact.isAcceptable(configuration)) {
+ try {
+ return fact.createComponentInstance(configuration);
+ } catch (Exception e) {
+ Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());
+ return null;
+ }
+ // }
+ // else {
+ // System.err.println("Configuration not accepted by : " + factoryName);
+ // return null;
+ // }
+ }
+
+ public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {
+ Factory fact = getFactoryByName(bc, factoryName);
+
+ if (fact == null) {
+ System.err.println("Factory " + factoryName + " not found");
+ return null;
+ }
+
+ try {
+ Properties props = new Properties();
+ props.put("name", name);
+ return fact.createComponentInstance(props);
+ } catch (Exception e) {
+ System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {
+ ServiceReference[] refs = null;
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return new ServiceReference[0];
+ } else {
+ return refs;
+ }
+ }
+
+ public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {
+ ServiceReference[] refs = null;
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return null;
+ } else {
+ return refs[0];
+ }
+ }
+
+ public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {
+ ServiceReference[] refs = null;
+ String filter = null;
+ if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
+ filter = "(" + "factory.name" + "=" + name + ")";
+ } else {
+ filter = "(" + "instance.name" + "=" + name + ")";
+ }
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return null;
+ } else {
+ return refs[0];
+ }
+ }
+
+ public static Object getServiceObject(BundleContext bc, String itf, String filter) {
+ ServiceReference ref = getServiceReference(bc, itf, filter);
+ if (ref != null) {
+ return bc.getService(ref);
+ } else {
+ return null;
+ }
+ }
+
+ public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {
+ ServiceReference[] refs = getServiceReferences(bc, itf, filter);
+ if (refs != null) {
+ Object[] list = new Object[refs.length];
+ for (int i = 0; i < refs.length; i++) {
+ list[i] = bc.getService(refs[i]);
+ }
+ return list;
+ } else {
+ return new Object[0];
+ }
+ }
+
+ public static ServiceContext getServiceContext(ComponentInstance ci) {
+ if (ci instanceof CompositeManager) {
+ return ((CompositeManager) ci).getServiceContext();
+ } else {
+ throw new RuntimeException("Cannot get the service context form an non composite instance");
+ }
+ }
+
+ public static Factory getFactoryByName(ServiceContext bc, String factoryName) {
+ ServiceReference[] refs;
+ try {
+ refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
+ if (refs == null) { return null; }
+ return ((Factory) bc.getService(refs[0]));
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
+ return null;
+ }
+ }
+
+ public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {
+ Factory fact = getFactoryByName(bc, factoryName);
+
+ if (fact == null) { return null; }
+
+ if (fact.isAcceptable(configuration)) {
+ try {
+ return fact.createComponentInstance(configuration);
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ e.printStackTrace();
+ return null;
+ }
+ } else {
+ System.err.println("Configuration not accepted by : " + factoryName);
+ return null;
+ }
+ }
+
+ public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {
+ ServiceReference[] refs = null;
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return new ServiceReference[0];
+ } else {
+ return refs;
+ }
+ }
+
+ public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {
+ ServiceReference[] refs = null;
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return null;
+ } else {
+ return refs[0];
+ }
+ }
+
+ public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {
+ ServiceReference[] refs = null;
+ String filter = null;
+ if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
+ filter = "(" + "factory.name" + "=" + name + ")";
+ } else {
+ filter = "(" + "instance.name" + "=" + name + ")";
+ }
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return null;
+ } else {
+ return refs[0];
+ }
+ }
+
+ public static Object getServiceObject(ServiceContext bc, String itf, String filter) {
+ ServiceReference ref = getServiceReference(bc, itf, filter);
+ if (ref != null) {
+ return bc.getService(ref);
+ } else {
+ return null;
+ }
+ }
+
+ public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {
+ ServiceReference[] refs = getServiceReferences(bc, itf, filter);
+ if (refs != null) {
+ Object[] list = new Object[refs.length];
+ for (int i = 0; i < refs.length; i++) {
+ list[i] = bc.getService(refs[i]);
+ }
+ return list;
+ } else {
+ return new Object[0];
+ }
+ }
+
+}
Propchange: felix/sandbox/clement/ipojo/tests/tests.core/src/main/resources/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Jan 27 15:21:24 2008
@@ -0,0 +1,6 @@
+target*
+bin*
+.settings*
+.classpath
+.project
+.checkstyle