Author: davsclaus
Date: Tue Dec  6 15:49:44 2011
New Revision: 1210988

URL: http://svn.apache.org/viewvc?rev=1210988&view=rev
Log:
Added example based on user forum issue

Added:
    
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/example/
    
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/example/FilterRoute.scala
    
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/example/FilterRouteTest.scala

Added: 
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/example/FilterRoute.scala
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/example/FilterRoute.scala?rev=1210988&view=auto
==============================================================================
--- 
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/example/FilterRoute.scala
 (added)
+++ 
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/example/FilterRoute.scala
 Tue Dec  6 15:49:44 2011
@@ -0,0 +1,39 @@
+/**
+ * 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.example
+
+import org.apache.camel.scala.dsl.builder.{RouteBuilder, RouteBuilderSupport}
+
+/**
+ * A Camel route which filters unwanted messages using Scala predicates.
+ */
+// START SNIPPET: e1
+// the class should extend the RouteBuilderSupport from 
org.apache.camel.scala.dsl.builder package
+class FilterRoute extends RouteBuilderSupport {
+
+  // then define any method which creates a new 
org.apache.camel.scala.dsl.builder.RouteBuilder instance
+  def createMyFilterRoute = new RouteBuilder {
+    // and here we can use the Scala DSL to define the routes
+    from("direct:start")
+      // in the filter, we can use the scala closures in the predicate
+      // here we check the IN message having a header with the key gold equals 
to true
+      .filter(_.in("gold") == "true")
+        .to("mock:gold")
+  }
+
+}
+// END SNIPPET: e1

Added: 
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/example/FilterRouteTest.scala
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/example/FilterRouteTest.scala?rev=1210988&view=auto
==============================================================================
--- 
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/example/FilterRouteTest.scala
 (added)
+++ 
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/example/FilterRouteTest.scala
 Tue Dec  6 15:49:44 2011
@@ -0,0 +1,51 @@
+/**
+ * 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.example
+
+import org.apache.camel.test.junit4.CamelTestSupport
+import org.junit.Test
+
+// START SNIPPET: e1
+// we want to use the Camel test kit to test the FilterRouteExample which we 
can do by extending
+// the CamelTestSupport class from camel-test
+class FilterRouteTest extends CamelTestSupport {
+
+  // then override this method to provide the RouteBuilder instance from 
camel-core
+  override def createRouteBuilder() = new 
FilterRoute().createMyFilterRoute.builder
+
+  // and here we just have regular JUnit test method which uses the API from 
camel-test
+
+  @Test
+  def testFilterRouteGold() {
+    getMockEndpoint("mock:gold").expectedMessageCount(1)
+
+    template.sendBodyAndHeader("direct:start", "Hello World", "gold", "true")
+
+    assertMockEndpointsSatisfied()
+  }
+
+  @Test
+  def testFilterRouteNotGold() {
+    getMockEndpoint("mock:gold").expectedMessageCount(0)
+
+    template.sendBodyAndHeader("direct:start", "Hello World", "gold", "false")
+
+    assertMockEndpointsSatisfied()
+  }
+
+}
+// END SNIPPET: e1


Reply via email to