2010-03-14 22:19:20 +01:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
|
|
|
|
*/
|
|
|
|
|
package se.scalablesolutions.akka.spring
|
|
|
|
|
|
|
|
|
|
import org.scalatest.Spec
|
|
|
|
|
import org.scalatest.matchers.ShouldMatchers
|
|
|
|
|
import org.scalatest.junit.JUnitRunner
|
|
|
|
|
import org.junit.runner.RunWith
|
2010-06-16 11:24:47 +02:00
|
|
|
import org.springframework.core.io.ResourceEditor
|
|
|
|
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
2010-03-14 22:19:20 +01:00
|
|
|
|
|
|
|
|
/**
|
2010-07-26 18:47:25 +02:00
|
|
|
* Test for TypedActorFactoryBean
|
2010-03-14 22:19:20 +01:00
|
|
|
* @author michaelkober
|
|
|
|
|
*/
|
|
|
|
|
@RunWith(classOf[JUnitRunner])
|
2010-07-26 18:47:25 +02:00
|
|
|
class TypedActorFactoryBeanTest extends Spec with ShouldMatchers {
|
2010-03-14 22:19:20 +01:00
|
|
|
|
2010-07-26 18:47:25 +02:00
|
|
|
describe("A TypedActorFactoryBean") {
|
|
|
|
|
val bean = new TypedActorFactoryBean
|
2010-03-14 22:19:20 +01:00
|
|
|
it("should have java getters and setters for all properties") {
|
|
|
|
|
bean.setTarget("java.lang.String")
|
|
|
|
|
assert(bean.getTarget == "java.lang.String")
|
|
|
|
|
bean.setTimeout(1000)
|
|
|
|
|
assert(bean.getTimeout == 1000)
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-26 18:47:25 +02:00
|
|
|
it("should create a remote typed actor when a host is set") {
|
2010-03-14 22:19:20 +01:00
|
|
|
bean.setHost("some.host.com");
|
|
|
|
|
assert(bean.isRemote)
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 10:41:06 +02:00
|
|
|
it("should create object that implements the given interface") {
|
|
|
|
|
bean.setInterface("com.biz.IPojo");
|
|
|
|
|
assert(bean.hasInterface)
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-26 18:47:25 +02:00
|
|
|
it("should create an typed actor with dispatcher if dispatcher is set") {
|
2010-03-30 10:41:06 +02:00
|
|
|
val props = new DispatcherProperties()
|
|
|
|
|
props.dispatcherType = "executor-based-event-driven"
|
|
|
|
|
bean.setDispatcher(props);
|
|
|
|
|
assert(bean.hasDispatcher)
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-14 22:19:20 +01:00
|
|
|
it("should return the object type") {
|
|
|
|
|
bean.setTarget("java.lang.String")
|
|
|
|
|
assert(bean.getObjectType == classOf[String])
|
|
|
|
|
}
|
2010-06-21 20:56:29 +02:00
|
|
|
|
|
|
|
|
it("should create a proxy of type ResourceEditor") {
|
2010-07-26 18:47:25 +02:00
|
|
|
val bean = new TypedActorFactoryBean()
|
2010-06-21 20:56:29 +02:00
|
|
|
// we must have a java class here
|
|
|
|
|
bean.setTarget("org.springframework.core.io.ResourceEditor")
|
|
|
|
|
val entries = new PropertyEntries()
|
|
|
|
|
val entry = new PropertyEntry()
|
2010-06-16 11:24:47 +02:00
|
|
|
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
|
2010-06-21 20:56:29 +02:00
|
|
|
val target:ResourceEditor = bean.createInstance.asInstanceOf[ResourceEditor]
|
|
|
|
|
assert(target.getSource === entry.value)
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 11:49:30 +02:00
|
|
|
it("should create an application context and verify dependency injection") {
|
2010-06-30 16:26:15 +02:00
|
|
|
var ctx = new ClassPathXmlApplicationContext("appContext.xml");
|
2010-06-21 20:56:29 +02:00
|
|
|
val target:ResourceEditor = ctx.getBean("bean").asInstanceOf[ResourceEditor]
|
|
|
|
|
assert(target.getSource === "someString")
|
2010-07-06 11:49:30 +02:00
|
|
|
|
|
|
|
|
val pojoInf = ctx.getBean("pojoInf").asInstanceOf[PojoInf];
|
|
|
|
|
println("pojoInf = " + pojoInf.getString)
|
2010-07-07 11:12:16 +02:00
|
|
|
Thread.sleep(200)
|
|
|
|
|
assert(pojoInf.isPostConstructInvoked)
|
2010-07-06 11:49:30 +02:00
|
|
|
assert(pojoInf.getString == "akka rocks")
|
|
|
|
|
assert(pojoInf.gotApplicationContext)
|
2010-06-21 20:56:29 +02:00
|
|
|
}
|
2010-07-06 07:00:04 +02:00
|
|
|
|
2010-07-26 18:47:25 +02:00
|
|
|
it("should stop the created typed actor when scope is singleton and the context is closed") {
|
2010-07-06 07:00:04 +02:00
|
|
|
var ctx = new ClassPathXmlApplicationContext("appContext.xml");
|
|
|
|
|
val target = ctx.getBean("bean-singleton").asInstanceOf[SampleBean]
|
|
|
|
|
assert(!target.down)
|
|
|
|
|
ctx.close
|
|
|
|
|
assert(target.down)
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-26 18:47:25 +02:00
|
|
|
it("should not stop the created typed actor when scope is prototype and the context is closed") {
|
2010-07-06 07:00:04 +02:00
|
|
|
var ctx = new ClassPathXmlApplicationContext("appContext.xml");
|
|
|
|
|
val target = ctx.getBean("bean-prototype").asInstanceOf[SampleBean]
|
|
|
|
|
assert(!target.down)
|
|
|
|
|
ctx.close
|
|
|
|
|
assert(!target.down)
|
|
|
|
|
}
|
2010-03-14 22:19:20 +01:00
|
|
|
}
|
|
|
|
|
}
|