when(ep2.getImportingBundles()).thenReturn(new Bundle[] { bundle, b3 });
when(ep2.getName()).thenReturn("org.apache.aries.jmx.b2");
when(ep2.getVersion()).thenReturn(Version.parseVersion("2.0.1"));
PackageAdmin admin = mock(PackageAdmin.class);
when(admin.getExportedPackages(b1)).thenReturn(new ExportedPackage[] { ep1 });
when(admin.getExportedPackages(b2)).thenReturn(new ExportedPackage[] { ep2 });
when(admin.getExportedPackages(b3)).thenReturn(null);
//check first with DynamicImport
Dictionary<String, String> headers = new Hashtable<String, String>();
headers.put(Constants.DYNAMICIMPORT_PACKAGE, "*");
when(bundle.getHeaders()).thenReturn(headers);
assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0" , "org.apache.aries.jmx.b2;2.0.1"}
, getBundleImportedPackages(context, bundle, admin));
//check with ImportPackage statement
headers.remove(Constants.DYNAMICIMPORT_PACKAGE);
String importPackageStatement = "org.apache.aries.jmx.b1;version=0.0.0;resolution:=optional,org.apache.aries.jmx.b2;attribute:=value";
headers.put(Constants.IMPORT_PACKAGE, importPackageStatement);
when(admin.getExportedPackages("org.apache.aries.jmx.b1")).thenReturn(new ExportedPackage[] { ep1 });
when(admin.getExportedPackages("org.apache.aries.jmx.b2")).thenReturn(new ExportedPackage[] { ep2 });
assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0" , "org.apache.aries.jmx.b2;2.0.1"}
, getBundleImportedPackages(context, bundle, admin));