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/09/24 16:26:55 UTC
svn commit: r698589 [2/2] - in /felix/trunk/ipojo:
core/src/main/java/org/apache/felix/ipojo/
core/src/main/java/org/apache/felix/ipojo/handlers/configuration/
core/src/main/java/org/apache/felix/ipojo/util/
handler/eventadmin/src/main/resources/ handl...
Added: felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForImmediate.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForImmediate.java?rev=698589&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForImmediate.java (added)
+++ felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForImmediate.java Wed Sep 24 07:26:55 2008
@@ -0,0 +1,349 @@
+package org.apache.felix.ipojo.test.scenarios.configadmin;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.configadmin.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public class ManagedServiceTestForImmediate extends OSGiTestCase {
+
+ private String factNameImm = "CA-ImmConfigurableProvider";
+ private String msp = "foo";
+
+ private ComponentFactory factImm;
+
+ private ConfigurationAdmin admin;
+
+
+ public void setUp() {
+ factImm = (ComponentFactory) Utils.getFactoryByName(context, factNameImm);
+ admin = (ConfigurationAdmin) Utils.getServiceObject(context, ConfigurationAdmin.class.getName(), null);
+ assertNotNull("Check configuration admin availability", admin);
+ cleanConfigurationAdmin();
+ }
+
+ public void tearDown() {
+ cleanConfigurationAdmin();
+ admin = null;
+ }
+
+ private void cleanConfigurationAdmin() {
+ try {
+ Configuration[] configurations = admin.listConfigurations("(service.pid=" + msp + ")");
+ for (int i = 0; configurations != null && i < configurations.length; i++) {
+ configurations[i].delete();
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvalidSyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public void testFactoryCreationAndReconfiguration() {
+ Properties props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ ComponentInstance instance = null;
+ try {
+ instance = factImm.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ FooService fs = (FooService) context.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message", mes);
+ assertEquals("Check count", 1, count);
+
+ //Update
+ Configuration configuration;
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ fs = (FooService) context.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message2", mes);
+ assertEquals("Check count", 2, count);
+
+ instance.dispose();
+
+ }
+
+ public void testMSFCreationAndReconfiguration() {
+ Configuration conf = null;
+ try {
+ conf = admin.createFactoryConfiguration(factNameImm);
+ Dictionary props = conf.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ conf.update(props);
+ Thread.sleep(100); // Wait for the creation.
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+
+ Architecture arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), conf.getPid());
+ assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+ FooService fs = (FooService) context.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message", mes);
+ assertEquals("Check count", 1, count);
+
+ //Update
+ Configuration configuration;
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), conf.getPid());
+ assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+ fs = (FooService) context.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message2", mes);
+ assertEquals("Check count", 2, count);
+
+ try {
+ conf.delete();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ public void testCreationAndReconfiguration2() {
+ // The configuration exists before the instance creation.
+
+ //Update
+ Configuration configuration;
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ Properties props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ ComponentInstance instance = null;
+ try {
+ instance = factImm.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ FooService fs = (FooService) context.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message2", mes); // Already reconfigured.
+ assertEquals("Check count", 1, count);
+
+ instance.dispose();
+
+ //Reconfiguration
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message3");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ // Recreation of the instance.
+ props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ instance = null;
+ try {
+ instance = factImm.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ fs = (FooService) context.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message3", mes); // Already reconfigured.
+ assertEquals("Check count", 1, count);
+
+ instance.dispose();
+
+
+ }
+
+ public void testCreationAndReconfiguration3() {
+ // The configuration exists before the instance creation.
+
+ //Update
+ Configuration configuration;
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ Properties props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ ComponentInstance instance = null;
+ try {
+ instance = factImm.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ FooService fs = (FooService) context.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message2", mes); // Already reconfigured.
+ assertEquals("Check count", 1, count);
+
+ //Reconfiguration
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message3");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ instance.dispose();
+
+ // Recreation of the instance.
+ props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ instance = null;
+ try {
+ instance = factImm.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ fs = (FooService) context.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message3", mes); // Already reconfigured.
+ assertEquals("Check count", 1, count);
+
+ instance.dispose();
+
+
+ }
+
+
+
+
+}
Added: felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForService.java?rev=698589&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForService.java (added)
+++ felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/ManagedServiceTestForService.java Wed Sep 24 07:26:55 2008
@@ -0,0 +1,349 @@
+package org.apache.felix.ipojo.test.scenarios.configadmin;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.configadmin.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public class ManagedServiceTestForService extends OSGiTestCase {
+
+ private String factNameSvc = "CA-ConfigurableProvider";
+ private String msp = "foo";
+
+ private ComponentFactory factSvc;
+
+ private ConfigurationAdmin admin;
+
+
+ public void setUp() {
+ factSvc = (ComponentFactory) Utils.getFactoryByName(context, factNameSvc);
+ admin = (ConfigurationAdmin) Utils.getServiceObject(context, ConfigurationAdmin.class.getName(), null);
+ assertNotNull("Check configuration admin availability", admin);
+ cleanConfigurationAdmin();
+ }
+
+ public void tearDown() {
+ cleanConfigurationAdmin();
+ admin = null;
+ }
+
+ private void cleanConfigurationAdmin() {
+ try {
+ Configuration[] configurations = admin.listConfigurations("(service.pid=" + msp + ")");
+ for (int i = 0; configurations != null && i < configurations.length; i++) {
+ configurations[i].delete();
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvalidSyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public void testFactoryCreationAndReconfiguration() {
+ Properties props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ ComponentInstance instance = null;
+ try {
+ instance = factSvc.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check no object", 0, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ FooService fs = (FooService) context.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message", mes);
+ assertEquals("Check count", 1, count);
+
+ //Update
+ Configuration configuration;
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ fs = (FooService) context.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message2", mes);
+ assertEquals("Check count", 2, count);
+
+ instance.dispose();
+
+ }
+
+ public void testMSFCreationAndReconfiguration() {
+ Configuration conf = null;
+ try {
+ conf = admin.createFactoryConfiguration(factNameSvc);
+ Dictionary props = conf.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ conf.update(props);
+ Thread.sleep(100); // Wait for the creation.
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+
+ Architecture arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), conf.getPid());
+ assertEquals("Check no object", 0, arch.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+ FooService fs = (FooService) context.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message", mes);
+ assertEquals("Check count", 1, count);
+
+ //Update
+ Configuration configuration;
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), conf.getPid());
+ assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ arch = (Architecture) Utils.getServiceObject(context, org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+ fs = (FooService) context.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, arch.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message2", mes);
+ assertEquals("Check count", 2, count);
+
+ try {
+ conf.delete();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ public void testCreationAndReconfiguration2() {
+ // The configuration exists before the instance creation.
+
+ //Update
+ Configuration configuration;
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ Properties props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ ComponentInstance instance = null;
+ try {
+ instance = factSvc.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check no object", 0, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ FooService fs = (FooService) context.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message2", mes); // Already reconfigured.
+ assertEquals("Check count", 1, count);
+
+ instance.dispose();
+
+ //Reconfiguration
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message3");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ // Recreation of the instance.
+ props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ instance = null;
+ try {
+ instance = factSvc.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check no object", 0, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ fs = (FooService) context.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message3", mes); // Already reconfigured.
+ assertEquals("Check count", 1, count);
+
+ instance.dispose();
+
+
+ }
+
+ public void testCreationAndReconfiguration3() {
+ // The configuration exists before the instance creation.
+
+ //Update
+ Configuration configuration;
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ Properties props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ ComponentInstance instance = null;
+ try {
+ instance = factSvc.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check no object", 0, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ FooService fs = (FooService) context.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message2", mes); // Already reconfigured.
+ assertEquals("Check count", 1, count);
+
+ //Reconfiguration
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message3");
+ configuration.update(prc);
+ Thread.sleep(5);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ instance.dispose();
+
+ // Recreation of the instance.
+ props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ instance = null;
+ try {
+ instance = factSvc.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check no object", 0, instance.getInstanceDescription().getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ fs = (FooService) context.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, instance.getInstanceDescription().getCreatedObjects().length);
+ assertEquals("Check message", "message3", mes); // Already reconfigured.
+ assertEquals("Check count", 1, count);
+
+ instance.dispose();
+
+
+ }
+
+
+
+
+}
Added: felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/CheckService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/CheckService.java?rev=698589&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/CheckService.java (added)
+++ felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/CheckService.java Wed Sep 24 07:26:55 2008
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.configadmin.service;
+
+import java.util.Properties;
+
+public interface CheckService {
+
+ public static final String foo = "foo";
+
+ public boolean check();
+
+ public Properties getProps();
+
+}
Added: felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/FooService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/FooService.java?rev=698589&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/FooService.java (added)
+++ felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/configadmin/service/FooService.java Wed Sep 24 07:26:55 2008
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.configadmin.service;
+
+import java.util.Properties;
+
+public interface FooService {
+
+ boolean foo();
+
+ Properties fooProps();
+
+ Boolean getObject();
+
+ boolean getBoolean();
+
+ int getInt();
+
+ long getLong();
+
+ double getDouble();
+
+}
Added: felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java?rev=698589&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java (added)
+++ felix/trunk/ipojo/tests/core/configadmin/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java Wed Sep 24 07:26:55 2008
@@ -0,0 +1,346 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.util;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.HandlerManagerFactory;
+import org.apache.felix.ipojo.ServiceContext;
+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 HandlerManagerFactory 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 (HandlerManagerFactory) 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) {
+ e.printStackTrace();
+ 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("instance.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 ServiceReference getServiceReferenceByPID(BundleContext bc, String itf, String pid) {
+ ServiceReference[] refs = null;
+ String filter = "(" + "service.pid" + "=" + pid + ")";
+ try {
+ refs = bc.getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ System.err.println("Invalid Filter : " + filter);
+ }
+ if (refs == null) {
+ return null;
+ } else if (refs.length == 1) {
+ return refs[0];
+ } else {
+ Assert.fail("A service lookup by PID returned several providers (" + refs.length + ")" + " for " + itf + " with " + pid);
+ return null;
+ }
+ }
+
+ 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];
+ }
+ }
+
+ public static boolean contains(String string, String[] array) {
+ for (int i = 0; array != null && i < array.length; i++) {
+ if (array[i] != null && array[i].equals(string)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean contains(int value, int[] array) {
+ for (int i = 0; array != null && i < array.length; i++) {
+ if (array[i] == value) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static void waitForService(BundleContext context, String itf, String filter) {
+ ServiceReference[] refs = getServiceReferences(context, itf, filter);
+ int count = 0;
+ if (refs.length != 0) {
+ return;
+ } else {
+ while(refs.length == 0) {
+ try {
+ Thread.sleep(5);
+ } catch (InterruptedException e) {
+ // Interrupted
+ }
+ count++;
+ if (count == 10) {
+ throw new RuntimeException("Timeout ... no services match with " + filter);
+ }
+ refs = getServiceReferences(context, itf, filter);
+ }
+ }
+ }
+
+}
Added: felix/trunk/ipojo/tests/core/configadmin/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configadmin/src/main/resources/metadata.xml?rev=698589&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/core/configadmin/src/main/resources/metadata.xml (added)
+++ felix/trunk/ipojo/tests/core/configadmin/src/main/resources/metadata.xml Wed Sep 24 07:26:55 2008
@@ -0,0 +1,21 @@
+<ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="org.apache.felix.ipojo http://people.apache.org/~clement/ipojo/schemas/core.xsd" xmlns="org.apache.felix.ipojo">
+ <component classname="org.apache.felix.ipojo.test.scenarios.component.ConfigurableFooProvider"
+ name="CA-ConfigurableProvider">
+ <provides></provides>
+ <properties>
+ <property name="message" method="setMessage"/>
+ </properties>
+ </component>
+ <component classname="org.apache.felix.ipojo.test.scenarios.component.ConfigurableFooProvider"
+ immediate="true"
+ name="CA-ImmConfigurableProvider">
+ <provides></provides>
+ <properties>
+ <property name="message" method="setMessage"/>
+ </properties>
+ </component>
+
+
+
+</ipojo>
Modified: felix/trunk/ipojo/tests/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/pom.xml?rev=698589&r1=698588&r2=698589&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/pom.xml (original)
+++ felix/trunk/ipojo/tests/pom.xml Wed Sep 24 07:26:55 2008
@@ -43,6 +43,7 @@
<module>handler/temporal</module>
<module>handler/whiteboard</module>
<module>handler/eventadmin</module>
+ <module>core/configadmin</module>
</modules>
<profiles>