use of org.springframework.context.support.ClassPathXmlApplicationContext in project spring-framework by spring-projects.
the class BshScriptFactoryTests method nonStaticPrototypeScript.
@Test
public void nonStaticPrototypeScript() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshRefreshableContext.xml", getClass());
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
assertTrue("Should be a proxy for refreshable scripts", AopUtils.isAopProxy(messenger));
assertTrue("Should be an instance of Refreshable", messenger instanceof Refreshable);
assertEquals("Hello World!", messenger.getMessage());
assertEquals("Hello World!", messenger2.getMessage());
messenger.setMessage("Bye World!");
messenger2.setMessage("Byebye World!");
assertEquals("Bye World!", messenger.getMessage());
assertEquals("Byebye World!", messenger2.getMessage());
Refreshable refreshable = (Refreshable) messenger;
refreshable.refresh();
assertEquals("Hello World!", messenger.getMessage());
assertEquals("Byebye World!", messenger2.getMessage());
assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
}
use of org.springframework.context.support.ClassPathXmlApplicationContext in project spring-framework by spring-projects.
the class BshScriptFactoryTests method staticScriptWithTwoInterfacesSpecified.
@Test
public void staticScriptWithTwoInterfacesSpecified() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfigExtra"));
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerWithConfigExtra");
messenger.setMessage(null);
assertNull(messenger.getMessage());
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
ctx.close();
assertNull(messenger.getMessage());
}
use of org.springframework.context.support.ClassPathXmlApplicationContext in project spring-framework by spring-projects.
the class BshScriptFactoryTests method refreshableFromTag.
@Test
public void refreshableFromTag() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
assertEquals("Hello World!", messenger.getMessage());
assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable);
}
use of org.springframework.context.support.ClassPathXmlApplicationContext in project spring-framework by spring-projects.
the class BshScriptFactoryTests method applicationEventListener.
@Test
public void applicationEventListener() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
Messenger eventListener = (Messenger) ctx.getBean("eventListener");
ctx.publishEvent(new MyEvent(ctx));
assertEquals("count=2", eventListener.getMessage());
}
use of org.springframework.context.support.ClassPathXmlApplicationContext in project spring-framework by spring-projects.
the class BshScriptFactoryTests method staticScriptWithNullReturnValue.
@Test
public void staticScriptWithNullReturnValue() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfig"));
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerWithConfig");
messenger.setMessage(null);
assertNull(messenger.getMessage());
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
}
Aggregations