pekko/akka-actors/src/test/scala/CamelSpec.scala

102 lines
2.8 KiB
Scala
Raw Normal View History

2009-05-09 17:18:31 +02:00
/**
* Copyright (C) 2009 Scalable Solutions.
*/
package se.scalablesolutions.akka.camel
2009-05-09 17:18:31 +02:00
/*
2009-09-02 09:10:21 +02:00
import config.ActiveObjectGuiceConfigurator
2009-05-09 17:18:31 +02:00
import annotation.oneway
2009-09-02 09:10:21 +02:00
import config.ScalaConfig._
2009-05-09 17:18:31 +02:00
import com.google.inject.{AbstractModule, Scopes}
2009-07-13 00:39:32 +02:00
//import com.jteigen.scalatest.JUnit4Runner
2009-05-09 17:18:31 +02:00
2009-05-11 13:48:32 +02:00
import org.apache.camel.component.bean.ProxyHelper
2009-05-09 17:18:31 +02:00
import org.junit.runner.RunWith
import org.scalatest._
import org.scalatest.matchers._
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext
import org.apache.camel.Endpoint
import org.apache.camel.Exchange
import org.apache.camel.Processor
import org.apache.camel.Producer
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.impl.DefaultCamelContext
2009-05-11 13:48:32 +02:00
// REQUIRES: -Djava.naming.factory.initial=org.apache.camel.util.jndi.CamelInitialContextFactory
*/
2009-05-09 17:18:31 +02:00
/**
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*
2009-07-13 00:39:32 +02:00
//@RunWith(classOf[JUnit4Runner])
2009-05-09 17:18:31 +02:00
class CamelSpec extends Spec with ShouldMatchers {
describe("A Camel routing scheme") {
2009-05-11 13:48:32 +02:00
it("should route message from direct:test to actor A using @Bean endpoint") {
2009-05-09 17:18:31 +02:00
val latch = new CountDownLatch(1);
val conf = new ActiveObjectGuiceConfigurator
conf.configure(
2009-05-09 17:18:31 +02:00
RestartStrategy(AllForOne, 3, 5000),
Component(
"camelfoo",
classOf[CamelFoo],
classOf[CamelFooImpl],
LifeCycle(Permanent, 1000),
1000) ::
Nil
).addRoutes(new RouteBuilder() {
def configure = {
2009-05-11 13:48:32 +02:00
from("direct:test").to("bean:camelfoo").process(new Processor() {
2009-05-09 17:18:31 +02:00
def process(e: Exchange) = {
println("Received exchange: " + e.getIn())
latch.countDown
}
})
2009-05-09 20:40:36 +02:00
}}
).supervise
2009-05-09 17:18:31 +02:00
2009-05-11 13:48:32 +02:00
val endpoint = conf.getRoutingEndpoint("direct:test")
val proxy = ProxyHelper.createProxy(endpoint, classOf[CamelFoo])
proxy.foo("hello there")
2009-05-11 21:28:31 +02:00
2009-05-11 13:48:32 +02:00
val exchange = endpoint.createExchange
println("----- " + exchange)
exchange.getIn().setBody("hello there")
val producer = endpoint.createProducer
println("----- " + producer)
producer.process(exchange)
// now lets sleep for a while
val received = latch.await(5, TimeUnit.SECONDS)
received should equal (true)
conf.stop
2009-05-09 17:18:31 +02:00
}
}
}
trait CamelFoo {
@oneway def foo(msg: String)
}
trait CamelBar {
def bar(msg: String): String
}
class CamelFooImpl extends CamelFoo {
def foo(msg: String) = println("CamelFoo.foo:" + msg)
}
class CamelBarImpl extends CamelBar {
def bar(msg: String) = msg + "return_bar "
}
*/