You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/03/03 10:11:38 UTC

[1/2] camel git commit: CAMEL-7644: camel-scala, must use ScalaRouteBuilder to ensure a CamelContext is provided when creating routes. The old class is deprecated.

Repository: camel
Updated Branches:
  refs/heads/master ae08cd979 -> 01f08a626


CAMEL-7644: camel-scala, must use ScalaRouteBuilder to ensure a CamelContext is provided when creating routes. The old class is deprecated.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c469ad77
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c469ad77
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c469ad77

Branch: refs/heads/master
Commit: c469ad776a86086c5edbed2cac998dd0596aa7d8
Parents: ae08cd9
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 3 09:19:25 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 3 09:19:25 2015 +0100

----------------------------------------------------------------------
 .../apache/camel/builder/BuilderSupport.java    |  5 ++--
 .../camel/scala/dsl/builder/RouteBuilder.scala  |  3 +++
 .../scala/dsl/builder/ScalaRouteBuilder.scala   | 25 ++++++++++++++++++++
 .../apache/camel/scala/dsl/CamelCBRTest.scala   |  8 ++++---
 4 files changed, 36 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c469ad77/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java b/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
index e8713c5..85d51eb 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
@@ -494,12 +494,13 @@ public abstract class BuilderSupport {
         return context;
     }
     
-    @Deprecated
     public void setContext(CamelContext context) {
-        this.context = (ModelCamelContext)context;
+        ObjectHelper.notNull(context, "CamelContext", this);
+        this.context = context.adapt(ModelCamelContext.class);
     }
 
     public void setContext(ModelCamelContext context) {
+        ObjectHelper.notNull(context, "CamelContext", this);
         this.context = context;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/c469ad77/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
index 5d68b63..1c58e78 100644
--- a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
+++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
@@ -36,7 +36,10 @@ import org.slf4j.{Logger, LoggerFactory}
 
 /**
  * Scala RouteBuilder implementation
+ *
+ * @deprecated use ScalaRouteBuilder
  */
+@Deprecated
 class RouteBuilder extends Preamble with DSL with RoutesBuilder with Languages with Functions {
 
   val builder = new org.apache.camel.builder.RouteBuilder {

http://git-wip-us.apache.org/repos/asf/camel/blob/c469ad77/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/ScalaRouteBuilder.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/ScalaRouteBuilder.scala b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/ScalaRouteBuilder.scala
new file mode 100644
index 0000000..e0b88cf
--- /dev/null
+++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/ScalaRouteBuilder.scala
@@ -0,0 +1,25 @@
+/**
+ * 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.builder
+
+import org.apache.camel.CamelContext
+
+class ScalaRouteBuilder(val context:CamelContext) extends RouteBuilder {
+
+  builder.setContext(context)
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/c469ad77/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/CamelCBRTest.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/CamelCBRTest.scala b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/CamelCBRTest.scala
index aa21856..8cb8746 100644
--- a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/CamelCBRTest.scala
+++ b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/CamelCBRTest.scala
@@ -17,12 +17,14 @@
 package org.apache.camel.scala.dsl
 
 import org.apache.camel.test.junit4.CamelTestSupport
-import org.apache.camel.scala.dsl.builder.{RouteBuilder, RouteBuilderSupport}
+import org.apache.camel.scala.dsl.builder.{ScalaRouteBuilder, RouteBuilder, RouteBuilderSupport}
 import org.junit.Test
 
 class CamelCBRTest extends CamelTestSupport with RouteBuilderSupport {
 
-  override protected def createRouteBuilder = builder
+  override protected def createRouteBuilder = {
+    builder
+  }
 
   @Test
   def testFoo() {
@@ -45,7 +47,7 @@ class CamelCBRTest extends CamelTestSupport with RouteBuilderSupport {
     assertMockEndpointsSatisfied()
   }
 
-  val builder = new RouteBuilder {
+  lazy val builder = new ScalaRouteBuilder(context()) {
     "direct:start" ==> {
       choice {
         when(simple("${body} == 'foo'")) to "mock:foo"


[2/2] camel git commit: CAMEL-7644: camel-scala, must use ScalaRouteBuilder to ensure a CamelContext is provided when creating routes. The old class is deprecated.

Posted by da...@apache.org.
CAMEL-7644: camel-scala, must use ScalaRouteBuilder to ensure a CamelContext is provided when creating routes. The old class is deprecated.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/01f08a62
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/01f08a62
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/01f08a62

Branch: refs/heads/master
Commit: 01f08a6267232089adba90a380050ba5dc9c43d2
Parents: c469ad7
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 3 10:10:37 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 3 10:10:37 2015 +0100

----------------------------------------------------------------------
 .../camel/scala/dsl/ScalaRouteBuilderTest.scala | 49 ++++++++++++++++++++
 .../camel/scala/dsl/ScalaTestSupport.scala      |  5 +-
 2 files changed, 53 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/01f08a62/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ScalaRouteBuilderTest.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ScalaRouteBuilderTest.scala b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ScalaRouteBuilderTest.scala
new file mode 100644
index 0000000..5afb77b
--- /dev/null
+++ b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ScalaRouteBuilderTest.scala
@@ -0,0 +1,49 @@
+/**
+ * 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 java.util.Properties
+
+import org.apache.camel.scala.dsl.builder.{ScalaRouteBuilder, RouteBuilder}
+import org.junit.Test
+
+class ScalaRouteBuilderTest extends ScalaTestSupport {
+
+  override def useOverridePropertiesWithPropertiesComponent(): Properties = {
+    val prop = new Properties()
+    prop.put("foo", "direct:foo")
+    prop.put("bar", "mock:bar")
+    prop
+  }
+
+  @Test
+  def testScalaRouteBuilder() {
+    getMockEndpoint("mock:bar").expectedMessageCount(1)
+
+    template().sendBody("{{foo}}", "Hello World")
+
+    assertMockEndpointsSatisfied()
+  }
+
+  // must use lazy as we want to evaluate this after CamelContext has been created
+  override lazy val builder: RouteBuilder = {
+    new ScalaRouteBuilder(context()) {
+      from("{{foo}}").to("{{bar}}")
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/01f08a62/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ScalaTestSupport.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ScalaTestSupport.scala b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ScalaTestSupport.scala
index e749f28..514f864 100644
--- a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ScalaTestSupport.scala
+++ b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ScalaTestSupport.scala
@@ -44,7 +44,10 @@ abstract class ScalaTestSupport extends CamelTestSupport with RouteBuilderSuppor
   def in(message: Any) : Exchange =  createExchangeWithBody(message)
   
   val builder : RouteBuilder
-  
+
+  /**
+   * Creates the route builder, make sure to use lazy modifier, and create a ScalaRouteBuilder instance
+   */
   override protected def createRouteBuilder = builder
 
   override def setUp() {