camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-9062: Java DSL should build expressions as languages so they model can be dumped, and build similar as we do in XML DSL
Date Fri, 07 Aug 2015 11:53:26 GMT
Repository: camel
Updated Branches:
  refs/heads/master 3fc9de754 -> c63c25033


CAMEL-9062: Java DSL should build expressions as languages so they model can be dumped, and
build similar as we do in XML DSL


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

Branch: refs/heads/master
Commit: c63c250337737951041a32daaca678d69653340d
Parents: c81a051
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Aug 7 13:23:46 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Aug 7 14:00:27 2015 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/builder/Builder.java  | 87 +++++++++++++-------
 .../apache/camel/builder/BuilderSupport.java    | 63 +++++++-------
 .../org/apache/camel/builder/ValueBuilder.java  |  1 -
 .../language/ExchangePropertyExpression.java    |  4 +-
 .../apache/camel/builder/NotifyBuilderTest.java |  2 +-
 .../FileSplitStreamingWithChoiceTest.java       |  2 +-
 .../camel/issues/RegExPredicateIssueTest.java   |  2 +-
 .../camel/processor/ValidateRegExpTest.java     |  2 +-
 .../AdviceWithWeaveAfterLastSplitTest.java      |  2 +-
 ...umpModelAsXmlTransformRouteConstantTest.java | 64 ++++++++++++++
 ...umpModelAsXmlTransformRouteLanguageTest.java | 65 +++++++++++++++
 11 files changed, 228 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c63c2503/camel-core/src/main/java/org/apache/camel/builder/Builder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/Builder.java b/camel-core/src/main/java/org/apache/camel/builder/Builder.java
index ed0d932..6633f2b 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/Builder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/Builder.java
@@ -17,12 +17,23 @@
 package org.apache.camel.builder;
 
 import org.apache.camel.Expression;
+import org.apache.camel.model.language.ConstantExpression;
+import org.apache.camel.model.language.ExchangePropertyExpression;
+import org.apache.camel.model.language.HeaderExpression;
+import org.apache.camel.model.language.LanguageExpression;
+import org.apache.camel.model.language.MethodCallExpression;
+import org.apache.camel.model.language.SimpleExpression;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * A helper class for including portions of the <a
  * href="http://camel.apache.org/expression.html">expression</a> and
  * <a href="http://camel.apache.org/predicate.html">predicate</a> <a
  * href="http://camel.apache.org/dsl.html">Java DSL</a>
+ * <p/>
+ * Implementation of this builder should favor build expressions using the definition classes
+ * from the <tt>org.apache.camel.model.language</tt> package, to build the routes
using the same
+ * types as it would happen when using XML DSL.
  *
  * @version 
  */
@@ -58,13 +69,13 @@ public final class Builder {
      * @return the builder
      */
     public static ValueBuilder bean(Object beanOrBeanRef, String method) {
-        Expression expression;
+        Expression exp;
         if (beanOrBeanRef instanceof String) {
-            expression = ExpressionBuilder.beanExpression((String) beanOrBeanRef, method);
+            exp = new MethodCallExpression((String) beanOrBeanRef, method);
         } else {
-            expression = ExpressionBuilder.beanExpression(beanOrBeanRef, method);
+            exp = new MethodCallExpression(beanOrBeanRef, method);
         }
-        return new ValueBuilder(expression);
+        return new ValueBuilder(exp);
     }
     
     /**
@@ -76,23 +87,28 @@ public final class Builder {
      * @return the builder
      */
     public static ValueBuilder bean(Class<?> beanType, String method) {
-        Expression expression = ExpressionBuilder.beanExpression(beanType, method);
-        return new ValueBuilder(expression);
+        Expression exp = new MethodCallExpression(beanType, method);
+        return new ValueBuilder(exp);
     }
 
     /**
      * Returns a constant expression
      */
     public static ValueBuilder constant(Object value) {
-        Expression expression = ExpressionBuilder.constantExpression(value);
-        return new ValueBuilder(expression);
+        Expression exp;
+        if (value instanceof String) {
+            exp = new ConstantExpression((String) value);
+        } else {
+            exp = ExpressionBuilder.constantExpression(value);
+        }
+        return new ValueBuilder(exp);
     }
     
     /**
      * Returns a constant expression
      */
     public static ValueBuilder language(String language, String expression) {
-        Expression exp = ExpressionBuilder.languageExpression(language, expression);
+        Expression exp = new LanguageExpression(language, expression);
         return new ValueBuilder(exp);
     }
 
@@ -100,25 +116,25 @@ public final class Builder {
      * Returns a simple expression  
      */
     public static ValueBuilder simple(String value) {
-        Expression expression = ExpressionBuilder.simpleExpression(value);
-        return new ValueBuilder(expression);
+        Expression exp = new SimpleExpression(value);
+        return new ValueBuilder(exp);
     }
     
     /**
      * Returns a simple expression
      */
     public static ValueBuilder simple(String value, Class<?> resultType) {
-        Expression expression = ExpressionBuilder.simpleExpression(value);
-        expression = ExpressionBuilder.convertToExpression(expression, resultType);
-        return new ValueBuilder(expression);
+        SimpleExpression exp = new SimpleExpression(value);
+        exp.setResultType(resultType);
+        return new ValueBuilder(exp);
     }
 
     /**
      * Returns a predicate and value builder for headers on an exchange
      */
     public static ValueBuilder header(String name) {
-        Expression expression = ExpressionBuilder.headerExpression(name);
-        return new ValueBuilder(expression);
+        Expression exp = new HeaderExpression(name);
+        return new ValueBuilder(exp);
     }
 
     /**
@@ -135,16 +151,16 @@ public final class Builder {
      * Returns a predicate and value builder for properties on an exchange
      */
     public static ValueBuilder exchangeProperty(String name) {
-        Expression expression = ExpressionBuilder.exchangePropertyExpression(name);
-        return new ValueBuilder(expression);
+        Expression exp = new ExchangePropertyExpression(name);
+        return new ValueBuilder(exp);
     }
 
     /**
      * Returns a predicate and value builder for the inbound body on an exchange
      */
     public static ValueBuilder body() {
-        Expression expression = ExpressionBuilder.bodyExpression();
-        return new ValueBuilder(expression);
+        Expression exp = new SimpleExpression("${body}");
+        return new ValueBuilder(exp);
     }
 
     /**
@@ -152,23 +168,30 @@ public final class Builder {
      * specific type
      */
     public static <T> ValueBuilder bodyAs(Class<T> type) {
-        Expression expression = ExpressionBuilder.bodyExpression(type);
-        return new ValueBuilder(expression);
+        ObjectHelper.notNull(type, "type");
+        Expression exp = new SimpleExpression(String.format("${bodyAs(%s)}", type.getCanonicalName()));
+        return new ValueBuilder(exp);
     }
 
     /**
      * Returns a predicate and value builder for the outbound body on an
      * exchange
+     *
+     * @deprecated use {@link #body()}
      */
+    @Deprecated
     public static ValueBuilder outBody() {
-        Expression expression = ExpressionBuilder.outBodyExpression();
-        return new ValueBuilder(expression);
+        Expression exp = new SimpleExpression("${out.body}");
+        return new ValueBuilder(exp);
     }
 
     /**
      * Returns a predicate and value builder for the outbound message body as a
      * specific type
+     *
+     * @deprecated use {@link #bodyAs(Class)}
      */
+    @Deprecated
     public static <T> ValueBuilder outBodyAs(Class<T> type) {
         Expression expression = ExpressionBuilder.outBodyExpression(type);
         return new ValueBuilder(expression);
@@ -186,7 +209,10 @@ public final class Builder {
     /**
      * Returns a predicate and value builder for the fault message body as a
      * specific type
+     *
+     * @deprecated use {@link #bodyAs(Class)}
      */
+    @Deprecated
     public static <T> ValueBuilder faultBodyAs(Class<T> type) {
         Expression expression = ExpressionBuilder.faultBodyExpression(type);
         return new ValueBuilder(expression);
@@ -196,7 +222,8 @@ public final class Builder {
      * Returns an expression for the given system property
      */
     public static ValueBuilder systemProperty(final String name) {
-        return systemProperty(name, null);
+        Expression exp = new SimpleExpression(String.format("${sys.%s}", name));
+        return new ValueBuilder(exp);
     }
 
     /**
@@ -210,16 +237,16 @@ public final class Builder {
      * Returns a predicate and value builder for the exception message on an exchange
      */
     public static ValueBuilder exceptionMessage() {
-        Expression expression = ExpressionBuilder.exchangeExceptionMessageExpression();
-        return new ValueBuilder(expression);
+        Expression exp = new SimpleExpression("${exception.message}");
+        return new ValueBuilder(exp);
     }
     
     /**
      * Returns a predicate and value builder for the exception stacktrace on an exchange
      */
     public static ValueBuilder exceptionStackTrace() {
-        Expression expression = ExpressionBuilder.exchangeExceptionStackTraceExpression();
-        return new ValueBuilder(expression);
+        Expression exp = new SimpleExpression("${exception.stacktrace}");
+        return new ValueBuilder(exp);
     }
 
     /**
@@ -245,7 +272,9 @@ public final class Builder {
      *
      * @param uri   endpoint uri
      * @return the builder
+     * @deprecated not in use, and not available in XML DSL
      */
+    @Deprecated
     public static ValueBuilder sendTo(String uri) {
         Expression expression = ExpressionBuilder.toExpression(uri);
         return new ValueBuilder(expression);

http://git-wip-us.apache.org/repos/asf/camel/blob/c63c2503/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 85d51eb..cdaf71f 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
@@ -29,7 +29,6 @@ import org.apache.camel.builder.xml.XPathBuilder;
 import org.apache.camel.model.ModelCamelContext;
 import org.apache.camel.model.language.ExchangePropertyExpression;
 import org.apache.camel.model.language.HeaderExpression;
-import org.apache.camel.model.language.MethodCallExpression;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,8 +57,8 @@ public abstract class BuilderSupport {
      * Returns a value builder for the given header
      */
     public ValueBuilder header(String name) {
-        HeaderExpression expression = new HeaderExpression(name);
-        return new ValueBuilder(expression);
+        Expression exp = new HeaderExpression(name);
+        return new ValueBuilder(exp);
     }
 
     /**
@@ -69,16 +68,16 @@ public abstract class BuilderSupport {
      */
     @Deprecated
     public ValueBuilder property(String name) {
-        ExchangePropertyExpression expression = new ExchangePropertyExpression(name);
-        return new ValueBuilder(expression);
+        Expression exp = new ExchangePropertyExpression(name);
+        return new ValueBuilder(exp);
     }
     
     /**
      * Returns a value builder for the given exchange property
      */
     public ValueBuilder exchangeProperty(String name) {
-        ExchangePropertyExpression expression = new ExchangePropertyExpression(name);
-        return new ValueBuilder(expression);
+        Expression exp = new ExchangePropertyExpression(name);
+        return new ValueBuilder(exp);
     }
 
     /**
@@ -91,15 +90,29 @@ public abstract class BuilderSupport {
     /**
      * Returns a predicate and value builder for the inbound message body as a
      * specific type
+     *
+     * @deprecated use {@link #bodyAs(Class)}
      */
+    @Deprecated
     public <T> ValueBuilder body(Class<T> type) {
+        return bodyAs(type);
+    }
+
+    /**
+     * Returns a predicate and value builder for the inbound message body as a
+     * specific type
+     */
+    public <T> ValueBuilder bodyAs(Class<T> type) {
         return Builder.bodyAs(type);
     }
 
     /**
      * Returns a predicate and value builder for the outbound body on an
      * exchange
+     *
+     * @deprecated use {@link #body()}
      */
+    @Deprecated
     public ValueBuilder outBody() {
         return Builder.outBody();
     }
@@ -107,7 +120,10 @@ public abstract class BuilderSupport {
     /**
      * Returns a predicate and value builder for the outbound message body as a
      * specific type
+     *
+     * @deprecated use {@link #bodyAs(Class)}
      */
+    @Deprecated
     public <T> ValueBuilder outBody(Class<T> type) {
         return Builder.outBodyAs(type);
     }
@@ -123,7 +139,10 @@ public abstract class BuilderSupport {
     /**
      * Returns a predicate and value builder for the fault message body as a
      * specific type
+     *
+     * @deprecated use {@link #bodyAs(Class)}
      */
+    @Deprecated
     public <T> ValueBuilder faultBodyAs(Class<T> type) {
         return Builder.faultBodyAs(type);
     }
@@ -217,13 +236,7 @@ public abstract class BuilderSupport {
      */
     @Deprecated
     public ValueBuilder bean(Object beanOrBeanRef, String method) {
-        MethodCallExpression expression;
-        if (beanOrBeanRef instanceof String) {
-            expression = new MethodCallExpression((String) beanOrBeanRef, method);
-        } else {
-            expression = new MethodCallExpression(beanOrBeanRef, method);
-        }
-        return new ValueBuilder(expression);
+        return Builder.bean(beanOrBeanRef, method);
     }
 
     /**
@@ -236,8 +249,7 @@ public abstract class BuilderSupport {
      */
     @Deprecated
     public ValueBuilder bean(Class<?> beanType) {
-        MethodCallExpression expression = new MethodCallExpression(beanType);
-        return new ValueBuilder(expression);
+        return Builder.bean(beanType);
     }
     
     /**
@@ -251,8 +263,7 @@ public abstract class BuilderSupport {
      */
     @Deprecated
     public ValueBuilder bean(Class<?> beanType, String method) {
-        MethodCallExpression expression = new MethodCallExpression(beanType, method);
-        return new ValueBuilder(expression);
+        return Builder.bean(beanType, method);
     }
 
     /**
@@ -279,13 +290,7 @@ public abstract class BuilderSupport {
      * @return the builder
      */
     public ValueBuilder method(Object beanOrBeanRef, String method) {
-        MethodCallExpression expression;
-        if (beanOrBeanRef instanceof String) {
-            expression = new MethodCallExpression((String) beanOrBeanRef, method);
-        } else {
-            expression = new MethodCallExpression(beanOrBeanRef, method);
-        }
-        return new ValueBuilder(expression);
+        return Builder.bean(beanOrBeanRef, method);
     }
 
     /**
@@ -296,8 +301,7 @@ public abstract class BuilderSupport {
      * @return the builder
      */
     public ValueBuilder method(Class<?> beanType) {
-        MethodCallExpression expression = new MethodCallExpression(beanType);
-        return new ValueBuilder(expression);
+        return Builder.bean(beanType);
     }
 
     /**
@@ -309,8 +313,7 @@ public abstract class BuilderSupport {
      * @return the builder
      */
     public ValueBuilder method(Class<?> beanType, String method) {
-        MethodCallExpression expression = new MethodCallExpression(beanType, method);
-        return new ValueBuilder(expression);
+        return Builder.bean(beanType, method);
     }
 
     /**
@@ -318,7 +321,9 @@ public abstract class BuilderSupport {
      *
      * @param uri endpoint uri to send the exchange to
      * @return the builder
+     * @deprecated not in use, and not available in XML DSL
      */
+    @Deprecated
     public ValueBuilder sendTo(String uri) {
         return Builder.sendTo(uri);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/c63c2503/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
index e9fca82..a8faf61 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
@@ -24,7 +24,6 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Predicate;
 import org.apache.camel.builder.xml.Namespaces;
-import org.apache.camel.model.language.ExpressionDefinition;
 import org.apache.camel.spi.NamespaceAware;
 import org.apache.camel.util.ExpressionToPredicateAdapter;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/c63c2503/camel-core/src/main/java/org/apache/camel/model/language/ExchangePropertyExpression.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/language/ExchangePropertyExpression.java
b/camel-core/src/main/java/org/apache/camel/model/language/ExchangePropertyExpression.java
index bfd5491..77ee04d 100644
--- a/camel-core/src/main/java/org/apache/camel/model/language/ExchangePropertyExpression.java
+++ b/camel-core/src/main/java/org/apache/camel/model/language/ExchangePropertyExpression.java
@@ -35,8 +35,8 @@ public class ExchangePropertyExpression extends ExpressionDefinition {
     public ExchangePropertyExpression() {
     }
 
-    public ExchangePropertyExpression(String expression) {
-        super(expression);
+    public ExchangePropertyExpression(String name) {
+        super(name);
     }
 
     public String getLanguage() {

http://git-wip-us.apache.org/repos/asf/camel/blob/c63c2503/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java b/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java
index e1d0124..8c56713 100644
--- a/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java
+++ b/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java
@@ -335,7 +335,7 @@ public class NotifyBuilderTest extends ContextTestSupport {
                 .filter(body().contains("World")).whenDone(3)
                 .create();
 
-        assertEquals("filter(body contains World).whenDone(3)", notify.toString());
+        assertEquals("filter(simple{${body}} contains World).whenDone(3)", notify.toString());
 
         assertEquals(false, notify.matches());
 

http://git-wip-us.apache.org/repos/asf/camel/blob/c63c2503/camel-core/src/test/java/org/apache/camel/issues/FileSplitStreamingWithChoiceTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/FileSplitStreamingWithChoiceTest.java
b/camel-core/src/test/java/org/apache/camel/issues/FileSplitStreamingWithChoiceTest.java
index 73fcebd..bde7b6b 100644
--- a/camel-core/src/test/java/org/apache/camel/issues/FileSplitStreamingWithChoiceTest.java
+++ b/camel-core/src/test/java/org/apache/camel/issues/FileSplitStreamingWithChoiceTest.java
@@ -56,7 +56,7 @@ public class FileSplitStreamingWithChoiceTest extends ContextTestSupport
{
                     .split(body().tokenize(LS)).streaming()
                     .to("mock:split")
                     .choice()
-                        .when(body(String.class).isNotNull()).to("mock:body")
+                        .when(bodyAs(String.class).isNotNull()).to("mock:body")
                         .otherwise().to("mock:other")
                     .end();
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/c63c2503/camel-core/src/test/java/org/apache/camel/issues/RegExPredicateIssueTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/RegExPredicateIssueTest.java
b/camel-core/src/test/java/org/apache/camel/issues/RegExPredicateIssueTest.java
index 27e005c..1fe09ef 100644
--- a/camel-core/src/test/java/org/apache/camel/issues/RegExPredicateIssueTest.java
+++ b/camel-core/src/test/java/org/apache/camel/issues/RegExPredicateIssueTest.java
@@ -31,7 +31,7 @@ public class RegExPredicateIssueTest extends ContextTestSupport {
             public void configure() throws Exception {
                 from("direct:a")
                     .choice()
-                        .when(body(String.class).regex("^0.*$")).to("mock:result")
+                        .when(bodyAs(String.class).regex("^0.*$")).to("mock:result")
                         .otherwise().to("mock:other")
                     .end();
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/c63c2503/camel-core/src/test/java/org/apache/camel/processor/ValidateRegExpTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/ValidateRegExpTest.java b/camel-core/src/test/java/org/apache/camel/processor/ValidateRegExpTest.java
index ee3f345..0e0211f 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/ValidateRegExpTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/ValidateRegExpTest.java
@@ -70,7 +70,7 @@ public class ValidateRegExpTest extends ContextTestSupport {
         return new RouteBuilder() {
             public void configure() {
                 from("direct:start")
-                    .validate(body(String.class).regex("^\\d{2}\\.\\d{2}\\.\\d{4}$"))
+                    .validate(bodyAs(String.class).regex("^\\d{2}\\.\\d{2}\\.\\d{4}$"))
                     .to("mock:result");
             }
         };

http://git-wip-us.apache.org/repos/asf/camel/blob/c63c2503/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveAfterLastSplitTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveAfterLastSplitTest.java
b/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveAfterLastSplitTest.java
index f94b13d..f50b728 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveAfterLastSplitTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveAfterLastSplitTest.java
@@ -48,7 +48,7 @@ public class AdviceWithWeaveAfterLastSplitTest extends ContextTestSupport
{
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:input").split(body(String.class).tokenize(",")).log("within
split: ${body}").end();
+                from("direct:input").split(bodyAs(String.class).tokenize(",")).log("within
split: ${body}").end();
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/c63c2503/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteConstantTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteConstantTest.java
b/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteConstantTest.java
new file mode 100644
index 0000000..8147225
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteConstantTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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.util;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.converter.jaxp.XmlConverter;
+import org.apache.camel.model.ModelHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ *
+ */
+public class DumpModelAsXmlTransformRouteConstantTest extends ContextTestSupport {
+
+    public void testDumpModelAsXml() throws Exception {
+        String xml = ModelHelper.dumpModelAsXml(context, context.getRouteDefinition("myRoute"));
+        assertNotNull(xml);
+        log.info(xml);
+
+        Document doc = new XmlConverter().toDOMDocument(xml);
+        NodeList nodes = doc.getElementsByTagName("constant");
+        assertEquals(1, nodes.getLength());
+        Element node = (Element)nodes.item(0);
+        assertNotNull("Node <simple> expected to be instanceof Element", node);
+        assertEquals("Hello World", node.getTextContent());
+
+        nodes = doc.getElementsByTagName("to");
+        assertEquals(1, nodes.getLength());
+        node = (Element)nodes.item(0);
+        assertNotNull("Node <to> expected to be instanceof Element", node);
+        assertEquals("mock:result", node.getAttribute("uri"));
+        assertEquals("myMock", node.getAttribute("id"));
+        assertEquals("true", node.getAttribute("customId"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").routeId("myRoute")
+                   .transform(constant("Hello World"))
+                   .to("mock:result").id("myMock");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/c63c2503/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteLanguageTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteLanguageTest.java
b/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteLanguageTest.java
new file mode 100644
index 0000000..40d6aa2
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteLanguageTest.java
@@ -0,0 +1,65 @@
+/**
+ * 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.util;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.converter.jaxp.XmlConverter;
+import org.apache.camel.model.ModelHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ *
+ */
+public class DumpModelAsXmlTransformRouteLanguageTest extends ContextTestSupport {
+
+    public void testDumpModelAsXml() throws Exception {
+        String xml = ModelHelper.dumpModelAsXml(context, context.getRouteDefinition("myRoute"));
+        assertNotNull(xml);
+        log.info(xml);
+
+        Document doc = new XmlConverter().toDOMDocument(xml);
+        NodeList nodes = doc.getElementsByTagName("language");
+        assertEquals(1, nodes.getLength());
+        Element node = (Element)nodes.item(0);
+        assertNotNull("Node <simple> expected to be instanceof Element", node);
+        assertEquals("constant", node.getAttribute("language"));
+        assertEquals("Hello World", node.getTextContent());
+
+        nodes = doc.getElementsByTagName("to");
+        assertEquals(1, nodes.getLength());
+        node = (Element)nodes.item(0);
+        assertNotNull("Node <to> expected to be instanceof Element", node);
+        assertEquals("mock:result", node.getAttribute("uri"));
+        assertEquals("myMock", node.getAttribute("id"));
+        assertEquals("true", node.getAttribute("customId"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").routeId("myRoute")
+                   .transform(language("constant", "Hello World"))
+                   .to("mock:result").id("myMock");
+            }
+        };
+    }
+}


Mime
View raw message