aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1449200 - in /aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests: BundleEventHookTest.java DynamicImportTest.java SubsystemTest.java
Date Fri, 22 Feb 2013 20:25:49 GMT
Author: jwross
Date: Fri Feb 22 20:25:49 2013
New Revision: 1449200

URL: http://svn.apache.org/r1449200
Log:
Add tests for dynamic package imports in sharing policy when no Import-Package header.

Modified:
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BundleEventHookTest.java
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/DynamicImportTest.java
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BundleEventHookTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BundleEventHookTest.java?rev=1449200&r1=1449199&r2=1449200&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BundleEventHookTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BundleEventHookTest.java
Fri Feb 22 20:25:49 2013
@@ -18,15 +18,11 @@
  */
 package org.apache.aries.subsystem.itests;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
@@ -35,7 +31,6 @@ import java.util.concurrent.TimeoutExcep
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.eclipse.equinox.region.RegionDigraph;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -45,9 +40,7 @@ import org.osgi.framework.BundleExceptio
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceListener;
 import org.osgi.framework.ServiceReference;
-import org.osgi.framework.namespace.IdentityNamespace;
 import org.osgi.service.subsystem.Subsystem;
-import org.osgi.service.subsystem.SubsystemConstants;
 
 @RunWith(MavenConfiguredJUnit4TestRunner.class)
 public class BundleEventHookTest extends SubsystemTest {

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/DynamicImportTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/DynamicImportTest.java?rev=1449200&r1=1449199&r2=1449200&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/DynamicImportTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/DynamicImportTest.java
Fri Feb 22 20:25:49 2013
@@ -1,14 +1,23 @@
 package org.apache.aries.subsystem.itests;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.options;
 
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.Dictionary;
+import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.aries.subsystem.itests.hello.api.Hello;
+import org.apache.aries.unittest.fixture.ArchiveFixture;
+import org.apache.aries.unittest.fixture.ArchiveFixture.JarFixture;
+import org.apache.aries.unittest.fixture.ArchiveFixture.ManifestFixture;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -22,8 +31,11 @@ import org.osgi.framework.ServiceRegistr
 import org.osgi.framework.hooks.weaving.WeavingHook;
 import org.osgi.framework.hooks.weaving.WovenClass;
 import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemConstants;
 import org.osgi.service.subsystem.SubsystemException;
 
+import aQute.lib.osgi.Constants;
+
 /*
  * Simple iTest for dynamic imports. In the first instance we'll use a 
  * DynamicImport-Package header because it's the simplest to set up. 
@@ -41,6 +53,9 @@ public class DynamicImportTest extends S
 		super.setUp();
 		if (!_testAppCreated) { 
 			createApplication("dynamicImport", new String[]{"dynamicImport.jar"});
+			createEmptyClass();
+			createBundleA();
+			createApplicationA();
 			_testAppCreated = true;
 		}
 	}
@@ -103,4 +118,86 @@ public class DynamicImportTest extends S
 //				org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=7777")
 		);
 	}
+	
+	/*
+	 * Subsystem-SymbolicName: application.a.esa
+	 * Subsystem-Content: bundle.a.jar
+	 */
+	private static final String APPLICATION_A = "application.a.esa";
+	/*
+	 * Bundle-SymbolicName: bundle.a.jar
+	 */
+	private static final String BUNDLE_A = "bundle.a.jar";
+	
+	private static void createApplicationA() throws IOException {
+		createApplicationAManifest();
+		createSubsystem(APPLICATION_A, BUNDLE_A);
+	}
+	
+	private static void createApplicationAManifest() throws IOException {
+		Map<String, String> attributes = new HashMap<String, String>();
+		attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, APPLICATION_A);
+		createManifest(APPLICATION_A + ".mf", attributes);
+	}
+	
+	private static void createBundleA() throws IOException {
+		JarFixture bundle = ArchiveFixture.newJar();
+		bundle.binary("Empty.class", new FileInputStream("Empty.class"));
+		ManifestFixture manifest = bundle.manifest();
+		manifest.attribute(Constants.BUNDLE_SYMBOLICNAME, BUNDLE_A);
+		write(BUNDLE_A, bundle);
+	}
+	
+	/*
+	 * Dynamic package imports added by a weaver to a woven class should be
+	 * added to the region's sharing policy even if the subsystem has no
+	 * Import-Package header.
+	 */
+	@Test
+	public void testDynamicPackageImportsAddedToSharingPolicyWhenNoImportPackageHeader() throws
Exception {
+		final AtomicBoolean weavingHookCalled = new AtomicBoolean(false);
+		Dictionary<String, Object> props = new Hashtable<String, Object>();
+		props.put("osgi.woven.packages", "org.osgi.framework");
+		ServiceRegistration<WeavingHook> reg = bundleContext.registerService(
+				WeavingHook.class, 
+				new WeavingHook() {
+					@Override
+					public void weave(WovenClass wovenClass) {
+						if (BUNDLE_A.equals(wovenClass.getBundleWiring().getBundle().getSymbolicName())) {
+							wovenClass.getDynamicImports().add("org.osgi.framework");
+							weavingHookCalled.set(true);
+						}
+					}
+				}, 
+				props);
+		try {
+			Subsystem s = installSubsystemFromFile(APPLICATION_A);
+			try {
+				assertNull("Import-Package header should not exist", s.getSubsystemHeaders(null).get(Constants.IMPORT_PACKAGE));
+				Bundle a = getConstituentAsBundle(s, BUNDLE_A, null, null);
+				// Force the class load so the weaving hook gets called.
+				a.loadClass("Empty");
+				assertTrue("Weaving hook not called", weavingHookCalled.get());
+				try {
+					// Try to load a class from the dynamically imported package.
+					a.loadClass("org.osgi.framework.Bundle");
+				}
+				catch (Exception e) {
+					fail("Woven dynamic package import not added to the region's sharing policy");
+				}
+			}
+			finally {
+				try {
+					s.uninstall();
+				}
+				catch (Exception e) {}
+			}
+		}
+		finally {
+			try {
+				reg.unregister();
+			}
+			catch (Exception e) {}
+		}
+	}
 }

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java?rev=1449200&r1=1449199&r2=1449200&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
Fri Feb 22 20:25:49 2013
@@ -1002,4 +1002,80 @@ public abstract class SubsystemTest exte
 			return location.substring(8);
 		return location;
 	}
+	
+	protected static final byte[] EMPTY_CLASS = new byte[] {
+			(byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 
+			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x32, 
+			(byte)0x00, (byte)0x12, (byte)0x07, (byte)0x00, 
+			(byte)0x02, (byte)0x01, (byte)0x00, (byte)0x05, 
+			(byte)0x45, (byte)0x6d, (byte)0x70, (byte)0x74, 
+			(byte)0x79, (byte)0x07, (byte)0x00, (byte)0x04, 
+			(byte)0x01, (byte)0x00, (byte)0x10, (byte)0x6a, 
+			(byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2f, 
+			(byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67, 
+			(byte)0x2f, (byte)0x4f, (byte)0x62, (byte)0x6a, 
+			(byte)0x65, (byte)0x63, (byte)0x74, (byte)0x07, 
+			(byte)0x00, (byte)0x06, (byte)0x01, (byte)0x00, 
+			(byte)0x14, (byte)0x6a, (byte)0x61, (byte)0x76, 
+			(byte)0x61, (byte)0x2f, (byte)0x69, (byte)0x6f, 
+			(byte)0x2f, (byte)0x53, (byte)0x65, (byte)0x72, 
+			(byte)0x69, (byte)0x61, (byte)0x6c, (byte)0x69, 
+			(byte)0x7a, (byte)0x61, (byte)0x62, (byte)0x6c, 
+			(byte)0x65, (byte)0x01, (byte)0x00, (byte)0x06, 
+			(byte)0x3c, (byte)0x69, (byte)0x6e, (byte)0x69, 
+			(byte)0x74, (byte)0x3e, (byte)0x01, (byte)0x00, 
+			(byte)0x03, (byte)0x28, (byte)0x29, (byte)0x56, 
+			(byte)0x01, (byte)0x00, (byte)0x04, (byte)0x43, 
+			(byte)0x6f, (byte)0x64, (byte)0x65, (byte)0x0a, 
+			(byte)0x00, (byte)0x03, (byte)0x00, (byte)0x0b, 
+			(byte)0x0c, (byte)0x00, (byte)0x07, (byte)0x00, 
+			(byte)0x08, (byte)0x01, (byte)0x00, (byte)0x0f, 
+			(byte)0x4c, (byte)0x69, (byte)0x6e, (byte)0x65, 
+			(byte)0x4e, (byte)0x75, (byte)0x6d, (byte)0x62, 
+			(byte)0x65, (byte)0x72, (byte)0x54, (byte)0x61, 
+			(byte)0x62, (byte)0x6c, (byte)0x65, (byte)0x01, 
+			(byte)0x00, (byte)0x12, (byte)0x4c, (byte)0x6f, 
+			(byte)0x63, (byte)0x61, (byte)0x6c, (byte)0x56, 
+			(byte)0x61, (byte)0x72, (byte)0x69, (byte)0x61, 
+			(byte)0x62, (byte)0x6c, (byte)0x65, (byte)0x54, 
+			(byte)0x61, (byte)0x62, (byte)0x6c, (byte)0x65, 
+			(byte)0x01, (byte)0x00, (byte)0x04, (byte)0x74, 
+			(byte)0x68, (byte)0x69, (byte)0x73, (byte)0x01, 
+			(byte)0x00, (byte)0x07, (byte)0x4c, (byte)0x45, 
+			(byte)0x6d, (byte)0x70, (byte)0x74, (byte)0x79, 
+			(byte)0x3b, (byte)0x01, (byte)0x00, (byte)0x0a, 
+			(byte)0x53, (byte)0x6f, (byte)0x75, (byte)0x72, 
+			(byte)0x63, (byte)0x65, (byte)0x46, (byte)0x69, 
+			(byte)0x6c, (byte)0x65, (byte)0x01, (byte)0x00, 
+			(byte)0x0a, (byte)0x45, (byte)0x6d, (byte)0x70, 
+			(byte)0x74, (byte)0x79, (byte)0x2e, (byte)0x6a, 
+			(byte)0x61, (byte)0x76, (byte)0x61, (byte)0x00, 
+			(byte)0x21, (byte)0x00, (byte)0x01, (byte)0x00, 
+			(byte)0x03, (byte)0x00, (byte)0x01, (byte)0x00, 
+			(byte)0x05, (byte)0x00, (byte)0x00, (byte)0x00, 
+			(byte)0x01, (byte)0x00, (byte)0x01, (byte)0x00, 
+			(byte)0x07, (byte)0x00, (byte)0x08, (byte)0x00, 
+			(byte)0x01, (byte)0x00, (byte)0x09, (byte)0x00, 
+			(byte)0x00, (byte)0x00, (byte)0x2f, (byte)0x00, 
+			(byte)0x01, (byte)0x00, (byte)0x01, (byte)0x00, 
+			(byte)0x00, (byte)0x00, (byte)0x05, (byte)0x2a, 
+			(byte)0xb7, (byte)0x00, (byte)0x0a, (byte)0xb1, 
+			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02, 
+			(byte)0x00, (byte)0x0c, (byte)0x00, (byte)0x00, 
+			(byte)0x00, (byte)0x06, (byte)0x00, (byte)0x01, 
+			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, 
+			(byte)0x00, (byte)0x0d, (byte)0x00, (byte)0x00, 
+			(byte)0x00, (byte)0x0c, (byte)0x00, (byte)0x01, 
+			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05, 
+			(byte)0x00, (byte)0x0e, (byte)0x00, (byte)0x0f, 
+			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, 
+			(byte)0x00, (byte)0x10, (byte)0x00, (byte)0x00, 
+			(byte)0x00, (byte)0x02, (byte)0x00, (byte)0x11
+		};
+	
+	protected static void createEmptyClass() throws IOException {
+		FileOutputStream fos = new FileOutputStream("Empty.class");
+		fos.write(EMPTY_CLASS);
+		fos.close();
+	}
 }



Mime
View raw message