tests for accessing active objects from Camel routes (ticket #266)

This commit is contained in:
Martin Krasser 2010-06-10 17:05:09 +02:00
parent e56c02504f
commit 08970389d7
7 changed files with 46 additions and 15 deletions

View file

@ -2,20 +2,30 @@ package se.scalablesolutions.akka.camel.component
import org.scalatest.{BeforeAndAfterEach, BeforeAndAfterAll, FeatureSpec}
import org.apache.camel.builder.RouteBuilder
import se.scalablesolutions.akka.actor.Actor._
import se.scalablesolutions.akka.camel._
import se.scalablesolutions.akka.actor.{ActorRegistry, ActiveObject}
import org.apache.camel.{ExchangePattern, Exchange, Processor}
import se.scalablesolutions.akka.camel._
import org.apache.camel.impl.{DefaultCamelContext, SimpleRegistry}
import org.apache.camel.{ResolveEndpointFailedException, ExchangePattern, Exchange, Processor}
/**
* @author Martin Krasser
*/
class ActiveObjectComponentFeatureTest extends FeatureSpec with BeforeAndAfterAll with BeforeAndAfterEach {
import ActiveObjectComponentFeatureTest._
import CamelContextManager.template
override protected def beforeAll = {
val activePojo = ActiveObject.newInstance(classOf[Pojo]) // not a consumer
val activePojoBase = ActiveObject.newInstance(classOf[PojoBase])
val activePojoIntf = ActiveObject.newInstance(classOf[PojoIntf], new PojoImpl)
CamelContextManager.init
val registry = new SimpleRegistry
registry.put("pojo", activePojo)
CamelContextManager.init(new DefaultCamelContext(registry))
CamelContextManager.context.addRoutes(new CustomRouteBuilder)
CamelContextManager.start
CamelContextManager.activeObjectRegistry.put("base", activePojoBase)
@ -29,7 +39,6 @@ class ActiveObjectComponentFeatureTest extends FeatureSpec with BeforeAndAfterAl
feature("Communicate with an active object from a Camel application using active object endpoint URIs") {
import ActiveObjectComponent.InternalSchema
import CamelContextManager.template
import ExchangePattern._
scenario("in-out exchange with proxy created from interface and method returning String") {
@ -71,4 +80,26 @@ class ActiveObjectComponentFeatureTest extends FeatureSpec with BeforeAndAfterAl
assert(result.getOut.getBody === null)
}
}
feature("Communicate with an active object from a Camel application from a custom Camel route") {
scenario("in-out exchange with externally registered active object") {
val result = template.requestBody("direct:test", "test")
assert(result === "foo: test")
}
scenario("in-out exchange with internally registered active object not possible") {
intercept[ResolveEndpointFailedException] {
template.requestBodyAndHeader("active-object:intf?method=m2", "x", "test", "y")
}
}
}
}
object ActiveObjectComponentFeatureTest {
class CustomRouteBuilder extends RouteBuilder {
def configure = {
from("direct:test").to("active-object:pojo?method=foo")
}
}
}