use of javax.management.openmbean.CompositeData in project aries by apache.
the class FrameworkMBeanTest method testMBeanInterface.
@Test
public void testMBeanInterface() throws IOException {
long[] bundleIds = new long[] { 1, 2 };
int[] newlevels = new int[] { 1, 1 };
CompositeData compData = framework.setBundleStartLevels(bundleIds, newlevels);
assertNotNull(compData);
BatchActionResult batch2 = BatchActionResult.from(compData);
assertNotNull(batch2.getCompleted());
assertTrue(batch2.isSuccess());
assertNull(batch2.getError());
assertNull(batch2.getRemainingItems());
File file = File.createTempFile("bundletest", ".jar");
file.deleteOnExit();
Manifest man = new Manifest();
man.getMainAttributes().putValue("Manifest-Version", "1.0");
JarOutputStream jaros = new JarOutputStream(new FileOutputStream(file), man);
jaros.flush();
jaros.close();
long bundleId = 0;
try {
bundleId = framework.installBundleFromURL(file.getAbsolutePath(), file.toURI().toString());
} catch (Exception e) {
fail("Installation of test bundle shouldn't fail");
}
try {
framework.uninstallBundle(bundleId);
} catch (Exception e) {
fail("Uninstallation of test bundle shouldn't fail");
}
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class Util method decode.
public static CompositeData decode(Byte[] wrap) {
if (null == wrap)
return null;
byte[] prim = new byte[wrap.length];
for (int i = 0; i < wrap.length; i++) {
prim[i] = wrap[i];
}
ByteArrayInputStream inBytes = new ByteArrayInputStream(prim);
ObjectInputStream inObject;
CompositeData data;
try {
inObject = new ObjectInputStream(inBytes);
data = (CompositeData) inObject.readObject();
inObject.close();
return data;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class ServiceStateMBeanTest method testGetServiceAndGetProperty.
@Test
public void testGetServiceAndGetProperty() throws Exception {
ServiceReference sref = bundleContext.getServiceReference(InterfaceA.class);
// Get service to increase service references
context().getService(sref);
Long serviceID = (Long) sref.getProperty(Constants.SERVICE_ID);
CompositeData svcData = mbean.getService(serviceID);
assertEquals(serviceID, svcData.get(ServiceStateMBean.IDENTIFIER));
assertEquals(sref.getBundle().getBundleId(), svcData.get(ServiceStateMBean.BUNDLE_IDENTIFIER));
Set<String> expectedClasses = new HashSet<String>(Arrays.asList(InterfaceA.class.getName(), ManagedService.class.getName()));
Set<String> actualClasses = new HashSet<String>(Arrays.asList((String[]) svcData.get(ServiceStateMBean.OBJECT_CLASS)));
assertEquals(expectedClasses, actualClasses);
Bundle[] ub = sref.getUsingBundles();
assertEquals("Precondition", 1, ub.length);
assertTrue(Arrays.equals(new Long[] { ub[0].getBundleId() }, (Long[]) svcData.get("UsingBundles")));
// Test mbean.getProperty()
String pid = (String) sref.getProperty(Constants.SERVICE_PID);
CompositeData pidData = mbean.getProperty(serviceID, Constants.SERVICE_PID);
assertEquals(pid, pidData.get("Value"));
assertEquals("String", pidData.get("Type"));
CompositeData idData = mbean.getProperty(serviceID, Constants.SERVICE_ID);
assertEquals("" + serviceID, idData.get("Value"));
assertEquals("Long", idData.get("Type"));
CompositeData ocData = mbean.getProperty(serviceID, Constants.OBJECTCLASS);
String form1 = InterfaceA.class.getName() + "," + ManagedService.class.getName();
String form2 = ManagedService.class.getName() + "," + InterfaceA.class.getName();
assertTrue(ocData.get("Value").equals(form1) || ocData.get("Value").equals(form2));
assertEquals("Array of String", ocData.get("Type"));
context().ungetService(sref);
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class ServiceStateMBeanTest method testListServicesSelectiveItems.
@SuppressWarnings("unchecked")
@Test
public void testListServicesSelectiveItems() throws Exception {
String filter = "(|(service.pid=org.apache.aries.jmx.test.ServiceB)(service.pid=jmx.test.B.factory))";
ServiceReference[] refs = bundleContext.getAllServiceReferences(null, filter);
TabularData svcData = mbean.listServices(null, filter, ServiceStateMBean.BUNDLE_IDENTIFIER);
assertEquals(refs.length, svcData.size());
long id = refs[0].getBundle().getBundleId();
for (ServiceReference ref : refs) {
assertEquals("Precondition", id, ref.getBundle().getBundleId());
}
for (CompositeData cd : new ArrayList<CompositeData>((Collection<CompositeData>) svcData.values())) {
assertEquals(id, cd.get(ServiceStateMBean.BUNDLE_IDENTIFIER));
assertNotNull(cd.get(ServiceStateMBean.IDENTIFIER));
assertNull(cd.get(ServiceStateMBean.OBJECT_CLASS));
assertNull(cd.get(ServiceStateMBean.USING_BUNDLES));
}
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class BundleWiringStateMBeanTest method jmxCapReqToMap.
private Map<Map<String, Object>, Map<String, String>> jmxCapReqToMap(CompositeData[] jmxCapabilitiesOrRequirements) {
Map<Map<String, Object>, Map<String, String>> actualCapabilities = new HashMap<Map<String, Object>, Map<String, String>>();
for (CompositeData jmxCapReq : jmxCapabilitiesOrRequirements) {
Map<String, Object> aMap = getJmxAttributes(jmxCapReq);
Map<String, String> dMap = getJmxDirectives(jmxCapReq);
actualCapabilities.put(aMap, dMap);
}
return actualCapabilities;
}
Aggregations