Added support for scope and depdenency injection on target bean

This commit is contained in:
Johan Rask 2010-06-16 11:24:47 +02:00
parent be40cf6507
commit 15d1ded344
14 changed files with 430 additions and 19 deletions

View file

@ -7,6 +7,8 @@ import org.scalatest.Spec
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
import org.springframework.core.io.ResourceEditor
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Test for ActiveObjectFactoryBean
@ -45,5 +47,27 @@ class ActiveObjectFactoryBeanTest extends Spec with ShouldMatchers {
bean.setTarget("java.lang.String")
assert(bean.getObjectType == classOf[String])
}
it("should create a proxy of type ResourceEditor") {
val bean = new ActiveObjectFactoryBean()
// we must have a java class here
bean.setTarget("org.springframework.core.io.ResourceEditor")
val entries = new PropertyEntries()
val entry = new PropertyEntry()
entry.name = "source"
entry.value = "sourceBeanIsAString"
entries.add(entry)
bean.setProperty(entries)
assert(bean.getObjectType == classOf[ResourceEditor])
// Check that we have injected the depencency correctly
val target:ResourceEditor = bean.createInstance.asInstanceOf[ResourceEditor]
assert(target.getSource === entry.value)
}
it("should create an application context and inject a string dependency") {
var ctx = new ClassPathXmlApplicationContext("appContext.xml");
val target:ResourceEditor = ctx.getBean("bean").asInstanceOf[ResourceEditor]
assert(target.getSource === "someString")
}
}
}