提交 a0b3da71 编写于 作者: J Jeff Brown
上级 fbcdc573
...@@ -133,69 +133,61 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase { ...@@ -133,69 +133,61 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
void testUseTwoSpringNamespaces() { void testUseTwoSpringNamespaces() {
def beanReader = new GroovyBeanDefinitionReader() def beanReader = new GroovyBeanDefinitionReader()
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder() TestScope scope = new TestScope()
try {
builder.bind("bar", "success")
builder.activate()
TestScope scope = new TestScope()
GenericApplicationContext appCtx = beanReader.getSpringConfig().getUnrefreshedApplicationContext()
appCtx.getBeanFactory().registerScope("test", scope)
beanReader.beans {
xmlns aop:"http://www.springframework.org/schema/aop"
xmlns jee:"http://www.springframework.org/schema/jee"
scopedList(ArrayList) { bean ->
bean.scope = "test"
aop.'scoped-proxy'()
}
jee.'jndi-lookup'(id:"foo", 'jndi-name':"bar")
GenericApplicationContext appCtx = beanReader.getSpringConfig().getUnrefreshedApplicationContext()
appCtx.getBeanFactory().registerScope("test", scope)
beanReader.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 = beanReader.createApplicationContext() appCtx = beanReader.createApplicationContext()
assertEquals "success", 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 assert ['one', 'two'] == appCtx.getBean("foo")
assertEquals 2, scope.instanceCount
beanReader = new GroovyBeanDefinitionReader() assertNotNull appCtx.getBean("scopedList")
assertNotNull appCtx.getBean("scopedList").size()
assertNotNull appCtx.getBean("scopedList").size()
appCtx = beanReader.getSpringConfig().getUnrefreshedApplicationContext() // should only be true because bean not initialized until proxy called
appCtx.getBeanFactory().registerScope("test", scope) assertEquals 2, scope.instanceCount
beanReader.beans {
xmlns aop:"http://www.springframework.org/schema/aop",
jee:"http://www.springframework.org/schema/jee"
scopedList(ArrayList) { bean ->
bean.scope = "test"
aop.'scoped-proxy'()
}
jee.'jndi-lookup'(id:"foo", 'jndi-name':"bar") beanReader = new GroovyBeanDefinitionReader()
appCtx = beanReader.getSpringConfig().getUnrefreshedApplicationContext()
appCtx.getBeanFactory().registerScope("test", scope)
beanReader.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'()
} }
appCtx = beanReader.createApplicationContext()
assertEquals "success", 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 util.list(id: 'foo') {
assertEquals 4, scope.instanceCount value 'one'
value 'two'
}
}
appCtx = beanReader.createApplicationContext()
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
finally { assertEquals 4, scope.instanceCount
builder.deactivate()
}
} }
void testSpringAOPSupport() { void testSpringAOPSupport() {
...@@ -262,24 +254,17 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase { ...@@ -262,24 +254,17 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
void testSpringNamespaceBean() { void testSpringNamespaceBean() {
def beanReader = new GroovyBeanDefinitionReader() def beanReader = new GroovyBeanDefinitionReader()
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder() beanReader.beans {
try { xmlns util: 'http://www.springframework.org/schema/util'
util.list(id: 'foo') {
builder.bind("bar", "success") value 'one'
builder.activate() value 'two'
beanReader.beans {
xmlns jee:"http://www.springframework.org/schema/jee"
jee.'jndi-lookup'(id:"foo", 'jndi-name':"bar")
} }
ApplicationContext appCtx = beanReader.createApplicationContext()
assertEquals "success", appCtx.getBean("foo")
}
finally {
builder.deactivate()
} }
def ctx = beanReader.createApplicationContext()
assert ['one', 'two'] == ctx.getBean('foo')
} }
void testNamedArgumentConstructor() { void testNamedArgumentConstructor() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册