@ -57,247 +57,247 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
@@ -57,247 +57,247 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
assertEquals "hello" , foo
}
void testSingletonPropertyOnBeanDefinition ( ) {
void testSingletonPropertyOnBeanDefinition ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
singletonBean ( Bean1 ) { bean - >
bean . singleton = true
}
nonSingletonBean ( Bean1 ) { bean - >
bean . singleton = false
}
unSpecifiedScopeBean ( Bean1 )
}
appCtx . refresh ( )
assertTrue 'singletonBean should have been a singleton' , appCtx . isSingleton ( 'singletonBean' )
assertFalse 'nonSingletonBean should not have been a singleton' , appCtx . isSingleton ( 'nonSingletonBean' )
assertTrue 'unSpecifiedScopeBean should not have been a singleton' , appCtx . isSingleton ( 'unSpecifiedScopeBean' )
}
void testInheritPropertiesFromAbstractBean ( ) {
reader . beans {
singletonBean ( Bean1 ) { bean - >
bean . singleton = true
}
nonSingletonBean ( Bean1 ) { bean - >
bean . singleton = false
}
unSpecifiedScopeBean ( Bean1 )
}
appCtx . refresh ( )
assertTrue 'singletonBean should have been a singleton' , appCtx . isSingleton ( 'singletonBean' )
assertFalse 'nonSingletonBean should not have been a singleton' , appCtx . isSingleton ( 'nonSingletonBean' )
assertTrue 'unSpecifiedScopeBean should not have been a singleton' , appCtx . isSingleton ( 'unSpecifiedScopeBean' )
}
void testInheritPropertiesFromAbstractBean ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
myB ( Bean1 ) {
person = "wombat"
}
myAbstractA ( Bean2 ) { bean - >
bean . 'abstract' = true
age = 10
bean1 = myB
}
myConcreteB {
it . parent = myAbstractA
}
}
appCtx . refresh ( )
def bean = appCtx . getBean ( "myConcreteB" )
assertEquals 10 , bean . age
assertNotNull bean . bean1
}
void testContextComponentScanSpringTag ( ) {
reader . beans {
myB ( Bean1 ) {
person = "wombat"
}
myAbstractA ( Bean2 ) { bean - >
bean . 'abstract' = true
age = 10
bean1 = myB
}
myConcreteB {
it . parent = myAbstractA
}
}
appCtx . refresh ( )
def bean = appCtx . getBean ( "myConcreteB" )
assertEquals 10 , bean . age
assertNotNull bean . bean1
}
void testContextComponentScanSpringTag ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
xmlns context: "http://www.springframework.org/schema/context"
reader . beans {
xmlns context: "http://www.springframework.org/schema/context"
context . 'component-scan' ( 'base-package' : " org.springframework.context.groovy" )
}
context . 'component-scan' ( 'base-package' : " org.springframework.context.groovy" )
}
appCtx . refresh ( )
appCtx . refresh ( )
def p = appCtx . getBean ( "person" )
assertTrue ( p instanceof AdvisedPerson )
assertNotNull p
}
def p = appCtx . getBean ( "person" )
assertTrue ( p instanceof AdvisedPerson )
assertNotNull p
}
void testUseSpringNamespaceAsMethod ( ) {
void testUseSpringNamespaceAsMethod ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
xmlns aop: "http://www.springframework.org/schema/aop"
fred ( AdvisedPerson ) {
name = "Fred"
age = 45
}
birthdayCardSenderAspect ( BirthdayCardSender )
reader . beans {
xmlns aop: "http://www.springframework.org/schema/aop"
aop {
config ( "proxy-target-class" : true ) {
aspect ( id: "sendBirthdayCard" , ref: "birthdayCardSenderAspect" ) {
after method: "onBirthday" , pointcut: "execution(void org.springframework.context.groovy.AdvisedPerson.birthday()) and this(person)"
}
}
}
}
fred ( AdvisedPerson ) {
name = "Fred"
age = 45
}
birthdayCardSenderAspect ( BirthdayCardSender )
aop {
config ( "proxy-target-class" : true ) {
aspect ( id: "sendBirthdayCard" , ref: "birthdayCardSenderAspect" ) {
after method: "onBirthday" , pointcut: "execution(void org.springframework.context.groovy.AdvisedPerson.birthday()) and this(person)"
}
}
}
}
appCtx . refresh ( )
appCtx . refresh ( )
def fred = appCtx . getBean ( "fred" )
assertTrue ( fred instanceof SpringProxy )
fred . birthday ( )
def fred = appCtx . getBean ( "fred" )
assertTrue ( fred instanceof SpringProxy )
fred . birthday ( )
BirthdayCardSender birthDaySender = appCtx . getBean ( "birthdayCardSenderAspect" )
BirthdayCardSender birthDaySender = appCtx . getBean ( "birthdayCardSenderAspect" )
assertEquals 1 , birthDaySender . peopleSentCards . size ( )
assertEquals "Fred" , birthDaySender . peopleSentCards [ 0 ] . name
}
assertEquals 1 , birthDaySender . peopleSentCards . size ( )
assertEquals "Fred" , birthDaySender . peopleSentCards [ 0 ] . name
}
void testUseTwoSpringNamespaces ( ) {
void testUseTwoSpringNamespaces ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
TestScope scope = new TestScope ( )
appCtx . getBeanFactory ( ) . registerScope ( "test" , scope )
TestScope scope = new TestScope ( )
appCtx . getBeanFactory ( ) . registerScope ( "test" , scope )
reader . beans {
xmlns aop: "http://www.springframework.org/schema/aop"
xmlns util: "http://www.springframework.org/schema/util"
scopedList ( ArrayList ) { bean - >
bean . scope = "test"
aop . 'scoped-proxy' ( )
}
util . list ( id: 'foo' ) {
value 'one'
value 'two'
}
reader . beans {
xmlns aop: "http://www.springframework.org/schema/aop"
xmlns util: "http://www.springframework.org/schema/util"
scopedList ( ArrayList ) { bean - >
bean . scope = "test"
aop . 'scoped-proxy' ( )
}
util . list ( id: 'foo' ) {
value 'one'
value 'two'
}
}
appCtx . refresh ( )
appCtx . refresh ( )
assert [ 'one' , 'two' ] = = appCtx . getBean ( "foo" )
assert [ 'one' , 'two' ] = = appCtx . getBean ( "foo" )
assertNotNull appCtx . getBean ( "scopedList" )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
assertNotNull appCtx . getBean ( "scopedList" )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
// should only be true because bean not initialized until proxy called
assertEquals 2 , scope . instanceCount
// should only be true because bean not initialized until proxy called
assertEquals 2 , scope . instanceCount
appCtx = new GenericApplicationContext ( )
reader = new GroovyBeanDefinitionReader ( appCtx )
appCtx . getBeanFactory ( ) . registerScope ( "test" , scope )
reader . beans {
xmlns aop: "http://www.springframework.org/schema/aop" ,
util: "http://www.springframework.org/schema/util"
scopedList ( ArrayList ) { bean - >
bean . scope = "test"
aop . 'scoped-proxy' ( )
}
util . list ( id: 'foo' ) {
value 'one'
value 'two'
}
}
appCtx . refresh ( )
assert [ 'one' , 'two' ] = = appCtx . getBean ( "foo" )
assertNotNull appCtx . getBean ( "scopedList" )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
// should only be true because bean not initialized until proxy called
assertEquals 4 , scope . instanceCount
}
void testSpringAopSupport ( ) {
appCtx . getBeanFactory ( ) . registerScope ( "test" , scope )
reader . beans {
xmlns aop: "http://www.springframework.org/schema/aop" ,
util: "http://www.springframework.org/schema/util"
scopedList ( ArrayList ) { bean - >
bean . scope = "test"
aop . 'scoped-proxy' ( )
}
util . list ( id: 'foo' ) {
value 'one'
value 'two'
}
}
appCtx . refresh ( )
assert [ 'one' , 'two' ] = = appCtx . getBean ( "foo" )
assertNotNull appCtx . getBean ( "scopedList" )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
// should only be true because bean not initialized until proxy called
assertEquals 4 , scope . instanceCount
}
void testSpringAopSupport ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
xmlns aop: "http://www.springframework.org/schema/aop"
reader . beans {
xmlns aop: "http://www.springframework.org/schema/aop"
fred ( AdvisedPerson ) {
name = "Fred"
age = 45
}
birthdayCardSenderAspect ( BirthdayCardSender )
fred ( AdvisedPerson ) {
name = "Fred"
age = 45
}
birthdayCardSenderAspect ( BirthdayCardSender )
aop . config ( "proxy-target-class" : true ) {
aspect ( id: "sendBirthdayCard" , ref: "birthdayCardSenderAspect" ) {
after method: "onBirthday" , pointcut: "execution(void org.springframework.context.groovy.AdvisedPerson.birthday()) and this(person)"
}
}
}
aop . config ( "proxy-target-class" : true ) {
aspect ( id: "sendBirthdayCard" , ref: "birthdayCardSenderAspect" ) {
after method: "onBirthday" , pointcut: "execution(void org.springframework.context.groovy.AdvisedPerson.birthday()) and this(person)"
}
}
}
appCtx . refresh ( )
appCtx . refresh ( )
def fred = appCtx . getBean ( "fred" )
assertTrue ( fred instanceof SpringProxy )
fred . birthday ( )
def fred = appCtx . getBean ( "fred" )
assertTrue ( fred instanceof SpringProxy )
fred . birthday ( )
BirthdayCardSender birthDaySender = appCtx . getBean ( "birthdayCardSenderAspect" )
BirthdayCardSender birthDaySender = appCtx . getBean ( "birthdayCardSenderAspect" )
assertEquals 1 , birthDaySender . peopleSentCards . size ( )
assertEquals "Fred" , birthDaySender . peopleSentCards [ 0 ] . name
}
assertEquals 1 , birthDaySender . peopleSentCards . size ( )
assertEquals "Fred" , birthDaySender . peopleSentCards [ 0 ] . name
}
void testSpringScopedProxyBean ( ) {
void testSpringScopedProxyBean ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
TestScope scope = new TestScope ( )
appCtx . getBeanFactory ( ) . registerScope ( "test" , scope )
reader . beans {
xmlns aop: "http://www.springframework.org/schema/aop"
scopedList ( ArrayList ) { bean - >
bean . scope = "test"
aop . 'scoped-proxy' ( )
}
}
appCtx . refresh ( )
assertNotNull appCtx . getBean ( "scopedList" )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
// should only be true because bean not initialized until proxy called
assertEquals 2 , scope . instanceCount
}
void testSpringNamespaceBean ( ) {
TestScope scope = new TestScope ( )
appCtx . getBeanFactory ( ) . registerScope ( "test" , scope )
reader . beans {
xmlns aop: "http://www.springframework.org/schema/aop"
scopedList ( ArrayList ) { bean - >
bean . scope = "test"
aop . 'scoped-proxy' ( )
}
}
appCtx . refresh ( )
assertNotNull appCtx . getBean ( "scopedList" )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
assertNotNull appCtx . getBean ( "scopedList" ) . size ( )
// should only be true because bean not initialized until proxy called
assertEquals 2 , scope . instanceCount
}
void testSpringNamespaceBean ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
xmlns util: 'http://www.springframework.org/schema/util'
util . list ( id: 'foo' ) {
value 'one'
value 'two'
}
}
reader . beans {
xmlns util: 'http://www.springframework.org/schema/util'
util . list ( id: 'foo' ) {
value 'one'
value 'two'
}
}
appCtx . refresh ( )
assert [ 'one' , 'two' ] = = appCtx . getBean ( 'foo' )
}
assert [ 'one' , 'two' ] = = appCtx . getBean ( 'foo' )
}
void testNamedArgumentConstructor ( ) {
void testNamedArgumentConstructor ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
holyGrail ( HolyGrailQuest )
knights ( KnightOfTheRoundTable , "Camelot" , leader: "lancelot" , quest: holyGrail )
}
appCtx . refresh ( )
reader . beans {
holyGrail ( HolyGrailQuest )
knights ( KnightOfTheRoundTable , "Camelot" , leader: "lancelot" , quest: holyGrail )
}
appCtx . refresh ( )
KnightOfTheRoundTable knights = appCtx . getBean ( "knights" )
HolyGrailQuest quest = appCtx . getBean ( "holyGrail" )
KnightOfTheRoundTable knights = appCtx . getBean ( "knights" )
HolyGrailQuest quest = appCtx . getBean ( "holyGrail" )
assertEquals "Camelot" , knights . name
assertEquals "lancelot" , knights . leader
assertEquals quest , knights . quest
}
assertEquals "Camelot" , knights . name
assertEquals "lancelot" , knights . leader
assertEquals quest , knights . quest
}
void testAbstractBeanDefinition ( ) {
void testAbstractBeanDefinition ( ) {
def appCtx = new GenericGroovyApplicationContext ( )
appCtx . reader . beans {
abstractBean {
@ -317,9 +317,9 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
@@ -317,9 +317,9 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
appCtx . abstractBean
}
assertEquals "Lancelot" , knights . leader
}
}
void testAbstractBeanDefinitionWithClass ( ) {
void testAbstractBeanDefinitionWithClass ( ) {
def appCtx = new GenericGroovyApplicationContext ( )
appCtx . reader . beans {
abstractBean ( KnightOfTheRoundTable ) { bean - >
@ -340,30 +340,30 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
@@ -340,30 +340,30 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
def knights = appCtx . knights
assert knights
assertEquals "Lancelot" , knights . leader
}
}
void testScopes ( ) {
void testScopes ( ) {
def appCtx = new GenericGroovyApplicationContext ( )
appCtx . reader . beans {
myBean ( ScopeTest ) { bean - >
bean . scope = "prototype"
}
myBean2 ( ScopeTest )
}
appCtx . refresh ( )
myBean ( ScopeTest ) { bean - >
bean . scope = "prototype"
}
myBean2 ( ScopeTest )
}
appCtx . refresh ( )
def b1 = appCtx . myBean
def b2 = appCtx . myBean
def b1 = appCtx . myBean
def b2 = appCtx . myBean
assert b1 ! = b2
assert b1 ! = b2
b1 = appCtx . myBean2
b2 = appCtx . myBean2
b1 = appCtx . myBean2
b2 = appCtx . myBean2
assertEquals b1 , b2
}
assertEquals b1 , b2
}
void testSimpleBean ( ) {
void testSimpleBean ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
@ -430,10 +430,10 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
@@ -430,10 +430,10 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
marge ( Bean2 ) {
person = "marge"
bean1 = { Bean1 b - >
person = "homer"
age = 45
props = [ overweight: true , height: "1.8m" ]
children = [ "bart" , "lisa" ] }
person = "homer"
age = 45
props = [ overweight: true , height: "1.8m" ]
children = [ "bart" , "lisa" ] }
children = [ bart , lisa ]
}
}
@ -558,7 +558,7 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
@@ -558,7 +558,7 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
age = 45
}
marge ( Bean4 ) { bean - >
bean . factoryMethod = "getInstance"
bean . factoryMethod = "getInstance"
person = "marge"
}
}
@ -600,28 +600,28 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
@@ -600,28 +600,28 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
assert "mcBain" , appCtx . getBean ( "mcBain" ) . person
}
void testGetBeanDefinitions ( ) {
void testGetBeanDefinitions ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
jeff ( Bean1 ) {
person = 'jeff'
}
graeme ( Bean1 ) {
person = 'graeme'
}
guillaume ( Bean1 ) {
person = 'guillaume'
}
}
reader . beans {
jeff ( Bean1 ) {
person = 'jeff'
}
graeme ( Bean1 ) {
person = 'graeme'
}
guillaume ( Bean1 ) {
person = 'guillaume'
}
}
junit . framework . TestCase . assertEquals 'beanDefinitions was the wrong size' , 3 , reader . registry . beanDefinitionCount
assertNotNull 'beanDefinitions did not contain jeff' , reader . registry . getBeanDefinition ( 'jeff' )
assertNotNull 'beanDefinitions did not contain guillaume' , reader . registry . getBeanDefinition ( 'guillaume' )
assertNotNull 'beanDefinitions did not contain graeme' , reader . registry . getBeanDefinition ( 'graeme' )
}
assertNotNull 'beanDefinitions did not contain jeff' , reader . registry . getBeanDefinition ( 'jeff' )
assertNotNull 'beanDefinitions did not contain guillaume' , reader . registry . getBeanDefinition ( 'guillaume' )
assertNotNull 'beanDefinitions did not contain graeme' , reader . registry . getBeanDefinition ( 'graeme' )
}
void testBeanWithFactoryBean ( ) {
void testBeanWithFactoryBean ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
@ -679,11 +679,11 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
@@ -679,11 +679,11 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
quest ( HolyGrailQuest )
quest ( HolyGrailQuest )
knight ( KnightOfTheRoundTable , "Bedivere" ) {
quest = ref ( "quest" )
}
knight ( KnightOfTheRoundTable , "Bedivere" ) {
quest = ref ( "quest" )
}
}
appCtx . refresh ( )
@ -692,43 +692,43 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
@@ -692,43 +692,43 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
knight . embarkOnQuest ( )
}
void testAbstractBeanSpecifyingClass ( ) {
void testAbstractBeanSpecifyingClass ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
abstractKnight ( KnightOfTheRoundTable ) { bean - >
bean . 'abstract' = true
leader = "King Arthur"
}
reader . beans {
abstractKnight ( KnightOfTheRoundTable ) { bean - >
bean . 'abstract' = true
leader = "King Arthur"
}
lancelot ( "lancelot" ) { bean - >
bean . parent = ref ( "abstractKnight" )
}
lancelot ( "lancelot" ) { bean - >
bean . parent = ref ( "abstractKnight" )
}
abstractPerson ( Bean1 ) { bean - >
bean . 'abstract' = true
age = 45
}
homerBean { bean - >
bean . parent = ref ( "abstractPerson" )
person = "homer"
}
}
abstractPerson ( Bean1 ) { bean - >
bean . 'abstract' = true
age = 45
}
homerBean { bean - >
bean . parent = ref ( "abstractPerson" )
person = "homer"
}
}
appCtx . refresh ( )
def lancelot = appCtx . getBean ( "lancelot" )
assertEquals "King Arthur" , lancelot . leader
assertEquals "lancelot" , lancelot . name
def lancelot = appCtx . getBean ( "lancelot" )
assertEquals "King Arthur" , lancelot . leader
assertEquals "lancelot" , lancelot . name
def homerBean = appCtx . getBean ( "homerBean" )
def homerBean = appCtx . getBean ( "homerBean" )
assertEquals 45 , homerBean . age
assertEquals "homer" , homerBean . person
}
assertEquals 45 , homerBean . age
assertEquals "homer" , homerBean . person
}
void testGroovyBeanDefinitionReaderWithScript ( ) {
def script = '' '
def script = '' '
def appCtx = new org . springframework . context . support . GenericGroovyApplicationContext ( )
appCtx . reader . beans {
quest ( org . springframework . context . groovy . HolyGrailQuest ) { }
@ -737,38 +737,38 @@ knight(org.springframework.context.groovy.KnightOfTheRoundTable, "Bedivere") { q
@@ -737,38 +737,38 @@ knight(org.springframework.context.groovy.KnightOfTheRoundTable, "Bedivere") { q
}
appCtx . refresh ( )
return appCtx
'' '
def appCtx = new GroovyShell ( ) . evaluate ( script )
'' '
def appCtx = new GroovyShell ( ) . evaluate ( script )
def knight = appCtx . getBean ( 'knight' )
knight . embarkOnQuest ( )
}
def knight = appCtx . getBean ( 'knight' )
knight . embarkOnQuest ( )
}
// test for GRAILS - 5057
void testRegisterBeans ( ) {
// test for GRAILS - 5057
void testRegisterBeans ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
personA ( AdvisedPerson ) {
name = "Bob"
}
}
reader . beans {
personA ( AdvisedPerson ) {
name = "Bob"
}
}
appCtx . refresh ( )
assertEquals "Bob" , appCtx . getBean ( "personA" ) . name
assertEquals "Bob" , appCtx . getBean ( "personA" ) . name
appCtx = new GenericApplicationContext ( )
reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
personA ( AdvisedPerson ) {
name = "Fred"
}
}
reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
personA ( AdvisedPerson ) {
name = "Fred"
}
}
appCtx . refresh ( )
assertEquals "Fred" , appCtx . getBean ( "personA" ) . name
}
assertEquals "Fred" , appCtx . getBean ( "personA" ) . name
}
void testListOfBeansAsConstructorArg ( ) {
def appCtx = new GenericApplicationContext ( )
@ -815,80 +815,80 @@ return appCtx
@@ -815,80 +815,80 @@ return appCtx
assertEquals "bart" , beanWithMap . peopleByName . bart . person
}
void testAnonymousInnerBeanViaBeanMethod ( ) {
void testAnonymousInnerBeanViaBeanMethod ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
bart ( Bean1 ) {
person = "bart"
age = 11
}
lisa ( Bean1 ) {
person = "lisa"
age = 9
}
marge ( Bean2 ) {
person = "marge"
bean1 = bean ( Bean1 ) {
person = "homer"
age = 45
props = [ overweight: true , height: "1.8m" ]
children = [ "bart" , "lisa" ]
}
children = [ bart , lisa ]
}
}
appCtx . refresh ( )
def marge = appCtx . getBean ( "marge" )
assertEquals "homer" , marge . bean1 . person
}
void testAnonymousInnerBeanViaBeanMethodWithConstructorArgs ( ) {
reader . beans {
bart ( Bean1 ) {
person = "bart"
age = 11
}
lisa ( Bean1 ) {
person = "lisa"
age = 9
}
marge ( Bean2 ) {
person = "marge"
bean1 = bean ( Bean1 ) {
person = "homer"
age = 45
props = [ overweight: true , height: "1.8m" ]
children = [ "bart" , "lisa" ]
}
children = [ bart , lisa ]
}
}
appCtx . refresh ( )
def marge = appCtx . getBean ( "marge" )
assertEquals "homer" , marge . bean1 . person
}
void testAnonymousInnerBeanViaBeanMethodWithConstructorArgs ( ) {
def appCtx = new GenericApplicationContext ( )
def reader = new GroovyBeanDefinitionReader ( appCtx )
reader . beans {
bart ( Bean1 ) {
person = "bart"
age = 11
}
lisa ( Bean1 ) {
person = "lisa"
age = 9
}
marge ( Bean2 ) {
person = "marge"
bean3 = bean ( Bean3 , "homer" , lisa ) {
person = "homer"
age = 45
}
children = [ bart , lisa ]
}
}
appCtx . refresh ( )
def marge = appCtx . getBean ( "marge" )
assertEquals "homer" , marge . bean3 . person
assertEquals "lisa" , marge . bean3 . bean1 . person
}
reader . beans {
bart ( Bean1 ) {
person = "bart"
age = 11
}
lisa ( Bean1 ) {
person = "lisa"
age = 9
}
marge ( Bean2 ) {
person = "marge"
bean3 = bean ( Bean3 , "homer" , lisa ) {
person = "homer"
age = 45
}
children = [ bart , lisa ]
}
}
appCtx . refresh ( )
def marge = appCtx . getBean ( "marge" )
assertEquals "homer" , marge . bean3 . person
assertEquals "lisa" , marge . bean3 . bean1 . person
}
}
class HolyGrailQuest {
void start ( ) { println "lets begin" }
void start ( ) { println "lets begin" }
}
class KnightOfTheRoundTable {
String name
String leader
KnightOfTheRoundTable ( String n ) {
this . name = n
}
HolyGrailQuest quest
void embarkOnQuest ( ) {
quest . start ( )
}
String name
String leader
KnightOfTheRoundTable ( String n ) {
this . name = n
}
HolyGrailQuest quest
void embarkOnQuest ( ) {
quest . start ( )
}
}
// simple bean
@ -900,7 +900,7 @@ class Bean1 {
@@ -900,7 +900,7 @@ class Bean1 {
}
// bean referencing other bean
class Bean2 {
int age
int age
String person
Bean1 bean1
Bean3 bean3
@ -928,17 +928,17 @@ class Bean4 {
@@ -928,17 +928,17 @@ class Bean4 {
}
// bean with List - valued constructor arg
class Bean5 {
Bean5 ( List < Bean1 > people ) {
this . people = people
}
List < Bean1 > people
Bean5 ( List < Bean1 > people ) {
this . people = people
}
List < Bean1 > people
}
// bean with Map - valued constructor arg
class Bean6 {
Bean6 ( Map < String , Bean1 > peopleByName ) {
this . peopleByName = peopleByName
}
Map < String , Bean1 > peopleByName
Bean6 ( Map < String , Bean1 > peopleByName ) {
this . peopleByName = peopleByName
}
Map < String , Bean1 > peopleByName
}
// a factory bean
class Bean1Factory {
@ -949,44 +949,44 @@ class Bean1Factory {
@@ -949,44 +949,44 @@ class Bean1Factory {
class ScopeTest { }
class TestScope implements Scope {
int instanceCount
int instanceCount
public Object remove ( String name ) {
// do nothing
}
public Object remove ( String name ) {
// do nothing
}
public void registerDestructionCallback ( String name , Runnable callback ) {
}
public void registerDestructionCallback ( String name , Runnable callback ) {
}
public String getConversationId ( ) {
return "mock"
}
public String getConversationId ( ) {
return "mock"
}
public Object get ( String name , ObjectFactory < ? > objectFactory ) {
instanceCount + +
objectFactory . getObject ( )
public Object get ( String name , ObjectFactory < ? > objectFactory ) {
instanceCount + +
objectFactory . getObject ( )
}
}
public Object resolveContextualObject ( String s ) {
return null ; // noop
}
public Object resolveContextualObject ( String s ) {
return null ; // noop
}
}
class BirthdayCardSender {
List peopleSentCards = [ ]
public void onBirthday ( AdvisedPerson person ) {
peopleSentCards < < person
}
List peopleSentCards = [ ]
public void onBirthday ( AdvisedPerson person ) {
peopleSentCards < < person
}
}
@Component ( value = "person" )
public class AdvisedPerson {
int age ;
String name ;
int age ;
String name ;
public void birthday ( ) {
+ + age ;
}
public void birthday ( ) {
+ + age ;
}
}
class SomeClass {