FrameworkUtils { public static String[] getBundleImportedPackages(BundleContext localBundleContext, Bundle bundle, PackageAdmin packageAdmin) throws IllegalArgumentException { if (bundle == null) { throw new IllegalArgumentException("Argument bundle cannot be null"); } if (packageAdmin == null) { throw new IllegalArgumentException("Argument packageAdmin cannot be null"); } List<String> result = new ArrayList<String>(); for (ExportedPackage ep : getBundleImportedPackagesRaw(localBundleContext, bundle, packageAdmin)) { result.add(ep.getName()+";"+ep.getVersion()); } return result.toArray(new String[0]); } private  FrameworkUtils(); static Bundle resolveBundle(BundleContext bundleContext, long bundleId); static long[] getBundleIds(Bundle[] bundles); static long[] getBundleIds(List<Bundle> bundles); static ServiceReference resolveService(BundleContext bundleContext, long serviceId); static long[] getServiceIds(ServiceReference[] serviceReferences); static String[] getBundleExportedPackages(Bundle bundle, PackageAdmin packageAdmin); static long[] getFragmentIds(Bundle bundle, PackageAdmin packageAdmin); static long[] getHostIds(Bundle fragment, PackageAdmin packageAdmin); static String[] getBundleImportedPackages(BundleContext localBundleContext, Bundle bundle,
            PackageAdmin packageAdmin); static long[] getRegisteredServiceIds(Bundle bundle); static long[] getServicesInUseByBundle(Bundle bundle); static boolean isBundlePendingRemoval(Bundle bundle, PackageAdmin packageAdmin); static boolean isBundleRequiredByOthers(Bundle bundle, PackageAdmin packageAdmin); @SuppressWarnings("unchecked") static long[] getBundleDependencies(BundleContext localBundleContext, 
                                               Bundle bundle,
                                               PackageAdmin packageAdmin); static long[] getDependentBundles(Bundle bundle, PackageAdmin packageAdmin); static String getBundleState(Bundle bundle); static boolean arrayContains(Object[] array, Object value); static List<String> extractHeaderDeclaration(String headerStatement);  }
@Test public void testGetBundleImportedPackages() throws Exception { Bundle bundle = mock(Bundle.class); BundleContext context = mock(BundleContext.class); Bundle b1 = mock(Bundle.class); Bundle b2 = mock(Bundle.class); Bundle b3 = mock(Bundle.class); when(context.getBundles()).thenReturn(new Bundle[] { bundle, b1, b2, b3 }); ExportedPackage ep1 = mock(ExportedPackage.class); when(ep1.getImportingBundles()).thenReturn(new Bundle[] { bundle, b2, b3 }); when(ep1.getName()).thenReturn("org.apache.aries.jmx.b1"); when(ep1.getVersion()).thenReturn(Version.emptyVersion); ExportedPackage ep2 = mock(ExportedPackage.class); 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); 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)); 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;version=\"[2.0, 3.0)\""; 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)); }