You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2013/04/29 20:10:10 UTC
svn commit: r1477242 - in /felix/trunk/ipojo/runtime/core-it/src/it:
ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/
ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/
ipojo-core-fact...
Author: clement
Date: Mon Apr 29 18:10:09 2013
New Revision: 1477242
URL: http://svn.apache.org/r1477242
Log:
Move tests to avoid using the managed service factory directly (not exposed anymore)
Modified:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicPropsReconfiguration.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticPropsReconfiguration.java
Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java?rev=1477242&r1=1477241&r2=1477242&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java Mon Apr 29 18:10:09 2013
@@ -116,8 +116,7 @@ public class TestManagedServiceTestForIm
prc.put("message", "message2");
configuration.update(prc);
System.err.println("updated ? ");
- //Thread.sleep(UPDATE_WAIT_TIME);
- listener.waitForEvent(configuration.getPid(), "1");
+ Thread.sleep(UPDATE_WAIT_TIME);
} catch (Exception e) {
fail(e.getMessage());
}
@@ -187,8 +186,7 @@ public class TestManagedServiceTestForIm
}
prc.put("message", "message2");
configuration.update(prc);
- //Thread.sleep(UPDATE_WAIT_TIME);
- listener.waitForEvent(configuration.getPid(), "1");
+ Thread.sleep(UPDATE_WAIT_TIME);
} catch (Exception e) {
fail(e.getMessage());
}
@@ -274,7 +272,7 @@ public class TestManagedServiceTestForIm
}
prc.put("message", "message3");
configuration.update(prc);
- listener.waitForEvent(msp, "1");
+ Thread.sleep(UPDATE_WAIT_TIME);
} catch (Exception e) {
fail(e.getMessage());
}
@@ -321,7 +319,7 @@ public class TestManagedServiceTestForIm
}
prc.put("message", "message2");
configuration.update(prc);
- listener.waitForEvent(msp, "1");
+ Thread.sleep(UPDATE_WAIT_TIME);
} catch (Exception e) {
fail(e.getMessage());
}
@@ -359,7 +357,7 @@ public class TestManagedServiceTestForIm
prc.put("message", "message3");
configuration.update(prc);
//Thread.sleep(UPDATE_WAIT_TIME);
- listener.waitForEvent(msp, "1");
+ Thread.sleep(UPDATE_WAIT_TIME);
} catch (Exception e) {
fail(e.getMessage());
}
Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java?rev=1477242&r1=1477241&r2=1477242&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java Mon Apr 29 18:10:09 2013
@@ -24,13 +24,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
import org.ops4j.pax.exam.spi.reactors.PerMethod;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedServiceFactory;
import java.io.IOException;
import java.util.Hashtable;
@@ -38,7 +35,7 @@ import java.util.Properties;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNull;
/**
* iPOJO does not expose the ManagedServiceFactory anymore, we must use the configuration admin.
@@ -330,6 +327,7 @@ public class TestDynamicallyConfigurable
conf.put("bar", new Integer(2));
conf.put("propagated1", "propagated");
conf.put("propagated2", new Integer(1));
+ conf.put(".notpropagated", "xxx");
// Asynchronous dispatching of the configuration
configuration.update(conf);
@@ -340,10 +338,11 @@ public class TestDynamicallyConfigurable
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
- assertNotNull("Check the propagated1 existency", fooRef.getProperty("propagated1"));
+ assertNotNull("Check the propagated1 existence", fooRef.getProperty("propagated1"));
String prop1 = (String) fooRef.getProperty("propagated1");
- assertNotNull("Check the propagated2 existency", fooRef.getProperty("propagated2"));
+ assertNotNull("Check the propagated2 existence", fooRef.getProperty("propagated2"));
Integer prop2 = (Integer) fooRef.getProperty("propagated2");
+ assertNull("Check the not propagated non-existence", fooRef.getProperty(".notpropagated"));
assertEquals("Check foo equality", fooP, "foo");
assertEquals("Check bar equality", barP, new Integer(2));
Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java?rev=1477242&r1=1477241&r2=1477242&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java Mon Apr 29 18:10:09 2013
@@ -240,8 +240,8 @@ public class Common {
private boolean getBundleStability(BundleContext bc) {
boolean stability = true;
Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
+ for (Bundle bundle : bundles) {
+ stability = stability && (bundle.getState() == Bundle.ACTIVE);
}
return stability;
}
Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java?rev=1477242&r1=1477241&r2=1477242&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java Mon Apr 29 18:10:09 2013
@@ -21,9 +21,10 @@ package org.apache.felix.ipojo.runtime.c
import org.apache.felix.ipojo.runtime.core.services.FooService;
import org.junit.Test;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedServiceFactory;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import java.io.IOException;
import java.util.Properties;
import static org.junit.Assert.*;
@@ -33,23 +34,13 @@ import static org.junit.Assert.*;
*/
public class TestConfigAdmin extends Common {
- private ManagedServiceFactory getFactoryByName(String pid) {
- ServiceReference[] refs;
-
- refs = osgiHelper.getServiceReferences(ManagedServiceFactory.class.getName(), "(service.pid=" + pid + ")");
- if (refs == null) {
- return null;
- }
-
- return ((ManagedServiceFactory) osgiHelper.getServiceObject((refs[0])));
- }
-
/**
* Check creation.
*/
@Test
- public void testCreation() {
- ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
+ public void testCreation() throws IOException, InterruptedException {
+ ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class, null);
+ Configuration conf = admin.createFactoryConfiguration("Factories-FooProviderType-2", "?");
Properties p = new Properties();
p.put("int", 3);
@@ -58,24 +49,28 @@ public class TestConfigAdmin extends Com
p.put("strAProp", new String[]{"a"});
p.put("intAProp", new int[]{1, 2});
- try {
- f.updated("ok2", p);
- ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "ok2");
- assertNotNull("Check instance creation", ref);
- f.deleted("ok2");
- ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "ok2");
- assertNull("Check instance deletion", ref);
- } catch (ConfigurationException e) {
- fail("An acceptable configuration is rejected : " + e.getMessage());
- }
+ conf.update(p);
+ Thread.sleep(200);
+
+ String pid = conf.getPid();
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
+ assertNotNull("Check instance creation", ref);
+
+ // Deletion of the configuration
+ conf.delete();
+ Thread.sleep(200);
+
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
+ assertNull("Check instance deletion", ref);
}
/**
* Check creation (push String).
*/
@Test
- public void testCreationString() {
- ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
+ public void testCreationString() throws IOException, InterruptedException {
+ ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class, null);
+ Configuration conf = admin.createFactoryConfiguration("Factories-FooProviderType-2", "?");
Properties p = new Properties();
p.put("int", "3");
@@ -84,24 +79,28 @@ public class TestConfigAdmin extends Com
p.put("strAProp", "{a}");
p.put("intAProp", "{1,2}");
- try {
- f.updated("ok2", p);
- ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "ok2");
- assertNotNull("Check instance creation", ref);
- f.deleted("ok2");
- ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "ok2");
- assertNull("Check instance deletion", ref);
- } catch (ConfigurationException e) {
- fail("An acceptable configuration is rejected : " + e.getMessage());
- }
+ conf.update(p);
+ Thread.sleep(200);
+
+ String pid = conf.getPid();
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
+
+ assertNotNull("Check instance creation", ref);
+
+ conf.delete();
+ Thread.sleep(200);
+
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
+ assertNull("Check instance deletion", ref);
}
/**
* Check update and delete.
*/
@Test
- public void testUpdate() {
- ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
+ public void testUpdate() throws IOException, InterruptedException {
+ ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class, null);
+ Configuration conf = admin.createFactoryConfiguration("Factories-FooProviderType-2", "?");
Properties p = new Properties();
p.put("int", 3);
@@ -110,21 +109,27 @@ public class TestConfigAdmin extends Com
p.put("strAProp", new String[]{"a"});
p.put("intAProp", new int[]{1, 2});
- try {
- f.updated("okkkk", p);
- ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
- assertNotNull("Check instance creation", ref);
- p.put("int", new Integer("4"));
- f.updated("okkkk", p);
- ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
- Integer test = (Integer) ref.getProperty("int");
- assertEquals("Check instance modification", 4, test.intValue());
- f.deleted("okkkk");
- ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
- assertNull("Check instance deletion", ref);
- } catch (ConfigurationException e) {
- fail("An acceptable configuration is rejected : " + e.getMessage());
- }
+ conf.update(p);
+ Thread.sleep(200);
+
+ String pid = conf.getPid();
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
+
+ assertNotNull("Check instance creation", ref);
+
+ p.put("int", 4);
+ conf.update(p);
+ Thread.sleep(200);
+
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
+ Integer test = (Integer) ref.getProperty("int");
+ assertEquals("Check instance modification", 4, test.intValue());
+
+ conf.delete();
+ Thread.sleep(200);
+
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
+ assertNull("Check instance deletion", ref);
}
/**
@@ -132,8 +137,9 @@ public class TestConfigAdmin extends Com
* (Push String).
*/
@Test
- public void testUpdateString() {
- ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
+ public void testUpdateString() throws IOException, InterruptedException {
+ ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class, null);
+ Configuration conf = admin.createFactoryConfiguration("Factories-FooProviderType-2", "?");
Properties p = new Properties();
p.put("int", "3");
@@ -142,21 +148,23 @@ public class TestConfigAdmin extends Com
p.put("strAProp", "{a}");
p.put("intAProp", "{1,2}");
- try {
- f.updated("okkkk", p);
- ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
- assertNotNull("Check instance creation", ref);
- p.put("int", new Integer("4"));
- f.updated("okkkk", p);
- ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
- Integer test = (Integer) ref.getProperty("int");
- assertEquals("Check instance modification", 4, test.intValue());
- f.deleted("okkkk");
- ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
- assertNull("Check instance deletion", ref);
- } catch (ConfigurationException e) {
- fail("An acceptable configuration is rejected : " + e.getMessage());
- }
+ conf.update(p);
+ Thread.sleep(200);
+
+ String pid = conf.getPid();
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
+ assertNotNull("Check instance creation", ref);
+ p.put("int", new Integer("4"));
+ conf.update(p);
+ Thread.sleep(200);
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
+ Integer test = (Integer) ref.getProperty("int");
+ assertEquals("Check instance modification", 4, test.intValue());
+ conf.delete();
+ Thread.sleep(200);
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
+ assertNull("Check instance deletion", ref);
}
}
Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java?rev=1477242&r1=1477241&r2=1477242&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java Mon Apr 29 18:10:09 2013
@@ -111,7 +111,8 @@ public class TestReconfiguration extends
@Test public void testRevalidationOnReconfigurationUsingConfigAdmin() throws InvalidSyntaxException {
Configuration configuration = null;
try {
- configuration = admin.createFactoryConfiguration("org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType", null);
+ configuration = admin.createFactoryConfiguration("org.apache.felix.ipojo.runtime.core.components" +
+ ".ReconfigurableSimpleType", "?");
} catch (IOException e) {
fail(e.getMessage());
}
@@ -201,7 +202,7 @@ public class TestReconfiguration extends
Configuration configuration = null;
try {
configuration = admin.createFactoryConfiguration("org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType2",
- null);
+ "?");
} catch (IOException e) {
fail(e.getMessage());
}
@@ -293,7 +294,7 @@ public class TestReconfiguration extends
Configuration configuration = null;
try {
configuration = admin.createFactoryConfiguration("org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType3",
- null);
+ "?");
} catch (IOException e) {
fail(e.getMessage());
}
Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicPropsReconfiguration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicPropsReconfiguration.java?rev=1477242&r1=1477241&r2=1477242&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicPropsReconfiguration.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicPropsReconfiguration.java Mon Apr 29 18:10:09 2013
@@ -24,9 +24,10 @@ import org.apache.felix.ipojo.runtime.co
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedServiceFactory;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import java.io.IOException;
import java.util.Properties;
import static junit.framework.Assert.assertEquals;
@@ -41,9 +42,9 @@ public class TestDynamicPropsReconfigura
String type2 = "PS-FooProviderType-Dyn2";
Properties p3 = new Properties();
p3.put("instance.name", "FooProvider-3");
- p3.put("int", new Integer(0));
- p3.put("boolean", new Boolean(true));
- p3.put("string", new String(""));
+ p3.put("int", 0);
+ p3.put("boolean", true);
+ p3.put("string", "");
p3.put("strAProp", new String[0]);
p3.put("intAProp", new int[0]);
fooProvider3 = ipojoHelper.createComponentInstance(type2, p3);
@@ -86,9 +87,9 @@ public class TestDynamicPropsReconfigura
Factory fact = (Factory) osgiHelper.getServiceObject(fact_ref);
Properties p3 = new Properties();
p3.put("instance.name", "FooProvider-3");
- p3.put("int", new Integer(1));
- p3.put("boolean", new Boolean(true));
- p3.put("string", new String("foo"));
+ p3.put("int", 1);
+ p3.put("boolean", true);
+ p3.put("string", "foo");
p3.put("strAProp", new String[]{"foo", "bar", "baz"});
p3.put("intAProp", new int[]{1, 2, 3});
try {
@@ -108,8 +109,8 @@ public class TestDynamicPropsReconfigura
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"));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[]{"foo", "bar", "baz"};
for (int i = 0; i < strAProp.length; i++) {
@@ -137,8 +138,8 @@ public class TestDynamicPropsReconfigura
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"));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[]{"foo", "bar"};
for (int i = 0; i < strAProp.length; i++) {
@@ -153,9 +154,9 @@ public class TestDynamicPropsReconfigura
fact = (Factory) osgiHelper.getServiceObject(fact_ref);
p3 = new Properties();
p3.put("instance.name", "FooProvider-3");
- p3.put("int", new Integer(1));
- p3.put("boolean", new Boolean(true));
- p3.put("string", new String("foo"));
+ p3.put("int", 1);
+ p3.put("boolean", true);
+ p3.put("string", "foo");
p3.put("strAProp", new String[]{"foo", "bar", "baz"});
p3.put("intAProp", new int[]{1, 2, 3});
try {
@@ -175,8 +176,8 @@ public class TestDynamicPropsReconfigura
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"));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[]{"foo", "bar", "baz"};
for (int i = 0; i < strAProp.length; i++) {
@@ -191,9 +192,6 @@ public class TestDynamicPropsReconfigura
fail("Check the intAProp Equality");
}
}
-
- fact = null;
- fs = null;
}
@Test
@@ -209,8 +207,8 @@ public class TestDynamicPropsReconfigura
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(""));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "");
assertNotNull("Check strAProp not nullity", strAProp);
String[] v = new String[0];
for (int i = 0; i < strAProp.length; i++) {
@@ -282,8 +280,8 @@ public class TestDynamicPropsReconfigura
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"));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[]{"foo", "bar"};
for (int i = 0; i < strAProp.length; i++) {
@@ -291,7 +289,7 @@ public class TestDynamicPropsReconfigura
fail("Check the strAProp Equality");
}
}
- assertNull("Check intAProp hidding (no value)", intAProp);
+ assertNull("Check intAProp hiding (no value)", intAProp);
// Reconfiguration
fact_ref = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "PS-FooProviderType-Dyn2");
@@ -320,8 +318,8 @@ public class TestDynamicPropsReconfigura
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"));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[]{"foo", "bar", "baz"};
for (int i = 0; i < strAProp.length; i++) {
@@ -336,13 +334,10 @@ public class TestDynamicPropsReconfigura
fail("Check the intAProp Equality");
}
}
-
- fact = null;
- fs = null;
}
@Test
- public void testMSFReconf() {
+ public void testReconfigurationUsingManagedService() throws IOException, InterruptedException {
ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
@@ -354,8 +349,8 @@ public class TestDynamicPropsReconfigura
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(""));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "");
assertNotNull("Check strAProp not nullity", strAProp);
String[] v = new String[0];
for (int i = 0; i < strAProp.length; i++) {
@@ -372,19 +367,18 @@ public class TestDynamicPropsReconfigura
}
// Reconfiguration
- ServiceReference fact_ref = ipojoHelper.getServiceReferenceByName(ManagedServiceFactory.class.getName(), "PS-FooProviderType-Dyn2");
- ManagedServiceFactory fact = (ManagedServiceFactory) osgiHelper.getServiceObject(fact_ref);
+ ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
+ Configuration configuration = admin.getConfiguration("FooProvider-3", "?");
+
Properties p3 = new Properties();
- p3.put("int", new Integer(1));
- p3.put("boolean", new Boolean(true));
- p3.put("string", new String("foo"));
+ p3.put("int", 1);
+ p3.put("boolean", true);
+ p3.put("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);
- }
+
+ configuration.update(p3);
+ Thread.sleep(200);
sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
@@ -397,8 +391,8 @@ public class TestDynamicPropsReconfigura
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"));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[]{"foo", "bar", "baz"};
for (int i = 0; i < strAProp.length; i++) {
@@ -426,8 +420,8 @@ public class TestDynamicPropsReconfigura
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"));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[]{"foo", "bar"};
for (int i = 0; i < strAProp.length; i++) {
@@ -435,22 +429,19 @@ public class TestDynamicPropsReconfigura
fail("Check the strAProp Equality");
}
}
- assertNull("Check intAProp hidding (no value)", intAProp);
+ assertNull("Check intAProp hiding (no value)", intAProp);
// Reconfiguration
- fact_ref = ipojoHelper.getServiceReferenceByName(ManagedServiceFactory.class.getName(), "PS-FooProviderType-Dyn2");
- fact = (ManagedServiceFactory) osgiHelper.getServiceObject(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("int", 1);
+ p3.put("boolean", true);
+ p3.put("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);
- }
+
+ configuration.update(p3);
+ Thread.sleep(200);
sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
@@ -463,8 +454,8 @@ public class TestDynamicPropsReconfigura
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"));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[]{"foo", "bar", "baz"};
for (int i = 0; i < strAProp.length; i++) {
@@ -479,13 +470,10 @@ public class TestDynamicPropsReconfigura
fail("Check the intAProp Equality");
}
}
-
- fact = null;
- fs = null;
}
@Test
- public void testMSFReconfString() {
+ public void testReconfiguraitonUsingManagedServiceWithStrings() throws IOException, InterruptedException {
ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
@@ -497,8 +485,8 @@ public class TestDynamicPropsReconfigura
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(""));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "");
assertNotNull("Check strAProp not nullity", strAProp);
String[] v = new String[0];
for (int i = 0; i < strAProp.length; i++) {
@@ -515,19 +503,19 @@ public class TestDynamicPropsReconfigura
}
// Reconfiguration
- ServiceReference fact_ref = ipojoHelper.getServiceReferenceByName(ManagedServiceFactory.class.getName(), "PS-FooProviderType-Dyn2");
- ManagedServiceFactory fact = (ManagedServiceFactory) osgiHelper.getServiceObject(fact_ref);
+ ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
+ Configuration configuration = admin.getConfiguration("FooProvider-3", "?");
+
+
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);
- }
+
+ configuration.update(p3);
+ Thread.sleep(200);
sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
@@ -540,8 +528,8 @@ public class TestDynamicPropsReconfigura
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"));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[]{"foo", "bar", "baz"};
for (int i = 0; i < strAProp.length; i++) {
@@ -569,8 +557,8 @@ public class TestDynamicPropsReconfigura
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"));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[]{"foo", "bar"};
for (int i = 0; i < strAProp.length; i++) {
@@ -581,19 +569,16 @@ public class TestDynamicPropsReconfigura
assertNull("Check intAProp hidding (no value)", intAProp);
// Reconfiguration
- fact_ref = ipojoHelper.getServiceReferenceByName(ManagedServiceFactory.class.getName(), "PS-FooProviderType-Dyn2");
- fact = (ManagedServiceFactory) osgiHelper.getServiceObject(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);
- }
+
+ configuration.update(p3);
+ Thread.sleep(200);
sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
@@ -606,8 +591,8 @@ public class TestDynamicPropsReconfigura
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"));
+ assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[]{"foo", "bar", "baz"};
for (int i = 0; i < strAProp.length; i++) {
@@ -622,9 +607,6 @@ public class TestDynamicPropsReconfigura
fail("Check the intAProp Equality");
}
}
-
- fact = null;
- fs = null;
}
@Test
Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticPropsReconfiguration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticPropsReconfiguration.java?rev=1477242&r1=1477241&r2=1477242&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticPropsReconfiguration.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestStaticPropsReconfiguration.java Mon Apr 29 18:10:09 2013
@@ -23,9 +23,10 @@ import org.apache.felix.ipojo.runtime.co
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedServiceFactory;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import java.io.IOException;
import java.util.Dictionary;
import java.util.Properties;
@@ -42,9 +43,9 @@ public class TestStaticPropsReconfigurat
Properties p2 = new Properties();
p2.put("instance.name", "FooProvider-2");
- p2.put("int", new Integer(4));
- p2.put("long", new Long(42));
- p2.put("string", new String("bar"));
+ p2.put("int", 4);
+ p2.put("long", (long) 42);
+ p2.put("string", "bar");
p2.put("strAProp", new String[]{"bar", "foo"});
p2.put("intAProp", new int[]{1, 2, 3});
ipojoHelper.createComponentInstance(type, p2);
@@ -124,8 +125,6 @@ public class TestStaticPropsReconfigurat
}
}
- fact = null;
-
}
@Test
@@ -142,7 +141,7 @@ public class TestStaticPropsReconfigurat
assertEquals("Check intProp equality", intProp, new Integer(4));
assertEquals("Check longProp equality", longProp, new Long(42));
- assertEquals("Check strProp equality", strProp, new String("bar"));
+ assertEquals("Check strProp equality", strProp, "bar");
assertNotNull("Check strAProp not nullity", strAProp);
String[] v = new String[]{"bar", "foo"};
@@ -161,11 +160,11 @@ public class TestStaticPropsReconfigurat
// Reconfiguration
ServiceReference fact_ref = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "PS-FooProviderType-2");
- Dictionary reconf = new Properties();
+ Properties reconf = new Properties();
reconf.put("instance.name", "FooProvider-2");
- reconf.put("int", new Integer(5));
- reconf.put("long", new Long(43));
- reconf.put("string", new String("toto"));
+ reconf.put("int", 5);
+ reconf.put("long", (long) 43);
+ reconf.put("string", "toto");
reconf.put("strAProp", new String[]{"foo", "baz"});
reconf.put("intAProp", new int[]{3, 2, 1});
Factory fact = (Factory) osgiHelper.getServiceObject(fact_ref);
@@ -184,7 +183,7 @@ public class TestStaticPropsReconfigurat
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"));
+ assertEquals("Check strProp equality after reconfiguration", strProp, "toto");
assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
v = new String[]{"foo", "baz"};
for (int i = 0; i < strAProp.length; i++) {
@@ -199,11 +198,10 @@ public class TestStaticPropsReconfigurat
fail("Check the intAProp Equality");
}
}
- fact = null;
}
@Test
- public void testMSFFactory1() {
+ public void testMSFFactory1() throws IOException, InterruptedException {
ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-1");
assertNotNull("Check the availability of the FS service", sr);
@@ -216,7 +214,7 @@ public class TestStaticPropsReconfigurat
assertEquals("Check intProp equality", intProp, new Integer(2));
assertEquals("Check longProp equality", longProp, new Long(40));
- assertEquals("Check strProp equality", strProp, new String("foo"));
+ assertEquals("Check strProp equality", strProp, "foo");
assertNotNull("Check strAProp not nullity", strAProp);
String[] v = new String[]{"foo", "bar"};
for (int i = 0; i < strAProp.length; i++) {
@@ -233,19 +231,18 @@ public class TestStaticPropsReconfigurat
}
// Reconfiguration
- ServiceReference fact_ref = ipojoHelper.getServiceReferenceByName(ManagedServiceFactory.class.getName(), "PS-FooProviderType-2");
- Dictionary reconf = new Properties();
- reconf.put("int", new Integer(5));
- reconf.put("long", new Long(43));
- reconf.put("string", new String("toto"));
+ ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
+ Configuration configuration = admin.getConfiguration("FooProvider-1", "?");
+
+ Properties reconf = new Properties();
+ reconf.put("int", 5);
+ reconf.put("long", (long) 43);
+ reconf.put("string", "toto");
reconf.put("strAProp", new String[]{"foo", "baz"});
reconf.put("intAProp", new int[]{3, 2, 1});
- ManagedServiceFactory fact = (ManagedServiceFactory) osgiHelper.getServiceObject(fact_ref);
- try {
- fact.updated("FooProvider-1", reconf);
- } catch (ConfigurationException e) {
- fail("Configuration non acceptable : " + reconf);
- }
+
+ configuration.update(reconf);
+ Thread.sleep(200);
sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-1");
assertNotNull("Check the availability of the FS service", sr);
@@ -259,7 +256,7 @@ public class TestStaticPropsReconfigurat
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"));
+ assertEquals("Check strProp equality after reconfiguration", strProp, "toto");
assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
v = new String[]{"foo", "baz"};
for (int i = 0; i < strAProp.length; i++) {
@@ -274,13 +271,10 @@ public class TestStaticPropsReconfigurat
fail("Check the intAProp Equality");
}
}
-
- fact = null;
-
}
@Test
- public void testReconfMSF2() {
+ public void testReconfMSF2() throws IOException, InterruptedException {
ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-2");
assertNotNull("Check the availability of the FS service", sr);
@@ -293,7 +287,7 @@ public class TestStaticPropsReconfigurat
assertEquals("Check intProp equality", intProp, new Integer(4));
assertEquals("Check longProp equality", longProp, new Long(42));
- assertEquals("Check strProp equality", strProp, new String("bar"));
+ assertEquals("Check strProp equality", strProp, "bar");
assertNotNull("Check strAProp not nullity", strAProp);
String[] v = new String[]{"bar", "foo"};
@@ -310,20 +304,19 @@ public class TestStaticPropsReconfigurat
}
}
+ ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
+ Configuration configuration = admin.getConfiguration("FooProvider-2", "?");
+
// Reconfiguration
- ServiceReference fact_ref = ipojoHelper.getServiceReferenceByName(ManagedServiceFactory.class.getName(), "PS-FooProviderType-2");
- Dictionary reconf = new Properties();
- reconf.put("int", new Integer(5));
- reconf.put("long", new Long(43));
- reconf.put("string", new String("toto"));
+ Properties reconf = new Properties();
+ reconf.put("int", 5);
+ reconf.put("long", (long) 43);
+ reconf.put("string", "toto");
reconf.put("strAProp", new String[]{"foo", "baz"});
reconf.put("intAProp", new int[]{3, 2, 1});
- ManagedServiceFactory fact = (ManagedServiceFactory) osgiHelper.getServiceObject(fact_ref);
- try {
- fact.updated("FooProvider-2", reconf);
- } catch (ConfigurationException e) {
- fail("Configuration non acceptable : " + reconf);
- }
+
+ configuration.update(reconf);
+ Thread.sleep(200);
// Check service properties after the reconfiguration
intProp = (Integer) sr.getProperty("int");
@@ -334,7 +327,7 @@ public class TestStaticPropsReconfigurat
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"));
+ assertEquals("Check strProp equality after reconfiguration", strProp, "toto");
assertNotNull("Check strAProp not nullity after reconfiguration", strAProp);
v = new String[]{"foo", "baz"};
for (int i = 0; i < strAProp.length; i++) {