Author: gertv
Date: Tue Mar 24 12:51:18 2009
New Revision: 757766

URL: http://svn.apache.org/viewvc?rev=757766&view=rev
Log:
CAMEL-463: Add support for rollback() to the Scala DSL

Added:
    camel/trunk/components/camel-scala/src/test/resources/log4j.properties   
(with props)
    
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RollbackTest.scala
Modified:
    
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
    
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
    
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala

Modified: 
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala?rev=757766&r1=757765&r2=757766&view=diff
==============================================================================
--- 
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
 (original)
+++ 
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
 Tue Mar 24 12:51:18 2009
@@ -40,6 +40,7 @@
   def process(function: Exchange => Unit) : DSL
   def recipients(expression: Exchange => Any) : DSL
   def resequence(expression: Exchange => Any) : SResequenceDefinition
+  def rollback : DSL
   def setbody(expression: Exchange => Any) : DSL
   def setheader(header: String, expression: Exchange => Any) : DSL
   def split(expression: Exchange => Any) : SSplitDefinition

Modified: 
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala?rev=757766&r1=757765&r2=757766&view=diff
==============================================================================
--- 
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
 (original)
+++ 
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
 Tue Mar 24 12:51:18 2009
@@ -104,6 +104,8 @@
   
   def resequence(expression: Exchange => Any) = new 
SResequenceDefinition(target.resequence(expression))
   
+  def rollback = new 
SProcessorDefinition(target.rollback.asInstanceOf[RawProcessorDefinition])
+  
   def setbody(expression: Exchange => Any) = new 
SProcessorDefinition(target.setBody(expression).asInstanceOf[ProcessorDefinition[P]
 forSome {type P}])
   
   def setheader(name: String, expression: Exchange => Any) = new 
SProcessorDefinition(target.setHeader(name, 
expression).asInstanceOf[ProcessorDefinition[P] forSome {type P}])

Modified: 
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala?rev=757766&r1=757765&r2=757766&view=diff
==============================================================================
--- 
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
 (original)
+++ 
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
 Tue Mar 24 12:51:18 2009
@@ -80,6 +80,7 @@
   def loadbalance = stack.top.loadbalance
   def delay(delay: Period) = stack.top.delay(delay)
   def resequence(expression: Exchange => Any) = 
stack.top.resequence(expression)
+  def rollback = stack.top.rollback
   def setbody(expression : Exchange => Any) = stack.top.setbody(expression)
   def setheader(name: String, expression: Exchange => Any) = 
stack.top.setheader(name, expression)
   def thread(count: Int) = stack.top.thread(count)

Added: camel/trunk/components/camel-scala/src/test/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/test/resources/log4j.properties?rev=757766&view=auto
==============================================================================
--- camel/trunk/components/camel-scala/src/test/resources/log4j.properties 
(added)
+++ camel/trunk/components/camel-scala/src/test/resources/log4j.properties Tue 
Mar 24 12:51:18 2009
@@ -0,0 +1,38 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, file
+
+log4j.logger.org.apache.activemq.spring=WARN
+#log4j.logger.org.apache.camel=DEBUG
+#log4j.logger.org.apache.camel.component=TRACE
+log4j.logger.org.apache.camel.impl.converter=WARN
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - 
%m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - 
%m%n
+log4j.appender.file.file=target/camel-scala-test.log
+log4j.appender.file.append=true

Propchange: 
camel/trunk/components/camel-scala/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RollbackTest.scala
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RollbackTest.scala?rev=757766&view=auto
==============================================================================
--- 
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RollbackTest.scala
 (added)
+++ 
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RollbackTest.scala
 Tue Mar 24 12:51:18 2009
@@ -0,0 +1,77 @@
+/**
+ * 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 org.w3c.dom.Document
+import scala.dsl.builder.RouteBuilder
+import junit.framework.Assert._
+
+/**
+ * Test case for rollback
+ */
+class RollbackTest extends ScalaTestSupport {
+  
+  var handled = false;
+  
+  def testSimple = {
+    test {
+      try {
+        template.requestBody("direct:a", "The Joker")
+        fail("Expected a RollbackExchangeException")
+      } catch {
+        // oh no, not the Joker again, let's send Batman
+        case e: RuntimeCamelException if 
(e.getCause().isInstanceOf[RollbackExchangeException]) => 
template.requestBody("direct:a", "Batman")
+        case unknown => fail("We didn't expect " + unknown)
+      }
+    }
+  }
+  
+  def testBlock = {
+    "mock:b" expect { _.count = 2 }
+    "mock:ok" expect { _.count = 1 }
+    test {
+      try {
+        template.requestBody("direct:b", "Lex Luthor")
+        fail("Expected a RollbackExchangeException")
+      } catch {
+        // oh no, not Lex Luthor again, let's send Superman
+        case e: RuntimeCamelException if 
(e.getCause().isInstanceOf[RollbackExchangeException]) => 
template.requestBody("direct:b", "Superman")
+        case unknown => fail("We didn't expect " + unknown)
+      }
+    }
+  }
+    
+  val builder =
+    new RouteBuilder {
+       //START SNIPPET: simple
+       "direct:a" to("mock:a") when(_.in != "Batman") rollback
+       //END SNIPPET: simple
+      
+       //START SNIPPET: block
+       "direct:b" ==> {
+         to("mock:b")
+         choice {
+           when(_.in != "Superman") {
+             rollback
+           }
+           otherwise to "mock:ok"
+         }
+       }
+       //END SNIPPET: block
+    }
+
+}


Reply via email to