You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by mn...@apache.org on 2012/07/10 18:44:09 UTC

svn commit: r1359774 - in /aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests: SubsystemDependencyTestBase.java SubsystemDependency_4DTest.java SubsystemDependency_4ETest.java

Author: mnuttall
Date: Tue Jul 10 16:44:08 2012
New Revision: 1359774

URL: http://svn.apache.org/viewvc?rev=1359774&view=rev
Log:
Aries-865: Start on test for OSGi Subsystem CTT section 4E.

Added:
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependency_4ETest.java
Modified:
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependencyTestBase.java
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependency_4DTest.java

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependencyTestBase.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependencyTestBase.java?rev=1359774&r1=1359773&r2=1359774&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependencyTestBase.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependencyTestBase.java Tue Jul 10 16:44:08 2012
@@ -2,6 +2,7 @@ package org.apache.aries.subsystem.ctt.i
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.osgi.framework.namespace.BundleNamespace.BUNDLE_NAMESPACE;
 import static org.osgi.framework.namespace.PackageNamespace.PACKAGE_NAMESPACE;
 
@@ -16,6 +17,7 @@ import org.junit.BeforeClass;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
@@ -242,4 +244,24 @@ public abstract class SubsystemDependenc
 		assertEquals ("Wrong bundle provider", expectedProvidingBundleName, providingBundle);
 	}
 
+	/**
+	 * Verify that bundles with names bundleNames are installed into the subsystem with subsystemName
+	 * and bundle context bc
+	 * @param bc
+	 * @param subsystemName
+	 * @param bundleNames
+	 */
+	protected void verifyBundlesInstalled (BundleContext bc, String subsystemName, String ... bundleNames)
+	{
+		for (String bundleName: bundleNames) {
+			boolean bundleFound = false;
+			inner: for (Bundle b: bc.getBundles()) { 
+				if (b.getSymbolicName().equals(bundleName)) { 
+					bundleFound = true;
+					break inner;
+				}
+			}
+			assertTrue ("Bundle " + bundleName + " not found in " + subsystemName + "subsystem", bundleFound);
+		}
+	}
 }

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependency_4DTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependency_4DTest.java?rev=1359774&r1=1359773&r2=1359774&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependency_4DTest.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependency_4DTest.java Tue Jul 10 16:44:08 2012
@@ -1,6 +1,5 @@
 package org.apache.aries.subsystem.ctt.itests;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import java.util.HashMap;
@@ -9,6 +8,7 @@ import java.util.Map;
 import org.junit.Before;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.service.subsystem.Subsystem;
 import org.osgi.service.subsystem.SubsystemConstants;
 
@@ -47,18 +47,12 @@ public class SubsystemDependency_4DTest 
 	public void verifyBundesFandGinstalledIntoRootSubsystem() throws Exception
 	{
 		startSubsystem();
-		Bundle[] rootBundles = bundleContext.getBundles();
-		boolean bundleFinstalled = false;
-		boolean bundleGinstalled = false;
-		for (Bundle b : rootBundles) { 
-			if (b.getSymbolicName().equals(BUNDLE_F)) bundleFinstalled = true;
-			if (b.getSymbolicName().equals(BUNDLE_G)) bundleGinstalled = true;
-		}
-		assertTrue ("Bundle F not found in root subsystem", bundleFinstalled);
-		assertTrue ("Bundle G not found in root subsystem", bundleGinstalled);
+		verifyBundlesInstalled (bundleContext, "Root", BUNDLE_F, BUNDLE_G);
 		stopSubsystem();
 	}
 	
+
+	
 	// - Verify the wiring of C and E wire to F->x and G->y respectively
 	@Test
 	public void verifyBundleCWiredToPackageXFromBundleF() throws Exception

Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependency_4ETest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependency_4ETest.java?rev=1359774&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependency_4ETest.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/ctt/itests/SubsystemDependency_4ETest.java Tue Jul 10 16:44:08 2012
@@ -0,0 +1,149 @@
+package org.apache.aries.subsystem.ctt.itests;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemConstants;
+
+/*
+ *  E) Test acceptDependencies policy
+    1. Root is the only acceptDependencies policy
+       a. - Register repository R2
+          - Using the Root subsystem, install a composite subsystem S1 with 
+            - no content bundles 
+            - imports package x, requires bundle A and requires capability y
+          - Using the subsystem S1, install an application S2 with
+            - content bundles C, D and E
+          - Verify that bundles A and B got installed into the Root Subsystem
+          - Verify the wiring of C, D and E wire to A->x, A, B->y respectively
+          - Repeat test with S2 as a composite that imports package x, requires bundle A and required capability y
+          - Repeat test with S2 as a feature
+       b. - same as 4E1a except S2 is a content resource of S1
+          - There are 6 combinations to test
+            - app_app, app_comp, app_feat, comp_app, comp_comp, comp_feat
+    2. A non-Root subsystem has acceptDependencies policy
+       a. - Register repository R2
+          - Using the Root subsystem, install a composite subsystem S1 with 
+            - no content bundles 
+            - acceptTransitive policy
+            - no sharing policy
+          - Using the subsystem S1, install an application S2 with
+            - content bundles C, D and E
+            - note sharing policy gets computed
+          - Verify that bundles A and B got installed into the S1 Subsystem
+          - Verify the wiring of C, D and E wire to A->x, A, B->y respectively
+          - Repeat test with S2 as a composite that imports package x, requires bundle A and required capability y
+          - Repeat test with S2 as a feature
+       b. - same as 4E2a except S2 is a content resource of S1
+          - There are 6 combinations to test
+            - app_app, app_comp, app_feat, comp_app, comp_comp, comp_feat
+    3. Invalid sharing policy prevents dependency installation
+       a. - Register repository R2
+          - Using the Root subsystem, install a composite subsystem S1 with 
+            - no content bundles 
+            - NO acceptDependency policy
+            - no sharing policy
+          - Using the subsystem S1, install an application S2 with
+            - content bundles C, D and E
+            - note the sharing policy gets computed
+          - Verify the installation of S2 fails because there is no valid place to install the 
+            required transitive resources A and B that allow S2 constituents to have access.
+          - Verify resources A and B are not installed in the Root subsystem.
+          - Repeat test with S2 as a composite that imports package x, requires bundle A and requires capability y.
+          - Repeat test with S2 as a feature
+       c. - same as 4E3a except S1 is a composite that has S2 in its Subsystem-Content; S1 fails to install
+ */
+public class SubsystemDependency_4ETest extends SubsystemDependencyTestBase 
+{
+	/*
+	1. Root is the only acceptDependencies policy
+    a. - Register repository R2
+       - Using the Root subsystem, install a composite subsystem S1 with 
+         - no content bundles 
+         - imports package x, requires bundle A and requires capability y
+       - Using the subsystem S1, install an application S2 with
+         - content bundles C, D and E
+       - Verify that bundles A and B got installed into the Root Subsystem
+       - Verify the wiring of C, D and E wire to A->x, A, B->y respectively
+       - Repeat test with S2 as a composite that imports package x, requires bundle A and required capability y
+       - Repeat test with S2 as a feature
+    b. - same as 4E1a except S2 is a content resource of S1
+       - There are 6 combinations to test
+         - app_app, app_comp, app_feat, comp_app, comp_comp, comp_feat
+	*/
+	private static final String SUBSYSTEM_4E_S1 = "sdt_composite4e_s1.esa";
+	private static final String SUBSYSTEM_4E_S2 = "sdt_application4e_s1.esa";
+	private static boolean _testSubsystemsCreated = false;
+	private Subsystem subsystem_s1;
+	
+	@Before
+	public void setUp() throws Exception
+	{
+		super.setUp();
+		if (!_testSubsystemsCreated) { 
+			createComposite4E_S1();
+			createApplication4E_S2();
+		}
+		registerRepositoryR2();
+	}
+	
+	/*
+	 * Using the subsystem S1, install an application S2 with
+         - content bundles C, D and E
+       - Verify that bundles A and B got installed into the Root Subsystem
+	 */
+	@Test
+	public void verifyBundlesAandBInstalledIntoRootSubsystem() throws Exception
+	{
+		Subsystem s1 = installSubsystemFromFile(SUBSYSTEM_4E_S1);
+		startSubsystem(s1);
+		
+		Subsystem s2 = installSubsystemFromFile(s1, SUBSYSTEM_4E_S2);
+		startSubsystem(s2);
+		
+		verifyBundlesInstalled (bundleContext, "Root", BUNDLE_A, BUNDLE_B);
+		
+		stopSubsystem(s2);
+		stopSubsystem(s1);
+		uninstallSubsystem(s2);
+		uninstallSubsystem(s1);
+		
+	}
+	
+	/*
+	 * a composite subsystem S1 with 
+         - no content bundles 
+         - imports package x, requires bundle A and requires capability y
+	 */
+	private static void createComposite4E_S1() throws Exception
+	{
+		Map<String, String> attributes = new HashMap<String, String>();
+		attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, SUBSYSTEM_4E_S1);
+		attributes.put(SubsystemConstants.SUBSYSTEM_TYPE, SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE);
+		attributes.put(Constants.IMPORT_PACKAGE, "x");
+		attributes.put(Constants.REQUIRE_BUNDLE, BUNDLE_A);
+		attributes.put(Constants.REQUIRE_CAPABILITY, "y"); 
+		createManifest(SUBSYSTEM_4E_S1 + ".mf", attributes);
+		createSubsystem(SUBSYSTEM_4E_S1);
+	}
+
+	/* an application S2 with
+    - content bundles C, D and E */
+	private static void createApplication4E_S2() throws Exception
+	{
+		Map<String, String> attributes = new HashMap<String, String>();
+		attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, SUBSYSTEM_4E_S2);
+		attributes.put(SubsystemConstants.SUBSYSTEM_TYPE, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION);
+		String appContent = BUNDLE_C + ", " + BUNDLE_D + ", " + BUNDLE_E;
+		attributes.put(SubsystemConstants.SUBSYSTEM_CONTENT, appContent);
+		createManifest(SUBSYSTEM_4E_S2 + ".mf", attributes);
+		createSubsystem(SUBSYSTEM_4E_S2);
+	}
+
+
+	
+}