diff options
author | Thomas Watson | 2017-01-23 15:49:28 +0000 |
---|---|---|
committer | Thomas Watson | 2017-01-23 16:20:32 +0000 |
commit | c7ddbdee1796b57ef64239ca52c86ad204f73a06 (patch) | |
tree | 5d35261f278a69aad8d2f53f00a3f3d9a4a008c5 | |
parent | fd327fcab66d794888abd97647d45b2fd7862745 (diff) | |
download | rt.equinox.bundles-c7ddbdee1796b57ef64239ca52c86ad204f73a06.tar.gz rt.equinox.bundles-c7ddbdee1796b57ef64239ca52c86ad204f73a06.tar.xz rt.equinox.bundles-c7ddbdee1796b57ef64239ca52c86ad204f73a06.zip |
Bug 510679 - Fix implementation of ScrService and add very basic test
Change-Id: I4f79c6c96accc17fb531e7a7a5289130f77d33d5
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
8 files changed, 90 insertions, 6 deletions
diff --git a/bundles/org.eclipse.equinox.ds.tests/.classpath b/bundles/org.eclipse.equinox.ds.tests/.classpath index d81e9c02f..90ccffe4f 100644 --- a/bundles/org.eclipse.equinox.ds.tests/.classpath +++ b/bundles/org.eclipse.equinox.ds.tests/.classpath @@ -31,5 +31,6 @@ <classpathentry kind="src" output="scr_test/tb23" path="bundles_src/tb23"/> <classpathentry kind="src" output="scr_test/tb25" path="bundles_src/tb25"/> <classpathentry kind="src" output="scr_test/tb26" path="bundles_src/tb26"/> + <classpathentry kind="src" output="scr_test/tb27" path="bundles_src/tb27"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/bundles/org.eclipse.equinox.ds.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.ds.tests/META-INF/MANIFEST.MF index a9d43fb37..8bf07ea0c 100644 --- a/bundles/org.eclipse.equinox.ds.tests/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.ds.tests/META-INF/MANIFEST.MF @@ -8,6 +8,7 @@ Bundle-Activator: org.eclipse.equinox.ds.tests.DSTestsActivator Bundle-ActivationPolicy: lazy Require-Bundle: org.junit Import-Package: + org.apache.felix.scr;version="1.6.0", org.eclipse.osgi.service.urlconversion;version="1.0.0", org.osgi.framework;version="1.3.0", org.osgi.service.cm;version="1.2.0", diff --git a/bundles/org.eclipse.equinox.ds.tests/build.properties b/bundles/org.eclipse.equinox.ds.tests/build.properties index 55429d97a..c7239fb29 100644 --- a/bundles/org.eclipse.equinox.ds.tests/build.properties +++ b/bundles/org.eclipse.equinox.ds.tests/build.properties @@ -40,6 +40,7 @@ bin.includes = META-INF/,\ scr_test/tb24.jar,\ scr_test/tb25.jar,\ scr_test/tb26.jar,\ + scr_test/tb27.jar,\ test.xml jars.compile.order = .,\ scr_test/tb1.jar,\ @@ -69,7 +70,8 @@ jars.compile.order = .,\ scr_test/tb23.jar,\ scr_test/tb24.jar,\ scr_test/tb25.jar,\ - scr_test/tb26.jar + scr_test/tb26.jar,\ + scr_test/tb27.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/ @@ -126,3 +128,5 @@ source.scr_test/tb25.jar = bundles_src/tb25/ manifest.scr_test/tb25.jar = META-INF/MANIFEST.MF source.scr_test/tb26.jar = bundles_src/tb26/ manifest.scr_test/tb26.jar = META-INF/MANIFEST.MF +source.scr_test/tb27.jar = bundles_src/tb27/ +manifest.scr_test/tb27.jar = META-INF/MANIFEST.MF diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb27/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb27/META-INF/MANIFEST.MF new file mode 100755 index 000000000..6b98fa56f --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb27/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Bundle-SymbolicName: org.eclipse.equinox.ds.tests.tb27 +Require-Capability: osgi.extender; + filter:="(&(osgi.extender=osgi.component)(version>=1.3)(!(version>=2.0)))" +Service-Component: OSGI-INF/*.xml diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb27/OSGI-INF/test1.xml b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb27/OSGI-INF/test1.xml new file mode 100755 index 000000000..58e44244a --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb27/OSGI-INF/test1.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<root> + <scr:component + name="test1" + enabled="true" + immediate="true" + xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0"> + <implementation class="org.eclipse.equinox.ds.tests.tb27.impl.TestService"/> + <service> + <provide interface="java.util.List"/> + </service> + <reference name="log" interface="org.osgi.service.log.LogService" /> + </scr:component> +</root> diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb27/org/eclipse/equinox/ds/tests/tb27/impl/TestService.java b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb27/org/eclipse/equinox/ds/tests/tb27/impl/TestService.java new file mode 100644 index 000000000..ce77a212d --- /dev/null +++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb27/org/eclipse/equinox/ds/tests/tb27/impl/TestService.java @@ -0,0 +1,19 @@ +package org.eclipse.equinox.ds.tests.tb27.impl; + +import java.util.AbstractCollection; +import java.util.Collections; +import java.util.Iterator; + +public class TestService<T> extends AbstractCollection<T> { + + @Override + public Iterator<T> iterator() { + return (Iterator<T>) Collections.emptyList().iterator(); + } + + @Override + public int size() { + return 0; + } + +} 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 b08b45a62..7b1f03659 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 @@ -32,6 +32,9 @@ import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import org.apache.felix.scr.Component; +import org.apache.felix.scr.Reference; +import org.apache.felix.scr.ScrService; import org.eclipse.equinox.ds.tests.BundleInstaller; import org.eclipse.equinox.ds.tests.DSTestsActivator; import org.junit.Before; @@ -2897,6 +2900,33 @@ public class DSTest { } } + @SuppressWarnings("deprecation") +@Test + public void testScrService() throws BundleException { + Bundle tb27 = installBundle("tb27"); + ServiceReference<ScrService> ref = getContext().getServiceReference(ScrService.class); + ScrService scrService = ref == null ? null : getContext().getService(ref); + assertNotNull("No ScrService.", scrService); + try { + tb27.start(); + waitBundleStart(); + Component[] tb27Comps = scrService.getComponents(tb27); + assertNotNull("No tb26 components.", tb27Comps); + assertEquals("Wrong number of components.", 1, tb27Comps.length); + Component test1 = tb27Comps[0]; + assertEquals("Wrong name.", "test1", test1.getName()); + Reference[] refs = test1.getReferences(); + assertNotNull("No references.", refs); + assertEquals("Wrong number of references.", 1, refs.length); + assertEquals("Wrong ref name.", "log", refs[0].getName()); + ServiceReference<?>[] services = refs[0].getServiceReferences(); + assertNotNull("No service references.", services); + assertEquals("Wrong number of service refs.", 1, services.length); + } finally { + uninstallBundle(tb27); + } + } + /** * Asserts that two lists contain equal elements (the order doesn't matter). */ diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ScrServiceImpl.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ScrServiceImpl.java index 7f5a97f35..22d702d92 100644 --- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ScrServiceImpl.java +++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ScrServiceImpl.java @@ -36,8 +36,14 @@ public class ScrServiceImpl implements ScrService { } private Component[] toComponents(Collection<ComponentDescriptionDTO> componentDescriptionDTOs) { - // TODO Auto-generated method stub - return null; + Collection<Component> components = new ArrayList<Component>(); + for (ComponentDescriptionDTO dto : componentDescriptionDTOs) { + Component component = toComponent(dto); + if (component != null) { + components.add(component); + } + } + return components.isEmpty() ? null : components.toArray(new Component[0]); } @Override @@ -52,8 +58,12 @@ public class ScrServiceImpl implements ScrService { } private Component toComponent(ComponentDescriptionDTO dto) { - // TODO Auto-generated method stub - return null; + Collection<ComponentConfigurationDTO> configs = scr.getComponentConfigurationDTOs(dto); + if (configs.isEmpty()) { + return null; + } + + return new ComponentImpl(configs.iterator().next()); } @Override @@ -324,8 +334,8 @@ public class ScrServiceImpl implements ScrService { this.unsatisfied = unsatisifed; } - @SuppressWarnings("rawtypes") @Override + @SuppressWarnings("rawtypes") public ServiceReference[] getServiceReferences() { Collection<ServiceReference<?>> serviceReferences = new ArrayList<ServiceReference<?>>(); for (ServiceReferenceDTO serviceRefDTO : unsatisfied.targetServices) { |