diff options
author | sboshev | 2009-05-11 11:20:53 +0000 |
---|---|---|
committer | sboshev | 2009-05-11 11:20:53 +0000 |
commit | bd977365d94a498e80aec2b2a97d8e95b9a1098c (patch) | |
tree | 899c0963c5aacc4245f80766d3e1ebf2ad9dc85d /bundles/org.eclipse.equinox.ds.tests | |
parent | 7251a13924c3e0be584c4baefa06b4665bd36233 (diff) | |
download | rt.equinox.bundles-bd977365d94a498e80aec2b2a97d8e95b9a1098c.tar.gz rt.equinox.bundles-bd977365d94a498e80aec2b2a97d8e95b9a1098c.tar.xz rt.equinox.bundles-bd977365d94a498e80aec2b2a97d8e95b9a1098c.zip |
new DS tests added
Diffstat (limited to 'bundles/org.eclipse.equinox.ds.tests')
18 files changed, 1680 insertions, 616 deletions
diff --git a/bundles/org.eclipse.equinox.ds.tests/.classpath b/bundles/org.eclipse.equinox.ds.tests/.classpath index 7e682e418..2a5daf645 100644 --- a/bundles/org.eclipse.equinox.ds.tests/.classpath +++ b/bundles/org.eclipse.equinox.ds.tests/.classpath @@ -3,9 +3,9 @@ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> - <classpathentry kind="src" output="scr_test/tb2" path="bundles_src/tb2"/> <classpathentry kind="src" output="scr_test/tb1" path="bundles_src/tb1"/> - <classpathentry kind="src" output="scr_test/tb10" path="bundles_src/tb10"/> + <classpathentry kind="src" output="scr_test/tb1a" path="bundles_src/tb1a"/> + <classpathentry kind="src" output="scr_test/tb2" path="bundles_src/tb2"/> <classpathentry kind="src" output="scr_test/tb3" path="bundles_src/tb3"/> <classpathentry kind="src" output="scr_test/tb4" path="bundles_src/tb4"/> <classpathentry kind="src" output="scr_test/tb5" path="bundles_src/tb5"/> @@ -13,6 +13,7 @@ <classpathentry kind="src" output="scr_test/tb7" path="bundles_src/tb7"/> <classpathentry kind="src" output="scr_test/tb8" path="bundles_src/tb8"/> <classpathentry kind="src" output="scr_test/tb9" path="bundles_src/tb9"/> + <classpathentry kind="src" output="scr_test/tb10" path="bundles_src/tb10"/> <classpathentry kind="src" output="scr_test/tb11" path="bundles_src/tb11"/> <classpathentry kind="src" output="scr_test/tb12" path="bundles_src/tb12"/> <classpathentry kind="src" output="scr_test/tb13" path="bundles_src/tb13"/> @@ -22,5 +23,10 @@ <classpathentry kind="src" output="scr_test/tb17" path="bundles_src/tb17"/> <classpathentry kind="src" output="scr_test/tb18" path="bundles_src/tb18"/> <classpathentry kind="src" output="scr_test/tb19" path="bundles_src/tb19"/> + <classpathentry kind="src" output="scr_test/tb20" path="bundles_src/tb20"/> + <classpathentry kind="src" output="scr_test/tb21" path="bundles_src/tb21"/> + <classpathentry kind="src" output="scr_test/tb21a" path="bundles_src/tb21a"/> + <classpathentry kind="src" output="scr_test/tb22" path="bundles_src/tb22"/> + <classpathentry kind="src" output="scr_test/tb23" path="bundles_src/tb23"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/bundles/org.eclipse.equinox.ds.tests/build.properties b/bundles/org.eclipse.equinox.ds.tests/build.properties index c1dc252dd..291eb8db2 100644 --- a/bundles/org.eclipse.equinox.ds.tests/build.properties +++ b/bundles/org.eclipse.equinox.ds.tests/build.properties @@ -3,6 +3,7 @@ bin.includes = META-INF/,\ .,\ osgi_config.xml,\ scr_test/tb1.jar,\ + scr_test/tb1a.jar,\ scr_test/tb2.jar,\ scr_test/tb3.jar,\ scr_test/tb4.jar,\ @@ -20,9 +21,15 @@ bin.includes = META-INF/,\ scr_test/tb16.jar,\ scr_test/tb17.jar,\ scr_test/tb18.jar,\ - scr_test/tb19.jar + scr_test/tb19.jar,\ + scr_test/tb20.jar,\ + scr_test/tb21.jar,\ + scr_test/tb21a.jar,\ + scr_test/tb22.jar,\ + scr_test/tb23.jar jars.compile.order = .,\ scr_test/tb1.jar,\ + scr_test/tb1a.jar,\ scr_test/tb2.jar,\ scr_test/tb3.jar,\ scr_test/tb4.jar,\ @@ -31,7 +38,7 @@ jars.compile.order = .,\ scr_test/tb7.jar,\ scr_test/tb8.jar,\ scr_test/tb9.jar,\ - scr_test/tb10.jar,\ + scr_test/tb10.jar,\ scr_test/tb11.jar,\ scr_test/tb12.jar,\ scr_test/tb13.jar,\ @@ -40,9 +47,16 @@ jars.compile.order = .,\ scr_test/tb16.jar,\ scr_test/tb17.jar,\ scr_test/tb18.jar,\ - scr_test/tb19.jar + scr_test/tb19.jar,\ + scr_test/tb20.jar,\ + scr_test/tb21.jar,\ + scr_test/tb21a.jar,\ + scr_test/tb22.jar,\ + scr_test/tb23.jar source.scr_test/tb1.jar = bundles_src/tb1/ manifest.scr_test/tb1.jar = META-INF/MANIFEST.MF +source.scr_test/tb1a.jar = bundles_src/tb1a/ +manifest.scr_test/tb1a.jar = META-INF/MANIFEST.MF source.scr_test/tb2.jar = bundles_src/tb2/ manifest.scr_test/tb2.jar = META-INF/MANIFEST.MF source.scr_test/tb3.jar = bundles_src/tb3/ @@ -79,3 +93,13 @@ source.scr_test/tb18.jar = bundles_src/tb18/ manifest.scr_test/tb18.jar = META-INF/MANIFEST.MF source.scr_test/tb19.jar = bundles_src/tb19/ manifest.scr_test/tb19.jar = META-INF/MANIFEST.MF +source.scr_test/tb20.jar = bundles_src/tb20/ +manifest.scr_test/tb20.jar = META-INF/MANIFEST.MF +source.scr_test/tb21.jar = bundles_src/tb21/ +manifest.scr_test/tb21.jar = META-INF/MANIFEST.MF +source.scr_test/tb21a.jar = bundles_src/tb21a/ +manifest.scr_test/tb21a.jar = META-INF/MANIFEST.MF +source.scr_test/tb22.jar = bundles_src/tb22/ +manifest.scr_test/tb22.jar = META-INF/MANIFEST.MF +source.scr_test/tb23.jar = bundles_src/tb23/ +manifest.scr_test/tb23.jar = META-INF/MANIFEST.MF diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb20/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb20/META-INF/MANIFEST.MF new file mode 100644 index 000000000..1ae166041 --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb20/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-Name: Declaritive services test +Bundle-Description: Declaritive services TB20 +Bundle-Category: test +Bundle-ActivationPolicy: lazy +Import-Package: org.eclipse.equinox.ds.tests.tbc, + org.osgi.framework, + org.osgi.service.component;version="1.0.0" +Service-Component: org/eclipse/equinox/ds/tests/tb20/components.xml diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb20/org/eclipse/equinox/ds/tests/tb20/Comp.java b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb20/org/eclipse/equinox/ds/tests/tb20/Comp.java new file mode 100644 index 000000000..23dcefd7d --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb20/org/eclipse/equinox/ds/tests/tb20/Comp.java @@ -0,0 +1,25 @@ +package org.eclipse.equinox.ds.tests.tb20; + +import java.util.Dictionary; + +import org.eclipse.equinox.ds.tests.tbc.PropertiesProvider; +import org.osgi.service.component.ComponentContext; + +public class Comp implements PropertiesProvider { + private ComponentContext ctxt; + + protected void activate(ComponentContext ctxt) { + this.ctxt = ctxt; + } + + protected void deactivate(ComponentContext ctxt) { + + } + + public Dictionary getProperties() { + if (ctxt == null) + return null; + + return ctxt.getProperties(); + } +} diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb20/org/eclipse/equinox/ds/tests/tb20/components.xml b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb20/org/eclipse/equinox/ds/tests/tb20/components.xml new file mode 100644 index 000000000..9b7c119ee --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb20/org/eclipse/equinox/ds/tests/tb20/components.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<components> + + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb20.component" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb20.Comp"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + </component> + +</components> diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21/META-INF/MANIFEST.MF new file mode 100644 index 000000000..7d649f03b --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-Name: Declaritive services test +Bundle-Description: Declaritive services TB21 +Bundle-Category: test +Import-Package: org.eclipse.equinox.ds.tests.tbc, + org.osgi.framework, + org.osgi.service.component;version="1.0.0" +Service-Component: org/eclipse/equinox/ds/tests/tb21/components.xml diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21/org/eclipse/equinox/ds/tests/tb21/ModifyRegistrator.java b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21/org/eclipse/equinox/ds/tests/tb21/ModifyRegistrator.java new file mode 100644 index 000000000..a9e9027f8 --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21/org/eclipse/equinox/ds/tests/tb21/ModifyRegistrator.java @@ -0,0 +1,76 @@ +package org.eclipse.equinox.ds.tests.tb21; + +import java.util.Dictionary; +import java.util.Map; + +import org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; + +public class ModifyRegistrator implements ComponentContextProvider { + private Dictionary properties; + private ComponentContext ctxt; + private static final int MODIFIED = 1 << 0; + private static final int MOD = 1 << 1; + private static final int MOD_CC = 1 << 2; + private static final int MOD_BC = 1 << 3; + private static final int MOD_MAP = 1 << 4; + private static final int MOD_CC_BC_MAP = 1 << 5; + private static final int ACTIVATE = 1 << 6; + private static final int DEACTIVATE = 1 << 7; + + protected void activate(ComponentContext ctxt) { + this.ctxt = ctxt; + properties = ctxt.getProperties(); + setDataBits(ACTIVATE); + } + + protected void deactivate(ComponentContext ctxt) { + setDataBits(DEACTIVATE); + } + + protected void modified() { + setDataBits(MODIFIED); + } + + protected void mod() { + setDataBits(MOD); + } + + protected void modCc(ComponentContext ctxt) { + setDataBits(MOD_CC); + } + + protected void modBc(BundleContext bc) { + setDataBits(MOD_BC); + } + + protected void modMap(Map props) { + setDataBits(MOD_MAP); + } + + protected void modCcBcMap(ComponentContext ctxt, BundleContext bc, Map props) { + setDataBits(MOD_CC_BC_MAP); + } + + protected void throwException(ComponentContext ctxt) { + throw new RuntimeException("Test method throwException(ComponentContext) is called!"); + } + + public Dictionary getProperties() { + return properties; + } + + private void setDataBits(int value) { + if (properties == null) { + return; + } + Object prop = properties.get("config.base.data"); + int data = (prop instanceof Integer) ? ((Integer) prop).intValue() : 0; + properties.put("config.base.data", new Integer(data | value)); + } + + public ComponentContext getComponentContext() { + return ctxt; + } +} diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21/org/eclipse/equinox/ds/tests/tb21/components.xml b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21/org/eclipse/equinox/ds/tests/tb21/components.xml new file mode 100644 index 000000000..61fd7b88d --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21/org/eclipse/equinox/ds/tests/tb21/components.xml @@ -0,0 +1,116 @@ +<?xml version="1.0" encoding="UTF-8"?> +<components> + + <!-- This component provides service that is used in the latter components --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb21.provider" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + </component> + + <!-- This component has not set modified method, NS 1.0.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb21.notsetNS100" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="mod", NS 1.0.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb21.NoArgs100" + modified="mod" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="modCc", NS 1.0.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb21.CcNS100" + modified="modCc" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="modBc", NS 1.0.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb21.BcNS100" + modified="modBc" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="modMap", NS 1.0.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb21.MapNS100" + modified="modMap" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="modCcBcMap", NS 1.0.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb21.CcBcMapNS100" + modified="modCcBcMap" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> +</components> diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21a/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21a/META-INF/MANIFEST.MF new file mode 100644 index 000000000..46a8c1fc8 --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21a/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-Name: Declaritive services test +Bundle-Description: Declaritive services TB21a +Bundle-Category: test +Import-Package: org.eclipse.equinox.ds.tests.tbc, + org.osgi.framework, + org.osgi.service.component;version="1.0.0" +Service-Component: org/eclipse/equinox/ds/tests/tb21a/components.xml diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21a/org/eclipse/equinox/ds/tests/tb21a/ModifyRegistrator.java b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21a/org/eclipse/equinox/ds/tests/tb21a/ModifyRegistrator.java new file mode 100644 index 000000000..fcfe7ed3c --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21a/org/eclipse/equinox/ds/tests/tb21a/ModifyRegistrator.java @@ -0,0 +1,76 @@ +package org.eclipse.equinox.ds.tests.tb21a; + +import java.util.Dictionary; +import java.util.Map; + +import org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; + +public class ModifyRegistrator implements ComponentContextProvider { + private Dictionary properties; + private ComponentContext ctxt; + private static final int MODIFIED = 1 << 0; + private static final int MOD = 1 << 1; + private static final int MOD_CC = 1 << 2; + private static final int MOD_BC = 1 << 3; + private static final int MOD_MAP = 1 << 4; + private static final int MOD_CC_BC_MAP = 1 << 5; + private static final int ACTIVATE = 1 << 6; + private static final int DEACTIVATE = 1 << 7; + + protected void activate(ComponentContext ctxt) { + this.ctxt = ctxt; + properties = ctxt.getProperties(); + setDataBits(ACTIVATE); + } + + protected void deactivate(ComponentContext ctxt) { + setDataBits(DEACTIVATE); + } + + protected void modified() { + setDataBits(MODIFIED); + } + + protected void mod() { + setDataBits(MOD); + } + + protected void modCc(ComponentContext ctxt) { + setDataBits(MOD_CC); + } + + protected void modBc(BundleContext bc) { + setDataBits(MOD_BC); + } + + protected void modMap(Map props) { + setDataBits(MOD_MAP); + } + + protected void modCcBcMap(ComponentContext ctxt, BundleContext bc, Map props) { + setDataBits(MOD_CC_BC_MAP); + } + + protected void throwException(ComponentContext ctxt) { + throw new RuntimeException("Test method throwException(ComponentContext) is called!"); + } + + public Dictionary getProperties() { + return properties; + } + + private void setDataBits(int value) { + if (properties == null) { + return; + } + Object prop = properties.get("config.base.data"); + int data = (prop instanceof Integer) ? ((Integer) prop).intValue() : 0; + properties.put("config.base.data", new Integer(data | value)); + } + + public ComponentContext getComponentContext() { + return ctxt; + } +} diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21a/org/eclipse/equinox/ds/tests/tb21a/components.xml b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21a/org/eclipse/equinox/ds/tests/tb21a/components.xml new file mode 100644 index 000000000..85633b7c3 --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb21a/org/eclipse/equinox/ds/tests/tb21a/components.xml @@ -0,0 +1,150 @@ +<?xml version="1.0" encoding="UTF-8"?> +<components> + + <!-- This component provides service that is used in the latter components --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb21.provider" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21a.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + </component> + + <!-- This component has not set modified method, NS 1.1.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.1.0" + name="org.eclipse.equinox.ds.tests.tb21.notsetNS110" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21a.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="mod", NS 1.1.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.1.0" + name="org.eclipse.equinox.ds.tests.tb21.NoArgs110" + modified="mod" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21a.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="modCc", NS 1.1.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.1.0" + name="org.eclipse.equinox.ds.tests.tb21.CcNS110" + modified="modCc" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21a.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="modBc", NS 1.1.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.1.0" + name="org.eclipse.equinox.ds.tests.tb21.BcNS110" + modified="modBc" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21a.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="modMap", NS 1.1.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.1.0" + name="org.eclipse.equinox.ds.tests.tb21.MapNS110" + modified="modMap" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21a.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="modCcBcMap", NS 1.1.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.1.0" + name="org.eclipse.equinox.ds.tests.tb21.CcBcMapNS110" + modified="modCcBcMap" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21a.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="noSuchMethod", NS 1.1.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.1.0" + name="org.eclipse.equinox.ds.tests.tb21.NotExistNS110" + modified="noSuchMethod" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21a.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> + + <!-- modified="throwException", NS 1.1.0 --> + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.1.0" + name="org.eclipse.equinox.ds.tests.tb21.ThrowExNS110" + modified="throwException" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb21a.ModifyRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + target="(component.name=org.eclipse.equinox.ds.tests.tb21.provider)"/> + </component> +</components> diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb22/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb22/META-INF/MANIFEST.MF new file mode 100644 index 000000000..362dff399 --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb22/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-Name: Declaritive services test +Bundle-Description: Declaritive services TB22 +Bundle-Category: test +Import-Package: org.eclipse.equinox.ds.tests.tbc, + org.osgi.framework, + org.osgi.service.component;version="1.0.0" +Service-Component: org/eclipse/equinox/ds/tests/tb22/components.xml diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb22/org/eclipse/equinox/ds/tests/tb22/Comp.java b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb22/org/eclipse/equinox/ds/tests/tb22/Comp.java new file mode 100644 index 000000000..0bb66241d --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb22/org/eclipse/equinox/ds/tests/tb22/Comp.java @@ -0,0 +1,25 @@ +package org.eclipse.equinox.ds.tests.tb22; + +import java.util.Dictionary; + +import org.eclipse.equinox.ds.tests.tbc.PropertiesProvider; +import org.osgi.service.component.ComponentContext; + +public class Comp implements PropertiesProvider { + private ComponentContext ctxt; + + protected void activate(ComponentContext ctxt) { + this.ctxt = ctxt; + } + + protected void deactivate(ComponentContext ctxt) { + + } + + public Dictionary getProperties() { + if (ctxt == null) + return null; + + return ctxt.getProperties(); + } +} diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb22/org/eclipse/equinox/ds/tests/tb22/components.xml b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb22/org/eclipse/equinox/ds/tests/tb22/components.xml new file mode 100644 index 000000000..061ff78c2 --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb22/org/eclipse/equinox/ds/tests/tb22/components.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<components> + + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb22.component" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb22.Comp"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <property name=".prop1" value="1"/> + <property name=".prop2" value="2"/> + <property name=".prop3" value="3"/> + </component> + +</components> diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb23/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb23/META-INF/MANIFEST.MF new file mode 100644 index 000000000..a339357c1 --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb23/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-Name: Declaritive services test +Bundle-Description: Declaritive services TB23 +Bundle-Category: test +Import-Package: org.eclipse.equinox.ds.tests.tbc, + org.osgi.framework, + org.osgi.service.component;version="1.0.0" +Service-Component: org/eclipse/equinox/ds/tests/tb23/components.xml diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb23/org/eclipse/equinox/ds/tests/tb23/BindRegistrator.java b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb23/org/eclipse/equinox/ds/tests/tb23/BindRegistrator.java new file mode 100644 index 000000000..c8b77d5e8 --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb23/org/eclipse/equinox/ds/tests/tb23/BindRegistrator.java @@ -0,0 +1,56 @@ +package org.eclipse.equinox.ds.tests.tb23; + +import java.util.Dictionary; + +import org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider; +import org.osgi.framework.ServiceReference; +import org.osgi.service.component.ComponentContext; + +public class BindRegistrator implements ComponentContextProvider { + private Dictionary properties; + private ComponentContext ctxt; + private static final int BIND = 1 << 0; + private static final int UNBIND = 1 << 1; + private static final int ACTIVATE = 1 << 2; + private static final int DEACTIVATE = 1 << 3; + + protected void activate(ComponentContext ctxt) { + this.ctxt = ctxt; + properties = ctxt.getProperties(); + setDataBits(ACTIVATE); + } + + protected void deactivate(ComponentContext ctxt) { + setDataBits(DEACTIVATE); + } + + protected void bind(ServiceReference sr) { + setDataBits(BIND); + throw new RuntimeException("Test method throwException(ComponentContext) is called!"); + } + + protected void bind_ex(ServiceReference sr) { + throw new RuntimeException("Test method bind_ex(ServiceReference) is called!"); + } + + protected void unbind(ServiceReference sr) { + setDataBits(UNBIND); + } + + public Dictionary getProperties() { + return properties; + } + + private void setDataBits(int value) { + if (properties == null) { + return; + } + Object prop = properties.get("config.base.data"); + int data = (prop instanceof Integer) ? ((Integer) prop).intValue() : 0; + properties.put("config.base.data", new Integer(data | value)); + } + + public ComponentContext getComponentContext() { + return ctxt; + } +} diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb23/org/eclipse/equinox/ds/tests/tb23/components.xml b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb23/org/eclipse/equinox/ds/tests/tb23/components.xml new file mode 100644 index 000000000..6133d23f0 --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb23/org/eclipse/equinox/ds/tests/tb23/components.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<components> + + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb23.provider" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb23.BindRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + </component> + + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb23.mandatory" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb23.BindRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + cardinality="1..1" + bind="bind_ex" + unbind="unbind"/> + </component> + + <component + xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" + name="org.eclipse.equinox.ds.tests.tb23.optional" + immediate="true"> + <implementation + class="org.eclipse.equinox.ds.tests.tb23.BindRegistrator"/> + <service> + <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/> + </service> + <reference + interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider" + name="ref" + cardinality="0..1" + bind="bind_ex" + unbind="unbind"/> + </component> + +</components> diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java index 55268175c..8784d0d81 100644 --- a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java +++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java @@ -57,33 +57,61 @@ public class DSTest extends TestCase { private static final String MBSRC_CLASS = "org.eclipse.equinox.ds.tests.tb4.AdvancedBounder"; private static final String SECURITY_CLASS = "org.eclipse.equinox.ds.tests.tb5.impl.SecurityTester"; - + private static final String BLOCK_ACTIVE_CLASS = "org.eclipse.equinox.ds.tests.tb2.impl.Blocker"; - + private static final String BLOCK_BIND_CLASS = "org.eclipse.equinox.ds.tests.tb3.impl.BindBlocker"; - + private static final String STATIC_CLASS = "org.eclipse.equinox.ds.tests.tb6.StaticComp"; - + private static final String REFERENCED_CLASS = "org.eclipse.equinox.ds.tests.tb6.ReferencedComp"; - + private static final String NS_CLASS = "org.eclipse.equinox.ds.tests.tbc.NamespaceProvider"; - + private static final String COMP_OPTIONAL_100 = "org.eclipse.equinox.ds.tests.tb11.optionalNS100"; - + private static final String COMP_OPTIONAL_110 = "org.eclipse.equinox.ds.tests.tb11.optionalNS110"; - + private static final String COMP_REQUIRE_100 = "org.eclipse.equinox.ds.tests.tb11.requireNS100"; - + private static final String COMP_REQUIRE_110 = "org.eclipse.equinox.ds.tests.tb11.requireNS110"; - + private static final String COMP_IGNORE_100 = "org.eclipse.equinox.ds.tests.tb11.ignoreNS100"; - + private static final String COMP_IGNORE_110 = "org.eclipse.equinox.ds.tests.tb11.ignoreNS110"; - + private static final String COMP_NOTSET_100 = "org.eclipse.equinox.ds.tests.tb11.notsetNS100"; - + private static final String COMP_NOTSET_110 = "org.eclipse.equinox.ds.tests.tb11.notsetNS110"; - + + private static final String MOD_NOTSET_NS100 = "org.eclipse.equinox.ds.tests.tb21.notsetNS100"; + + private static final String MOD_NOTSET_NS110 = "org.eclipse.equinox.ds.tests.tb21.notsetNS110"; + + private static final String MOD_NOARGS_NS100 = "org.eclipse.equinox.ds.tests.tb21.NoArgs100"; + + private static final String MOD_NOARGS_NS110 = "org.eclipse.equinox.ds.tests.tb21.NoArgs110"; + + private static final String MOD_CC_NS100 = "org.eclipse.equinox.ds.tests.tb21.CcNS100"; + + private static final String MOD_CC_NS110 = "org.eclipse.equinox.ds.tests.tb21.CcNS110"; + + private static final String MOD_BC_NS100 = "org.eclipse.equinox.ds.tests.tb21.BcNS100"; + + private static final String MOD_BC_NS110 = "org.eclipse.equinox.ds.tests.tb21.BcNS110"; + + private static final String MOD_MAP_NS100 = "org.eclipse.equinox.ds.tests.tb21.MapNS100"; + + private static final String MOD_MAP_NS110 = "org.eclipse.equinox.ds.tests.tb21.MapNS110"; + + private static final String MOD_CC_BC_MAP_NS100 = "org.eclipse.equinox.ds.tests.tb21.CcBcMapNS100"; + + private static final String MOD_CC_BC_MAP_NS110 = "org.eclipse.equinox.ds.tests.tb21.CcBcMapNS110"; + + private static final String MOD_NOT_EXIST_NS110 = "org.eclipse.equinox.ds.tests.tb21.NotExistNS110"; + + private static final String MOD_THROW_EX_NS110 = "org.eclipse.equinox.ds.tests.tb21.ThrowExNS110"; + private static int timeout = 1000; private Bundle tb1; @@ -109,21 +137,21 @@ public class DSTest extends TestCase { private ServiceTracker trackerMBSRC; private ServiceTracker trackerSecurity; - + private ServiceTracker trackerBAS; - + private ServiceTracker trackerBBS; - + private ServiceTracker trackerStatic; - + private ServiceTracker trackerReferenced; - + private ServiceTracker trackerNS; - + private ServiceTracker trackerBoundServiceCounterFactory; - + private ServiceTracker trackerBoundServiceCounterHelperFactory; - + private ServiceTracker trackerStaticServiceCounterFactory; private ServiceTracker trackerBaseService; @@ -131,17 +159,17 @@ public class DSTest extends TestCase { private Hashtable registeredServices = new Hashtable(); private int scr_restart_timeout = 33000; - + private boolean synchronousBuild = false; - + private BundleInstaller installer; - + public void setUp() throws Exception { - DSTestsActivator.activateSCR(); - + DSTestsActivator.activateSCR(); + timeout = getSystemProperty("scr.test.timeout", timeout); scr_restart_timeout = getSystemProperty("scr.restart.timeout", scr_restart_timeout); - + String synchronousBuildProp = System.getProperty("equinox.ds.synchronous_build"); synchronousBuild = (synchronousBuildProp == null) || !synchronousBuildProp.equalsIgnoreCase("false"); @@ -150,7 +178,7 @@ public class DSTest extends TestCase { BundleContext bc = getContext(); installer = new BundleInstaller("/scr_test/", bc); - + // install test bundles tb1 = installBundle("tb1"); @@ -159,19 +187,16 @@ public class DSTest extends TestCase { waitBundleStart(); trackerNamedService = new ServiceTracker(bc, NAMED_CLASS, null); - Filter filter = bc - .createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '=' - + NAMED_CLASS + ")(" + Constants.OBJECTCLASS + '=' - + ComponentFactory.class.getName() + "))"); + Filter filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '=' + NAMED_CLASS + ")(" + + Constants.OBJECTCLASS + '=' + ComponentFactory.class.getName() + "))"); trackerNamedServiceFactory = new ServiceTracker(bc, filter, null); trackerCM = new ServiceTracker(bc, ConfigurationAdmin.class.getName(), null); trackerExtendedClass = new ServiceTracker(bc, EXTENDED_CLASS, null); trackerSAC = new ServiceTracker(bc, SAC_CLASS, null); trackerSC = new ServiceTracker(bc, SC_CLASS, null); trackerDynService = new ServiceTracker(bc, DYN_SERVICE_CLASS, null); - filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '=' - + DYN_SERVICE_CLASS + ")(" + Constants.OBJECTCLASS + '=' - + ComponentFactory.class.getName() + "))"); + filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '=' + DYN_SERVICE_CLASS + ")(" + + Constants.OBJECTCLASS + '=' + ComponentFactory.class.getName() + "))"); trackerDynServiceFactory = new ServiceTracker(bc, filter, null); trackerBSRC = new ServiceTracker(bc, BSRC_CLASS, null); trackerMBSRC = new ServiceTracker(bc, MBSRC_CLASS, null); @@ -181,14 +206,14 @@ public class DSTest extends TestCase { trackerStatic = new ServiceTracker(bc, STATIC_CLASS, null); trackerReferenced = new ServiceTracker(bc, REFERENCED_CLASS, null); trackerNS = new ServiceTracker(bc, NS_CLASS, null); - filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '=' - + "CountFactory" + ")(" + Constants.OBJECTCLASS + '=' + ComponentFactory.class.getName() + "))"); + filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '=' + "CountFactory" + ")(" + + Constants.OBJECTCLASS + '=' + ComponentFactory.class.getName() + "))"); trackerBoundServiceCounterFactory = new ServiceTracker(bc, filter, null); - filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '=' - + "CountHelperFactory" + ")(" + Constants.OBJECTCLASS + '=' + ComponentFactory.class.getName() + "))"); + filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '=' + "CountHelperFactory" + ")(" + + Constants.OBJECTCLASS + '=' + ComponentFactory.class.getName() + "))"); trackerBoundServiceCounterHelperFactory = new ServiceTracker(bc, filter, null); - filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '=' - + "StaticServiceCountFactory" + ")(" + Constants.OBJECTCLASS + '=' + ComponentFactory.class.getName() + "))"); + filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '=' + "StaticServiceCountFactory" + ")(" + + Constants.OBJECTCLASS + '=' + ComponentFactory.class.getName() + "))"); trackerStaticServiceCounterFactory = new ServiceTracker(bc, filter, null); trackerBaseService = new ServiceTracker(bc, PropertiesProvider.class.getName(), null); @@ -212,20 +237,20 @@ public class DSTest extends TestCase { trackerBoundServiceCounterFactory.open(); trackerBoundServiceCounterHelperFactory.open(); trackerStaticServiceCounterFactory.open(); - trackerBaseService.open(); + trackerBaseService.open(); } - + /** * This methods takes care of the configurations related to this test + * * @throws IOException * @throws InvalidSyntaxException * @throws InterruptedException */ private void clearConfigurations() throws IOException, InvalidSyntaxException { - ServiceReference cmSR = getContext().getServiceReference( - ConfigurationAdmin.class.getName()); + ServiceReference cmSR = getContext().getServiceReference(ConfigurationAdmin.class.getName()); if (cmSR == null) - return; + return; ConfigurationAdmin cm = (ConfigurationAdmin) getContext().getService(cmSR); // clean configurations from previous tests // clean factory configs for named service @@ -236,20 +261,43 @@ public class DSTest extends TestCase { clearConfiguration(cm, "(service.pid=" + SAC_CLASS + ")"); // clean configs for optionalNS100 clearConfiguration(cm, "(service.pid=" + COMP_OPTIONAL_100 + ")"); + clearConfiguration(cm, "(service.factoryPid=" + COMP_OPTIONAL_100 + ")"); // clean configs for optionalNS110 clearConfiguration(cm, "(service.pid=" + COMP_OPTIONAL_110 + ")"); + clearConfiguration(cm, "(service.factoryPid=" + COMP_OPTIONAL_110 + ")"); // clean configs for requireNS100 clearConfiguration(cm, "(service.pid=" + COMP_REQUIRE_100 + ")"); + clearConfiguration(cm, "(service.factoryPid=" + COMP_REQUIRE_100 + ")"); // clean configs for requireNS110 clearConfiguration(cm, "(service.pid=" + COMP_REQUIRE_110 + ")"); + clearConfiguration(cm, "(service.factoryPid=" + COMP_REQUIRE_110 + ")"); // clean configs for ignoreNS100 clearConfiguration(cm, "(service.pid=" + COMP_IGNORE_100 + ")"); + clearConfiguration(cm, "(service.factoryPid=" + COMP_IGNORE_100 + ")"); // clean configs for ignoreNS110 clearConfiguration(cm, "(service.pid=" + COMP_IGNORE_110 + ")"); + clearConfiguration(cm, "(service.factoryPid=" + COMP_IGNORE_110 + ")"); // clean configs for notsetNS100 clearConfiguration(cm, "(service.pid=" + COMP_NOTSET_100 + ")"); + clearConfiguration(cm, "(service.factoryPid=" + COMP_NOTSET_100 + ")"); // clean configs for notsetNS110 clearConfiguration(cm, "(service.pid=" + COMP_NOTSET_110 + ")"); + clearConfiguration(cm, "(service.factoryPid=" + COMP_NOTSET_110 + ")"); + + clearConfiguration(cm, "(service.pid=" + MOD_NOTSET_NS100 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_NOTSET_NS110 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_NOARGS_NS100 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_NOARGS_NS110 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_CC_NS100 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_CC_NS110 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_BC_NS100 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_BC_NS110 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_MAP_NS100 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_MAP_NS110 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_CC_BC_MAP_NS100 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_CC_BC_MAP_NS110 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_NOT_EXIST_NS110 + ")"); + clearConfiguration(cm, "(service.pid=" + MOD_THROW_EX_NS110 + ")"); getContext().ungetService(cmSR); try { @@ -277,13 +325,10 @@ public class DSTest extends TestCase { sleepTime = Integer.parseInt(propertyString); } catch (Exception e) { e.printStackTrace(); - System.out - .println("Error while parsing sleep value! The default one will be used : " - + defaultValue); + System.out.println("Error while parsing sleep value! The default one will be used : " + defaultValue); } if (sleepTime < 100) { - log("The sleep value is too low : " + sleepTime - + " ! The default one will be used : " + defaultValue); + log("The sleep value is too low : " + sleepTime + " ! The default one will be used : " + defaultValue); return defaultValue; } return sleepTime; @@ -293,6 +338,7 @@ public class DSTest extends TestCase { /* * (non-Javadoc) + * * @see org.eclipse.equinox.ds.tests.tbc.DSTest.#tearDown() */ public void tearDown() throws Exception { @@ -316,45 +362,49 @@ public class DSTest extends TestCase { trackerBoundServiceCounterFactory.close(); trackerBoundServiceCounterHelperFactory.close(); trackerBaseService.close(); - + if (installer != null) { - BundleInstaller bi = installer; - installer = null; - bi.shutdown(); + BundleInstaller bi = installer; + installer = null; + bi.shutdown(); } - + clearConfigurations(); } public void testBindUnbind() throws Exception { - + assertEquals("TestBundle1 must be running.", Bundle.ACTIVE, tb1.getState()); + Bundle tb1a = installBundle("tb1a"); + tb1a.start(); + waitBundleStart(); + ServiceReference sr1 = getContext().getServiceReference("org.eclipse.equinox.ds.tests.tb1a.Comp1"); + assertNotNull("Incorrect components should be ignored and the component Comp1 should be available", sr1); + getContext().ungetService(sr1); + uninstallBundle(tb1a); + Object s = trackerExtendedClass.getService(); assertNotNull("The BindUnbindSuccessor component should be available", s); - - assertTrue( - "The bind method on BindUnbindSuccessor component should be called to save the service reference", + + assertTrue("The bind method on BindUnbindSuccessor component should be called to save the service reference", ((BoundTester) s).getBoundObjectsCount() > 0); // disable the referenced component to trigger unbind event ComponentManager enabler = (ComponentManager) s; enabler.enableComponent(SAC_CLASS, false); Thread.sleep(timeout); - - assertNull("The SAC component should be disabled (unavailable)", trackerSAC - .getServiceReference()); - - assertTrue( - "The unbind method on BindUnbindSuccessor component should be called to reset the service reference", + + assertNull("The SAC component should be disabled (unavailable)", trackerSAC.getServiceReference()); + + assertTrue("The unbind method on BindUnbindSuccessor component should be called to reset the service reference", ((BoundTester) s).getBoundObjectsCount() < 1); // enable the referenced component enabler = (ComponentManager) trackerExtendedClass.getService(); enabler.enableComponent(SAC_CLASS, true); Thread.sleep(timeout); - assertNotNull("The SAC component should be available", trackerSAC - .getServiceReference()); + assertNotNull("The SAC component should be available", trackerSAC.getServiceReference()); } public void testUniqueComponentContext() throws Exception { @@ -363,8 +413,7 @@ public class DSTest extends TestCase { waitBundleStart(); Hashtable props; - ComponentFactory factory = (ComponentFactory) trackerNamedServiceFactory - .getService(); + ComponentFactory factory = (ComponentFactory) trackerNamedServiceFactory.getService(); assertNotNull("The NamedService component factory should be available", factory); // create the first service @@ -394,84 +443,70 @@ public class DSTest extends TestCase { assertNotNull("BindUnbindSuccessor component should be available", extendedClass); ComponentContext ctxt = ((ComponentContextProvider) extendedClass).getComponentContext(); - assertNotNull( - "The BindUnbindSuccessor component should be activated properly", - ctxt); + assertNotNull("The BindUnbindSuccessor component should be activated properly", ctxt); - assertNotNull("The AnotherComponent should be available before we disable it", - trackerSAC.getServiceReferences()); + assertNotNull("The AnotherComponent should be available before we disable it", trackerSAC.getServiceReferences()); assertTrue("The AnotherComponent should be available before we disable it", trackerSAC.getServiceReferences().length > 0); - assertNotNull("The Worker should be available before we disable it", - trackerSC.getServiceReferences()); - assertTrue("The Worker should be available before we disable it", - trackerSC.getServiceReferences().length > 0); + assertNotNull("The Worker should be available before we disable it", trackerSC.getServiceReferences()); + assertTrue("The Worker should be available before we disable it", trackerSC.getServiceReferences().length > 0); // *** test disableComponent() method boolean exceptionThrown = false; try { - ((ComponentManager)extendedClass).enableComponent("InvalidParameter", true); // test for disabling unexistent + ((ComponentManager) extendedClass).enableComponent("InvalidParameter", true); // test + // for + // disabling + // unexistent } catch (IllegalArgumentException iae) { - //expected exception + // expected exception exceptionThrown = true; } catch (Exception e) { - //unexpected exception - fail("Unexpected exception "+e.getMessage()); + // unexpected exception + fail("Unexpected exception " + e.getMessage()); } if (!exceptionThrown) { fail("Expected IllegalArgumentException but not thrown"); } - - ((ComponentManager)extendedClass).enableComponent(SAC_CLASS, false); + + ((ComponentManager) extendedClass).enableComponent(SAC_CLASS, false); Thread.sleep(timeout * 2); // let the SCR to unregister the service - assertNull( - "The service must not be available after we had disabled the component (AnotherComponent)", - trackerSAC.getServiceReferences()); + assertNull("The service must not be available after we had disabled the component (AnotherComponent)", trackerSAC + .getServiceReferences()); - ((ComponentManager)extendedClass).enableComponent(SC_CLASS, false); - Thread.sleep(timeout * 2); // let the SCR to unregister the service - assertNull( - "The service must not be available after we had disabled the component (Worker)", - trackerSC.getServiceReferences()); + ((ComponentManager) extendedClass).enableComponent(SC_CLASS, false); + Thread.sleep(timeout * 2); // let the SCR to unregister the service + assertNull("The service must not be available after we had disabled the component (Worker)", trackerSC + .getServiceReferences()); - //*** test enableComponent() method - ((ComponentManager)extendedClass).enableComponent(SAC_CLASS, true); + // *** test enableComponent() method + ((ComponentManager) extendedClass).enableComponent(SAC_CLASS, true); Thread.sleep(timeout * 2); // let the SCR to register the service - assertNotNull( - "The service must be available after we had enabled the component", - trackerSAC.getServiceReferences()); - assertTrue( - "The service must be available after we had enabled the component", + assertNotNull("The service must be available after we had enabled the component", trackerSAC.getServiceReferences()); + assertTrue("The service must be available after we had enabled the component", trackerSAC.getServiceReferences().length > 0); - ((ComponentManager)extendedClass).enableComponent(null, true); + ((ComponentManager) extendedClass).enableComponent(null, true); Thread.sleep(timeout * 2); - assertNotNull( - "The enableComponent() with passed null parameter, must enable the remaining disabled components", + assertNotNull("The enableComponent() with passed null parameter, must enable the remaining disabled components", trackerSC.getServiceReferences()); - assertTrue( - "The enableComponent() with passed null parameter, must enable the remaining disabled components", + assertTrue("The enableComponent() with passed null parameter, must enable the remaining disabled components", trackerSC.getServiceReferences().length > 0); - //*** test getBundleContext() - BundleContextProvider sacBCE = (BundleContextProvider) trackerSAC - .getService(); + // *** test getBundleContext() + BundleContextProvider sacBCE = (BundleContextProvider) trackerSAC.getService(); assertNotNull("AnotherComponent should be available", sacBCE); - assertSame( - "The two bundle context (this from the activator and from the ComponentContext object must be the same", - sacBCE.getBundleContext(), - ((ComponentContextProvider)extendedClass).getComponentContext().getBundleContext() - ); + assertSame("The two bundle context (this from the activator and from the ComponentContext object must be the same", + sacBCE.getBundleContext(), ((ComponentContextProvider) extendedClass).getComponentContext().getBundleContext()); - //*** test getComponentInstance() + // *** test getComponentInstance() Bundle bundle = installBundle("tb4"); assertNotNull("Installing tb4.jar should succeed", bundle); bundle.start(); waitBundleStart(); Hashtable props; - ComponentFactory factory = (ComponentFactory) trackerNamedServiceFactory - .getService(); + ComponentFactory factory = (ComponentFactory) trackerNamedServiceFactory.getService(); assertNotNull("NamedService component factory should be available", factory); props = new Hashtable(); @@ -483,88 +518,89 @@ public class DSTest extends TestCase { assertNotNull("getInstance() should not return null if we haven't disposed the component", cce); assertNotNull("the component instance should be initialized correctly", cce.getComponentContext()); ComponentInstance ctxtInstance = cce.getComponentContext().getComponentInstance(); - assertSame("The ComponentInstance object retrieved from the factory and from the ComponentContext must be the same", - ci, ctxtInstance); + assertSame( + "The ComponentInstance object retrieved from the factory and from the ComponentContext must be the same", ci, + ctxtInstance); // dispose the instance ci.dispose(); assertNull("getInstance() should return null when disposed", ci.getInstance()); - - //*** test getUsingBundle() + + // *** test getUsingBundle() ComponentContextProvider simpleComponentCCE = (ComponentContextProvider) trackerSC.getService(); assertNotNull("Worker should be available", simpleComponentCCE); assertNotNull("Worker's context should be not null", simpleComponentCCE.getComponentContext()); - assertNotNull("At least this bundle (TBC) must be using the Worker service", simpleComponentCCE.getComponentContext().getUsingBundle()); + assertNotNull("At least this bundle (TBC) must be using the Worker service", simpleComponentCCE + .getComponentContext().getUsingBundle()); - //*** test getProperties() + // *** test getProperties() Dictionary p = simpleComponentCCE.getComponentContext().getProperties(); assertNotNull("Worker properties must be not null", p); - assertEquals("The properties must contain the custom property defined in the component description", - p.get("custom"), "customvalue"); - assertEquals("The properties must contain the component.name property", - p.get(ComponentConstants.COMPONENT_NAME), SC_CLASS); - assertNotNull("The properties must contain the component.id property", - p.get(ComponentConstants.COMPONENT_ID)); - assertEquals("The component.id property must be of type java.lang.Long", - p.get(ComponentConstants.COMPONENT_ID).getClass().getName(), - Long.class.getName()); - - //*** test getServiceReference() + assertEquals("The properties must contain the custom property defined in the component description", p + .get("custom"), "customvalue"); + assertEquals("The properties must contain the component.name property", p.get(ComponentConstants.COMPONENT_NAME), + SC_CLASS); + assertNotNull("The properties must contain the component.id property", p.get(ComponentConstants.COMPONENT_ID)); + assertEquals("The component.id property must be of type java.lang.Long", p.get(ComponentConstants.COMPONENT_ID) + .getClass().getName(), Long.class.getName()); + + // *** test getServiceReference() ServiceReference ctxtServiceReference = ctxt.getServiceReference(); ServiceReference bcServiceReference = trackerExtendedClass.getServiceReference(); - assertEquals("The two ServiceReference should be equal",ctxtServiceReference, bcServiceReference); + assertEquals("The two ServiceReference should be equal", ctxtServiceReference, bcServiceReference); - //*** test locateService(String) + // *** test locateService(String) Object locateSac = ctxt.locateService("StandAloneComp"); - assertNotNull("The locateService() method should return non-null object", - locateSac); + assertNotNull("The locateService() method should return non-null object", locateSac); assertEquals("The object must implement " + SAC_CLASS, locateSac.getClass().getName(), SAC_CLASS); // test illegal call assertNull("Trying to get invalid reference should return null", ctxt.locateService("InvalidReference")); - ((ComponentManager)extendedClass).enableComponent(SAC_CLASS, false); // disable component to test that the locateService() don't return disabled components + ((ComponentManager) extendedClass).enableComponent(SAC_CLASS, false); // disable + // component + // to + // test + // that + // the + // locateService() + // don't + // return + // disabled + // components Thread.sleep(timeout); assertEquals("Check that the component is correctly disabled", 0, countAvailableServices(trackerSAC)); locateSac = ctxt.locateService("StandAloneComp"); - assertNull("The reference shouldn't be available with optional cardinality and disabled component", - locateSac); + assertNull("The reference shouldn't be available with optional cardinality and disabled component", locateSac); - ((ComponentManager)extendedClass).enableComponent(SAC_CLASS, true); + ((ComponentManager) extendedClass).enableComponent(SAC_CLASS, true); Thread.sleep(timeout * 2); assertTrue("Check that the component is correctly enabled", countAvailableServices(trackerSAC) > 0); - //*** test locateServices(String) + // *** test locateServices(String) Object[] boundObjects = ctxt.locateServices("StandAloneComp"); - int boundCount = ((BoundTester)extendedClass).getBoundObjectsCount(); + int boundCount = ((BoundTester) extendedClass).getBoundObjectsCount(); assertNotNull("The returned array of bound services should not be null", boundObjects); - assertEquals( - "The returned array of bound services should have the length equal to the internal count", - boundCount, boundObjects.length); + assertEquals("The returned array of bound services should have the length equal to the internal count", boundCount, + boundObjects.length); for (int i = 0; i < boundObjects.length; i++) { - assertNotNull( - "There shouldn't be null element in the bound objects array (" + i - + ")", boundObjects[i]); + assertNotNull("There shouldn't be null element in the bound objects array (" + i + ")", boundObjects[i]); } - assertNull("The locateServices() method should return null on invalid reference name", - ctxt.locateServices("InvalidReference")); + assertNull("The locateServices() method should return null on invalid reference name", ctxt + .locateServices("InvalidReference")); + + // *** test locateService(String, ServiceReference) + assertTrue("There must be at least one bound element", ((BoundTester) extendedClass).getBoundObjectsCount() > 0); - //*** test locateService(String, ServiceReference) - assertTrue("There must be at least one bound element", - ((BoundTester) extendedClass).getBoundObjectsCount() > 0); - ServiceReference sr1 = ((BoundTester) extendedClass).getBoundServiceRef(0); - assertNotNull("The ServiceReference bound to the BindUnbindSuccessor components should not be null", - sr1); + assertNotNull("The ServiceReference bound to the BindUnbindSuccessor components should not be null", sr1); Object fromSR1 = ctxt.getBundleContext().getService(sr1); Object fromCtxt = ctxt.locateService("StandAloneComp", sr1); try { - assertNotNull("The service object from BundleContext must not be null", - fromSR1); - assertNotNull("The service object from locateService() must not be null", - fromCtxt); + assertNotNull("The service object from BundleContext must not be null", fromSR1); + assertNotNull("The service object from locateService() must not be null", fromCtxt); assertSame( "The two objects retrieved from BundleContext and from locateService(String, ServiceReference) method must be the same", fromSR1, fromCtxt); @@ -572,13 +608,11 @@ public class DSTest extends TestCase { ctxt.getBundleContext().ungetService(sr1); } - assertNull( - "locateService() must return null when passed ServiceReference is null", - ctxt.locateService("StandAloneComp", null)); + assertNull("locateService() must return null when passed ServiceReference is null", ctxt.locateService( + "StandAloneComp", null)); - assertNull( - "locateService() must return null when passed ServiceReference isn't bound to the component", - ctxt.locateService("StandAloneComp", trackerExtendedClass.getServiceReference())); + assertNull("locateService() must return null when passed ServiceReference isn't bound to the component", ctxt + .locateService("StandAloneComp", trackerExtendedClass.getServiceReference())); assertNull( "locateService() must return null when the referenceName isn't correct even if the service reference is correct", @@ -601,8 +635,7 @@ public class DSTest extends TestCase { // see CM api for details assertNotNull("The ConfigurationAdmin should be available", cm); Configuration config = cm.getConfiguration(SAC_CLASS); - assertNotNull("The Configuration object should be created if don't exist", - config); + assertNotNull("The Configuration object should be created if don't exist", config); config.update(props); // let SCR & CM to complete it's job @@ -610,26 +643,21 @@ public class DSTest extends TestCase { ref = trackerSAC.getServiceReference(); // check the correctness of the properties - assertNotNull("The AnotherComponent's reference should be available", - ref); - assertEquals("Properties not overriden from later ones should not be lost", - "setFromFile", ref.getProperty("test.property.array")); - assertEquals( - "Properties set through the CM should take precedence before those set from file", - "setFromCM", ref.getProperty("test.property.value")); - assertEquals( - "Properties overriden from later ones in definition should take precedence", - "setFromDefinition", ref.getProperty("test.property.name")); - assertEquals( - "Properties set through the CM should take precedence before those set from definition", - "setFromCM", ref.getProperty("test.property.list")); - assertEquals("Properties not overriden from later ones should not be lost", - "setFromDefinition", ref.getProperty("test.property.cont")); - assertEquals("Must not allow overriding the component.name property", - SAC_CLASS, ref.getProperty("component.name")); + assertNotNull("The AnotherComponent's reference should be available", ref); + assertEquals("Properties not overriden from later ones should not be lost", "setFromFile", ref + .getProperty("test.property.array")); + assertEquals("Properties set through the CM should take precedence before those set from file", "setFromCM", ref + .getProperty("test.property.value")); + assertEquals("Properties overriden from later ones in definition should take precedence", "setFromDefinition", ref + .getProperty("test.property.name")); + assertEquals("Properties set through the CM should take precedence before those set from definition", "setFromCM", + ref.getProperty("test.property.list")); + assertEquals("Properties not overriden from later ones should not be lost", "setFromDefinition", ref + .getProperty("test.property.cont")); + assertEquals("Must not allow overriding the component.name property", SAC_CLASS, ref.getProperty("component.name")); assertNotNull("component.id property should be present", ref.getProperty(ComponentConstants.COMPONENT_ID)); - assertTrue("Must not allow overriding the component.id property", - ((Long) ref.getProperty("component.id")).longValue() > 0); + assertTrue("Must not allow overriding the component.id property", ((Long) ref.getProperty("component.id")) + .longValue() > 0); Bundle bundle = installBundle("tb4"); bundle.start(); @@ -640,14 +668,12 @@ public class DSTest extends TestCase { Hashtable cmProps = new Hashtable(); cmProps.put("override.property.3", "setFromCM"); c.update(cmProps); - + // let the config update reach the SCR Thread.sleep(timeout * 3); - ComponentFactory factory = (ComponentFactory) trackerNamedServiceFactory - .getService(); - assertNotNull("The NamedService ComponentFactory should be available", - factory); + ComponentFactory factory = (ComponentFactory) trackerNamedServiceFactory.getService(); + assertNotNull("The NamedService ComponentFactory should be available", factory); Hashtable newProps = new Hashtable(); newProps.put("override.property.1", "setFromMethod"); @@ -666,20 +692,16 @@ public class DSTest extends TestCase { ServiceReference current = refs[i]; if ("test".equals(current.getProperty("name"))) { serviceFound = true; - assertEquals( - "Properties set through newInstance method must override those from definition", - "setFromMethod", current.getProperty("override.property.1")); - assertEquals( - "Properties set through newInstance method must override those from file", - "setFromMethod", current.getProperty("override.property.2")); - assertEquals( - "Properties set through newInstance method must override those from ConfigurationAdmin", + assertEquals("Properties set through newInstance method must override those from definition", "setFromMethod", + current.getProperty("override.property.1")); + assertEquals("Properties set through newInstance method must override those from file", "setFromMethod", + current.getProperty("override.property.2")); + assertEquals("Properties set through newInstance method must override those from ConfigurationAdmin", "setFromMethod", current.getProperty("override.property.3")); - assertEquals("Must not override " + ComponentConstants.COMPONENT_NAME, - current.getProperty(ComponentConstants.COMPONENT_NAME), NAMED_CLASS); - assertTrue("Must not override " + ComponentConstants.COMPONENT_ID, - ((Long) current.getProperty(ComponentConstants.COMPONENT_ID)) - .longValue() > 0); + assertEquals("Must not override " + ComponentConstants.COMPONENT_NAME, current + .getProperty(ComponentConstants.COMPONENT_NAME), NAMED_CLASS); + assertTrue("Must not override " + ComponentConstants.COMPONENT_ID, ((Long) current + .getProperty(ComponentConstants.COMPONENT_ID)).longValue() > 0); } } assertTrue("Must have found service", serviceFound); @@ -690,17 +712,14 @@ public class DSTest extends TestCase { // test the conflict between factory and factoryPID c = cm.createFactoryConfiguration(NAMED_CLASS); - assertNotNull( - "CM should not return null Configuration from createFactoryConfiguration()", - c); + assertNotNull("CM should not return null Configuration from createFactoryConfiguration()", c); c.update(cmProps); Thread.sleep(timeout); - + bundle.start(); waitBundleStart(); - assertNull( - "The named service shouldn't be available when there is factory configuration for it", + assertNull("The named service shouldn't be available when there is factory configuration for it", trackerNamedServiceFactory.getService()); c.delete(); @@ -711,12 +730,12 @@ public class DSTest extends TestCase { Hashtable scProps1 = new Hashtable(); scProps1.put("name", "instance1"); scConfig1.update(scProps1); - + Configuration scConfig2 = cm.createFactoryConfiguration(SC_CLASS); Hashtable scProps2 = new Hashtable(); scProps2.put("name", "instance2"); scConfig2.update(scProps2); - + Thread.sleep(timeout * 3); try {// test factory configuration for normal component @@ -726,11 +745,11 @@ public class DSTest extends TestCase { scConfig2.delete(); } Thread.sleep(timeout * 3); - + assertEquals("The Worker should have one instance", 1, countAvailableServices(trackerSC)); ServiceReference scRef = trackerSC.getServiceReference(); assertNull("The Worker only instance shouldn't have \"name\" property", scRef.getProperty("name")); - + uninstallBundle(bundle); } @@ -744,49 +763,34 @@ public class DSTest extends TestCase { waitBundleStart(); assertEquals("tb4.jar should be ACTIVE", Bundle.ACTIVE, tb4.getState()); - ComponentFactory namedFactory = (ComponentFactory) trackerNamedServiceFactory - .getService(); - assertNotNull("NamedService component factory should be available", - namedFactory); - ComponentFactory dynFactory = (ComponentFactory) trackerDynServiceFactory - .getService(); - assertNotNull("DynamicWorker component factory should be available", - dynFactory); + ComponentFactory namedFactory = (ComponentFactory) trackerNamedServiceFactory.getService(); + assertNotNull("NamedService component factory should be available", namedFactory); + ComponentFactory dynFactory = (ComponentFactory) trackerDynServiceFactory.getService(); + assertNotNull("DynamicWorker component factory should be available", dynFactory); // create the mandatory elements - ComponentInstance namedServiceInstance = namedFactory - .newInstance((Dictionary) mandatoryProperty.clone()); - assertNotNull("NamedService component instance should not be null", - namedServiceInstance); + ComponentInstance namedServiceInstance = namedFactory.newInstance((Dictionary) mandatoryProperty.clone()); + assertNotNull("NamedService component instance should not be null", namedServiceInstance); Object namedService = namedServiceInstance.getInstance(); assertNotNull("NamedService should be created properly", namedService); - ComponentInstance dynServiceInstance = dynFactory - .newInstance((Dictionary) mandatoryProperty.clone()); - assertNotNull("DynamicWorker component instance should not be null", - dynServiceInstance); + ComponentInstance dynServiceInstance = dynFactory.newInstance((Dictionary) mandatoryProperty.clone()); + assertNotNull("DynamicWorker component instance should not be null", dynServiceInstance); Object dynService = dynServiceInstance.getInstance(); assertNotNull("DynamicWorker should be created properly", dynService); Thread.sleep(timeout * 2); Object bsrc = trackerBSRC.getService(); - assertNotNull("BoundReplacer should be available", - bsrc); - assertSame("NamedService bound should be our first instance", - ((BoundMainProvider) bsrc) - .getBoundService(BoundMainProvider.NAMED_SERVICE), namedService); - assertSame("DynamicWorker bound should be our first instance", - ((BoundMainProvider) bsrc) - .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), dynService); + assertNotNull("BoundReplacer should be available", bsrc); + assertSame("NamedService bound should be our first instance", ((BoundMainProvider) bsrc) + .getBoundService(BoundMainProvider.NAMED_SERVICE), namedService); + assertSame("DynamicWorker bound should be our first instance", ((BoundMainProvider) bsrc) + .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), dynService); // provide second dynamic service - ComponentInstance dynServiceInstance2 = dynFactory - .newInstance((Dictionary) mandatoryProperty.clone()); - assertNotNull( - "Second DynamicWorker component instance should not be null", - dynServiceInstance2); + ComponentInstance dynServiceInstance2 = dynFactory.newInstance((Dictionary) mandatoryProperty.clone()); + assertNotNull("Second DynamicWorker component instance should not be null", dynServiceInstance2); Object dynService2 = dynServiceInstance2.getInstance(); - assertNotNull("Second DynamicWorker instance should be available", - dynService2); + assertNotNull("Second DynamicWorker instance should be available", dynService2); // reset the events ((DSEventsProvider) bsrc).resetEvents(); @@ -794,87 +798,61 @@ public class DSTest extends TestCase { dynServiceInstance.dispose(); // check that service is replaced - assertNotSame( - "The bound dynamic service shouldn't be our first instance", - ((BoundMainProvider) bsrc) - .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), dynService); - assertSame("The bound dynamic service should be our second instance", - ((BoundMainProvider) bsrc) - .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), - dynService2); + assertNotSame("The bound dynamic service shouldn't be our first instance", ((BoundMainProvider) bsrc) + .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), dynService); + assertSame("The bound dynamic service should be our second instance", ((BoundMainProvider) bsrc) + .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), dynService2); // check the correct order of replacing - DSEvent[] replacedBoundDynamicServicesEvents = ((DSEventsProvider) bsrc) - .getEvents(); - assertEquals( - "There should two events after we have disposed the bound service", - 2, replacedBoundDynamicServicesEvents.length); - assertEquals("The first event should be bind event", - DSEvent.ACT_BOUND, replacedBoundDynamicServicesEvents[0] - .getAction()); - assertSame( - "The first event should have associated object the second instance", - dynService2, replacedBoundDynamicServicesEvents[0].getObject()); - - assertEquals("The second event should be unbind event", - DSEvent.ACT_UNBOUND, replacedBoundDynamicServicesEvents[1] - .getAction()); - assertSame( - "The second event should have associated object the first instance", - dynService, replacedBoundDynamicServicesEvents[1].getObject()); + DSEvent[] replacedBoundDynamicServicesEvents = ((DSEventsProvider) bsrc).getEvents(); + assertEquals("There should two events after we have disposed the bound service", 2, + replacedBoundDynamicServicesEvents.length); + assertEquals("The first event should be bind event", DSEvent.ACT_BOUND, replacedBoundDynamicServicesEvents[0] + .getAction()); + assertSame("The first event should have associated object the second instance", dynService2, + replacedBoundDynamicServicesEvents[0].getObject()); + + assertEquals("The second event should be unbind event", DSEvent.ACT_UNBOUND, replacedBoundDynamicServicesEvents[1] + .getAction()); + assertSame("The second event should have associated object the first instance", dynService, + replacedBoundDynamicServicesEvents[1].getObject()); // destroy and the second service dynServiceInstance2.dispose(); // check that the inspected service is deactivated - assertNull( - "The BoundReplacer should not be available as the destroyed service hasn't replacement", - trackerBSRC.getService()); + assertNull("The BoundReplacer should not be available as the destroyed service hasn't replacement", trackerBSRC + .getService()); // restore the BSRC - assertNotNull( - "The DynamicWorker component instance should be created properly", - dynFactory.newInstance((Dictionary) mandatoryProperty.clone())); + assertNotNull("The DynamicWorker component instance should be created properly", dynFactory + .newInstance((Dictionary) mandatoryProperty.clone())); Thread.sleep(timeout); Object bsrcObject = trackerBSRC.getService(); - assertNotNull( - "The BoundReplacer should be available again", - bsrcObject); - ComponentContext bsrcCtxt1 = ((ComponentContextProvider) bsrcObject) - .getComponentContext(); - assertNotNull( - "The BoundReplacer should be activated and ComponentContext available", - bsrcCtxt1); + assertNotNull("The BoundReplacer should be available again", bsrcObject); + ComponentContext bsrcCtxt1 = ((ComponentContextProvider) bsrcObject).getComponentContext(); + assertNotNull("The BoundReplacer should be activated and ComponentContext available", bsrcCtxt1); // prepare second static service instance - ComponentInstance namedServiceInstance2 = namedFactory - .newInstance((Dictionary) mandatoryProperty.clone()); - assertNotNull("Second NamedService instance should be created properly", - namedServiceInstance2); + ComponentInstance namedServiceInstance2 = namedFactory.newInstance((Dictionary) mandatoryProperty.clone()); + assertNotNull("Second NamedService instance should be created properly", namedServiceInstance2); Object namedService2 = namedServiceInstance2.getInstance(); - assertNotNull("Second NamedService instance should be created properly", - namedService2); + assertNotNull("Second NamedService instance should be created properly", namedService2); // destroy the first instance beforeCount = countAvailableServices(trackerNamedService); namedServiceInstance.dispose(); afterCount = countAvailableServices(trackerNamedService); - assertEquals( - "The NamedService instance should be removed from the registry", - beforeCount - 1, afterCount); + assertEquals("The NamedService instance should be removed from the registry", beforeCount - 1, afterCount); // check that the BSRC has been reactivated Object bsrcObject2 = trackerBSRC.getService(); // the BSRC object can be // recreated - assertNotNull("The BoundReplacer should not be null", - bsrcObject2); - ComponentContext bsrcCtxt2 = ((ComponentContextProvider) bsrcObject2) - .getComponentContext(); + assertNotNull("The BoundReplacer should not be null", bsrcObject2); + ComponentContext bsrcCtxt2 = ((ComponentContextProvider) bsrcObject2).getComponentContext(); assertNotNull("The second ComponentContext should not be null", bsrcCtxt2); - assertNotSame( - "The second ComponentContext should be different than the first one", - bsrcCtxt1, bsrcCtxt2); + assertNotSame("The second ComponentContext should be different than the first one", bsrcCtxt1, bsrcCtxt2); // destroy the second instance namedServiceInstance2.dispose(); @@ -904,10 +882,10 @@ public class DSTest extends TestCase { initialProps.put("mandatory.property", "true"); modifiedProps.put("mandatory.property", "false"); - ServiceRegistration dynRegistration1 = registerService(DynamicWorker.class.getName(), new DynamicWorker(), (Dictionary) initialProps.clone()); + ServiceRegistration dynRegistration1 = registerService(DynamicWorker.class.getName(), new DynamicWorker(), + (Dictionary) initialProps.clone()); - ServiceRegistration staticRegistration1 = registerService( - StaticWorker.class.getName(), new StaticWorker(), + ServiceRegistration staticRegistration1 = registerService(StaticWorker.class.getName(), new StaticWorker(), (Dictionary) initialProps.clone()); Bundle tb4 = installBundle("tb4"); @@ -916,14 +894,12 @@ public class DSTest extends TestCase { assertEquals("tb4.jar should be ACTIVE", Bundle.ACTIVE, tb4.getState()); // assure the MBSRC is available - assertTrue("The AdvancedBounder must be available", - countAvailableServices(trackerMBSRC) > 0); + assertTrue("The AdvancedBounder must be available", countAvailableServices(trackerMBSRC) > 0); Object bsrc = trackerMBSRC.getService(); assertNotNull("MBSRC isntance should be not null", bsrc); // register the second instances - ServiceRegistration dynRegistration2 = registerService( - DynamicWorker.class.getName(), new DynamicWorker(), + ServiceRegistration dynRegistration2 = registerService(DynamicWorker.class.getName(), new DynamicWorker(), (Dictionary) initialProps.clone()); // reset the bound services events @@ -935,48 +911,38 @@ public class DSTest extends TestCase { Object instance1 = bc.getService(dynRegistration1.getReference()); Object instance2 = bc.getService(dynRegistration2.getReference()); try { - + // check that service is replaced - assertNotSame("The bound dynamic service shouldn't be our first instance", - ((BoundMainProvider) bsrc) - .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), instance1); - assertSame("The bound dynamic service should be our second instance", - ((BoundMainProvider) bsrc) - .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), instance2); - + assertNotSame("The bound dynamic service shouldn't be our first instance", ((BoundMainProvider) bsrc) + .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), instance1); + assertSame("The bound dynamic service should be our second instance", ((BoundMainProvider) bsrc) + .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), instance2); + // check the correct order of replacing - DSEvent[] replacedBoundDynamicServicesEvents = ((DSEventsProvider) bsrc) - .getEvents(); - assertEquals( - "There should two events after we have disposed the bound service", 2, + DSEvent[] replacedBoundDynamicServicesEvents = ((DSEventsProvider) bsrc).getEvents(); + assertEquals("There should two events after we have disposed the bound service", 2, replacedBoundDynamicServicesEvents.length); - - assertEquals("The first event should be bind event", - DSEvent.ACT_BOUND, replacedBoundDynamicServicesEvents[0] - .getAction()); - assertSame( - "The first event should have associated object the second instance", - instance2, replacedBoundDynamicServicesEvents[0].getObject()); - - assertEquals("The second event should be unbind event", - DSEvent.ACT_UNBOUND, replacedBoundDynamicServicesEvents[1] - .getAction()); - assertSame( - "The second event should have associated object the first instance", - instance1, replacedBoundDynamicServicesEvents[1].getObject()); - + + assertEquals("The first event should be bind event", DSEvent.ACT_BOUND, replacedBoundDynamicServicesEvents[0] + .getAction()); + assertSame("The first event should have associated object the second instance", instance2, + replacedBoundDynamicServicesEvents[0].getObject()); + + assertEquals("The second event should be unbind event", DSEvent.ACT_UNBOUND, + replacedBoundDynamicServicesEvents[1].getAction()); + assertSame("The second event should have associated object the first instance", instance1, + replacedBoundDynamicServicesEvents[1].getObject()); + } finally { bc.ungetService(dynRegistration1.getReference()); bc.ungetService(dynRegistration2.getReference()); } instance1 = instance2 = null; - ComponentContext bsrcCtxt1 = ((ComponentContextProvider) bsrc) - .getComponentContext(); + ComponentContext bsrcCtxt1 = ((ComponentContextProvider) bsrc).getComponentContext(); assertNotNull("ComponentContext object should be available", bsrcCtxt1); - ServiceRegistration staticRegistration2 = registerService( - StaticWorker.class.getName(), new StaticWorker(), + ServiceRegistration staticRegistration2 = registerService(StaticWorker.class.getName(), new StaticWorker(), (Dictionary) initialProps.clone()); // change the first instance staticRegistration1.setProperties((Dictionary) modifiedProps.clone()); @@ -984,14 +950,10 @@ public class DSTest extends TestCase { Object bsrcObject2 = trackerMBSRC.getService(); // the BSRC object can be // recreated - assertNotNull("The BoundReplacer should not be null", - bsrcObject2); - ComponentContext bsrcCtxt2 = ((ComponentContextProvider) bsrcObject2) - .getComponentContext(); + assertNotNull("The BoundReplacer should not be null", bsrcObject2); + ComponentContext bsrcCtxt2 = ((ComponentContextProvider) bsrcObject2).getComponentContext(); assertNotNull("The second ComponentContext should not be null", bsrcCtxt2); - assertNotSame( - "The second ComponentContext should be different than the first one", - bsrcCtxt1, bsrcCtxt2); + assertNotSame("The second ComponentContext should be different than the first one", bsrcCtxt1, bsrcCtxt2); uninstallBundle(tb4); @@ -1009,8 +971,7 @@ public class DSTest extends TestCase { return; } BundleContext bc = getContext(); - ServiceReference padmRef = bc.getServiceReference(PermissionAdmin.class - .getName()); + ServiceReference padmRef = bc.getServiceReference(PermissionAdmin.class.getName()); assertNotNull("Permission Admin service not available.", padmRef); PermissionAdmin padm = (PermissionAdmin) bc.getService(padmRef); @@ -1018,16 +979,13 @@ public class DSTest extends TestCase { assertEquals("TestBundle1 must be running.", Bundle.ACTIVE, tb1.getState()); - PermissionInfo registerServiceInfo = new PermissionInfo( - ServicePermission.class.getName(), - "org.eclipse.equinox.ds.tests.tb5.impl.SecurityTester", - ServicePermission.REGISTER); - PermissionInfo getServiceInfo = new PermissionInfo(ServicePermission.class - .getName(), "org.eclipse.equinox.ds.tests.tb1.impl.AnotherComponent", ServicePermission.GET); + PermissionInfo registerServiceInfo = new PermissionInfo(ServicePermission.class.getName(), + "org.eclipse.equinox.ds.tests.tb5.impl.SecurityTester", ServicePermission.REGISTER); + PermissionInfo getServiceInfo = new PermissionInfo(ServicePermission.class.getName(), + "org.eclipse.equinox.ds.tests.tb1.impl.AnotherComponent", ServicePermission.GET); - PermissionInfo importPackage = new PermissionInfo( - PackagePermission.class.getName(), "org.eclipse.equinox.ds.tests.tb1.impl", - PackagePermission.IMPORT); + PermissionInfo importPackage = new PermissionInfo(PackagePermission.class.getName(), + "org.eclipse.equinox.ds.tests.tb1.impl", PackagePermission.IMPORT); // install the bundle to get the location Bundle tb5 = installBundle("tb5"); @@ -1040,61 +998,52 @@ public class DSTest extends TestCase { // do the test // set all permission needed for correct operation - padm.setPermissions(bundleLocation, new PermissionInfo[] { - registerServiceInfo, getServiceInfo, importPackage }); + padm.setPermissions(bundleLocation, new PermissionInfo[] { registerServiceInfo, getServiceInfo, importPackage }); // install tb5 = installBundle("tb5"); tb5.start(); waitBundleStart(); - assertEquals( - "The bundle location should be the same as the first one registered", - bundleLocation, tb5.getLocation()); + assertEquals("The bundle location should be the same as the first one registered", bundleLocation, tb5 + .getLocation()); // check that the component is available - assertTrue( - "The SecurityTester should be present because all needed permissions are set", + assertTrue("The SecurityTester should be present because all needed permissions are set", countAvailableServices(trackerSecurity) > 0); // uninstall uninstallBundle(tb5); // remove the register permission - the service shouldn't be available - padm.setPermissions(bundleLocation, new PermissionInfo[] { - importPackage, getServiceInfo }); + padm.setPermissions(bundleLocation, new PermissionInfo[] { importPackage, getServiceInfo }); // install tb5 = installBundle("tb5"); tb5.start(); waitBundleStart(); - assertEquals( - "The bundle location should be the same as the first one registered", - bundleLocation, tb5.getLocation()); + assertEquals("The bundle location should be the same as the first one registered", bundleLocation, tb5 + .getLocation()); // check that the service is unavailable - assertEquals( - "The SecurityTester shouldn't be present due to missing ServicePermission.REGISTER", - 0, countAvailableServices(trackerSecurity)); + assertEquals("The SecurityTester shouldn't be present due to missing ServicePermission.REGISTER", 0, + countAvailableServices(trackerSecurity)); // uninstall uninstallBundle(tb5); // remove the get permission and bring back the register permission - padm.setPermissions(bundleLocation, new PermissionInfo[] { - importPackage, registerServiceInfo }); + padm.setPermissions(bundleLocation, new PermissionInfo[] { importPackage, registerServiceInfo }); // install tb5 = installBundle("tb5"); tb5.start(); waitBundleStart(); - assertEquals( - "The bundle location should be the same as the first one registered", - bundleLocation, tb5.getLocation()); + assertEquals("The bundle location should be the same as the first one registered", bundleLocation, tb5 + .getLocation()); // check that the component is unavailable - assertEquals( - "The SecurityTester shouldn't be present due to missing ServicePermission.GET", - 0, countAvailableServices(trackerSecurity)); + assertEquals("The SecurityTester shouldn't be present due to missing ServicePermission.GET", 0, + countAvailableServices(trackerSecurity)); // uninstall uninstallBundle(tb5); @@ -1112,16 +1061,13 @@ public class DSTest extends TestCase { waitBundleStart(); // check that the ServiceProvider is registered - assertNotNull("The ServiceProvider should be registered as service", - getContext().getServiceReference( - "org.eclipse.equinox.ds.tests.tb4.ServiceProvider")); + assertNotNull("The ServiceProvider should be registered as service", getContext().getServiceReference( + "org.eclipse.equinox.ds.tests.tb4.ServiceProvider")); // check that the ServiceProvider is activated - assertTrue("The ServiceProvider should be activated", TestHelper - .isActivatedServiceProvider()); + assertTrue("The ServiceProvider should be activated", TestHelper.isActivatedServiceProvider()); // check that the Stand Alone Component is activated - assertTrue("The AnotherComponent should be activated", - TestHelper.isActivatedStandAlone()); + assertTrue("The AnotherComponent should be activated", TestHelper.isActivatedStandAlone()); uninstallBundle(tb4); } @@ -1136,25 +1082,18 @@ public class DSTest extends TestCase { waitBundleStart(); // check that all the components are present - assertTrue("The Component3 should be available", - checkAvailability(TAIL_CLASS)); - assertTrue("The Component2 should be available", - checkAvailability(MIDDLE_CLASS)); - assertTrue("The Component1 should be available", - checkAvailability(HEAD_CLASS)); + assertTrue("The Component3 should be available", checkAvailability(TAIL_CLASS)); + assertTrue("The Component2 should be available", checkAvailability(MIDDLE_CLASS)); + assertTrue("The Component1 should be available", checkAvailability(HEAD_CLASS)); BundleContext bc = getContext(); // get ComponentContext - ServiceReference cceRef = bc - .getServiceReference("org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider"); + ServiceReference cceRef = bc.getServiceReference("org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider"); assertNotNull("The GiveMeContext should be available", cceRef); - assertEquals( - "The GiveMeContext should be the implementation present in tb4.jar", - "org.eclipse.equinox.ds.tests.tb4.GiveMeContext", cceRef - .getProperty("component.name")); + assertEquals("The GiveMeContext should be the implementation present in tb4.jar", + "org.eclipse.equinox.ds.tests.tb4.GiveMeContext", cceRef.getProperty("component.name")); - ComponentContextProvider cce = (ComponentContextProvider) bc - .getService(cceRef); + ComponentContextProvider cce = (ComponentContextProvider) bc.getService(cceRef); assertNotNull("The service object should be retrieved correctly", cce); ComponentContext ctxt = cce.getComponentContext(); assertNotNull("The ComponentContext object should not be null", ctxt); @@ -1164,24 +1103,18 @@ public class DSTest extends TestCase { Thread.sleep(timeout); // check that no component is available - assertTrue("The Component3 shouldn't be available", - !checkAvailability(TAIL_CLASS)); - assertTrue("The Component2 shouldn't be available", - !checkAvailability(MIDDLE_CLASS)); - assertTrue("The Component1 shouldn't be available", - !checkAvailability(HEAD_CLASS)); + assertTrue("The Component3 shouldn't be available", !checkAvailability(TAIL_CLASS)); + assertTrue("The Component2 shouldn't be available", !checkAvailability(MIDDLE_CLASS)); + assertTrue("The Component1 shouldn't be available", !checkAvailability(HEAD_CLASS)); // enable the tail component ctxt.enableComponent(TAIL_CLASS); Thread.sleep(timeout); // check that the components are back online - assertTrue("The Component3 should be available", - checkAvailability(TAIL_CLASS)); - assertTrue("The Component2 should be available", - checkAvailability(MIDDLE_CLASS)); - assertTrue("The Component1 should be available", - checkAvailability(HEAD_CLASS)); + assertTrue("The Component3 should be available", checkAvailability(TAIL_CLASS)); + assertTrue("The Component2 should be available", checkAvailability(MIDDLE_CLASS)); + assertTrue("The Component1 should be available", checkAvailability(HEAD_CLASS)); // release the GiveMeContext bc.ungetService(cceRef); @@ -1195,94 +1128,102 @@ public class DSTest extends TestCase { ServiceReference ref = bc.getServiceReference(service); return ref != null; } - + private boolean checkFactoryAvailability(String factory) throws InvalidSyntaxException { BundleContext bc = getContext(); - ServiceReference[] refs = bc.getServiceReferences(ComponentFactory.class.getName(), "(" + ComponentConstants.COMPONENT_FACTORY + "=" + factory + ")"); + ServiceReference[] refs = bc.getServiceReferences(ComponentFactory.class.getName(), "(" + + ComponentConstants.COMPONENT_FACTORY + "=" + factory + ")"); return refs != null && refs.length > 0; } - + public void testBlockingComponents() throws Exception { final Bundle tb2 = installBundle("tb2"); final Bundle tb3 = installBundle("tb3"); final Bundle tb4 = installBundle("tb4"); - + new Thread() { public void run() { try { - tb2.start(); // start the blocking service - } catch (BundleException e) { } - } + tb2.start(); // start the blocking service + } catch (BundleException e) { + } + } }.start(); sleep0(scr_restart_timeout + timeout * 2); - + new Thread() { public void run() { try { - tb4.start(); // start the other - } catch (BundleException e) { } - } + tb4.start(); // start the other + } catch (BundleException e) { + } + } }.start(); - sleep0(timeout * 3); // sleep until the services are activated - + sleep0(timeout * 3); // sleep until the services are activated + // check that the first service is missing, and the second is available assertEquals("The blocking service should not be available", 0, countAvailableServices(trackerBAS)); - assertTrue("The service in the bundle should be available", checkAvailability("org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider")); - + assertTrue("The service in the bundle should be available", + checkAvailability("org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider")); + tb2.stop(); tb4.stop(); - + // check that AnotherComponent is available - assertTrue("The AnotherComponent should be available", checkAvailability("org.eclipse.equinox.ds.tests.tb1.impl.AnotherComponent")); - + assertTrue("The AnotherComponent should be available", + checkAvailability("org.eclipse.equinox.ds.tests.tb1.impl.AnotherComponent")); + // start the other blocking bundle new Thread() { public void run() { try { - tb3.start(); - } catch (BundleException e) { } - } + tb3.start(); + } catch (BundleException e) { + } + } }.start(); sleep0(scr_restart_timeout + timeout * 2); - + // start the non-blocking bundle new Thread() { public void run() { try { - tb4.start(); // start the other - } catch (BundleException e) { } - } + tb4.start(); // start the other + } catch (BundleException e) { + } + } }.start(); - sleep0(timeout * 3); // sleep until the services are activated - + sleep0(timeout * 3); // sleep until the services are activated + assertEquals("The blocking service should not be available", 0, countAvailableServices(trackerBBS)); - assertTrue("The service in the bundle should be available", checkAvailability("org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider")); - + assertTrue("The service in the bundle should be available", + checkAvailability("org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider")); + uninstallBundle(tb2); uninstallBundle(tb3); uninstallBundle(tb4); } - + public void testStaticPolicyBinding() throws Exception { Bundle tb6 = installBundle("tb6"); tb6.start(); waitBundleStart(); - + // check initial conditions assertTrue("The StaticComp should be available", checkAvailability(STATIC_CLASS)); assertTrue("The ReferencedComp shouldn't be available (disabled)", !checkAvailability(REFERENCED_CLASS)); - + // reset the events list Object initialStatic = trackerStatic.getService(); assertNotNull(STATIC_CLASS + " component should be non-null", initialStatic); - ComponentContext initialCtxt = ((ComponentContextProvider)initialStatic).getComponentContext(); - ((DSEventsProvider)initialStatic).resetEvents(); - assertEquals("There shouldn't be bound service to StaticComp", 0, ((BoundTester)initialStatic).getBoundObjectsCount()); - - + ComponentContext initialCtxt = ((ComponentContextProvider) initialStatic).getComponentContext(); + ((DSEventsProvider) initialStatic).resetEvents(); + assertEquals("There shouldn't be bound service to StaticComp", 0, ((BoundTester) initialStatic) + .getBoundObjectsCount()); + // enable the ReferencedComp initialCtxt.enableComponent(REFERENCED_CLASS); Thread.sleep(timeout * 2); @@ -1290,113 +1231,130 @@ public class DSTest extends TestCase { // check the availability after enablement assertTrue("The StaticComp should be available", checkAvailability(STATIC_CLASS)); assertTrue("The ReferencedComp should be available", checkAvailability(REFERENCED_CLASS)); - + // check that the SCR created new instance Object enabledStatic = trackerStatic.getService(); assertNotNull(STATIC_CLASS + " component should be non-null", enabledStatic); - ComponentContext enabledCtxt = ((ComponentContextProvider)enabledStatic).getComponentContext(); + ComponentContext enabledCtxt = ((ComponentContextProvider) enabledStatic).getComponentContext(); assertNotSame("The StaticComp must have been restarted", initialCtxt, enabledCtxt); - assertEquals("There should be one bound service to StaticComp", 1, ((BoundTester)enabledStatic).getBoundObjectsCount()); - + assertEquals("There should be one bound service to StaticComp", 1, ((BoundTester) enabledStatic) + .getBoundObjectsCount()); + // check the events - DSEvent[] initialEvents = ((DSEventsProvider)initialStatic).getEvents(); + DSEvent[] initialEvents = ((DSEventsProvider) initialStatic).getEvents(); assertEquals("The events in the first instance of StaticComp should only one", 1, initialEvents.length); assertEquals("The event should deactivate one", DSEvent.ACT_DEACTIVATE, initialEvents[0].getAction()); - - DSEvent[] enabledEvents = ((DSEventsProvider)enabledStatic).getEvents(); + + DSEvent[] enabledEvents = ((DSEventsProvider) enabledStatic).getEvents(); assertEquals("The events for the second instance of StaticComp should be two", 2, enabledEvents.length); assertEquals("The first event should bind event", DSEvent.ACT_BOUND, enabledEvents[0].getAction()); assertEquals("The second event should be activate event", DSEvent.ACT_ACTIVATE, enabledEvents[1].getAction()); - + // reset the events - ((DSEventsProvider)enabledStatic).resetEvents(); - + ((DSEventsProvider) enabledStatic).resetEvents(); + // disable the component enabledCtxt.disableComponent(REFERENCED_CLASS); Thread.sleep(timeout * 2); - + // check the availability assertTrue("The StaticComp should be available", checkAvailability(STATIC_CLASS)); assertTrue("The ReferencedComp shouldn't be available", !checkAvailability(REFERENCED_CLASS)); - + // check that the SCR created new instance Object disabledStatic = trackerStatic.getService(); assertNotNull(STATIC_CLASS + " component should be non-null", disabledStatic); - ComponentContext disabledCtxt = ((ComponentContextProvider)disabledStatic).getComponentContext(); + ComponentContext disabledCtxt = ((ComponentContextProvider) disabledStatic).getComponentContext(); assertNotSame("The StaticComp must have been restarted", enabledCtxt, disabledCtxt); - assertEquals("There should be one bound service to StaticComp", 0, ((BoundTester)disabledStatic).getBoundObjectsCount()); - - enabledEvents = ((DSEventsProvider)enabledStatic).getEvents(); - DSEvent[] disabledEvents = ((DSEventsProvider)disabledStatic).getEvents(); - - assertEquals("The second instance of StaticComp should have two events after disabling ReferencedComp", 2, enabledEvents.length); + assertEquals("There should be one bound service to StaticComp", 0, ((BoundTester) disabledStatic) + .getBoundObjectsCount()); + + enabledEvents = ((DSEventsProvider) enabledStatic).getEvents(); + DSEvent[] disabledEvents = ((DSEventsProvider) disabledStatic).getEvents(); + + assertEquals("The second instance of StaticComp should have two events after disabling ReferencedComp", 2, + enabledEvents.length); assertEquals("The first event should be deactivate", DSEvent.ACT_DEACTIVATE, enabledEvents[0].getAction()); assertEquals("The second event should be unbind", DSEvent.ACT_UNBOUND, enabledEvents[1].getAction()); - + assertEquals("There should only one event for the second instance of StaticComp", 1, disabledEvents.length); assertEquals("The event should be activate", DSEvent.ACT_ACTIVATE, disabledEvents[0].getAction()); - + uninstallBundle(tb6); } - + public void testCircularityHandling() throws Exception { Bundle tb7 = installBundle("tb7"); tb7.start(); waitBundleStart(); - + final String UNBREAKABLE = "org.eclipse.equinox.ds.tests.tb7.UnbreakableCircuit"; final String DYN_BREAKABLE = "org.eclipse.equinox.ds.tests.tb7.DynamicCircuit"; final String STATIC_BREAKABLE = "org.eclipse.equinox.ds.tests.tb7.StaticCircuit"; - + // check that the unbreakable circuit isn't available - assertTrue("The first service from the unbreakable circularity shouldn't be available", !checkAvailability(UNBREAKABLE + "1")); - assertTrue("The second service from the unbreakable circularity shouldn't be available", !checkAvailability(UNBREAKABLE + "2")); - - // check that the breakable circuit with dynamic optional reference is available - assertTrue("The first service from the breakable circularity with dynamic optional reference should be available", checkAvailability(DYN_BREAKABLE + "1")); - assertTrue("The second service from the breakable circularity with dynamic optional reference should be available", checkAvailability(DYN_BREAKABLE + "2")); - - // check that the breakable circuit with dynamic optional reference has bound correctly + assertTrue("The first service from the unbreakable circularity shouldn't be available", + !checkAvailability(UNBREAKABLE + "1")); + assertTrue("The second service from the unbreakable circularity shouldn't be available", + !checkAvailability(UNBREAKABLE + "2")); + + // check that the breakable circuit with dynamic optional reference is + // available + assertTrue("The first service from the breakable circularity with dynamic optional reference should be available", + checkAvailability(DYN_BREAKABLE + "1")); + assertTrue("The second service from the breakable circularity with dynamic optional reference should be available", + checkAvailability(DYN_BREAKABLE + "2")); + + // check that the breakable circuit with dynamic optional reference has + // bound correctly ServiceReference dynBreak2Ref = getContext().getServiceReference(DYN_BREAKABLE + "2"); Object dynBreak2 = getContext().getService(dynBreak2Ref); try { - assertEquals("The DynamicCircuit2 component should have one bound object", 1, ((BoundTester)dynBreak2).getBoundObjectsCount()); - assertNotNull("The DynamicCircuit2 component should have one non-null bound object", ((BoundTester)dynBreak2).getBoundService(0)); + assertEquals("The DynamicCircuit2 component should have one bound object", 1, ((BoundTester) dynBreak2) + .getBoundObjectsCount()); + assertNotNull("The DynamicCircuit2 component should have one non-null bound object", ((BoundTester) dynBreak2) + .getBoundService(0)); } finally { getContext().ungetService(dynBreak2Ref); } - // check that the breakable circuit with static optional reference isn't available - assertTrue("The first service from the breakable circularity with static optional reference should be available", checkAvailability(STATIC_BREAKABLE + "1")); - assertTrue("The second service from the breakable circularity with static optional reference should be available", checkAvailability(STATIC_BREAKABLE + "2")); - + // check that the breakable circuit with static optional reference isn't + // available + assertTrue("The first service from the breakable circularity with static optional reference should be available", + checkAvailability(STATIC_BREAKABLE + "1")); + assertTrue("The second service from the breakable circularity with static optional reference should be available", + checkAvailability(STATIC_BREAKABLE + "2")); + // check that the optional reference isn't satisfied ServiceReference staticBreak2Ref = getContext().getServiceReference(STATIC_BREAKABLE + "2"); Object staticBreak2 = getContext().getService(staticBreak2Ref); try { - assertEquals("The StaticCircuit2 component shouldn't have bound objects", 0, ((BoundTester)staticBreak2).getBoundObjectsCount()); + assertEquals("The StaticCircuit2 component shouldn't have bound objects", 0, ((BoundTester) staticBreak2) + .getBoundObjectsCount()); } finally { getContext().ungetService(staticBreak2Ref); } - + // check that the worker hasn't been blocked Bundle tb5 = installBundle("tb5"); tb5.start(); waitBundleStart(); - + // check that the AnotherComponent service is available - assertTrue("The AnotherComponent should be available", checkAvailability("org.eclipse.equinox.ds.tests.tb1.impl.AnotherComponent")); - assertTrue("The service in TB5 should be available which means that the working thread of the SCR isn't blocked", checkAvailability("org.eclipse.equinox.ds.tests.tb5.impl.SecurityTester")); - + assertTrue("The AnotherComponent should be available", + checkAvailability("org.eclipse.equinox.ds.tests.tb1.impl.AnotherComponent")); + assertTrue("The service in TB5 should be available which means that the working thread of the SCR isn't blocked", + checkAvailability("org.eclipse.equinox.ds.tests.tb5.impl.SecurityTester")); + uninstallBundle(tb5); uninstallBundle(tb7); } - + // tests namespace handling in xml component description parser public void testNamespaceHandling() throws Exception { Bundle tb8 = installBundle("tb8"); tb8.start(); waitBundleStart(); - + // check the root component handling assertTrue("The root1 component should be available", isNSComponentAvailable(101)); assertTrue("The root2 component should be available", isNSComponentAvailable(102)); @@ -1421,10 +1379,10 @@ public class DSTest extends TestCase { assertTrue("The nonroot15 component should be available", isNSComponentAvailable(125)); assertTrue("The nonroot16 component should be available", isNSComponentAvailable(126)); assertTrue("The nonroot17 component should be available", isNSComponentAvailable(127)); - + uninstallBundle(tb8); } - + private boolean isNSComponentAvailable(int nsid) { Object[] services = trackerNS.getServices(); if (services == null) { @@ -1432,28 +1390,28 @@ public class DSTest extends TestCase { } for (int i = 0; i < services.length; i++) { if (services[i] instanceof NamespaceProvider) { - NamespaceProvider s = (NamespaceProvider)services[i]; + NamespaceProvider s = (NamespaceProvider) services[i]; if (s.getComponentNSID() == nsid) { return true; } } } - + return false; } - + // tests wildcard handling in mf (e.g. Service-Component: OSGI-INF/*.xml) public void testWildcardHandling() throws Exception { Bundle tb9 = installBundle("tb9"); tb9.start(); waitBundleStart(); - + final String WILD = "org.eclipse.equinox.ds.tests.tb9.Wildcard"; - + // check that the both components are available assertTrue("The first Wildcard component should be available", checkAvailability(WILD + "1")); assertTrue("The second Wildcard component should be available", checkAvailability(WILD + "2")); - + uninstallBundle(tb9); } @@ -1462,107 +1420,124 @@ public class DSTest extends TestCase { assertNotNull("Failed to install test bundle tb10.jar", tb10); tb10.start(); waitBundleStart(); - + // assert that the required components are available assertTrue("The referenced simple component should be available", checkAvailability(SC_CLASS)); assertTrue("The referenced factory component should be available", checkFactoryAvailability("CountHelperFactory")); assertTrue("The dependent dynamic factory component should be available", checkFactoryAvailability("CountFactory")); - + // retrieve the helper factory ComponentFactory helperFactory = (ComponentFactory) trackerBoundServiceCounterHelperFactory.getService(); assertNotNull("The helper factory must be retrievable", helperFactory); - + // retrieve the observed factory ComponentFactory observedFactory = (ComponentFactory) trackerBoundServiceCounterFactory.getService(); assertNotNull("The observed factory must be retrievable", observedFactory); - + // instantiate observed components ComponentInstance observedInstance1 = observedFactory.newInstance(null); assertNotNull("Cannot instantiate component from observed factory [1]", observedInstance1); ComponentInstance observedInstance2 = observedFactory.newInstance(null); assertNotNull("Cannot instantiate component from observed factory [2]", observedInstance2); - + BoundCountProvider observedComponent1 = (BoundCountProvider) observedInstance1.getInstance(); BoundCountProvider observedComponent2 = (BoundCountProvider) observedInstance2.getInstance(); assertNotNull("The observed component must be non-null [1]", observedComponent1); assertNotNull("The observed component must be non-null [2]", observedComponent2); - - // check the bound services before instantiating helper factory components - both components must have 1 service bound - assertEquals("The bound service count must be 1 - only the simple component is available [1]", 1, observedComponent1.getBoundServiceCount(null)); - assertEquals("The bound service count must be 1 - only the simple component is available [2]", 1, observedComponent2.getBoundServiceCount(null)); - + + // check the bound services before instantiating helper factory components - + // both components must have 1 service bound + assertEquals("The bound service count must be 1 - only the simple component is available [1]", 1, + observedComponent1.getBoundServiceCount(null)); + assertEquals("The bound service count must be 1 - only the simple component is available [2]", 1, + observedComponent2.getBoundServiceCount(null)); + // instantiate three helper components and check the service count again for (int i = 0; i < 3; i++) { - helperFactory.newInstance(null); // don't keep track of the created instances, they will be disposed when the bundle is stopped and uninstalled + helperFactory.newInstance(null); // don't keep track of the created + // instances, they will be disposed when + // the bundle is stopped and uninstalled } - - // check the bound services count again - both components must have 4 services bound -> 1 simple component and 3 helper factory - assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [1]", 4, observedComponent1.getBoundServiceCount(null)); - assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [2]", 4, observedComponent2.getBoundServiceCount(null)); - + + // check the bound services count again - both components must have 4 + // services bound -> 1 simple component and 3 helper factory + assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [1]", 4, + observedComponent1.getBoundServiceCount(null)); + assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [2]", 4, + observedComponent2.getBoundServiceCount(null)); + uninstallBundle(tb10); } - + public void testStaticComponentFactoryServiceBinding() throws Exception { Bundle tb10 = installBundle("tb10"); assertNotNull("Failed to install test bundle tb10.jar", tb10); tb10.start(); waitBundleStart(); - + // assert that the required components are available assertTrue("The referenced simple component should be available", checkAvailability(SC_CLASS)); assertTrue("The referenced factory component should be available", checkFactoryAvailability("CountHelperFactory")); - assertTrue("The dependent static factory component should be available", checkFactoryAvailability("StaticServiceCountFactory")); - + assertTrue("The dependent static factory component should be available", + checkFactoryAvailability("StaticServiceCountFactory")); + // retrieve the helper and observer factories ComponentFactory helperFactory = (ComponentFactory) trackerBoundServiceCounterHelperFactory.getService(); ComponentFactory observedFactory = (ComponentFactory) trackerStaticServiceCounterFactory.getService(); assertNotNull("The helper factory must be retrievable", helperFactory); assertNotNull("The observed factory must be retrievable", observedFactory); - + // instantiate observed components ComponentInstance observedInstance1 = observedFactory.newInstance(null); ComponentInstance observedInstance2 = observedFactory.newInstance(null); assertNotNull("Cannot instantiate component from observed factory [1]", observedInstance1); assertNotNull("Cannot instantiate component from observed factory [2]", observedInstance2); - + BoundCountProvider observedComponent1 = (BoundCountProvider) observedInstance1.getInstance(); BoundCountProvider observedComponent2 = (BoundCountProvider) observedInstance2.getInstance(); assertNotNull("The observed component must be non-null [1]", observedComponent1); assertNotNull("The observed component must be non-null [2]", observedComponent2); - - // check the bound services before instantiating helper factory components - both components must have 1 service bound - assertEquals("The bound service count must be 1 - only the simple component is available [1]", 1, observedComponent1.getBoundServiceCount(null)); - assertEquals("The bound service count must be 1 - only the simple component is available [2]", 1, observedComponent2.getBoundServiceCount(null)); - + + // check the bound services before instantiating helper factory components - + // both components must have 1 service bound + assertEquals("The bound service count must be 1 - only the simple component is available [1]", 1, + observedComponent1.getBoundServiceCount(null)); + assertEquals("The bound service count must be 1 - only the simple component is available [2]", 1, + observedComponent2.getBoundServiceCount(null)); + // instantiate three helper components and check the service count again for (int i = 0; i < 3; i++) { - helperFactory.newInstance(null); // don't keep track of the created instances, they will be disposed when the bundle is stopped and uninstalled + helperFactory.newInstance(null); // don't keep track of the created + // instances, they will be disposed when + // the bundle is stopped and uninstalled } - + // check whether the factory is the same, it shouldn't be disposed assertSame(observedFactory, trackerStaticServiceCounterFactory.getService()); observedFactory = (ComponentFactory) trackerStaticServiceCounterFactory.getService(); - + // check that the components are reinstantiated observedInstance1 = observedFactory.newInstance(null); observedInstance2 = observedFactory.newInstance(null); assertNotNull("Cannot instantiate new observed component instance [1]", observedInstance1); assertNotNull("Cannot instantiate new observed component instance [2]", observedInstance2); - + // get the new instances observedComponent1 = (BoundCountProvider) observedInstance1.getInstance(); observedComponent2 = (BoundCountProvider) observedInstance2.getInstance(); assertNotNull("The observed component instance must be non-null [1]", observedComponent1); assertNotNull("The observed component instance must be non-null [2]", observedComponent2); - - // check the bound services count again - both components must have 4 services bound -> 1 simple component and 3 helper factory - assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [1]", 4, observedComponent1.getBoundServiceCount(null)); - assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [2]", 4, observedComponent2.getBoundServiceCount(null)); - + + // check the bound services count again - both components must have 4 + // services bound -> 1 simple component and 3 helper factory + assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [1]", 4, + observedComponent1.getBoundServiceCount(null)); + assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [2]", 4, + observedComponent2.getBoundServiceCount(null)); + uninstallBundle(tb10); } - + public void testConfigurationPolicy() throws Exception { ConfigurationAdmin cm = (ConfigurationAdmin) trackerCM.getService(); assertNotNull("The ConfigurationAdmin should be available", cm); @@ -1574,69 +1549,190 @@ public class DSTest extends TestCase { Hashtable props = new Hashtable(10); props.put("config.base.data", new Integer(1)); - // component notsetNS100 - property not set by Configuration Admin; XML NS 1.0.0 + // component notsetNS100 - property not set by Configuration Admin; XML NS + // 1.0.0 assertEquals("Configuration data should not be available for notsetNS100", 0, getBaseConfigData(COMP_NOTSET_100)); // component notsetNS100 - property set by Configuration Admin; XML NS 1.0.0 Configuration config = cm.getConfiguration(COMP_NOTSET_100); config.update(props); Thread.sleep(timeout * 3); - assertEquals("Configuration data should be available for notsetNS100 and equal to 1", 1, getBaseConfigData(COMP_NOTSET_100)); + assertEquals("Configuration data should be available for notsetNS100 and equal to 1", 1, + getBaseConfigData(COMP_NOTSET_100)); - // component notsetNS110 - property not set by Configuration Admin; XML NS 1.1.0 + // component notsetNS110 - property not set by Configuration Admin; XML NS + // 1.1.0 assertEquals("Configuration data should not be available for notsetNS110", 0, getBaseConfigData(COMP_NOTSET_110)); // component notsetNS110 - property set by Configuration Admin; XML NS 1.1.0 config = cm.getConfiguration(COMP_NOTSET_110); config.update(props); Thread.sleep(timeout * 3); - assertEquals("Configuration data should be available for notsetNS110 and equal to 1", 1, getBaseConfigData(COMP_NOTSET_110)); + assertEquals("Configuration data should be available for notsetNS110 and equal to 1", 1, + getBaseConfigData(COMP_NOTSET_110)); - // component optionalNS100 - property not set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT + // component optionalNS100 - property not set by Configuration Admin; XML NS + // 1.0.0 - INVALID COMPONENT assertEquals("Component optionalNS100 should not be activated", -1, getBaseConfigData(COMP_OPTIONAL_100)); - // component optionalNS100 - property set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT + // component optionalNS100 - property set by Configuration Admin; XML NS + // 1.0.0 - INVALID COMPONENT config = cm.getConfiguration(COMP_OPTIONAL_100); config.update(props); Thread.sleep(timeout * 3); assertEquals("Component optionalNS100 should not be activated", -1, getBaseConfigData(COMP_OPTIONAL_100)); - // component optionalNS110 - property not set by Configuration Admin; XML NS 1.1.0 - assertEquals("Configuration data should not be available for optionalNS110", 0, getBaseConfigData(COMP_OPTIONAL_110)); - // component optionalNS110 - property set by Configuration Admin; XML NS 1.1.0 + // component optionalNS110 - property not set by Configuration Admin; XML NS + // 1.1.0 + assertEquals("Configuration data should not be available for optionalNS110", 0, + getBaseConfigData(COMP_OPTIONAL_110)); + // component optionalNS110 - property set by Configuration Admin; XML NS + // 1.1.0 config = cm.getConfiguration(COMP_OPTIONAL_110); config.update(props); Thread.sleep(timeout * 3); - assertEquals("Configuration data should be available for optionalNS110 and equal to 1", 1, getBaseConfigData(COMP_OPTIONAL_110)); + assertEquals("Configuration data should be available for optionalNS110 and equal to 1", 1, + getBaseConfigData(COMP_OPTIONAL_110)); - // component requireNS100 - property not set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT + // component requireNS100 - property not set by Configuration Admin; XML NS + // 1.0.0 - INVALID COMPONENT assertEquals("Component requireNS100 should not be activated", -1, getBaseConfigData(COMP_REQUIRE_100)); - // component requireNS100 - property set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT + // component requireNS100 - property set by Configuration Admin; XML NS + // 1.0.0 - INVALID COMPONENT config = cm.getConfiguration(COMP_REQUIRE_100); config.update(props); Thread.sleep(timeout * 3); assertEquals("Component requireNS100 should not be activated", -1, getBaseConfigData(COMP_REQUIRE_100)); - // component requireNS110 - property not set by Configuration Admin; XML NS 1.1.0 - assertEquals("Configuration data should not be available for requireNS110, and it should not be satisfied", -1, getBaseConfigData(COMP_REQUIRE_110)); - // component requireNS110 - property set by Configuration Admin; XML NS 1.1.0 + // component requireNS110 - property not set by Configuration Admin; XML NS + // 1.1.0 + assertEquals("Configuration data should not be available for requireNS110, and it should not be satisfied", -1, + getBaseConfigData(COMP_REQUIRE_110)); + // component requireNS110 - property set by Configuration Admin; XML NS + // 1.1.0 config = cm.getConfiguration(COMP_REQUIRE_110); config.update(props); Thread.sleep(timeout * 3); - assertEquals("Configuration data should be available for requireNS110 and equal to 1", 1, getBaseConfigData(COMP_REQUIRE_110)); + assertEquals("Configuration data should be available for requireNS110 and equal to 1", 1, + getBaseConfigData(COMP_REQUIRE_110)); - // component ignoreNS100 - property not set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT + // component ignoreNS100 - property not set by Configuration Admin; XML NS + // 1.0.0 - INVALID COMPONENT assertEquals("Component ignoreNS100 should not be activated", -1, getBaseConfigData(COMP_IGNORE_100)); - // component ignoreNS100 - property set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT + // component ignoreNS100 - property set by Configuration Admin; XML NS 1.0.0 + // - INVALID COMPONENT config = cm.getConfiguration(COMP_IGNORE_100); config.update(props); Thread.sleep(timeout * 3); assertEquals("Component ignoreNS100 should not be activated", -1, getBaseConfigData(COMP_IGNORE_100)); - // component ignoreNS110 - property not set by Configuration Admin; XML NS 1.1.0 - assertEquals("Configuration data should not be available for ignoreNS110, but it should be satisfied", 0, getBaseConfigData(COMP_IGNORE_110)); + // component ignoreNS110 - property not set by Configuration Admin; XML NS + // 1.1.0 + assertEquals("Configuration data should not be available for ignoreNS110, but it should be satisfied", 0, + getBaseConfigData(COMP_IGNORE_110)); // component ignoreNS110 - property set by Configuration Admin; XML NS 1.1.0 config = cm.getConfiguration(COMP_IGNORE_110); config.update(props); Thread.sleep(timeout * 3); - assertEquals("Configuration data should not be available for ignoreNS110, but it should be satisfied", 0, getBaseConfigData(COMP_IGNORE_110)); + assertEquals("Configuration data should not be available for ignoreNS110, but it should be satisfied", 0, + getBaseConfigData(COMP_IGNORE_110)); + + uninstallBundle(tb11); + } + + // tests configuration-policy for factory configuration objects + public void testConfigurationPolicyFactoryConf() throws Exception { + ConfigurationAdmin cm = (ConfigurationAdmin) trackerCM.getService(); + assertNotNull("The ConfigurationAdmin should be available", cm); + + Bundle tb11 = installBundle("tb11"); + tb11.start(); + waitBundleStart(); + + Hashtable props = new Hashtable(10); + props.put("config.base.data", new Integer(1)); + + // component notsetNS100 - property not set by Configuration Admin; XML NS + // 1.0.0 + assertEquals("Configuration data should not be available for notsetNS100", 0, getBaseConfigData(COMP_NOTSET_100)); + // component notsetNS100 - property set by Configuration Admin; XML NS 1.0.0 + Configuration config = cm.createFactoryConfiguration(COMP_NOTSET_100); + config.update(props); + Thread.sleep(timeout * 3); + assertEquals("Configuration data should be available for notsetNS100 and equal to 1", 1, + getBaseConfigData(COMP_NOTSET_100)); + + // component notsetNS110 - property not set by Configuration Admin; XML NS + // 1.1.0 + assertEquals("Configuration data should not be available for notsetNS110", 0, getBaseConfigData(COMP_NOTSET_110)); + // component notsetNS110 - property set by Configuration Admin; XML NS 1.1.0 + config = cm.createFactoryConfiguration(COMP_NOTSET_110); + config.update(props); + Thread.sleep(timeout * 3); + assertEquals("Configuration data should be available for notsetNS110 and equal to 1", 1, + getBaseConfigData(COMP_NOTSET_110)); + + // component optionalNS100 - property not set by Configuration Admin; XML NS + // 1.0.0 - INVALID COMPONENT + assertEquals("Component optionalNS100 should not be activated", -1, getBaseConfigData(COMP_OPTIONAL_100)); + // component optionalNS100 - property set by Configuration Admin; XML NS + // 1.0.0 - INVALID COMPONENT + config = cm.createFactoryConfiguration(COMP_OPTIONAL_100); + config.update(props); + Thread.sleep(timeout * 3); + assertEquals("Component optionalNS100 should not be activated", -1, getBaseConfigData(COMP_OPTIONAL_100)); + + // component optionalNS110 - property not set by Configuration Admin; XML NS + // 1.1.0 + assertEquals("Configuration data should not be available for optionalNS110", 0, + getBaseConfigData(COMP_OPTIONAL_110)); + // component optionalNS110 - property set by Configuration Admin; XML NS + // 1.1.0 + config = cm.createFactoryConfiguration(COMP_OPTIONAL_110); + config.update(props); + Thread.sleep(timeout * 3); + assertEquals("Configuration data should be available for optionalNS110 and equal to 1", 1, + getBaseConfigData(COMP_OPTIONAL_110)); + + // component requireNS100 - property not set by Configuration Admin; XML NS + // 1.0.0 - INVALID COMPONENT + assertEquals("Component requireNS100 should not be activated", -1, getBaseConfigData(COMP_REQUIRE_100)); + // component requireNS100 - property set by Configuration Admin; XML NS + // 1.0.0 - INVALID COMPONENT + config = cm.createFactoryConfiguration(COMP_REQUIRE_100); + config.update(props); + Thread.sleep(timeout * 3); + assertEquals("Component requireNS100 should not be activated", -1, getBaseConfigData(COMP_REQUIRE_100)); + + // component requireNS110 - property not set by Configuration Admin; XML NS + // 1.1.0 + assertEquals("Configuration data should not be available for requireNS110, and it should not be satisfied", -1, + getBaseConfigData(COMP_REQUIRE_110)); + // component requireNS110 - property set by Configuration Admin; XML NS + // 1.1.0 + config = cm.createFactoryConfiguration(COMP_REQUIRE_110); + config.update(props); + Thread.sleep(timeout * 3); + assertEquals("Configuration data should be available for requireNS110 and equal to 1", 1, + getBaseConfigData(COMP_REQUIRE_110)); + + // component ignoreNS100 - property not set by Configuration Admin; XML NS + // 1.0.0 - INVALID COMPONENT + assertEquals("Component ignoreNS100 should not be activated", -1, getBaseConfigData(COMP_IGNORE_100)); + // component ignoreNS100 - property set by Configuration Admin; XML NS 1.0.0 + // - INVALID COMPONENT + config = cm.createFactoryConfiguration(COMP_IGNORE_100); + config.update(props); + Thread.sleep(timeout * 3); + assertEquals("Component ignoreNS100 should not be activated", -1, getBaseConfigData(COMP_IGNORE_100)); + + // component ignoreNS110 - property not set by Configuration Admin; XML NS + // 1.1.0 + assertEquals("Configuration data should not be available for ignoreNS110, but it should be satisfied", 0, + getBaseConfigData(COMP_IGNORE_110)); + // component ignoreNS110 - property set by Configuration Admin; XML NS 1.1.0 + config = cm.createFactoryConfiguration(COMP_IGNORE_110); + config.update(props); + Thread.sleep(timeout * 3); + assertEquals("Configuration data should not be available for ignoreNS110, but it should be satisfied", 0, + getBaseConfigData(COMP_IGNORE_110)); uninstallBundle(tb11); } @@ -1662,8 +1758,8 @@ public class DSTest extends TestCase { final String CC_BC_MAP_INT_NS110 = "org.eclipse.equinox.ds.tests.tb12.CcBcMapIntNS110"; PropertiesProvider bs = getBaseService(NOTSET_NS100); - ComponentContext cc = (bs instanceof ComponentContextProvider) ? - ((ComponentContextProvider) bs).getComponentContext() : null; + ComponentContext cc = (bs instanceof ComponentContextProvider) ? ((ComponentContextProvider) bs) + .getComponentContext() : null; assertNotNull("Component context should be available", cc); assertEquals("Activate method of " + NOTSET_NS100 + " should be called", 1 << 0, (1 << 0) & getBaseConfigData(bs)); @@ -1723,10 +1819,12 @@ public class DSTest extends TestCase { bs = getBaseService(CC_BC_MAP_NS110); assertNotNull(bs); - assertEquals("Activate method of " + CC_BC_MAP_NS110 + " should be called", 1 << 10, (1 << 10) & getBaseConfigData(bs)); + assertEquals("Activate method of " + CC_BC_MAP_NS110 + " should be called", 1 << 10, (1 << 10) + & getBaseConfigData(bs)); cc.disableComponent(CC_BC_MAP_NS110); Thread.sleep(timeout * 3); - assertEquals("Deactivate method of " + CC_BC_MAP_NS110 + " should be called", 1 << 11, (1 << 11) & getBaseConfigData(bs)); + assertEquals("Deactivate method of " + CC_BC_MAP_NS110 + " should be called", 1 << 11, (1 << 11) + & getBaseConfigData(bs)); bs = getBaseService(INT_NS110); assertNotNull(bs); @@ -1741,7 +1839,7 @@ public class DSTest extends TestCase { int data = getBaseConfigData(bs); assertEquals("Deactivate method of " + CC_BC_MAP_INT_NS110 + " should be called", 1 << 13, (1 << 13) & data); - //// Testing Deactivation reasons //// + // // Testing Deactivation reasons //// assertEquals("Deactivation reason shall be DEACTIVATION_REASON_DISABLED", 1, 0xFF & (data >> 16)); final String CONT_EXP = "org.eclipse.equinox.ds.tests.tb12.ContextExp"; @@ -1764,12 +1862,13 @@ public class DSTest extends TestCase { Configuration config = cm.getConfiguration(CC_BC_MAP_INT_NS110); Dictionary properties = config.getProperties(); if (properties == null) { - properties = new Hashtable(); + properties = new Hashtable(); } properties.put("configuration.dummy", "dummy"); config.update(properties); Thread.sleep(timeout * 3); - assertEquals("Deactivation reason shall be DEACTIVATION_REASON_CONFIGURATION_MODIFIED", 3, 0xFF & (getBaseConfigData(bs) >> 16)); + assertEquals("Deactivation reason shall be DEACTIVATION_REASON_CONFIGURATION_MODIFIED", 3, + 0xFF & (getBaseConfigData(bs) >> 16)); cc.enableComponent(CC_BC_MAP_INT_NS110); Thread.sleep(timeout * 3); @@ -1779,7 +1878,8 @@ public class DSTest extends TestCase { config = cm.getConfiguration(CC_BC_MAP_INT_NS110); config.delete(); Thread.sleep(timeout * 3); - assertEquals("Deactivation reason shall be DEACTIVATION_REASON_CONFIGURATION_DELETED", 4, 0xFF & (getBaseConfigData(bs) >> 16)); + assertEquals("Deactivation reason shall be DEACTIVATION_REASON_CONFIGURATION_DELETED", 4, + 0xFF & (getBaseConfigData(bs) >> 16)); cc.enableComponent(CC_BC_MAP_INT_NS110); Thread.sleep(timeout * 3); @@ -1789,8 +1889,8 @@ public class DSTest extends TestCase { bs = getBaseService(INT_NS110); assertNotNull(bs); - ComponentContext ccIntNS110 = (bs instanceof ComponentContextProvider) ? - ((ComponentContextProvider) bs).getComponentContext() : null; + ComponentContext ccIntNS110 = (bs instanceof ComponentContextProvider) ? ((ComponentContextProvider) bs) + .getComponentContext() : null; assertNotNull("Component context should be available for " + INT_NS110, ccIntNS110); ccIntNS110.getComponentInstance().dispose(); assertEquals("Deactivation reason shall be DEACTIVATION_REASON_DISPOSED", 5, 0xFF & (getBaseConfigData(bs) >> 16)); @@ -1798,7 +1898,8 @@ public class DSTest extends TestCase { bs = getBaseService(CC_BC_MAP_INT_NS110); assertNotNull(bs); tb12.stop(); - assertEquals("Deactivation reason shall be DEACTIVATION_REASON_BUNDLE_STOPPED", 6, 0xFF & (getBaseConfigData(bs) >> 16)); + assertEquals("Deactivation reason shall be DEACTIVATION_REASON_BUNDLE_STOPPED", 6, + 0xFF & (getBaseConfigData(bs) >> 16)); uninstallBundle(tb12); } @@ -1879,10 +1980,11 @@ public class DSTest extends TestCase { assertNull("Component " + OPT_REF_100 + " should not be activated", getBaseService(OPT_REF_100)); assertNotNull("Component " + OPT_REF_110 + " should be activated", bs = getBaseService(OPT_REF_110)); - ComponentContext cc = (bs instanceof ComponentContextProvider) ? - ((ComponentContextProvider) bs).getComponentContext() : null; + ComponentContext cc = (bs instanceof ComponentContextProvider) ? ((ComponentContextProvider) bs) + .getComponentContext() : null; assertNotNull("Component context should be available", cc); - assertNotNull("Optional reference name should be set to interface attribute", cc.locateService(ComponentContextProvider.class.getName())); + assertNotNull("Optional reference name should be set to interface attribute", cc + .locateService(ComponentContextProvider.class.getName())); uninstallBundle(tb14); } @@ -1903,8 +2005,8 @@ public class DSTest extends TestCase { PropertiesProvider serviceC3 = getBaseService(C3); assertNotNull("Component " + C3 + " should be activated", serviceC3); - ComponentContext cc = (serviceC1 instanceof ComponentContextProvider) ? - ((ComponentContextProvider) serviceC1).getComponentContext() : null; + ComponentContext cc = (serviceC1 instanceof ComponentContextProvider) ? ((ComponentContextProvider) serviceC1) + .getComponentContext() : null; assertNotNull("Component context should be available", cc); cc.disableComponent(C1); @@ -1916,7 +2018,7 @@ public class DSTest extends TestCase { uninstallBundle(tb15); } - + public void testReferenceTargetProperty() throws Exception { Bundle tb16 = installBundle("tb16"); tb16.start(); @@ -1927,12 +2029,13 @@ public class DSTest extends TestCase { final String C2 = "org.eclipse.equinox.ds.tests.tb16.C2"; PropertiesProvider bs = getBaseService(EXPOSER); - ComponentContext cc = (bs instanceof ComponentContextProvider) ? - ((ComponentContextProvider) bs).getComponentContext() : null; + ComponentContext cc = (bs instanceof ComponentContextProvider) ? ((ComponentContextProvider) bs) + .getComponentContext() : null; assertNotNull("Component context should be available", cc); PropertiesProvider serviceC2 = getBaseService(C2); - // target property of referenced service of component Component2 should not be satisfied + // target property of referenced service of component Component2 should not + // be satisfied assertNull("Component " + C2 + " should not be activated because of unsatisfied reference", serviceC2); cc.enableComponent(C1); @@ -1940,7 +2043,8 @@ public class DSTest extends TestCase { assertNotNull("Component " + C1 + " should be available", getBaseService(C1)); serviceC2 = getBaseService(C2); - // target property of referenced service of component Component2 should now be satisfied + // target property of referenced service of component Component2 should now + // be satisfied assertNotNull("Component " + C2 + " should be activated", serviceC2); uninstallBundle(tb16); @@ -1970,7 +2074,7 @@ public class DSTest extends TestCase { } properties.put("component.index", new Integer(i)); config.update(properties); - + sleep0(100); } } catch (IOException e) { @@ -2019,7 +2123,8 @@ public class DSTest extends TestCase { int successCount = 0; while ((successCount < 5) && (System.currentTimeMillis() - startTime < OVERLOAD_TIMEOUT)) { Thread.sleep(100); - if (!manager17.isAllComponentsRunning() || !manager18.isAllComponentsRunning() || !manager19.isAllComponentsRunning()) { + if (!manager17.isAllComponentsRunning() || !manager18.isAllComponentsRunning() + || !manager19.isAllComponentsRunning()) { successCount = 0; continue; } @@ -2038,15 +2143,297 @@ public class DSTest extends TestCase { uninstallBundle(tb19); } + public void testLazyBundles() throws Exception { + Bundle tb20 = installBundle("tb20"); + // lazy bundle + tb20.start(Bundle.START_ACTIVATION_POLICY); + waitBundleStart(); + + final String COMP = "org.eclipse.equinox.ds.tests.tb20.component"; + + Thread.sleep(timeout); + assertTrue("Provided service of Component " + COMP + " should be available.", trackerBaseService.size() > 0); + + uninstallBundle(tb20); + } + + // Testing modified attribute for XML NS 1.0.0 + public void testModified100() throws Exception { + ConfigurationAdmin cm = (ConfigurationAdmin) trackerCM.getService(); + assertNotNull("The ConfigurationAdmin should be available", cm); + + Bundle tb21 = installBundle("tb21"); + + Hashtable props = new Hashtable(10); + props.put("config.dummy.data", new Integer(1)); + cm.getConfiguration(MOD_NOTSET_NS100).update(props); + cm.getConfiguration(MOD_NOARGS_NS100).update(props); + cm.getConfiguration(MOD_CC_NS100).update(props); + cm.getConfiguration(MOD_BC_NS100).update(props); + cm.getConfiguration(MOD_MAP_NS100).update(props); + cm.getConfiguration(MOD_CC_BC_MAP_NS100).update(props); + + Thread.sleep(timeout * 3); + + tb21.start(); + waitBundleStart(); + + props.put("config.dummy.data", new Integer(2)); + Hashtable unsatisfyingProps = new Hashtable(10); + unsatisfyingProps.put("ref.target", "(component.name=org.eclipse.equinox.ds.tests.tb21.unexisting.provider)"); + + PropertiesProvider bs = getBaseService(MOD_NOTSET_NS100); + assertNotNull(bs); + cm.getConfiguration(MOD_NOTSET_NS100).update(props); + Thread.sleep(timeout * 3); + assertEquals("Modified method of " + MOD_NOTSET_NS100 + " should not be called", 0, (1 << 0) + & getBaseConfigData(bs)); + assertEquals("Deactivate method of " + MOD_NOTSET_NS100 + " should be called", 1 << 7, (1 << 7) + & getBaseConfigData(bs)); + bs = getBaseService(MOD_NOTSET_NS100); + cm.getConfiguration(MOD_NOTSET_NS100).update(unsatisfyingProps); + Thread.sleep(timeout * 3); + assertEquals("Modified method of " + MOD_NOTSET_NS100 + " should not be called", 0, (1 << 0) + & getBaseConfigData(bs)); + assertEquals("Deactivate method of " + MOD_NOTSET_NS100 + " should be called", 1 << 7, (1 << 7) + & getBaseConfigData(bs)); + + // INVALID COMPONENTS for XML NS 1.0.0 - modified attribute is set + bs = getBaseService(MOD_NOARGS_NS100); + assertEquals("Component " + MOD_NOARGS_NS100 + " should not be activated", null, bs); + bs = getBaseService(MOD_CC_NS100); + assertEquals("Component " + MOD_CC_NS100 + " should not be activated", null, bs); + bs = getBaseService(MOD_BC_NS100); + assertEquals("Component " + MOD_BC_NS100 + " should not be activated", null, bs); + bs = getBaseService(MOD_MAP_NS100); + assertEquals("Component " + MOD_MAP_NS100 + " should not be activated", null, bs); + bs = getBaseService(MOD_CC_BC_MAP_NS100); + assertEquals("Component " + MOD_CC_BC_MAP_NS100 + " should not be activated", null, bs); + + uninstallBundle(tb21); + } + + // Testing modified attribute for XML NS 1.1.0 + public void testModified110() throws Exception { + ConfigurationAdmin cm = (ConfigurationAdmin) trackerCM.getService(); + assertNotNull("The ConfigurationAdmin should be available", cm); + + Bundle tb21a = installBundle("tb21a"); + + Hashtable props = new Hashtable(10); + props.put("config.dummy.data", new Integer(1)); + cm.getConfiguration(MOD_NOTSET_NS110).update(props); + cm.getConfiguration(MOD_NOARGS_NS110).update(props); + cm.getConfiguration(MOD_CC_NS110).update(props); + cm.getConfiguration(MOD_BC_NS110).update(props); + cm.getConfiguration(MOD_MAP_NS110).update(props); + cm.getConfiguration(MOD_CC_BC_MAP_NS110).update(props); + + Thread.sleep(timeout * 3); + + tb21a.start(); + waitBundleStart(); + + props.put("config.dummy.data", new Integer(2)); + Hashtable unsatisfyingProps = new Hashtable(10); + unsatisfyingProps.put("ref.target", "(component.name=org.eclipse.equinox.ds.tests.tb21.unexisting.provider)"); + + PropertiesProvider bs = getBaseService(MOD_NOTSET_NS110); + cm.getConfiguration(MOD_NOTSET_NS110).update(props); + Thread.sleep(timeout * 3); + assertEquals("Modified method of " + MOD_NOTSET_NS110 + " should not be called", 0, (1 << 0) + & getBaseConfigData(bs)); + assertEquals("Deactivate method of " + MOD_NOTSET_NS110 + " should be called", 1 << 7, (1 << 7) + & getBaseConfigData(bs)); + bs = getBaseService(MOD_NOTSET_NS110); + cm.getConfiguration(MOD_NOTSET_NS110).update(unsatisfyingProps); + Thread.sleep(timeout * 3); + assertEquals("Modified method of " + MOD_NOTSET_NS110 + " should not be called", 0, (1 << 0) + & getBaseConfigData(bs)); + assertEquals("Deactivate method of " + MOD_NOTSET_NS110 + " should be called", 1 << 7, (1 << 7) + & getBaseConfigData(bs)); + // Re-activating + bs = getBaseService(MOD_NOTSET_NS110); + assertEquals("Activate method of " + MOD_NOTSET_NS110 + " should be called", 1 << 6, (1 << 6) + & getBaseConfigData(bs)); + + bs = getBaseService(MOD_NOARGS_NS110); + cm.getConfiguration(MOD_NOARGS_NS110).update(props); + Thread.sleep(timeout * 3); + assertEquals("Modified method of " + MOD_NOARGS_NS110 + " should be called", 1 << 1, (1 << 1) + & getBaseConfigData(bs)); + assertEquals("Deactivate method of " + MOD_NOARGS_NS110 + " should not be called", 0, (1 << 7) + & getBaseConfigData(bs)); + cm.getConfiguration(MOD_NOARGS_NS110).update(unsatisfyingProps); + Thread.sleep(timeout * 3); + assertEquals("Deactivate method of " + MOD_NOARGS_NS110 + " should be called", 1 << 7, (1 << 7) + & getBaseConfigData(bs)); + // Re-activating + bs = getBaseService(MOD_NOARGS_NS110); + assertEquals("Activate method of " + MOD_NOARGS_NS110 + " should be called", 1 << 6, (1 << 6) + & getBaseConfigData(bs)); + + bs = getBaseService(MOD_CC_NS110); + cm.getConfiguration(MOD_CC_NS110).update(props); + Thread.sleep(timeout * 3); + assertEquals("Modified method of " + MOD_CC_NS110 + " should be called", 1 << 2, (1 << 2) & getBaseConfigData(bs)); + assertEquals("Deactivate method of " + MOD_CC_NS110 + " should not be called", 0, (1 << 7) & getBaseConfigData(bs)); + cm.getConfiguration(MOD_CC_NS110).update(unsatisfyingProps); + Thread.sleep(timeout * 3); + assertEquals("Deactivate method of " + MOD_CC_NS110 + " should be called", 1 << 7, (1 << 7) & getBaseConfigData(bs)); + // Re-activating + bs = getBaseService(MOD_CC_NS110); + assertEquals("Activate method of " + MOD_CC_NS110 + " should be called", 1 << 6, (1 << 6) & getBaseConfigData(bs)); + + bs = getBaseService(MOD_BC_NS110); + cm.getConfiguration(MOD_BC_NS110).update(props); + Thread.sleep(timeout * 3); + assertEquals("Modified method of " + MOD_BC_NS110 + " should be called", 1 << 3, (1 << 3) & getBaseConfigData(bs)); + assertEquals("Deactivate method of " + MOD_BC_NS110 + " should not be called", 0, (1 << 7) & getBaseConfigData(bs)); + cm.getConfiguration(MOD_BC_NS110).update(unsatisfyingProps); + Thread.sleep(timeout * 3); + assertEquals("Deactivate method of " + MOD_BC_NS110 + " should be called", 1 << 7, (1 << 7) & getBaseConfigData(bs)); + // Re-activating + bs = getBaseService(MOD_BC_NS110); + assertEquals("Activate method of " + MOD_BC_NS110 + " should be called", 1 << 6, (1 << 6) & getBaseConfigData(bs)); + + bs = getBaseService(MOD_MAP_NS110); + cm.getConfiguration(MOD_MAP_NS110).update(props); + Thread.sleep(timeout * 3); + assertEquals("Modified method of " + MOD_MAP_NS110 + " should be called", 1 << 4, (1 << 4) & getBaseConfigData(bs)); + assertEquals("Deactivate method of " + MOD_MAP_NS110 + " should not be called", 0, (1 << 7) & getBaseConfigData(bs)); + cm.getConfiguration(MOD_MAP_NS110).update(unsatisfyingProps); + Thread.sleep(timeout * 3); + assertEquals("Deactivate method of " + MOD_MAP_NS110 + " should be called", 1 << 7, (1 << 7) + & getBaseConfigData(bs)); + // Re-activating + bs = getBaseService(MOD_MAP_NS110); + assertEquals("Activate method of " + MOD_MAP_NS110 + " should be called", 1 << 6, (1 << 6) & getBaseConfigData(bs)); + + bs = getBaseService(MOD_CC_BC_MAP_NS110); + cm.getConfiguration(MOD_CC_BC_MAP_NS110).update(props); + Thread.sleep(timeout * 3); + assertEquals("Modified method of " + MOD_CC_BC_MAP_NS110 + " should be called", 1 << 5, (1 << 5) + & getBaseConfigData(bs)); + assertEquals("Deactivate method of " + MOD_CC_BC_MAP_NS110 + " should not be called", 0, (1 << 7) + & getBaseConfigData(bs)); + cm.getConfiguration(MOD_CC_BC_MAP_NS110).update(unsatisfyingProps); + Thread.sleep(timeout * 3); + assertEquals("Deactivate method of " + MOD_CC_BC_MAP_NS110 + " should be called", 1 << 7, (1 << 7) + & getBaseConfigData(bs)); + // Re-activating + bs = getBaseService(MOD_CC_BC_MAP_NS110); + assertEquals("Activate method of " + MOD_CC_BC_MAP_NS110 + " should be called", 1 << 6, (1 << 6) + & getBaseConfigData(bs)); + + uninstallBundle(tb21a); + } + + // Testing modified attribute - special cases + public void testModifiedSpecialCases() throws Exception { + ConfigurationAdmin cm = (ConfigurationAdmin) trackerCM.getService(); + assertNotNull("The ConfigurationAdmin should be available", cm); + + Bundle tb21a = installBundle("tb21a"); + + Hashtable props = new Hashtable(10); + props.put("config.dummy.data", new Integer(1)); + cm.getConfiguration(MOD_CC_NS110).update(props); + cm.getConfiguration(MOD_NOT_EXIST_NS110).update(props); + cm.getConfiguration(MOD_THROW_EX_NS110).update(props); + cm.getConfiguration(MOD_BC_NS110).update(props); + Thread.sleep(timeout * 3); + + tb21a.start(); + waitBundleStart(); + + // Verifying correctness of updated component properties + PropertiesProvider bs = getBaseService(MOD_CC_NS110); + props.put("config.dummy.data", new Integer(2)); + cm.getConfiguration(MOD_CC_NS110).update(props); + Thread.sleep(timeout * 3); + Object val = ((ComponentContextProvider) bs).getComponentContext().getProperties().get("config.dummy.data"); + assertEquals("Modified method of " + MOD_CC_NS110 + " should be called", 1 << 2, (1 << 2) & getBaseConfigData(bs)); + assertTrue("Component properties should be updated properly for " + MOD_CC_NS110, (new Integer(2)).equals(val)); + + // Specified modified method doesn't exist, deactivate() should be called + // instead of modified + bs = getBaseService(MOD_NOT_EXIST_NS110); + cm.getConfiguration(MOD_NOT_EXIST_NS110).update(props); + Thread.sleep(timeout * 3); + assertEquals("Deactivate method of " + MOD_NOT_EXIST_NS110 + " should be called", 1 << 7, (1 << 7) + & getBaseConfigData(bs)); + // Re-activating + bs = getBaseService(MOD_NOT_EXIST_NS110); + assertEquals("Activate method of " + MOD_NOT_EXIST_NS110 + " should be called", 1 << 6, (1 << 6) + & getBaseConfigData(bs)); + + // Specified modified method throws exception. Normal workflow should + // continue, deactivate() should not be called + bs = getBaseService(MOD_THROW_EX_NS110); + cm.getConfiguration(MOD_THROW_EX_NS110).update(props); + Thread.sleep(timeout * 3); + assertEquals("Deactivate method of " + MOD_THROW_EX_NS110 + " should not be called", 0, (1 << 7) + & getBaseConfigData(bs)); + + // Deleting component configuration + bs = getBaseService(MOD_BC_NS110); + cm.getConfiguration(MOD_BC_NS110).delete(); + Thread.sleep(timeout * 3); + assertEquals("Modified method of " + MOD_BC_NS110 + " should not be called", 0, (1 << 5) & getBaseConfigData(bs)); + assertEquals("Deactivate method of " + MOD_BC_NS110 + " should be called", 1 << 7, (1 << 7) & getBaseConfigData(bs)); + // Re-activating + bs = getBaseService(MOD_BC_NS110); + assertEquals("Activate method of " + MOD_BC_NS110 + " should be called", 1 << 6, (1 << 6) & getBaseConfigData(bs)); + + uninstallBundle(tb21a); + } + + public void testPrivateProperties() throws Exception { + Bundle tb22 = installBundle("tb22"); + tb22.start(); + waitBundleStart(); + + final String COMP = "org.eclipse.equinox.ds.tests.tb22.component"; + + ServiceReference ref = trackerBaseService.getServiceReference(); + assertNotNull("Provided service of " + COMP + " should be available", ref); + String[] keys = ref.getPropertyKeys(); + for (int i = 0; i < keys.length; i++) { + assertTrue("Private properties should not be propagated", !keys[i].startsWith(".")); + } + + uninstallBundle(tb22); + } + + // Testing situation when bind method throws exception + public void testBindException() throws Exception { + Bundle tb23 = installBundle("tb23"); + + final String MANDATORY_REF_COMP = "org.eclipse.equinox.ds.tests.tb23.mandatory"; + final String OPTIONAL_REF_COMP = "org.eclipse.equinox.ds.tests.tb23.optional"; + tb23.start(); + waitBundleStart(); + + PropertiesProvider bs = getBaseService(MANDATORY_REF_COMP); + assertEquals("Component " + MANDATORY_REF_COMP + " should not be activated", null, bs); + bs = getBaseService(OPTIONAL_REF_COMP); + assertEquals("Component " + OPTIONAL_REF_COMP + " should be activated", 1 << 2, (1 << 2) & getBaseConfigData(bs)); + + uninstallBundle(tb23); + } + /** - * Searches for component with name componentName which provides PropertiesProvider. Returns value of its - * "config.base.data" property. + * Searches for component with name componentName which provides + * PropertiesProvider. Returns value of its "config.base.data" property. * - * @param componentName - the name of the component to get data - * @return the value of property "config.base.data", provided by PropertiesProvider.getProperties(). - * Returned value is -1 when component which provides PropertiesProvider and has specified name is - * not activated. Returned value is 0 when component with specified name is active but doesn't - * have property "config.base.data". + * @param componentName + * - the name of the component to get data + * @return the value of property "config.base.data", provided by + * PropertiesProvider.getProperties(). Returned value is -1 when + * component which provides PropertiesProvider and has specified name + * is not activated. Returned value is 0 when component with specified + * name is active but doesn't have property "config.base.data". */ private int getBaseConfigData(String componentName) { PropertiesProvider s = getBaseService(componentName); @@ -2061,7 +2448,7 @@ public class DSTest extends TestCase { if ((props = s.getProperties()) != null) { Object prop = props.get("config.base.data"); if (prop instanceof Integer) { - value = ((Integer)prop).intValue(); + value = ((Integer) prop).intValue(); } } } @@ -2075,9 +2462,9 @@ public class DSTest extends TestCase { } for (int i = 0; i < services.length; i++) { if (services[i] instanceof PropertiesProvider) { - PropertiesProvider s = (PropertiesProvider)services[i]; + PropertiesProvider s = (PropertiesProvider) services[i]; Dictionary props = s.getProperties(); - if (props != null && ((String)props.get(ComponentConstants.COMPONENT_NAME)).equals(componentName)) { + if (props != null && ((String) props.get(ComponentConstants.COMPONENT_NAME)).equals(componentName)) { return s; } } @@ -2090,22 +2477,22 @@ public class DSTest extends TestCase { } private Bundle installBundle(String bundle) throws BundleException { - Bundle b = installer.installBundle(bundle); - return b; + Bundle b = installer.installBundle(bundle); + return b; } private void uninstallBundle(Bundle bundle) throws BundleException { - installer.uninstallBundle(bundle); + installer.uninstallBundle(bundle); } private ServiceRegistration registerService(String className, Object service, Dictionary props) { ServiceRegistration sr = getContext().registerService(className, service, props); - + registeredServices.put(service, sr); - + return sr; } - + private void unregisterService(Object service) { ServiceRegistration sr = (ServiceRegistration) registeredServices.get(service); if (sr != null) { @@ -2113,17 +2500,17 @@ public class DSTest extends TestCase { registeredServices.remove(sr); } } - + private void unregisterService(ServiceRegistration reg) { Enumeration e = registeredServices.elements(); - while(e.hasMoreElements()) { + while (e.hasMoreElements()) { Object service = e.nextElement(); if (reg == null || registeredServices.get(service) == reg) { unregisterService(service); } } } - + private void unregisterAllServices() { Enumeration e = registeredServices.elements(); while (e.hasMoreElements()) { @@ -2131,11 +2518,11 @@ public class DSTest extends TestCase { unregisterService(service); } } - + private void log(String msg) { -// System.out.println("[Declarative Service TC] " + msg); + // System.out.println("[Declarative Service TC] " + msg); } - + public void sleep0(long millisToSleep) { long start = System.currentTimeMillis(); do { @@ -2151,5 +2538,5 @@ public class DSTest extends TestCase { sleep0(2 * timeout); } } - + } |