pekko/akka-spring/src/test/scala/ActiveObjectFactoryBeanTest.scala

95 lines
3.2 KiB
Scala
Raw Normal View History

/**
* 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
import org.springframework.core.io.ResourceEditor
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Test for ActiveObjectFactoryBean
* @author michaelkober
*/
@RunWith(classOf[JUnitRunner])
class ActiveObjectFactoryBeanTest extends Spec with ShouldMatchers {
describe("A ActiveObjectFactoryBean") {
val bean = new ActiveObjectFactoryBean
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)
}
it("should create a remote active object when a host is set") {
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)
}
it("should create an active object with dispatcher if dispatcher is set") {
val props = new DispatcherProperties()
props.dispatcherType = "executor-based-event-driven"
bean.setDispatcher(props);
assert(bean.hasDispatcher)
}
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-06-30 16:26:15 +02:00
val bean = new ActiveObjectFactoryBean()
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()
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)
}
it("should create an application context and inject a string dependency") {
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")
val sampleBean = ctx.getBean("sample").asInstanceOf[SampleBean];
Thread.sleep(300)
assert(sampleBean.gotApplicationContext)
2010-06-21 20:56:29 +02:00
}
it("should stop the created active object when scope is singleton and the context is closed") {
var ctx = new ClassPathXmlApplicationContext("appContext.xml");
val target = ctx.getBean("bean-singleton").asInstanceOf[SampleBean]
assert(!target.down)
ctx.close
assert(target.down)
}
it("should not stop the created active object when scope is prototype and the context is closed") {
var ctx = new ClassPathXmlApplicationContext("appContext.xml");
val target = ctx.getBean("bean-prototype").asInstanceOf[SampleBean]
assert(!target.down)
ctx.close
assert(!target.down)
}
}
}