}
@Test
public void testMBeanInterface() throws Exception {
BundleStateMBean mbean = getMBean(OBJECTNAME, BundleStateMBean.class);
assertNotNull(mbean);
//get bundles
Bundle a = getBundle("org.apache.aries.jmx.test.bundlea");
assertNotNull(a);
Bundle b = getBundle("org.apache.aries.jmx.test.bundleb");
assertNotNull(b);
Bundle frag = getBundle("org.apache.aries.jmx.test.fragc");
assertNotNull(frag);
Bundle d = getBundle("org.apache.aries.jmx.test.bundled");
assertNotNull(d);
// exportedPackages
String[] exports = mbean.getExportedPackages(a.getBundleId());
assertEquals(2, exports.length);
List<String> packages = Arrays.asList(exports);
assertTrue(packages.contains("org.apache.aries.jmx.test.bundlea.api;2.0.0"));
assertTrue(packages.contains("org.apache.aries.jmx.test.fragmentc;0.0.0"));
//fragments
long[] fragments = mbean.getFragments(a.getBundleId());
assertEquals(1, fragments.length);
assertEquals(frag.getBundleId() , fragments[0]);
//headers
TabularData headers = mbean.getHeaders(b.getBundleId());
assertNotNull(headers);
assertEquals(BundleStateMBean.HEADERS_TYPE, headers.getTabularType());
assertTrue(headers.values().size() >= 4 );
assertEquals("org.apache.aries.jmx.test.bundleb", Header.from(headers.get(new Object[] {Constants.BUNDLE_SYMBOLICNAME})).getValue());
//hosts
long[] hosts = mbean.getHosts(frag.getBundleId());
assertEquals(1, hosts.length);
assertEquals(a.getBundleId() , hosts[0]);
//imported packages
String[] imports = mbean.getImportedPackages(a.getBundleId());
assertTrue(imports.length >= 3);
List<String> importedPackages = Arrays.asList(imports);
assertTrue(importedPackages.contains("org.osgi.framework;1.5.0"));
assertTrue(importedPackages.contains("org.apache.aries.jmx.test.bundleb.api;1.1.0"));
//last modified
assertTrue(mbean.getLastModified(b.getBundleId()) > 0);
//location
assertEquals(b.getLocation(), mbean.getLocation(b.getBundleId()));
//registered services
long[] serviceIds = mbean.getRegisteredServices(a.getBundleId());
assertEquals(1, serviceIds.length);
//required bundles
long[] required = mbean.getRequiredBundles(d.getBundleId());
assertEquals(1, required.length);
assertEquals(a.getBundleId(), required[0]);
//requiring bundles
long[] requiring = mbean.getRequiringBundles(a.getBundleId());
assertEquals(1, requiring.length);
assertEquals(d.getBundleId(), requiring[0]);
//services in use
long[] servicesInUse = mbean.getServicesInUse(a.getBundleId());
assertEquals(1, servicesInUse.length);
//start level
long startLevel = mbean.getStartLevel(b.getBundleId());
assertTrue(startLevel >= 0);
//state
assertEquals("ACTIVE", mbean.getState(b.getBundleId()));
//isFragment
assertFalse(mbean.isFragment(b.getBundleId()));
assertTrue(mbean.isFragment(frag.getBundleId()));
//isRemovalPending
assertFalse(mbean.isRemovalPending(b.getBundleId()));
// isRequired
assertTrue(mbean.isRequired(a.getBundleId()));
assertFalse(mbean.isRequired(b.getBundleId()));
// listBundles
TabularData bundlesTable = mbean.listBundles();
assertNotNull(bundlesTable);
assertEquals(BundleStateMBean.BUNDLES_TYPE, bundlesTable.getTabularType());
assertEquals(bundleContext.getBundles().length, bundlesTable.values().size());