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 5ae35558be8cc17d9fef48d956f84170b42f9997 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Apr 16 16:54:53 2019 +0200 Move mock component out of camel-core. Work in progress. --- .../camel/component/mock/MockExpressionClause.java | 587 ---------------- .../mock/MockExpressionClauseSupport.java | 737 +-------------------- .../component/mock/MockAssertionClauseTest.java | 6 +- 3 files changed, 11 insertions(+), 1319 deletions(-) diff --git a/core/camel-core/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java b/core/camel-core/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java index 4dec652..04178ec 100644 --- a/core/camel-core/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java +++ b/core/camel-core/src/main/java/org/apache/camel/component/mock/MockExpressionClause.java @@ -27,7 +27,6 @@ import org.apache.camel.Message; import org.apache.camel.Predicate; import org.apache.camel.support.ExpressionAdapter; import org.apache.camel.support.ExpressionToPredicateAdapter; -import org.apache.camel.support.builder.xml.Namespaces; import org.apache.camel.support.language.ExpressionModel; /** @@ -334,32 +333,6 @@ public class MockExpressionClause<T> implements Expression, Predicate { * href="http://camel.apache.org/bean-language.html">bean language</a> * which basically means the bean is invoked to determine the expression * value. - * - * @param instance the instance of the bean - * @return the builder to continue processing the DSL - */ - public T method(Object instance) { - return delegate.method(instance); - } - - /** - * Evaluates an expression using the <a - * href="http://camel.apache.org/bean-language.html">bean language</a> - * which basically means the bean is invoked to determine the expression - * value. - * - * @param beanType the Class of the bean which we want to invoke - * @return the builder to continue processing the DSL - */ - public T method(Class<?> beanType) { - return delegate.method(beanType); - } - - /** - * Evaluates an expression using the <a - * href="http://camel.apache.org/bean-language.html">bean language</a> - * which basically means the bean is invoked to determine the expression - * value. * * @param bean the name of the bean looked up the registry * @param method the name of the method to invoke on the bean @@ -370,34 +343,6 @@ public class MockExpressionClause<T> implements Expression, Predicate { } /** - * Evaluates an expression using the <a - * href="http://camel.apache.org/bean-language.html">bean language</a> - * which basically means the bean is invoked to determine the expression - * value. - * - * @param instance the instance of the bean - * @param method the name of the method to invoke on the bean - * @return the builder to continue processing the DSL - */ - public T method(Object instance, String method) { - return delegate.method(instance, method); - } - - /** - * Evaluates an expression using the <a - * href="http://camel.apache.org/bean-language.html">bean language</a> - * which basically means the bean is invoked to determine the expression - * value. - * - * @param beanType the Class of the bean which we want to invoke - * @param method the name of the method to invoke on the bean - * @return the builder to continue processing the DSL - */ - public T method(Class<?> beanType, String method) { - return delegate.method(beanType, method); - } - - /** * Evaluates a <a href="http://camel.apache.org/groovy.html">Groovy * expression</a> * @@ -435,100 +380,6 @@ public class MockExpressionClause<T> implements Expression, Predicate { } /** - * Evaluates a <a - * href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @return the builder to continue processing the DSL - */ - public T jsonpath(String text, boolean suppressExceptions) { - return delegate.jsonpath(text, suppressExceptions); - } - - /** - * Evaluates a <a - * href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @return the builder to continue processing the DSL - */ - public T jsonpath(String text, Class<?> resultType) { - return delegate.jsonpath(text, resultType); - } - - /** - * Evaluates a <a - * href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @param resultType the return type expected by the expression - * @return the builder to continue processing the DSL - */ - public T jsonpath(String text, boolean suppressExceptions, Class<?> resultType) { - return delegate.jsonpath(text, suppressExceptions, resultType); - } - - /** - * Evaluates a <a - * href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @param resultType the return type expected by the expression - * @param headerName the name of the header to apply the expression to - * @return the builder to continue processing the DSL - */ - public T jsonpath(String text, boolean suppressExceptions, Class<?> resultType, String headerName) { - return delegate.jsonpath(text, suppressExceptions, true, resultType, headerName); - } - - /** - * Evaluates a <a - * href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> with writeAsString enabled. - * - * @param text the expression to be evaluated - * @return the builder to continue processing the DSL - */ - public T jsonpathWriteAsString(String text) { - return delegate.jsonpathWriteAsString(text); - } - - /** - * Evaluates a <a - * href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> with writeAsString enabled. - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @return the builder to continue processing the DSL - */ - public T jsonpathWriteAsString(String text, boolean suppressExceptions) { - return delegate.jsonpathWriteAsString(text, suppressExceptions); - } - - /** - * Evaluates a <a - * href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> with writeAsString enabled. - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @param headerName the name of the header to apply the expression to - * @return the builder to continue processing the DSL - */ - public T jsonpathWriteAsString(String text, boolean suppressExceptions, String headerName) { - return delegate.jsonpathWriteAsString(text, suppressExceptions, true, headerName); - } - - /** * Evaluates an <a href="http://camel.apache.org/ognl.html">OGNL * expression</a> * @@ -584,228 +435,6 @@ public class MockExpressionClause<T> implements Expression, Predicate { } /** - * Evaluates a <a href="http://camel.apache.org/simple.html">Simple - * expression</a> - * - * @param text the expression to be evaluated - * @param resultType the result type - * @return the builder to continue processing the DSL - */ - public T simple(String text, Class<?> resultType) { - return delegate.simple(text, resultType); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @return the builder to continue processing the DSL - */ - public T tokenize(String token) { - return delegate.tokenize(token); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param regex whether the token is a regular expression or not - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, boolean regex) { - return tokenize(token, regex, false); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param regex whether the token is a regular expression or not - * @param skipFirst whether to skip the first element - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, boolean regex, boolean skipFirst) { - return delegate.tokenize(token, null, regex, skipFirst); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param regex whether the token is a regular expression or not - * @param group to group by the given number - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, boolean regex, int group) { - return tokenize(token, regex, group, false); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param regex whether the token is a regular expression or not - * @param group to group by the given number - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, boolean regex, String group) { - return tokenize(token, regex, group, false); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param regex whether the token is a regular expression or not - * @param group to group by the given number - * @param skipFirst whether to skip the first element - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, boolean regex, int group, boolean skipFirst) { - return delegate.tokenize(token, null, regex, group, skipFirst); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param regex whether the token is a regular expression or not - * @param group to group by the given number - * @param skipFirst whether to skip the first element - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, boolean regex, String group, boolean skipFirst) { - return delegate.tokenize(token, null, regex, group, skipFirst); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param group to group by the given number - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, int group) { - return delegate.tokenize(token, group); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param group to group by the given number - * @param skipFirst whether to skip the first element - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, int group, boolean skipFirst) { - return delegate.tokenize(token, group, skipFirst); - } - - /** - * Evaluates a token expression on the given header - * - * @param token the token - * @param headerName name of header to tokenize - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, String headerName) { - return delegate.tokenize(token, headerName); - } - - /** - * Evaluates a token expression on the given header - * - * @param token the token - * @param headerName name of header to tokenize - * @param regex whether the token is a regular expression or not - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, String headerName, boolean regex) { - return delegate.tokenize(token, headerName, regex); - } - - /** - * Evaluates a token pair expression on the message body. - * <p/> - * Tokens is not included. - * - * @param startToken the start token - * @param endToken the end token - * @return the builder to continue processing the DSL - */ - public T tokenizePair(String startToken, String endToken) { - return tokenizePair(startToken, endToken, false); - } - - /** - * Evaluates a token pair expression on the message body - * - * @param startToken the start token - * @param endToken the end token - * @param includeTokens whether to include tokens - * @return the builder to continue processing the DSL - */ - public T tokenizePair(String startToken, String endToken, boolean includeTokens) { - return delegate.tokenizePair(startToken, endToken, includeTokens); - } - - /** - * Evaluates a XML token expression on the message body with XML content - * - * @param tagName the tag name of the child nodes to tokenize - * @return the builder to continue processing the DSL - */ - public T tokenizeXML(String tagName) { - return tokenizeXML(tagName, null); - } - - /** - * Evaluates a XML token expression on the message body with XML content - * - * @param tagName the tag name of the child nodes to tokenize - * @param group to group by the given number - * @return the builder to continue processing the DSL - */ - public T tokenizeXML(String tagName, int group) { - return tokenizeXML(tagName, null, group); - } - - /** - * Evaluates a token pair expression on the message body with XML content - * - * @param tagName the tag name of the child nodes to tokenize - * @param inheritNamespaceTagName parent or root tag name that contains namespace(s) to inherit - * @return the builder to continue processing the DSL - */ - public T tokenizeXML(String tagName, String inheritNamespaceTagName) { - return tokenizeXML(tagName, inheritNamespaceTagName, 0); - } - - /** - * Evaluates a token pair expression on the message body with XML content - * - * @param tagName the tag name of the child nodes to tokenize - * @param inheritNamespaceTagName parent or root tag name that contains namespace(s) to inherit - * @param group to group by the given number - * @return the builder to continue processing the DSL - */ - public T tokenizeXML(String tagName, String inheritNamespaceTagName, int group) { - return delegate.tokenizeXMLPair(tagName, inheritNamespaceTagName, group); - } - - public T xtokenize(String path, Namespaces namespaces) { - return xtokenize(path, 'i', namespaces); - } - - public T xtokenize(String path, char mode, Namespaces namespaces) { - return xtokenize(path, mode, namespaces, 0); - } - - public T xtokenize(String path, char mode, Namespaces namespaces, int group) { - return delegate.xtokenize(path, mode, namespaces, group); - } - - /** * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath * expression</a> * @@ -815,113 +444,6 @@ public class MockExpressionClause<T> implements Expression, Predicate { public T xpath(String text) { return delegate.xpath(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 - */ - public T xpath(String text, String headerName) { - return delegate.xpath(text, headerName); - } - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified result type - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Class<?> resultType) { - return delegate.xpath(text, resultType); - } - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified result type on the supplied - * header name's contents - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param headerName the name of the header to apply the expression to - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Class<?> resultType, String headerName) { - return delegate.xpath(text, resultType, headerName); - } - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified result type and set of namespace - * prefixes and URIs - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Class<?> resultType, Namespaces namespaces) { - return delegate.xpath(text, resultType, namespaces); - } - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified result type and set of namespace - * prefixes and URIs on the supplied header name's contents - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param headerName the name of the header to apply the expression to - * @param namespaces the namespace prefix and URIs to use - * - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Class<?> resultType, Namespaces namespaces, String headerName) { - return delegate.xpath(text, resultType, namespaces, headerName); - } - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified result type and set of namespace - * prefixes and URIs - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Class<?> resultType, Map<String, String> namespaces) { - return delegate.xpath(text, resultType, namespaces); - } - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Namespaces namespaces) { - return delegate.xpath(text, namespaces); - } - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Map<String, String> namespaces) { - return delegate.xpath(text, namespaces); - } /** * Evaluates an <a @@ -935,115 +457,6 @@ public class MockExpressionClause<T> implements Expression, Predicate { } /** - * 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 - */ - public T xquery(String text, String headerName) { - return delegate.xquery(text, headerName); - } - - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified result type - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Class<?> resultType) { - return delegate.xquery(text, resultType); - } - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified result type - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param headerName the name of the header to apply the expression to - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Class<?> resultType, String headerName) { - return delegate.xquery(text, resultType, headerName); - } - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified result type and set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Class<?> resultType, Namespaces namespaces) { - return delegate.xquery(text, resultType, namespaces); - } - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified result type - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param headerName the name of the header to apply the expression to - * @param namespaces the namespace prefix and URIs to use - * - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Class<?> resultType, Namespaces namespaces, String headerName) { - return delegate.xquery(text, resultType, namespaces, headerName); - } - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified result type and set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Class<?> resultType, Map<String, String> namespaces) { - return delegate.xquery(text, resultType, namespaces); - } - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Namespaces namespaces) { - return delegate.xquery(text, namespaces); - } - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Map<String, String> namespaces) { - return delegate.xquery(text, namespaces); - } - - /** * Evaluates a given language name with the expression text * * @param language the name of the language diff --git a/core/camel-core/src/main/java/org/apache/camel/component/mock/MockExpressionClauseSupport.java b/core/camel-core/src/main/java/org/apache/camel/component/mock/MockExpressionClauseSupport.java index b3f81e6..35795b0 100644 --- a/core/camel-core/src/main/java/org/apache/camel/component/mock/MockExpressionClauseSupport.java +++ b/core/camel-core/src/main/java/org/apache/camel/component/mock/MockExpressionClauseSupport.java @@ -16,20 +16,9 @@ */ package org.apache.camel.component.mock; -import java.util.Map; - import org.apache.camel.CamelContext; import org.apache.camel.Expression; -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.SimpleExpression; -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.ExpressionBuilder; -import org.apache.camel.support.builder.xml.Namespaces; import org.apache.camel.support.language.ExpressionModel; /** @@ -37,8 +26,6 @@ import org.apache.camel.support.language.ExpressionModel; */ public class MockExpressionClauseSupport<T> { - // 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; @@ -206,66 +193,16 @@ public class MockExpressionClauseSupport<T> { * which basically means the bean is invoked to determine the expression * value. * - * @param instance the instance of the bean - * @return the builder to continue processing the DSL - */ - public T method(Object instance) { - return expression(new MethodCallExpression(instance)); - } - - /** - * Evaluates an expression using the <a - * href="http://camel.apache.org/bean-language.html>bean language</a> - * which basically means the bean is invoked to determine the expression - * value. - * - * @param beanType the Class of the bean which we want to invoke - * @return the builder to continue processing the DSL - */ - public T method(Class<?> beanType) { - return expression(new MethodCallExpression(beanType)); - } - - /** - * Evaluates an expression using the <a - * href="http://camel.apache.org/bean-language.html>bean language</a> - * which basically means the bean is invoked to determine the expression - * value. - * * @param bean the name of the bean looked up the registry * @param method the name of the method to invoke on the bean * @return the builder to continue processing the DSL */ public T method(String bean, String method) { - return expression(new MethodCallExpression(bean, method)); - } - - /** - * Evaluates an expression using the <a - * href="http://camel.apache.org/bean-language.html>bean language</a> - * which basically means the bean is invoked to determine the expression - * value. - * - * @param instance the instance of the bean - * @param method the name of the method to invoke on the bean - * @return the builder to continue processing the DSL - */ - public T method(Object instance, String method) { - return expression(new MethodCallExpression(instance, method)); - } - - /** - * Evaluates an expression using the <a - * href="http://camel.apache.org/bean-language.html>bean language</a> - * which basically means the bean is invoked to determine the expression - * value. - * - * @param beanType the Class of the bean which we want to invoke - * @param method the name of the method to invoke on the bean - * @return the builder to continue processing the DSL - */ - public T method(Class<?> beanType, String method) { - return expression(new MethodCallExpression(beanType, method)); + if (method != null) { + return expression(ExpressionBuilder.languageExpression("bean", bean + "?method=" + method)); + } else { + return method(bean); + } } /** @@ -305,170 +242,6 @@ public class MockExpressionClauseSupport<T> { } /** - * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @return the builder to continue processing the DSL - */ - public T jsonpath(String text, boolean suppressExceptions) { - JsonPathExpression expression = new JsonPathExpression(text); - expression.setSuppressExceptions(suppressExceptions); - return expression(expression); - } - - /** - * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @param allowSimple whether to allow in inlined simple exceptions in the json path expression - * @return the builder to continue processing the DSL - */ - public T jsonpath(String text, boolean suppressExceptions, boolean allowSimple) { - JsonPathExpression expression = new JsonPathExpression(text); - expression.setSuppressExceptions(suppressExceptions); - expression.setAllowSimple(allowSimple); - return expression(expression); - } - - /** - * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @return the builder to continue processing the DSL - */ - public T jsonpath(String text, Class<?> resultType) { - JsonPathExpression expression = new JsonPathExpression(text); - expression.setResultType(resultType); - setExpressionType(expression); - return result; - } - - /** - * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @param resultType the return type expected by the expression - * @return the builder to continue processing the DSL - */ - public T jsonpath(String text, boolean suppressExceptions, Class<?> resultType) { - JsonPathExpression expression = new JsonPathExpression(text); - expression.setSuppressExceptions(suppressExceptions); - expression.setResultType(resultType); - setExpressionType(expression); - return result; - } - - /** - * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @param allowSimple whether to allow in inlined simple exceptions in the json path expression - * @param resultType the return type expected by the expression - * @return the builder to continue processing the DSL - */ - public T jsonpath(String text, boolean suppressExceptions, boolean allowSimple, Class<?> resultType) { - JsonPathExpression expression = new JsonPathExpression(text); - expression.setSuppressExceptions(suppressExceptions); - expression.setAllowSimple(allowSimple); - expression.setResultType(resultType); - setExpressionType(expression); - return result; - } - - /** - * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @param allowSimple whether to allow in inlined simple exceptions in the json path expression - * @param resultType the return type expected by the expression - * @param headerName the name of the header to apply the expression to - * @return the builder to continue processing the DSL - */ - public T jsonpath(String text, boolean suppressExceptions, boolean allowSimple, Class<?> resultType, String headerName) { - JsonPathExpression expression = new JsonPathExpression(text); - expression.setSuppressExceptions(suppressExceptions); - expression.setAllowSimple(allowSimple); - expression.setResultType(resultType); - expression.setHeaderName(headerName); - setExpressionType(expression); - return result; - } - - /** - * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> with writeAsString enabled. - * - * @param text the expression to be evaluated - * @return the builder to continue processing the DSL - */ - public T jsonpathWriteAsString(String text) { - return jsonpathWriteAsString(text, false); - } - - /** - * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> with writeAsString enabled. - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @return the builder to continue processing the DSL - */ - public T jsonpathWriteAsString(String text, boolean suppressExceptions) { - JsonPathExpression expression = new JsonPathExpression(text); - expression.setWriteAsString(true); - expression.setSuppressExceptions(suppressExceptions); - return expression(expression); - } - - /** - * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> with writeAsString enabled. - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @param allowSimple whether to allow in inlined simple exceptions in the json path expression - * @return the builder to continue processing the DSL - */ - public T jsonpathWriteAsString(String text, boolean suppressExceptions, boolean allowSimple) { - JsonPathExpression expression = new JsonPathExpression(text); - expression.setWriteAsString(true); - expression.setSuppressExceptions(suppressExceptions); - expression.setAllowSimple(allowSimple); - return expression(expression); - } - - /** - * Evaluates a <a href="http://camel.apache.org/jsonpath.html">Json Path - * expression</a> with writeAsString enabled. - * - * @param text the expression to be evaluated - * @param suppressExceptions whether to suppress exceptions such as PathNotFoundException - * @param allowSimple whether to allow in inlined simple exceptions in the json path expression - * @param headerName the name of the header to apply the expression to - * @return the builder to continue processing the DSL - */ - public T jsonpathWriteAsString(String text, boolean suppressExceptions, boolean allowSimple, String headerName) { - JsonPathExpression expression = new JsonPathExpression(text); - expression.setWriteAsString(true); - expression.setSuppressExceptions(suppressExceptions); - expression.setAllowSimple(allowSimple); - expression.setHeaderName(headerName); - return expression(expression); - } - - /** * Evaluates an <a href="http://camel.apache.org/ognl.html">OGNL * expression</a> * @@ -524,21 +297,6 @@ public class MockExpressionClauseSupport<T> { } /** - * Evaluates a <a href="http://camel.apache.org/simple.html">Simple - * expression</a> - * - * @param text the expression to be evaluated - * @param resultType the result type - * @return the builder to continue processing the DSL - */ - public T simple(String text, Class<?> resultType) { - SimpleExpression expression = new SimpleExpression(text); - expression.setResultType(resultType); - setExpressionType(expression); - return result; - } - - /** * Evaluates an <a href="http://camel.apache.org/hl7.html">HL7 Terser * expression</a> * @@ -550,226 +308,6 @@ public class MockExpressionClauseSupport<T> { } /** - * Evaluates a token expression on the message body - * - * @param token the token - * @return the builder to continue processing the DSL - */ - public T tokenize(String token) { - return tokenize(token, null, false); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param group to group by the given number - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, int group) { - return tokenize(token, null, false, group); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param group to group by the given number - * @param skipFirst whether to skip the very first element - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, int group, boolean skipFirst) { - return tokenize(token, null, false, group, skipFirst); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param regex whether the token is a regular expression or not - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, boolean regex) { - return tokenize(token, null, regex); - } - - /** - * Evaluates a token expression on the message body - * - * @param token the token - * @param regex whether the token is a regular expression or not - * @param group to group by the given number - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, boolean regex, int group) { - return tokenize(token, null, regex, group); - } - - /** - * Evaluates a token expression on the given header - * - * @param token the token - * @param headerName name of header to tokenize - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, String headerName) { - return tokenize(token, headerName, false); - } - - /** - * Evaluates a token expression on the given header - * - * @param token the token - * @param headerName name of header to tokenize - * @param regex whether the token is a regular expression or not - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, String headerName, boolean regex) { - TokenizerExpression expression = new TokenizerExpression(); - expression.setToken(token); - expression.setHeaderName(headerName); - expression.setRegex(regex); - setExpressionType(expression); - return result; - } - - /** - * Evaluates a token expression on the given header - * - * @param token the token - * @param headerName name of header to tokenize - * @param regex whether the token is a regular expression or not - * @param group to group by number of parts - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, String headerName, boolean regex, int group) { - return tokenize(token, headerName, regex, group, false); - } - - /** - * Evaluates a token expression on the given header - * - * @param token the token - * @param headerName name of header to tokenize - * @param regex whether the token is a regular expression or not - * @param skipFirst whether to skip the very first element - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, String headerName, boolean regex, boolean skipFirst) { - TokenizerExpression expression = new TokenizerExpression(); - expression.setToken(token); - expression.setHeaderName(headerName); - expression.setRegex(regex); - expression.setSkipFirst(skipFirst); - setExpressionType(expression); - return result; - } - - /** - * Evaluates a token expression on the given header - * - * @param token the token - * @param headerName name of header to tokenize - * @param regex whether the token is a regular expression or not - * @param group to group by number of parts - * @param skipFirst whether to skip the very first element - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, String headerName, boolean regex, int group, boolean skipFirst) { - return tokenize(token, headerName, regex, "" + group, skipFirst); - } - - /** - * Evaluates a token expression on the given header - * - * @param token the token - * @param headerName name of header to tokenize - * @param regex whether the token is a regular expression or not - * @param group to group by number of parts - * @param skipFirst whether to skip the very first element - * @return the builder to continue processing the DSL - */ - public T tokenize(String token, String headerName, boolean regex, String group, boolean skipFirst) { - TokenizerExpression expression = new TokenizerExpression(); - expression.setToken(token); - expression.setHeaderName(headerName); - expression.setRegex(regex); - expression.setGroup(group); - expression.setSkipFirst(skipFirst); - setExpressionType(expression); - return result; - } - - /** - * Evaluates a token pair expression on the message body - * - * @param startToken the start token - * @param endToken the end token - * @param includeTokens whether to include tokens - * @return the builder to continue processing the DSL - */ - public T tokenizePair(String startToken, String endToken, boolean includeTokens) { - TokenizerExpression expression = new TokenizerExpression(); - expression.setToken(startToken); - expression.setEndToken(endToken); - expression.setIncludeTokens(includeTokens); - setExpressionType(expression); - return result; - } - - /** - * Evaluates a token pair expression on the message body with XML content - * - * @param tagName the tag name of the child nodes to tokenize - * @param inheritNamespaceTagName optional parent or root tag name that contains namespace(s) to inherit - * @param group to group by the given number - * @return the builder to continue processing the DSL - */ - public T tokenizeXMLPair(String tagName, String inheritNamespaceTagName, int group) { - return tokenizeXMLPair(tagName, inheritNamespaceTagName, "" + group); - } - - /** - * Evaluates a token pair expression on the message body with XML content - * - * @param tagName the tag name of the child nodes to tokenize - * @param inheritNamespaceTagName optional parent or root tag name that contains namespace(s) to inherit - * @param group to group by the given number - * @return the builder to continue processing the DSL - */ - public T tokenizeXMLPair(String tagName, String inheritNamespaceTagName, String group) { - TokenizerExpression expression = new TokenizerExpression(); - expression.setToken(tagName); - expression.setInheritNamespaceTagName(inheritNamespaceTagName); - expression.setXml(true); - expression.setGroup(group); - setExpressionType(expression); - return result; - } - - /** - * 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 group to group by the given number - * @return the builder to continue processing the DSL - */ - public T xtokenize(String path, char mode, Namespaces namespaces, int group) { - XMLTokenizerExpression expression = new XMLTokenizerExpression(path); - expression.setMode(Character.toString(mode)); - expression.setNamespaces(namespaces.getNamespaces()); - - if (group > 0) { - expression.setGroup(group); - } - setExpressionType(expression); - return result; - } - - /** * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath * expression</a> * @@ -777,135 +315,7 @@ public class MockExpressionClauseSupport<T> { * @return the builder to continue processing the DSL */ 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 - */ - public T xpath(String text, String headerName) { - XPathExpression expression = new XPathExpression(text); - expression.setHeaderName(headerName); - return expression(expression); - } - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified result type - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Class<?> resultType) { - XPathExpression expression = new XPathExpression(text); - expression.setResultType(resultType); - setExpressionType(expression); - return result; - } - - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified result type on the supplied - * header name's contents - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param headerName the name of the header to apply the expression to - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Class<?> resultType, String headerName) { - XPathExpression expression = new XPathExpression(text); - expression.setHeaderName(headerName); - setExpressionType(expression); - return result; - } - - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified result type and set of namespace - * prefixes and URIs - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - 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 - * prefixes and URIs on the supplied header name's contents - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param namespaces the namespace prefix and URIs to use - * @param headerName the name of the header to apply the expression to - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Class<?> resultType, Namespaces namespaces, String headerName) { - XPathExpression expression = new XPathExpression(text); - expression.setResultType(resultType); - expression.setNamespaces(namespaces.getNamespaces()); - expression.setHeaderName(headerName); - setExpressionType(expression); - return result; - } - - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified result type and set of namespace - * prefixes and URIs - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Class<?> resultType, Map<String, String> namespaces) { - XPathExpression expression = new XPathExpression(text); - expression.setResultType(resultType); - expression.setNamespaces(namespaces); - setExpressionType(expression); - return result; - } - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Namespaces namespaces) { - return xpath(text, namespaces.getNamespaces()); - } - - /** - * Evaluates an <a href="http://camel.apache.org/xpath.html">XPath - * expression</a> with the specified set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xpath(String text, Map<String, String> namespaces) { - XPathExpression expression = new XPathExpression(text); - expression.setNamespaces(namespaces); - setExpressionType(expression); - return result; + return expression(ExpressionBuilder.languageExpression("xpath", text)); } /** @@ -916,136 +326,7 @@ public class MockExpressionClauseSupport<T> { * @return the builder to continue processing the DSL */ public T xquery(String text) { - return expression(new XQueryExpression(text)); - } - - /** - * 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 - */ - public T xquery(String text, String headerName) { - XQueryExpression expression = new XQueryExpression(text); - expression.setHeaderName(headerName); - return expression(expression); - } - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified result type - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Class<?> resultType) { - XQueryExpression expression = new XQueryExpression(text); - expression.setResultType(resultType); - setExpressionType(expression); - return result; - } - - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified result type - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param headerName the name of the header to apply the expression to - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Class<?> resultType, String headerName) { - XQueryExpression expression = new XQueryExpression(text); - expression.setHeaderName(headerName); - setExpressionType(expression); - return result; - } - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified result type and set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - 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> - * with the specified result type and set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param namespaces the namespace prefix and URIs to use - * @param headerName the name of the header to apply the expression to - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Class<?> resultType, Namespaces namespaces, String headerName) { - XQueryExpression expression = new XQueryExpression(text); - expression.setResultType(resultType); - expression.setNamespaces(namespaces.getNamespaces()); - expression.setHeaderName(headerName); - setExpressionType(expression); - return result; - } - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified result type and set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param resultType the return type expected by the expression - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Class<?> resultType, Map<String, String> namespaces) { - XQueryExpression expression = new XQueryExpression(text); - expression.setResultType(resultType); - expression.setNamespaces(namespaces); - setExpressionType(expression); - return result; - } - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Namespaces namespaces) { - return xquery(text, namespaces.getNamespaces()); - } - - /** - * Evaluates an <a - * href="http://camel.apache.org/xquery.html">XQuery expression</a> - * with the specified set of namespace prefixes and URIs - * - * @param text the expression to be evaluated - * @param namespaces the namespace prefix and URIs to use - * @return the builder to continue processing the DSL - */ - public T xquery(String text, Map<String, String> namespaces) { - XQueryExpression expression = new XQueryExpression(text); - expression.setNamespaces(namespaces); - setExpressionType(expression); - return result; + return expression(ExpressionBuilder.languageExpression("xquery", text)); } /** @@ -1056,9 +337,7 @@ public class MockExpressionClauseSupport<T> { * @return the builder to continue processing the DSL */ public T language(String language, String expression) { - LanguageExpression exp = new LanguageExpression(language, expression); - setExpressionType(exp); - return result; + return expression(ExpressionBuilder.languageExpression(language, expression)); } // Properties diff --git a/core/camel-core/src/test/java/org/apache/camel/component/mock/MockAssertionClauseTest.java b/core/camel-core/src/test/java/org/apache/camel/component/mock/MockAssertionClauseTest.java index 1118342..127098b 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/mock/MockAssertionClauseTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/mock/MockAssertionClauseTest.java @@ -25,7 +25,7 @@ public class MockAssertionClauseTest extends ContextTestSupport { @Test public void testAssertionClauseAll() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); - mock.allMessages().xpath("/person[@name='James']", Boolean.class); + mock.allMessages().xpath("/person[@name='James']"); template.sendBody("direct:start", "<person name='James' last='Hanson'/>"); template.sendBody("direct:start", "<person name='James' last='Jackson'/>"); @@ -37,10 +37,10 @@ public class MockAssertionClauseTest extends ContextTestSupport { public void testAssertionClausePer() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); - mock.message(0).xpath("/person[@last='Hanson']", Boolean.class); + mock.message(0).xpath("/person[@last='Hanson']"); mock.message(0).body().contains("Hanson"); - mock.message(1).xpath("/person[@last='Jackson']", Boolean.class); + mock.message(1).xpath("/person[@last='Jackson']"); mock.message(1).body().contains("Jackson"); template.sendBody("direct:start", "<person name='James' last='Hanson'/>");