use of org.springframework.context.ConfigurableApplicationContext in project spring-framework by spring-projects.
the class MBeanExporterTests method testAutodetectMBeans.
@Test
public void testAutodetectMBeans() throws Exception {
ConfigurableApplicationContext ctx = load("autodetectMBeans.xml");
try {
ctx.getBean("exporter");
MBeanServer server = ctx.getBean("server", MBeanServer.class);
ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true"));
assertNotNull(instance);
instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean2=true"));
assertNotNull(instance);
instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean3=true"));
assertNotNull(instance);
} finally {
ctx.close();
}
}
use of org.springframework.context.ConfigurableApplicationContext in project spring-framework by spring-projects.
the class MBeanExporterTests method testAutodetectLazyMBeans.
@Test
public void testAutodetectLazyMBeans() throws Exception {
ConfigurableApplicationContext ctx = load("autodetectLazyMBeans.xml");
try {
ctx.getBean("exporter");
MBeanServer server = ctx.getBean("server", MBeanServer.class);
ObjectName oname = ObjectNameManager.getInstance("spring:mbean=true");
assertNotNull(server.getObjectInstance(oname));
String name = (String) server.getAttribute(oname, "Name");
assertEquals("Invalid name returned", "Rob Harrop", name);
oname = ObjectNameManager.getInstance("spring:mbean=another");
assertNotNull(server.getObjectInstance(oname));
name = (String) server.getAttribute(oname, "Name");
assertEquals("Invalid name returned", "Juergen Hoeller", name);
} finally {
ctx.close();
}
}
use of org.springframework.context.ConfigurableApplicationContext in project spring-framework by spring-projects.
the class NotificationPublisherTests method testMBean.
@Test
public void testMBean() throws Exception {
// start the MBeanExporter
ConfigurableApplicationContext ctx = loadContext("org/springframework/jmx/export/notificationPublisherTests.xml");
this.server.addNotificationListener(ObjectNameManager.getInstance("spring:type=PublisherMBean"), listener, null, null);
MyNotificationPublisherMBean publisher = (MyNotificationPublisherMBean) ctx.getBean("publisherMBean");
publisher.sendNotification();
assertEquals("Notification not sent", 1, listener.count);
}
use of org.springframework.context.ConfigurableApplicationContext in project spring-framework by spring-projects.
the class AnnotationLazyInitMBeanTests method lazyNaming.
@Test
public void lazyNaming() throws Exception {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/lazyNaming.xml");
try {
MBeanServer server = (MBeanServer) ctx.getBean("server");
ObjectName oname = ObjectNameManager.getInstance("bean:name=testBean4");
assertNotNull(server.getObjectInstance(oname));
String name = (String) server.getAttribute(oname, "Name");
assertEquals("Invalid name returned", "TEST", name);
} finally {
ctx.close();
}
}
use of org.springframework.context.ConfigurableApplicationContext in project spring-framework by spring-projects.
the class AsyncAnnotationBeanPostProcessorTests method exceptionHandlerThrowsUnexpectedException.
@Test
public void exceptionHandlerThrowsUnexpectedException() {
Method m = ReflectionUtils.findMethod(TestBean.class, "failWithVoid");
TestableAsyncUncaughtExceptionHandler exceptionHandler = new TestableAsyncUncaughtExceptionHandler(true);
BeanDefinition processorDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class);
processorDefinition.getPropertyValues().add("exceptionHandler", exceptionHandler);
processorDefinition.getPropertyValues().add("executor", new DirectExecutor());
ConfigurableApplicationContext context = initContext(processorDefinition);
ITestBean testBean = context.getBean("target", ITestBean.class);
assertFalse("Handler should not have been called", exceptionHandler.isCalled());
try {
testBean.failWithVoid();
exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
} catch (Exception e) {
fail("No unexpected exception should have been received");
}
}
Aggregations