use of javax.management.openmbean.CompositeData in project aries by apache.
the class BundleWiringStateMBeanTest method getJmxAttributes.
@SuppressWarnings("unchecked")
private Map<String, Object> getJmxAttributes(CompositeData jmxCapReq) {
TabularData jmxAttributes = (TabularData) jmxCapReq.get(BundleWiringStateMBean.ATTRIBUTES);
Map<String, Object> aMap = new HashMap<String, Object>();
for (CompositeData jmxAttr : (Collection<CompositeData>) jmxAttributes.values()) {
PropertyData<Object> pd = PropertyData.from(jmxAttr);
Object val = pd.getValue();
if (val instanceof Object[]) {
val = Arrays.asList((Object[]) val);
}
aMap.put(pd.getKey(), val);
}
return aMap;
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class BundleWiringStateMBeanTest method getJmxDirectives.
@SuppressWarnings("unchecked")
private Map<String, String> getJmxDirectives(CompositeData jmxCapReq) {
TabularData jmxDirectives = (TabularData) jmxCapReq.get(BundleWiringStateMBean.DIRECTIVES);
Map<String, String> dMap = new HashMap<String, String>();
for (CompositeData jmxDir : (Collection<CompositeData>) jmxDirectives.values()) {
dMap.put((String) jmxDir.get(BundleWiringStateMBean.KEY), (String) jmxDir.get(BundleWiringStateMBean.VALUE));
}
return dMap;
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class BundleWiringStateMBeanTest method assertBundleWiring.
private void assertBundleWiring(BundleWiring bundleWiring, CompositeData jmxWiring) {
CompositeData[] jmxCapabilities = (CompositeData[]) jmxWiring.get(BundleWiringStateMBean.CAPABILITIES);
List<BundleCapability> capabilities = bundleWiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(capabilities.size(), jmxCapabilities.length);
Map<Map<String, Object>, Map<String, String>> expectedCapabilities = capabilitiesToMap(capabilities);
Map<Map<String, Object>, Map<String, String>> actualCapabilities = jmxCapReqToMap(jmxCapabilities);
Assert.assertEquals(expectedCapabilities, actualCapabilities);
CompositeData[] jmxRequirements = (CompositeData[]) jmxWiring.get(BundleWiringStateMBean.REQUIREMENTS);
List<BundleRequirement> requirements = bundleWiring.getRequirements(BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(requirements.size(), jmxRequirements.length);
Map<Map<String, Object>, Map<String, String>> expectedRequirements = requirementsToMap(requirements);
Map<Map<String, Object>, Map<String, String>> actualRequirements = jmxCapReqToMap(jmxRequirements);
Assert.assertEquals(expectedRequirements, actualRequirements);
List<BundleWire> requiredWires = bundleWiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
CompositeData[] jmxRequiredWires = (CompositeData[]) jmxWiring.get(BundleWiringStateMBean.REQUIRED_WIRES);
Assert.assertEquals(requiredWires.size(), jmxRequiredWires.length);
Set<List<Object>> expectedRequiredWires = new HashSet<List<Object>>();
for (BundleWire wire : requiredWires) {
List<Object> data = new ArrayList<Object>();
data.add(wire.getCapability().getRevision().getBundle().getBundleId());
data.add(wire.getCapability().getAttributes());
data.add(wire.getCapability().getDirectives());
data.add(wire.getRequirement().getRevision().getBundle().getBundleId());
data.add(wire.getRequirement().getAttributes());
data.add(wire.getRequirement().getDirectives());
expectedRequiredWires.add(data);
}
Set<List<Object>> actualRequiredWires = new HashSet<List<Object>>();
for (CompositeData wire : jmxRequiredWires) {
List<Object> data = new ArrayList<Object>();
data.add(wire.get(BundleWiringStateMBean.PROVIDER_BUNDLE_ID));
// TODO bundle revision id
data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
data.add(wire.get(BundleWiringStateMBean.REQUIRER_BUNDLE_ID));
data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
actualRequiredWires.add(data);
}
Assert.assertEquals(expectedRequiredWires, actualRequiredWires);
List<BundleWire> providedWires = bundleWiring.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE);
CompositeData[] jmxProvidedWires = (CompositeData[]) jmxWiring.get(BundleWiringStateMBean.PROVIDED_WIRES);
Assert.assertEquals(providedWires.size(), jmxProvidedWires.length);
HashSet<List<Object>> expectedProvidedWires = new HashSet<List<Object>>();
for (BundleWire wire : providedWires) {
List<Object> data = new ArrayList<Object>();
data.add(wire.getCapability().getRevision().getBundle().getBundleId());
data.add(wire.getCapability().getAttributes());
data.add(wire.getCapability().getDirectives());
data.add(wire.getRequirement().getRevision().getBundle().getBundleId());
data.add(wire.getRequirement().getAttributes());
data.add(wire.getRequirement().getDirectives());
expectedProvidedWires.add(data);
}
Set<List<Object>> actualProvidedWires = new HashSet<List<Object>>();
for (CompositeData wire : jmxProvidedWires) {
List<Object> data = new ArrayList<Object>();
data.add(wire.get(BundleWiringStateMBean.PROVIDER_BUNDLE_ID));
data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
data.add(wire.get(BundleWiringStateMBean.REQUIRER_BUNDLE_ID));
data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
actualProvidedWires.add(data);
}
Assert.assertEquals(expectedProvidedWires, actualProvidedWires);
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class BundleWiringStateMBeanTest method testRevisionsWiring.
@Test
public void testRevisionsWiring() throws Exception {
TabularData jmxWiringTable = brsMBean.getRevisionsWiring(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(1, jmxWiringTable.size());
CompositeData jmxWiring = (CompositeData) jmxWiringTable.values().iterator().next();
Assert.assertEquals(BundleWiringStateMBean.BUNDLE_WIRING_TYPE, jmxWiring.getCompositeType());
Assert.assertEquals(bundleA.getBundleId(), jmxWiring.get(BundleWiringStateMBean.BUNDLE_ID));
BundleWiring bw = (BundleWiring) bundleA.adapt(BundleWiring.class);
assertBundleWiring(bw, jmxWiring);
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class BundleWiringStateMBeanTest method testGetCurrentRevisionDeclaredRequirements.
@Test
public void testGetCurrentRevisionDeclaredRequirements() throws Exception {
Bundle a = getBundleByName("org.apache.aries.jmx.test.bundlea");
BundleRevision br = (BundleRevision) a.adapt(BundleRevision.class);
List<BundleRequirement> requirements = br.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
CompositeData[] jmxRequirements = brsMBean.getCurrentRevisionDeclaredRequirements(a.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(requirements.size(), jmxRequirements.length);
Map<Map<String, Object>, Map<String, String>> expectedRequirements = requirementsToMap(requirements);
Map<Map<String, Object>, Map<String, String>> actualRequirements = jmxCapReqToMap(jmxRequirements);
Assert.assertEquals(expectedRequirements, actualRequirements);
}
Aggregations