use of org.springframework.scripting.Messenger in project spring-framework by spring-projects.
the class GroovyScriptFactoryTests method testRefreshableFromTagProxyTargetClass.
// SPR-6268
@Test
public void testRefreshableFromTagProxyTargetClass() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-proxy-target-class.xml", getClass());
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
assertTrue(AopUtils.isAopProxy(messenger));
assertTrue(messenger instanceof Refreshable);
assertEquals("Hello World!", messenger.getMessage());
assertTrue(ctx.getBeansOfType(ConcreteMessenger.class).values().contains(messenger));
// Check that AnnotationUtils works with concrete proxied script classes
assertNotNull(AnnotationUtils.findAnnotation(messenger.getClass(), Component.class));
}
use of org.springframework.scripting.Messenger in project spring-framework by spring-projects.
the class GroovyScriptFactoryTests method testRefreshableFromTag.
@Test
public void testRefreshableFromTag() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
CallCounter countingAspect = (CallCounter) ctx.getBean("getMessageAspect");
assertTrue(AopUtils.isAopProxy(messenger));
assertTrue(messenger instanceof Refreshable);
assertEquals(0, countingAspect.getCalls());
assertEquals("Hello World!", messenger.getMessage());
assertEquals(1, countingAspect.getCalls());
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
}
use of org.springframework.scripting.Messenger in project spring-framework by spring-projects.
the class ScriptFactoryPostProcessorTests method testChangeScriptWithRefreshableBeanFunctionality.
@Test
public void testChangeScriptWithRefreshableBeanFunctionality() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.registerBeanDefinition(PROCESSOR_BEAN_NAME, processorBeanDefinition);
ctx.registerBeanDefinition(MESSENGER_BEAN_NAME, scriptedBeanDefinition);
ctx.refresh();
Messenger messenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
assertEquals(MESSAGE_TEXT, messenger.getMessage());
// cool; now let's change the script and check the refresh behaviour...
pauseToLetRefreshDelayKickIn(DEFAULT_SECONDS_TO_PAUSE);
StaticScriptSource source = getScriptSource(ctx);
source.setScript(CHANGED_SCRIPT);
Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
// the updated script surrounds the message in quotes before returning...
assertEquals(EXPECTED_CHANGED_MESSAGE_TEXT, refreshedMessenger.getMessage());
}
use of org.springframework.scripting.Messenger in project spring-framework by spring-projects.
the class ScriptFactoryPostProcessorTests method testChangeScriptWithNoRefreshableBeanFunctionality.
@Test
public void testChangeScriptWithNoRefreshableBeanFunctionality() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(false);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.registerBeanDefinition(PROCESSOR_BEAN_NAME, processorBeanDefinition);
ctx.registerBeanDefinition(MESSENGER_BEAN_NAME, scriptedBeanDefinition);
ctx.refresh();
Messenger messenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
assertEquals(MESSAGE_TEXT, messenger.getMessage());
// cool; now let's change the script and check the refresh behaviour...
pauseToLetRefreshDelayKickIn(DEFAULT_SECONDS_TO_PAUSE);
StaticScriptSource source = getScriptSource(ctx);
source.setScript(CHANGED_SCRIPT);
Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
assertEquals("Script seems to have been refreshed (must not be as no refreshCheckDelay set on ScriptFactoryPostProcessor)", MESSAGE_TEXT, refreshedMessenger.getMessage());
}
use of org.springframework.scripting.Messenger in project spring-framework by spring-projects.
the class GroovyScriptFactoryTests method testRefreshableJsr223FromTag.
@Test
public void testRefreshableJsr223FromTag() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-jsr223.xml", getClass());
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
assertTrue(AopUtils.isAopProxy(messenger));
assertTrue(messenger instanceof Refreshable);
assertEquals("Hello World!", messenger.getMessage());
}
Aggregations