camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r704009 - in /activemq/camel/trunk/components/camel-scala/src: main/scala/org/apache/camel/scala/dsl/ main/scala/org/apache/camel/scala/dsl/builder/ test/scala/org/apache/camel/scala/ test/scala/org/apache/camel/scala/dsl/ test/scala/org/ap...
Date Mon, 13 Oct 2008 10:44:03 GMT
Author: gertv
Date: Mon Oct 13 03:44:02 2008
New Revision: 704009

URL: http://svn.apache.org/viewvc?rev=704009&view=rev
Log:
CAMEL-463: Adding support for setting a header from a route

Added:
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetHeaderTest.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/test/Animal.scala
Modified:
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala?rev=704009&r1=704008&r2=704009&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
(original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
Mon Oct 13 03:44:02 2008
@@ -38,6 +38,7 @@
   def delay(delay: Period) : SDelayerType
   def resequence(expression: Exchange => Any) : SResequencerType
   def setbody(expression: Exchange => Any) : DSL
+  def setheader(header: String, expression: Exchange => Any) : DSL
   def aggregate(expression: Exchange => Any) : SAggregatorType
   def idempotentconsumer(expression: Exchange => Any): SIdempotentConsumerType
 

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala?rev=704009&r1=704008&r2=704009&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
(original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
Mon Oct 13 03:44:02 2008
@@ -92,6 +92,8 @@
   
   def setbody(expression: Exchange => Any) = new SProcessorType(target.setBody(expression).asInstanceOf[ProcessorType[P]
forSome {type P}])
   
+  def setheader(name: String, expression: Exchange => Any) = new SProcessorType(target.setHeader(name,
expression).asInstanceOf[ProcessorType[P] forSome {type P}])
+  
   def aggregate(expression: Exchange => Any) = new SAggregatorType(target.aggregator(expression))
 
 }

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala?rev=704009&r1=704008&r2=704009&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
(original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
Mon Oct 13 03:44:02 2008
@@ -74,6 +74,7 @@
   def delay(delay: Period) = stack.top.delay(delay)
   def resequence(expression: Exchange => Any) = stack.top.resequence(expression)
   def setbody(expression : Exchange => Any) = stack.top.setbody(expression)
+  def setheader(name: String, expression: Exchange => Any) = stack.top.setheader(name,
expression)
   def aggregate(expression: Exchange => Any) = stack.top.aggregate(expression)
 
 }

Modified: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala?rev=704009&r1=704008&r2=704009&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
(original)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
Mon Oct 13 03:44:02 2008
@@ -25,6 +25,10 @@
     messages.foreach(list.add(_))
     endpoint.expectedBodiesReceived(list)
   }
+  
+  def headerReceived(name: String, value: String) {
+    endpoint.expectedHeaderReceived(name, value)
+  }
 
   def count : Int = endpoint.getExpectedCount
   

Modified: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala?rev=704009&r1=704008&r2=704009&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala
(original)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala
Mon Oct 13 03:44:02 2008
@@ -17,7 +17,7 @@
 package org.apache.camel.scala.dsl;
  
 import scala.dsl.builder.RouteBuilder
-import org.apache.camel.scala.test.{Adult, Toddler}
+import org.apache.camel.scala.test.{Cat, Kitten}
 
 /**
  * Test for setting the message body from the Scala DSL
@@ -41,7 +41,7 @@
   def doTestExpression(from: String, mock: String) = {
     mock expect {_.received("Duchess", "Toulouse")}
     test {
-      from ! (new Adult("Duchess"), new Toddler("Toulouse"))
+      from ! (new Cat("Duchess"), new Kitten("Toulouse"))
     }    
   }
     

Added: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetHeaderTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetHeaderTest.scala?rev=704009&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetHeaderTest.scala
(added)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetHeaderTest.scala
Mon Oct 13 03:44:02 2008
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.scala.dsl;
+ 
+import scala.dsl.builder.RouteBuilder
+import org.apache.camel.scala.test.{Cat, Kitten}
+
+/**
+ * Test for setting the message header from the Scala DSL
+ */
+class SetHeaderTest extends ScalaTestSupport {
+
+  def testSimpleSetBody() = doTestConstant("direct:a", "mock:a")
+  def testBlockSetBody() = doTestConstant("direct:b", "mock:b")
+  
+  def testSimpleExpression() = doTestExpression("direct:c", "mock:c")
+  def testBodyExpression() = doTestExpression("direct:d", "mock:d")
+  
+  
+  def doTestConstant(from: String, mock: String) = {
+    mock expect { _.headerReceived("response", "pong?")}
+    test {
+      from ! ("ping")
+    }    
+  }
+  
+  def doTestExpression(from: String, mock: String) = {
+    mock expect {_.headerReceived("genus", "felis")}
+    test {
+      from ! (new Cat("Duchess"), new Kitten("Toulouse"))
+    }    
+  }
+    
+  val builder = new RouteBuilder with languages.El {
+     //START SNIPPET: simple
+     "direct:a" setheader("response", "pong?") to "mock:a"
+     "direct:c" setheader("genus",el("${in.body.genus}")) to "mock:c"
+     //END SNIPPET: simple
+     
+     //START SNIPPET: block
+     "direct:b" ==> {
+       setheader("response", "pong?")
+       to ("mock:b")
+     }
+     
+     "direct:d" ==> {
+       setheader("genus", el("${in.body.genus}"))
+       to ("mock:d")
+     }
+     //END SNIPPET: block
+     
+   }
+}
+
+

Added: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/test/Animal.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/test/Animal.scala?rev=704009&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/test/Animal.scala
(added)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/test/Animal.scala
Mon Oct 13 03:44:02 2008
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.scala.test;
+
+import _root_.scala.reflect.BeanProperty
+
+/**
+ * Just a simple Animal test class
+ */
+abstract class Animal(@BeanProperty val name: String, @BeanProperty val genus: String)
+
+case class Cat(override val name: String) extends Animal(name, "felis") 
+case class Kitten(override val name: String) extends Cat(name)
+
+case class Dog(override val name: String) extends Animal(name, "canis")
+case class Puppy(override val name: String) extends Dog(name)



Mime
View raw message