use of org.springframework.aop.target.dynamic.Refreshable 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.aop.target.dynamic.Refreshable 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());
}
use of org.springframework.aop.target.dynamic.Refreshable in project spring-framework by spring-projects.
the class GroovyScriptFactoryTests method testNonStaticScript.
@Test
public void testNonStaticScript() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyRefreshableContext.xml", getClass());
Messenger messenger = (Messenger) ctx.getBean("messenger");
assertTrue("Should be a proxy for refreshable scripts", AopUtils.isAopProxy(messenger));
assertTrue("Should be an instance of Refreshable", messenger instanceof Refreshable);
String desiredMessage = "Hello World!";
assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
Refreshable refreshable = (Refreshable) messenger;
refreshable.refresh();
assertEquals("Message is incorrect after refresh.", desiredMessage, messenger.getMessage());
assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
}
use of org.springframework.aop.target.dynamic.Refreshable in project spring-framework by spring-projects.
the class GroovyScriptFactoryTests method testNonStaticPrototypeScript.
@Test
public void testNonStaticPrototypeScript() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyRefreshableContext.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.aop.target.dynamic.Refreshable in project spring-framework by spring-projects.
the class GroovyScriptFactoryTests method testStaticPrototypeScript.
@Test
public void testStaticPrototypeScript() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
assertNotSame(messenger, messenger2);
assertSame(messenger.getClass(), messenger2.getClass());
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());
}
Aggregations