diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-06 00:28:36 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-06 00:28:36 +0000 |
commit | 00f9947613624b251551ba709824f97f1b6c2fb1 (patch) | |
tree | de2c513df053df6e6c93e9e206fb3a52016bc9c4 /sca-java-2.x/trunk/modules/extensibility-equinox/src/test | |
parent | 99429fad345a10b9a3cc2fa99f828fb656da63a5 (diff) |
Only search for bundles with SCA-Version: 1.1 header for Tuscany 2.x extension points and extensions
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@907138 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/extensibility-equinox/src/test')
4 files changed, 25 insertions, 48 deletions
diff --git a/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java b/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java index deb4221f4f..0b0e46fd15 100644 --- a/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java +++ b/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java @@ -19,17 +19,9 @@ package org.apache.tuscany.sca.extensibility.equinox; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; -import java.util.jar.JarInputStream; -import java.util.jar.Manifest; import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.junit.AfterClass; @@ -46,7 +38,8 @@ import org.osgi.framework.BundleContext; */ public class EquinoxServiceDiscovererTestCase { private static EquinoxServiceDiscoverer discoverer; - private static Bundle testBundle; + private static Bundle testBundle1; + private static Bundle testBundle2; private static TestEquinoxHost host; private static String getState(Bundle b) { @@ -82,44 +75,15 @@ public class EquinoxServiceDiscovererTestCase { host = new TestEquinoxHost(); BundleContext context = host.start(); - InputStream is = EquinoxServiceDiscovererTestCase.class.getResourceAsStream("/test-bundle.jar"); - testBundle = context.installBundle("test-bundle", is); + InputStream is = EquinoxServiceDiscovererTestCase.class.getResourceAsStream("/test-bundle-v1.jar"); + testBundle1 = context.installBundle("test-bundle-v1", is); is.close(); + + is = EquinoxServiceDiscovererTestCase.class.getResourceAsStream("/test-bundle-v2.jar"); + testBundle2 = context.installBundle("test-bundle-v2", is); + is.close(); + discoverer = new EquinoxServiceDiscoverer(context); - File dep = new File("target/bundles"); - List<Bundle> bundles = new ArrayList<Bundle>(); - if(dep.isDirectory()) { - for (File f : dep.listFiles()) { - BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f)); - JarInputStream jis = new JarInputStream(bis); - Manifest manifest = jis.getManifest(); - if (manifest == null || manifest.getMainAttributes().getValue("Bundle-Name") == null) { - bis.close(); - continue; - } - bis.close(); - bis = new BufferedInputStream(new FileInputStream(f)); - Bundle b = context.installBundle(f.getName(), bis); - System.out.println("Installed " + b.getSymbolicName() + " [" + getState(b) + "]"); - bundles.add(b); - bis.close(); - } - } - for (Bundle b : bundles) { - b.start(); - System.out.println("Started "+b.getSymbolicName() + " [" + getState(b) + "]"); - /* - // Get the Platform.getExtensionRegistry() - if ("org.eclipse.core.runtime".equals(b.getSymbolicName())) { - // The Platform class loaded by the bundle is different that the one - // on the classpath - Class<?> cls = b.loadClass("org.eclipse.core.runtime.Platform"); - Method m = cls.getMethod("getExtensionRegistry"); - Object reg = m.invoke(cls); - System.out.println(reg); - } - */ - } } /** @@ -127,9 +91,13 @@ public class EquinoxServiceDiscovererTestCase { */ @AfterClass public static void tearDownAfterClass() throws Exception { - if (testBundle != null) { + if (testBundle1 != null) { + // Uninstall the bundle to clean up the cache + testBundle1.uninstall(); + } + if (testBundle2 != null) { // Uninstall the bundle to clean up the cache - testBundle.uninstall(); + testBundle2.uninstall(); } host.stop(); System.out.println("Done"); @@ -137,8 +105,9 @@ public class EquinoxServiceDiscovererTestCase { @Test public void testDiscovery() throws IOException { + // Both version 1 and 2 should be found because test.TestService is not a Tuscany service Collection<ServiceDeclaration> descriptors = discoverer.getServiceDeclarations("test.TestService"); - Assert.assertEquals(1, descriptors.size()); + Assert.assertEquals(2, descriptors.size()); descriptors = discoverer.getServiceDeclarations("notthere"); Assert.assertEquals(0, descriptors.size()); } @@ -151,5 +120,13 @@ public class EquinoxServiceDiscovererTestCase { Assert.assertNull(descriptor); } + @Test + public void testTuscanyDiscovery() throws IOException { + Collection<ServiceDeclaration> descriptors = discoverer.getServiceDeclarations("org.apache.tuscany.sca.test.TestService"); + // Only the version 2 should be found + Assert.assertEquals(1, descriptors.size()); + ServiceDeclaration sd = descriptors.iterator().next(); + Assert.assertEquals("2", sd.getAttributes().get("version")); + } } diff --git a/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/resources/test-bundle-v1.jar b/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/resources/test-bundle-v1.jar Binary files differnew file mode 100644 index 0000000000..61c7b5a49e --- /dev/null +++ b/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/resources/test-bundle-v1.jar diff --git a/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/resources/test-bundle-v2.jar b/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/resources/test-bundle-v2.jar Binary files differnew file mode 100644 index 0000000000..b02c368c58 --- /dev/null +++ b/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/resources/test-bundle-v2.jar diff --git a/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/resources/test-bundle.jar b/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/resources/test-bundle.jar Binary files differdeleted file mode 100644 index afee051f61..0000000000 --- a/sca-java-2.x/trunk/modules/extensibility-equinox/src/test/resources/test-bundle.jar +++ /dev/null |