2 * @author Graeme Rocher
5 * Created: Nov 22, 2007
7 package org
.codehaus
.groovy
.grails
.reload
9 import grails
.spring
.BeanBuilder
10 import org
.springframework
.aop
.framework
.ProxyFactoryBean
11 import org
.aopalliance
.intercept
.MethodInterceptor
12 import org
.aopalliance
.intercept
.MethodInvocation
14 class SpringProxiedBeanReloadTests
extends GroovyTestCase
{
16 void testReloadCGLibProxiedBean() {
17 def gcl
= new GroovyClassLoader()
18 def cls
= gcl
.parseClass("class Book { String title = 'The Stand'; String author }")
20 def bb
= new BeanBuilder(gcl
)
22 interceptor(DummyInterceptor
)
24 author
= "Stephen King"
26 myBean(ProxyFactoryBean
) {
28 autodetectInterfaces
= false
29 interceptorNames
= 'interceptor'
33 def appCtx
= bb
.createApplicationContext()
35 println
"Bean = " + appCtx
.getBean("myBean")
36 println
"Class = " + appCtx
.getBean('myBean').getClass()
37 assertEquals
"The Stand", appCtx
.getBean('myBean').title
38 assertEquals
"Stephen King", appCtx
.getBean('myBean').author
41 gcl
= new GroovyClassLoader()
42 cls
= gcl
.parseClass("class Book { String title = 'The Shining'; String author }")
44 bb
= new BeanBuilder(gcl
)
45 def beanDefinitions
= bb
.beans
{
46 interceptor(DummyInterceptor
)
48 author
= "Stephen King"
50 myBean(ProxyFactoryBean
) {
52 autodetectInterfaces
= false
53 interceptorNames
= 'interceptor'
57 bb
.registerBeans(appCtx
)
59 assertEquals
"The Shining", appCtx
.getBean('myBean').title
60 assertEquals
"Stephen King", appCtx
.getBean('myBean').author
64 class DummyInterceptor
implements MethodInterceptor
{
65 public Object
invoke(MethodInvocation methodInvocation
) {
66 return methodInvocation
.proceed();