use of org.springframework.jmx.JmxTestBean in project spring-framework by spring-projects.
the class MBeanExporterTests method testWithExposeClassLoader.
@Test
void testWithExposeClassLoader() throws Exception {
String name = "Rob Harrop";
String otherName = "Juergen Hoeller";
JmxTestBean bean = new JmxTestBean();
bean.setName(name);
ObjectName objectName = ObjectNameManager.getInstance("spring:type=Test");
Map<String, Object> beans = new HashMap<>();
beans.put(objectName.toString(), bean);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer());
exporter.setBeans(beans);
exporter.setExposeManagedResourceClassLoader(true);
start(exporter);
assertIsRegistered("Bean instance not registered", objectName);
Object result = server.invoke(objectName, "add", new Object[] { 2, 3 }, new String[] { int.class.getName(), int.class.getName() });
assertThat(Integer.valueOf(5)).as("Incorrect result return from add").isEqualTo(result);
assertThat(server.getAttribute(objectName, "Name")).as("Incorrect attribute value").isEqualTo(name);
server.setAttribute(objectName, new Attribute("Name", otherName));
assertThat(bean.getName()).as("Incorrect updated name.").isEqualTo(otherName);
}
use of org.springframework.jmx.JmxTestBean in project spring-framework by spring-projects.
the class MBeanExporterTests method testExportJdkProxy.
@Test
void testExportJdkProxy() throws Exception {
JmxTestBean bean = new JmxTestBean();
bean.setName("Rob Harrop");
ProxyFactory factory = new ProxyFactory();
factory.setTarget(bean);
factory.addAdvice(new NopInterceptor());
factory.setInterfaces(IJmxTestBean.class);
IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
String name = "bean:mmm=whatever";
Map<String, Object> beans = new HashMap<>();
beans.put(name, proxy);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(beans);
exporter.registerBeans();
ObjectName oname = ObjectName.getInstance(name);
Object nameValue = server.getAttribute(oname, "Name");
assertThat(nameValue).isEqualTo("Rob Harrop");
}
use of org.springframework.jmx.JmxTestBean in project spring-framework by spring-projects.
the class JmxUtilsTests method isMBeanWithStandardMBeanWrapper.
@Test
void isMBeanWithStandardMBeanWrapper() throws NotCompliantMBeanException {
StandardMBean mbean = new StandardMBean(new JmxTestBean(), IJmxTestBean.class);
assertThat(JmxUtils.isMBean(mbean.getClass())).as("Standard MBean not detected correctly").isTrue();
}
use of org.springframework.jmx.JmxTestBean in project spring-framework by spring-projects.
the class NotificationListenerTests method testRegisterNotificationListenerForMBean.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerForMBean() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean();
Map<String, Object> beans = new HashMap<>();
beans.put(objectName.getCanonicalName(), bean);
CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
Map notificationListeners = new HashMap();
notificationListeners.put(objectName, listener);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(beans);
exporter.setNotificationListenerMappings(notificationListeners);
start(exporter);
// update the attribute
String attributeName = "Name";
server.setAttribute(objectName, new Attribute(attributeName, "Rob Harrop"));
assertEquals("Listener not notified", 1, listener.getCount(attributeName));
}
use of org.springframework.jmx.JmxTestBean in project spring-framework by spring-projects.
the class JmxUtilsTests method testIsMBeanWithStandardMBeanWrapper.
@Test
public void testIsMBeanWithStandardMBeanWrapper() throws Exception {
StandardMBean mbean = new StandardMBean(new JmxTestBean(), IJmxTestBean.class);
assertTrue("Standard MBean not detected correctly", JmxUtils.isMBean(mbean.getClass()));
}
Aggregations