Skip to content

Commit a0b3da7

Browse files
fix test
Copying in changes from apache/grails-core@54e2f72
1 parent fbcdc57 commit a0b3da7

File tree

1 file changed

+52
-67
lines changed

1 file changed

+52
-67
lines changed

spring-lang-groovy/src/test/groovy/org/springframework/context/groovy/GroovyBeanDefinitionReaderTests.groovy

Lines changed: 52 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -133,69 +133,61 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
133133
void testUseTwoSpringNamespaces() {
134134
def beanReader = new GroovyBeanDefinitionReader()
135135

136-
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder()
137-
try {
138-
139-
builder.bind("bar", "success")
140-
builder.activate()
141-
TestScope scope = new TestScope()
142-
143-
GenericApplicationContext appCtx = beanReader.getSpringConfig().getUnrefreshedApplicationContext()
144-
appCtx.getBeanFactory().registerScope("test", scope)
145-
beanReader.beans {
146-
xmlns aop:"http://www.springframework.org/schema/aop"
147-
xmlns jee:"http://www.springframework.org/schema/jee"
148-
scopedList(ArrayList) { bean ->
149-
bean.scope = "test"
150-
aop.'scoped-proxy'()
151-
}
152-
153-
jee.'jndi-lookup'(id:"foo", 'jndi-name':"bar")
136+
TestScope scope = new TestScope()
154137

138+
GenericApplicationContext appCtx = beanReader.getSpringConfig().getUnrefreshedApplicationContext()
139+
appCtx.getBeanFactory().registerScope("test", scope)
140+
beanReader.beans {
141+
xmlns aop:"http://www.springframework.org/schema/aop"
142+
xmlns util:"http://www.springframework.org/schema/util"
143+
scopedList(ArrayList) { bean ->
144+
bean.scope = "test"
145+
aop.'scoped-proxy'()
155146
}
147+
util.list(id: 'foo') {
148+
value 'one'
149+
value 'two'
150+
}
151+
}
156152

157-
appCtx = beanReader.createApplicationContext()
158-
159-
assertEquals "success", appCtx.getBean("foo")
160-
161-
assertNotNull appCtx.getBean("scopedList")
162-
assertNotNull appCtx.getBean("scopedList").size()
163-
assertNotNull appCtx.getBean("scopedList").size()
153+
appCtx = beanReader.createApplicationContext()
164154

165-
// should only be true because bean not initialized until proxy called
166-
assertEquals 2, scope.instanceCount
155+
assert ['one', 'two'] == appCtx.getBean("foo")
167156

168-
beanReader = new GroovyBeanDefinitionReader()
157+
assertNotNull appCtx.getBean("scopedList")
158+
assertNotNull appCtx.getBean("scopedList").size()
159+
assertNotNull appCtx.getBean("scopedList").size()
169160

170-
appCtx = beanReader.getSpringConfig().getUnrefreshedApplicationContext()
171-
appCtx.getBeanFactory().registerScope("test", scope)
172-
beanReader.beans {
173-
xmlns aop:"http://www.springframework.org/schema/aop",
174-
jee:"http://www.springframework.org/schema/jee"
175-
scopedList(ArrayList) { bean ->
176-
bean.scope = "test"
177-
aop.'scoped-proxy'()
178-
}
161+
// should only be true because bean not initialized until proxy called
162+
assertEquals 2, scope.instanceCount
179163

180-
jee.'jndi-lookup'(id:"foo", 'jndi-name':"bar")
164+
beanReader = new GroovyBeanDefinitionReader()
181165

166+
appCtx = beanReader.getSpringConfig().getUnrefreshedApplicationContext()
167+
appCtx.getBeanFactory().registerScope("test", scope)
168+
beanReader.beans {
169+
xmlns aop:"http://www.springframework.org/schema/aop",
170+
util:"http://www.springframework.org/schema/util"
171+
scopedList(ArrayList) { bean ->
172+
bean.scope = "test"
173+
aop.'scoped-proxy'()
182174
}
183-
appCtx = beanReader.createApplicationContext()
184-
185-
assertEquals "success", appCtx.getBean("foo")
186-
187-
assertNotNull appCtx.getBean("scopedList")
188-
assertNotNull appCtx.getBean("scopedList").size()
189-
assertNotNull appCtx.getBean("scopedList").size()
190175

191-
// should only be true because bean not initialized until proxy called
192-
assertEquals 4, scope.instanceCount
176+
util.list(id: 'foo') {
177+
value 'one'
178+
value 'two'
179+
}
180+
}
181+
appCtx = beanReader.createApplicationContext()
182+
183+
assert ['one', 'two'] == appCtx.getBean("foo")
193184

185+
assertNotNull appCtx.getBean("scopedList")
186+
assertNotNull appCtx.getBean("scopedList").size()
187+
assertNotNull appCtx.getBean("scopedList").size()
194188

195-
}
196-
finally {
197-
builder.deactivate()
198-
}
189+
// should only be true because bean not initialized until proxy called
190+
assertEquals 4, scope.instanceCount
199191
}
200192

201193
void testSpringAOPSupport() {
@@ -262,24 +254,17 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
262254
void testSpringNamespaceBean() {
263255
def beanReader = new GroovyBeanDefinitionReader()
264256

265-
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder()
266-
try {
267-
268-
builder.bind("bar", "success")
269-
builder.activate()
270-
271-
beanReader.beans {
272-
xmlns jee:"http://www.springframework.org/schema/jee"
273-
jee.'jndi-lookup'(id:"foo", 'jndi-name':"bar")
257+
beanReader.beans {
258+
xmlns util: 'http://www.springframework.org/schema/util'
259+
util.list(id: 'foo') {
260+
value 'one'
261+
value 'two'
274262
}
275-
276-
ApplicationContext appCtx = beanReader.createApplicationContext()
277-
278-
assertEquals "success", appCtx.getBean("foo")
279-
}
280-
finally {
281-
builder.deactivate()
282263
}
264+
265+
def ctx = beanReader.createApplicationContext()
266+
267+
assert ['one', 'two'] == ctx.getBean('foo')
283268
}
284269

285270
void testNamedArgumentConstructor() {

0 commit comments

Comments
 (0)