@Test
public void testMultiLayeredAttribute() throws Exception{
// note: test PS MarkSweep
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName mS = new ObjectName("java.lang:name=CarBean");
CarBean cb = new CarBean();
mbs.registerMBean(cb, mS);
MultiLayeredAttribute mla = new MultiLayeredAttribute(mbs);
Attribute attr = new Attribute("Car.*", null, null);
Map<Attribute, Object> result = mla.getAll(mS, attr);
assertTrue ( result.size() == 4);
for (Map.Entry<Attribute, Object> entry : result.entrySet()) {
if (entry.getKey().getAlias().equals("Car_name")) {
assertThat(entry.getValue().toString(), equalTo(Car.NAME));
} else if (entry.getKey().getAlias().equals("Car_autoShow")) {
assertThat(entry.getValue().toString(), equalTo(Car.AUTOSHOW));
} else if (entry.getKey().getAlias().equals("Car_engine")) {
assertThat(entry.getValue().toString(),
equalTo((new Integer(Car.ENGINE)).toString()));
} else if (entry.getKey().getAlias().equals("Car_power")) {
assertThat(entry.getValue().toString(),
equalTo((new Integer(Car.POWER)).toString()));
} else {
fail("Unknown attribute " + entry.getKey().toString());
}
}
attr = new Attribute("Map.*.*", null, null);
result = mla.getAll(mS, attr);
assertEquals(cb.getMap().size() * 4, result.size());
mbs.unregisterMBean(mS);
}