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 2019/04/17 09:41:25 UTC

[camel] 08/38: Move mock component out of camel-core. Work in progress.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch mock
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 050789672c3a96363d360c12cf3585c8bda523dd
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Apr 15 21:33:43 2019 +0200

    Move mock component out of camel-core. Work in progress.
---
 .../apache/camel/builder/ExpressionBuilder.java    |  3 +
 .../camel/builder/ExpressionClauseSupport.java     |  1 -
 .../camel/component/mock/AssertionClause.java      |  3 +-
 .../mock/MockExpressionClauseSupport.java}         | 80 +++++++++-------------
 4 files changed, 36 insertions(+), 51 deletions(-)

diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java b/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
index 5b4e215..ebbe476 100644
--- a/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
+++ b/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
@@ -77,6 +77,9 @@ import org.apache.camel.util.StringHelper;
  */
 public final class ExpressionBuilder {
 
+    // TODO: Make this possible to have a base class in camel-support, and then extend it here, so we can have both
+    // and maybe deprecate this and refer to the builder in camel-support
+
     private static final Pattern OFFSET_PATTERN = Pattern.compile("([+-])([^+-]+)");
 
     /**
diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java b/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
index b77da58..ddfd467 100644
--- a/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
+++ b/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
@@ -21,7 +21,6 @@ import java.util.Map;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Expression;
 import org.apache.camel.support.builder.xml.Namespaces;
-// TODO: All these should be behind support language so we can separate
 import org.apache.camel.model.language.ConstantExpression;
 import org.apache.camel.model.language.ExchangePropertyExpression;
 import org.apache.camel.model.language.GroovyExpression;
diff --git a/core/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java b/core/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
index 795f7d5..5556cba 100644
--- a/core/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
+++ b/core/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
@@ -25,7 +25,6 @@ import org.apache.camel.Expression;
 import org.apache.camel.Predicate;
 import org.apache.camel.StreamCache;
 import org.apache.camel.builder.ExpressionClause;
-import org.apache.camel.builder.ExpressionClauseSupport;
 import org.apache.camel.builder.ValueBuilder;
 import org.apache.camel.support.PredicateAssertHelper;
 import org.apache.camel.support.language.ExpressionModel;
@@ -33,7 +32,7 @@ import org.apache.camel.support.language.ExpressionModel;
 /**
  * A builder of assertions on message exchanges
  */
-public abstract class AssertionClause extends ExpressionClauseSupport<ValueBuilder> implements Runnable {
+public abstract class AssertionClause extends MockExpressionClauseSupport<ValueBuilder> implements Runnable {
 
     protected final MockEndpoint mock;
     protected volatile int currentIndex;
diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java b/core/camel-core/src/main/java/org/apache/camel/component/mock/MockExpressionClauseSupport.java
similarity index 94%
copy from core/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
copy to core/camel-core/src/main/java/org/apache/camel/component/mock/MockExpressionClauseSupport.java
index b77da58..eb58656 100644
--- a/core/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
+++ b/core/camel-core/src/main/java/org/apache/camel/component/mock/MockExpressionClauseSupport.java
@@ -14,47 +14,36 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.builder;
+package org.apache.camel.component.mock;
 
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Expression;
-import org.apache.camel.support.builder.xml.Namespaces;
-// TODO: All these should be behind support language so we can separate
-import org.apache.camel.model.language.ConstantExpression;
-import org.apache.camel.model.language.ExchangePropertyExpression;
-import org.apache.camel.model.language.GroovyExpression;
-import org.apache.camel.model.language.HeaderExpression;
-import org.apache.camel.model.language.Hl7TerserExpression;
-import org.apache.camel.model.language.JavaScriptExpression;
+import org.apache.camel.builder.ExpressionBuilder;
 import org.apache.camel.model.language.JsonPathExpression;
 import org.apache.camel.model.language.LanguageExpression;
 import org.apache.camel.model.language.MethodCallExpression;
-import org.apache.camel.model.language.MvelExpression;
-import org.apache.camel.model.language.OgnlExpression;
-import org.apache.camel.model.language.RefExpression;
 import org.apache.camel.model.language.SimpleExpression;
-import org.apache.camel.model.language.SpELExpression;
 import org.apache.camel.model.language.TokenizerExpression;
 import org.apache.camel.model.language.XMLTokenizerExpression;
 import org.apache.camel.model.language.XPathExpression;
 import org.apache.camel.model.language.XQueryExpression;
+import org.apache.camel.support.builder.xml.Namespaces;
 import org.apache.camel.support.language.ExpressionModel;
 
 /**
  * A support class for building expression clauses.
  */
-public class ExpressionClauseSupport<T> {
+public class MockExpressionClauseSupport<T> {
 
-    // Implementation detail: We must use the specific model.language.xxx classes to make the DSL use these specific types
-    // which ensures that the route model dumped as XML uses these types, eg <header> instead of <language name="header"> etc.
+    // TODO: make the model.language class not here as we want to use this in camel-mock but have similar method api compatability
 
     private T result;
     private Expression expressionValue;
     private ExpressionModel expressionType;
 
-    public ExpressionClauseSupport(T result) {
+    public MockExpressionClauseSupport(T result) {
         this.result = result;
     }
 
@@ -87,11 +76,7 @@ public class ExpressionClauseSupport<T> {
      * do not use this if you want dynamic values during routing.
      */
     public T constant(Object value) {
-        if (value instanceof String) {
-            return expression(new ConstantExpression((String) value));
-        } else {
-            return expression(ExpressionBuilder.constantExpression(value));
-        }
+        return expression(ExpressionBuilder.constantExpression(value));
     }
 
     /**
@@ -119,8 +104,7 @@ public class ExpressionClauseSupport<T> {
      * An expression of an inbound message body
      */
     public T body() {
-        // reuse simple as this allows the model to represent this as a known JAXB type
-        return expression(new SimpleExpression("${body}"));
+        return expression(ExpressionBuilder.bodyExpression());
     }
 
     /**
@@ -148,7 +132,7 @@ public class ExpressionClauseSupport<T> {
      * An expression of an inbound message header of the given name
      */
     public T header(String name) {
-        return expression(new HeaderExpression(name));
+        return expression(ExpressionBuilder.headerExpression(name));
     }
 
     /**
@@ -190,7 +174,7 @@ public class ExpressionClauseSupport<T> {
      * An expression of an exchange property of the given name
      */
     public T exchangeProperty(String name) {
-        return expression(new ExchangePropertyExpression(name));
+        return expression(ExpressionBuilder.exchangePropertyExpression(name));
     }
 
     /**
@@ -213,7 +197,7 @@ public class ExpressionClauseSupport<T> {
      * @return the builder to continue processing the DSL
      */
     public T method(String bean) {
-        return expression(new MethodCallExpression(bean));
+        return expression(ExpressionBuilder.beanExpression(bean));
     }
 
     /**
@@ -292,7 +276,7 @@ public class ExpressionClauseSupport<T> {
      * @return the builder to continue processing the DSL
      */
     public T groovy(String text) {
-        return expression(new GroovyExpression(text));
+        return expression(ExpressionBuilder.languageExpression("groovy", text));
     }
 
     /**
@@ -306,7 +290,7 @@ public class ExpressionClauseSupport<T> {
      */
     @Deprecated
     public T javaScript(String text) {
-        return expression(new JavaScriptExpression(text));
+        return expression(ExpressionBuilder.languageExpression("js", text));
     }
 
     /**
@@ -317,7 +301,7 @@ public class ExpressionClauseSupport<T> {
      * @return the builder to continue processing the DSL
      */
     public T jsonpath(String text) {
-        return jsonpath(text, false);
+        return expression(ExpressionBuilder.languageExpression("jsonpath", text));
     }
 
     /**
@@ -492,7 +476,7 @@ public class ExpressionClauseSupport<T> {
      * @return the builder to continue processing the DSL
      */
     public T ognl(String text) {
-        return expression(new OgnlExpression(text));
+        return expression(ExpressionBuilder.languageExpression("ognl", text));
     }
 
     /**
@@ -503,7 +487,7 @@ public class ExpressionClauseSupport<T> {
      * @return the builder to continue processing the DSL
      */
     public T mvel(String text) {
-        return expression(new MvelExpression(text));
+        return expression(ExpressionBuilder.languageExpression("mvel", text));
     }
 
     /**
@@ -514,7 +498,7 @@ public class ExpressionClauseSupport<T> {
      * @return the builder to continue processing the DSL
      */
     public T ref(String ref) {
-        return expression(new RefExpression(ref));
+        return expression(ExpressionBuilder.languageExpression("ref", ref));
     }
 
     /**
@@ -525,7 +509,7 @@ public class ExpressionClauseSupport<T> {
      * @return the builder to continue processing the DSL
      */
     public T spel(String text) {
-        return expression(new SpELExpression(text));
+        return expression(ExpressionBuilder.languageExpression("spel", text));
     }
 
     /**
@@ -536,7 +520,7 @@ public class ExpressionClauseSupport<T> {
      * @return the builder to continue processing the DSL
      */
     public T simple(String text) {
-        return expression(new SimpleExpression(text));
+        return expression(ExpressionBuilder.languageExpression("simple", text));
     }
 
     /**
@@ -562,7 +546,7 @@ public class ExpressionClauseSupport<T> {
      * @return the builder to continue processing the DSL
      */
     public T hl7terser(String text) {
-        return expression(new Hl7TerserExpression(text));
+        return expression(ExpressionBuilder.languageExpression("hl7terser", text));
     }
 
     /**
@@ -765,11 +749,11 @@ public class ExpressionClauseSupport<T> {
 
     /**
      * Evaluates an XML token expression on the message body with XML content
-     * 
+     *
      * @param path the xpath like path notation specifying the child nodes to tokenize
      * @param mode one of 'i', 'w', or 'u' to inject the namespaces to the token, to
      *        wrap the token with its ancestor contet, or to unwrap to its element child
-     * @param namespaces the namespace map to the namespace bindings 
+     * @param namespaces the namespace map to the namespace bindings
      * @param group to group by the given number
      * @return the builder to continue processing the DSL
      */
@@ -795,11 +779,11 @@ public class ExpressionClauseSupport<T> {
     public T xpath(String text) {
         return expression(new XPathExpression(text));
     }
-    
+
     /**
      * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
      * expression</a> on the supplied header name's contents
-     * 
+     *
      * @param text the expression to be evaluated
      * @param headerName the name of the header to apply the expression to
      * @return the builder to continue processing the DSL
@@ -809,7 +793,7 @@ public class ExpressionClauseSupport<T> {
         expression.setHeaderName(headerName);
         return expression(expression);
     }
-    
+
     /**
      * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
      * expression</a> with the specified result type
@@ -825,7 +809,7 @@ public class ExpressionClauseSupport<T> {
         return result;
     }
 
-    
+
     /**
      * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
      * expression</a> with the specified result type on the supplied
@@ -842,7 +826,7 @@ public class ExpressionClauseSupport<T> {
         setExpressionType(expression);
         return result;
     }
-    
+
 
     /**
      * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
@@ -857,7 +841,7 @@ public class ExpressionClauseSupport<T> {
     public T xpath(String text, Class<?> resultType, Namespaces namespaces) {
         return xpath(text, resultType, namespaces.getNamespaces());
     }
-    
+
     /**
      * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath
      * expression</a> with the specified result type and set of namespace
@@ -938,7 +922,7 @@ public class ExpressionClauseSupport<T> {
     /**
      * Evaluates an <a href="http://camel.apache.org/xquery.html">XQuery
      * expression</a>
-     * 
+     *
      * @param text the expression to be evaluated
      * @param headerName the name of the header to apply the expression to
      * @return the builder to continue processing the DSL
@@ -964,8 +948,8 @@ public class ExpressionClauseSupport<T> {
         setExpressionType(expression);
         return result;
     }
-    
-    
+
+
     /**
      * Evaluates an <a
      * href="http://camel.apache.org/xquery.html">XQuery expression</a>
@@ -996,7 +980,7 @@ public class ExpressionClauseSupport<T> {
     public T xquery(String text, Class<?> resultType, Namespaces namespaces) {
         return xquery(text, resultType, namespaces.getNamespaces());
     }
-    
+
     /**
      * Evaluates an <a
      * href="http://camel.apache.org/xquery.html">XQuery expression</a>