@Test
public void testToCompositeData() throws Exception {
Bundle bundle = mock(Bundle.class);
BundleContext context = mock(BundleContext.class);
PackageAdmin packageAdmin = mock(PackageAdmin.class);
StartLevel startLevel = mock(StartLevel.class);
Bundle b1 = mock(Bundle.class);
when(b1.getSymbolicName()).thenReturn("b1");
when(b1.getBundleId()).thenReturn(new Long(44));
Bundle b2 = mock(Bundle.class);
when(b2.getSymbolicName()).thenReturn("b2");
when(b2.getBundleId()).thenReturn(new Long(55));
Bundle b3 = mock(Bundle.class);
when(b3.getSymbolicName()).thenReturn("b3");
when(b3.getBundleId()).thenReturn(new Long(66));
when(context.getBundles()).thenReturn(new Bundle[] { bundle, b1, b2, b3 });
when(bundle.getSymbolicName()).thenReturn("test");
when(bundle.getVersion()).thenReturn(Version.emptyVersion);
when(bundle.getBundleId()).thenReturn(new Long(1));
when(bundle.getLastModified()).thenReturn(new Long(12345));
when(bundle.getLocation()).thenReturn("location");
//headers
Dictionary<String, String> headers = new Hashtable<String, String>();
headers.put(Constants.BUNDLE_SYMBOLICNAME, "test");
headers.put(Constants.BUNDLE_VERSION, "0.0.0");
when(bundle.getHeaders()).thenReturn(headers);
//exported packages
ExportedPackage exported = mock(ExportedPackage.class);
when(exported.getName()).thenReturn("org.apache.aries.jmx");
when(exported.getVersion()).thenReturn(new Version("1.0.0"));
when(packageAdmin.getExportedPackages(bundle)).thenReturn(new ExportedPackage[] { exported });
//imported packages
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"));
headers.put(Constants.DYNAMICIMPORT_PACKAGE, "*");
when(packageAdmin.getExportedPackages(b1)).thenReturn(new ExportedPackage[] { ep1 });
when(packageAdmin.getExportedPackages(b2)).thenReturn(new ExportedPackage[] { ep2 });
when(packageAdmin.getExportedPackages(b3)).thenReturn(null);
//required bundles
RequiredBundle rb1 = mock(RequiredBundle.class);
when(rb1.getBundle()).thenReturn(b1);
when(rb1.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b2 });
RequiredBundle rb2 = mock(RequiredBundle.class);
when(rb2.getBundle()).thenReturn(b2);
when(rb2.getRequiringBundles()).thenReturn(new Bundle[] { b1 });
RequiredBundle rb3 = mock(RequiredBundle.class);
when(rb3.getBundle()).thenReturn(b3);
when(rb3.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b1, b2 });
headers.put(Constants.REQUIRE_BUNDLE, "b1;bundle-version=\"1.0.0\",b3;bundle-version=\"2.0.0\"");
when(packageAdmin.getRequiredBundles("b1")).thenReturn(new RequiredBundle[] { rb1 });
when(packageAdmin.getRequiredBundles("b2")).thenReturn(new RequiredBundle[] { rb2 });
when(packageAdmin.getRequiredBundles("b3")).thenReturn(new RequiredBundle[] { rb3 });
//services in use
ServiceReference s1 = mock(ServiceReference.class);
when(s1.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(15));
ServiceReference s2 = mock(ServiceReference.class);