}
@Test
public void testMBeanInterface() throws Exception {
ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
assertNotNull(mbean);
//get bundles
Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
assertNotNull(a);
Bundle b = context().getBundleByName("org.apache.aries.jmx.test.bundleb");
assertNotNull(b);
// get services
ServiceReference refA = bundleContext.getServiceReference(InterfaceA.class.getName());
assertNotNull(refA);
long serviceAId = (Long) refA.getProperty(Constants.SERVICE_ID);
assertTrue(serviceAId > -1);
ServiceReference refB = bundleContext.getServiceReference(InterfaceB.class.getName());
assertNotNull(refB);
long serviceBId = (Long) refB.getProperty(Constants.SERVICE_ID);
assertTrue(serviceBId > -1);
ServiceReference[] refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
assertNotNull(refs);
assertEquals(1, refs.length);
ServiceReference msf = refs[0];
// getBundleIdentifier
assertEquals(a.getBundleId(), mbean.getBundleIdentifier(serviceAId));
//getObjectClass
String[] objectClass = mbean.getObjectClass(serviceAId);
assertEquals(2, objectClass.length);
List<String> classNames = Arrays.asList(objectClass);
assertTrue(classNames.contains(InterfaceA.class.getName()));
assertTrue(classNames.contains(ManagedService.class.getName()));
// getProperties
TabularData serviceProperties = mbean.getProperties(serviceBId);
assertNotNull(serviceProperties);
assertEquals(JmxConstants.PROPERTIES_TYPE, serviceProperties.getTabularType());
assertTrue(serviceProperties.values().size() > 1);
assertEquals("org.apache.aries.jmx.test.ServiceB",
PropertyData.from(serviceProperties.get(new Object[] { Constants.SERVICE_PID })).getValue());
// getUsingBundles
long[] usingBundles = mbean.getUsingBundles(serviceBId);
assertEquals(1, usingBundles.length);
assertEquals(a.getBundleId(), usingBundles[0]);
// listServices
TabularData allServices = mbean.listServices();
assertNotNull(allServices);
assertEquals(bundleContext.getAllServiceReferences(null, null).length, allServices.values().size());
// notifications