use of javax.management.openmbean.CompositeData in project aries by apache.
the class BundleWiringData method getRequirements.
private static CompositeData[] getRequirements(List<BundleRequirement> requirementList) throws OpenDataException {
CompositeData[] reqData = new CompositeData[requirementList.size()];
for (int i = 0; i < requirementList.size(); i++) {
BundleRequirement requirement = requirementList.get(i);
reqData[i] = getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_REQUIREMENT_TYPE, requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet());
}
return reqData;
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class ServiceDataTest method testToCompositeData.
@Test
public void testToCompositeData() throws Exception {
ServiceReference<?> reference = mock(ServiceReference.class);
Bundle bundle = mock(Bundle.class);
String[] interfaces = new String[] { "org.apache.aries.jmx.Test", "org.apache.aries.jmx.Mock" };
Bundle b1 = mock(Bundle.class);
when(b1.getBundleId()).thenReturn(new Long(6));
Bundle b2 = mock(Bundle.class);
when(b2.getBundleId()).thenReturn(new Long(9));
when(reference.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(98));
when(reference.getBundle()).thenReturn(bundle);
when(bundle.getBundleId()).thenReturn(new Long(34));
when(reference.getProperty(Constants.OBJECTCLASS)).thenReturn(interfaces);
when(reference.getUsingBundles()).thenReturn(new Bundle[] { b1, b2 });
when(reference.getPropertyKeys()).thenReturn(new String[] { "x.vendor", "x.domain", "x.index", "x.optimized" });
when(reference.getProperty("x.vendor")).thenReturn("aries");
when(reference.getProperty("x.domain")).thenReturn("test");
when(reference.getProperty("x.index")).thenReturn(new Long(67));
when(reference.getProperty("x.optimized")).thenReturn(true);
ServiceData serviceData = new ServiceData(reference);
CompositeData compositeData = serviceData.toCompositeData();
assertEquals(new Long(98), compositeData.get(IDENTIFIER));
assertEquals(new Long(34), compositeData.get(BUNDLE_IDENTIFIER));
assertArrayEquals(new Long[] { new Long(6), new Long(9) }, (Long[]) compositeData.get(USING_BUNDLES));
assertArrayEquals(interfaces, (String[]) compositeData.get(OBJECT_CLASS));
TabularData propertiesTable = (TabularData) compositeData.get(PROPERTIES);
@SuppressWarnings("unchecked") Collection<CompositeData> propertyData = (Collection<CompositeData>) propertiesTable.values();
assertEquals(4, propertyData.size());
for (CompositeData propertyRow : propertyData) {
String key = (String) propertyRow.get(KEY);
if (key.equals("x.vendor")) {
assertEquals("aries", propertyRow.get(VALUE));
assertEquals(STRING, propertyRow.get(TYPE));
} else if (key.equals("x.domain")) {
assertEquals("test", propertyRow.get(VALUE));
assertEquals(STRING, propertyRow.get(TYPE));
} else if (key.equals("x.index")) {
assertEquals("67", propertyRow.get(VALUE));
assertEquals(LONG, propertyRow.get(TYPE));
} else if (key.equals("x.optimized")) {
assertEquals("true", propertyRow.get(VALUE));
assertEquals(BOOLEAN, propertyRow.get(TYPE));
} else {
fail("unknown key parsed from properties");
}
}
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class ServiceEventDataTest method testToCompositeData.
@Test
public void testToCompositeData() throws Exception {
ServiceEvent event = mock(ServiceEvent.class);
ServiceReference reference = mock(ServiceReference.class);
Bundle bundle = mock(Bundle.class);
when(event.getType()).thenReturn(ServiceEvent.REGISTERED);
when(event.getServiceReference()).thenReturn(reference);
when(reference.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(44));
when(reference.getProperty(Constants.OBJECTCLASS)).thenReturn(new String[] { "org.apache.aries.jmx.Mock" });
when(reference.getBundle()).thenReturn(bundle);
when(bundle.getBundleId()).thenReturn(new Long(1));
when(bundle.getLocation()).thenReturn("string");
when(bundle.getSymbolicName()).thenReturn("org.apache.aries.jmx.core");
ServiceEventData eventData = new ServiceEventData(event);
CompositeData data = eventData.toCompositeData();
assertEquals(new Long(44), data.get(IDENTIFIER));
assertEquals(new Long(1), data.get(BUNDLE_IDENTIFIER));
assertEquals("string", data.get(BUNDLE_LOCATION));
assertEquals("org.apache.aries.jmx.core", data.get(BUNDLE_SYMBOLIC_NAME));
assertArrayEquals(new String[] { "org.apache.aries.jmx.Mock" }, (String[]) data.get(OBJECT_CLASS));
assertEquals(ServiceEvent.REGISTERED, data.get(EVENT));
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class ServiceEventDataTest method testFrom.
@Test
public void testFrom() throws Exception {
Map<String, Object> items = new HashMap<String, Object>();
items.put(IDENTIFIER, new Long(7));
items.put(BUNDLE_IDENTIFIER, new Long(67));
items.put(BUNDLE_LOCATION, "string");
items.put(BUNDLE_SYMBOLIC_NAME, "test");
items.put(OBJECT_CLASS, new String[] { "org.apache.aries.jmx.Mock" });
items.put(EVENT, ServiceEvent.MODIFIED);
CompositeData compositeData = new CompositeDataSupport(SERVICE_EVENT_TYPE, items);
ServiceEventData event = ServiceEventData.from(compositeData);
assertEquals(7, event.getServiceId());
assertEquals(67, event.getBundleId());
assertArrayEquals(new String[] { "org.apache.aries.jmx.Mock" }, event.getServiceInterfaces());
assertEquals("test", event.getBundleSymbolicName());
assertEquals("string", event.getBundleLocation());
assertEquals(ServiceEvent.MODIFIED, event.getEventType());
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class PackageStateTest method testListPackages.
@Test
public void testListPackages() throws IOException {
Bundle bundle = Mockito.mock(Bundle.class);
Bundle impBundle = Mockito.mock(Bundle.class);
Mockito.when(context.getBundles()).thenReturn(new Bundle[] { bundle });
ExportedPackage exported = Mockito.mock(ExportedPackage.class);
Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
Mockito.when(exported.getImportingBundles()).thenReturn(new Bundle[] { impBundle });
Mockito.when(exported.getName()).thenReturn("test");
Mockito.when(exported.getExportingBundle()).thenReturn(bundle);
Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(4));
Mockito.when(impBundle.getBundleId()).thenReturn(Long.valueOf(5));
Mockito.when(admin.getExportedPackages(bundle)).thenReturn(new ExportedPackage[] { exported });
TabularData table = mbean.listPackages();
Assert.assertEquals(PackageStateMBean.PACKAGES_TYPE, table.getTabularType());
Collection values = table.values();
Assert.assertEquals(1, values.size());
CompositeData data = (CompositeData) values.iterator().next();
Long[] exportingBundles = (Long[]) data.get(PackageStateMBean.EXPORTING_BUNDLES);
Assert.assertArrayEquals(new Long[] { Long.valueOf(4) }, exportingBundles);
String name = (String) data.get(PackageStateMBean.NAME);
Assert.assertEquals("test", name);
String version = (String) data.get(PackageStateMBean.VERSION);
Assert.assertEquals("1.0.0", version);
}
Aggregations