Its a wrap!

This commit is contained in:
Viktor Klang 2010-09-19 17:02:15 +02:00
parent 551f25aba8
commit dfa637b090
6 changed files with 23 additions and 21 deletions

View file

@ -33,18 +33,15 @@ import scala.reflect.BeanProperty
*/
class ActorComponent extends DefaultComponent {
def createEndpoint(uri: String, remaining: String, parameters: JavaMap[String, Object]): ActorEndpoint = {
val idAndUuid = idAndUuidPair(remaining)
new ActorEndpoint(uri, this, idAndUuid._1, idAndUuid._2)
val (id,uuid) = idAndUuidPair(remaining)
new ActorEndpoint(uri, this, id, uuid)
}
private def idAndUuidPair(remaining: String): Tuple2[Option[String], Option[Uuid]] = {
remaining split ":" toList match {
case id :: Nil => (Some(id), None)
case "id" :: id :: Nil => (Some(id), None)
case "uuid" :: uuid :: Nil => (None, Some(uuidFrom(uuid)))
case _ => throw new IllegalArgumentException(
"invalid path format: %s - should be <actorid> or id:<actorid> or uuid:<actoruuid>" format remaining)
}
private def idAndUuidPair(remaining: String): Tuple2[Option[String],Option[Uuid]] = remaining match {
case null | "" => throw new IllegalArgumentException("invalid path format: [%s] - should be <actorid> or id:<actorid> or uuid:<actoruuid>" format remaining)
case id if id startsWith "id:" => (Some(id substring 3),None)
case uuid if uuid startsWith "uuid:" => (None,Some(uuidFrom(uuid substring 5)))
case id => (Some(id),None)
}
}

View file

@ -4,10 +4,13 @@ import org.apache.camel.{Endpoint, AsyncProcessor}
import org.apache.camel.impl.DefaultCamelContext
import org.junit._
import org.scalatest.junit.JUnitSuite
import se.scalablesolutions.akka.actor.uuidFrom
class ActorComponentTest extends JUnitSuite {
val component: ActorComponent = ActorComponentTest.actorComponent
def testUUID = uuidFrom("93da8c80-c3fd-11df-abed-60334b120057")
@Test def shouldCreateEndpointWithIdDefined = {
val ep1: ActorEndpoint = component.createEndpoint("actor:abc").asInstanceOf[ActorEndpoint]
val ep2: ActorEndpoint = component.createEndpoint("actor:id:abc").asInstanceOf[ActorEndpoint]
@ -20,15 +23,15 @@ class ActorComponentTest extends JUnitSuite {
}
@Test def shouldCreateEndpointWithUuidDefined = {
val ep: ActorEndpoint = component.createEndpoint("actor:uuid:abc").asInstanceOf[ActorEndpoint]
assert(ep.uuid === Some("abc"))
val ep: ActorEndpoint = component.createEndpoint("actor:uuid:" + testUUID).asInstanceOf[ActorEndpoint]
assert(ep.uuid === Some(testUUID))
assert(ep.id === None)
assert(!ep.blocking)
}
@Test def shouldCreateEndpointWithBlockingSet = {
val ep: ActorEndpoint = component.createEndpoint("actor:uuid:abc?blocking=true").asInstanceOf[ActorEndpoint]
assert(ep.uuid === Some("abc"))
val ep: ActorEndpoint = component.createEndpoint("actor:uuid:"+testUUID+"?blocking=true").asInstanceOf[ActorEndpoint]
assert(ep.uuid === Some(testUUID))
assert(ep.id === None)
assert(ep.blocking)
}