You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/04/11 14:40:39 UTC
[1/2] git commit: Added some simple language tests according to the
question of the mailing list
Repository: camel
Updated Branches:
refs/heads/master 41f047112 -> e6fbbf046
Added some simple language tests according to the question of the mailing list
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/210735d7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/210735d7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/210735d7
Branch: refs/heads/master
Commit: 210735d71e5700f93e5ef2cd75ed721e6e1692cb
Parents: 41f0471
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Apr 11 20:32:56 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Apr 11 20:33:42 2014 +0800
----------------------------------------------------------------------
.../camel/language/simple/SimpleTest.java | 6 +++
.../language/SpringSimpleExpressionTest.java | 38 ++++++++++++++++
.../language/SpringSimpleExpressionTest.xml | 47 ++++++++++++++++++++
3 files changed, 91 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/210735d7/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
index c9e22a3..32dec6e 100644
--- a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
@@ -217,6 +217,12 @@ public class SimpleTest extends LanguageTestSupport {
assertExpression("${body[0][code]}", 4321);
}
+ public void testOGNLBodyExpression() throws Exception {
+ exchange.getIn().setBody("hello world");
+ assertPredicate("${body} == 'hello world'", true);
+ assertPredicate("${body.toUpperCase()} == 'HELLO WORLD'", true);
+ }
+
public void testOGNLCallReplace() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("cool", "Camel rocks");
http://git-wip-us.apache.org/repos/asf/camel/blob/210735d7/components/camel-spring/src/test/java/org/apache/camel/language/SpringSimpleExpressionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/language/SpringSimpleExpressionTest.java b/components/camel-spring/src/test/java/org/apache/camel/language/SpringSimpleExpressionTest.java
new file mode 100644
index 0000000..2488eff
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/language/SpringSimpleExpressionTest.java
@@ -0,0 +1,38 @@
+/**
+ * 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.language;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringSimpleExpressionTest extends SpringTestSupport {
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/language/SpringSimpleExpressionTest.xml");
+ }
+
+ public void testSimpleEmptyString() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("False");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/210735d7/components/camel-spring/src/test/resources/org/apache/camel/language/SpringSimpleExpressionTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/language/SpringSimpleExpressionTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/language/SpringSimpleExpressionTest.xml
new file mode 100644
index 0000000..32879b3
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/language/SpringSimpleExpressionTest.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <choice>
+ <when>
+ <simple>
+ ${body} == "Hello World"
+ </simple>
+ <transform>
+ <constant>correct</constant>
+ </transform>
+ </when>
+ <otherwise>
+ <transform>
+ <constant>incorrect</constant>
+ </transform>
+ </otherwise>
+ </choice>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
+
+</beans>
[2/2] git commit: CAMEL-7359 Throwing exception when bodyAs(type) has
some addition text
Posted by ni...@apache.org.
CAMEL-7359 Throwing exception when bodyAs(type) has some addition text
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e6fbbf04
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e6fbbf04
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e6fbbf04
Branch: refs/heads/master
Commit: e6fbbf0462984f8c8c0f352e7f07fe2a7dd9a12b
Parents: 210735d
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Apr 11 20:39:53 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Apr 11 20:39:53 2014 +0800
----------------------------------------------------------------------
.../simple/ast/SimpleFunctionExpression.java | 7 +++++--
.../apache/camel/language/simple/SimpleTest.java | 17 ++++++++++++++++-
2 files changed, 21 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e6fbbf04/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java b/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
index d02f050..32a22b2 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
@@ -195,9 +195,11 @@ public class SimpleFunctionExpression extends LiteralExpression {
String remainder = ifStartsWithReturnRemainder("bodyAs", function);
if (remainder != null) {
String type = ObjectHelper.between(remainder, "(", ")");
- if (type == null) {
+ remainder = ObjectHelper.after(remainder, ")");
+ if (type == null || ObjectHelper.isNotEmpty(remainder)) {
throw new SimpleParserException("Valid syntax: ${bodyAs(type)} was: " + function, token.getIndex());
}
+
type = StringHelper.removeQuotes(type);
return ExpressionBuilder.bodyExpression(type);
}
@@ -205,7 +207,8 @@ public class SimpleFunctionExpression extends LiteralExpression {
remainder = ifStartsWithReturnRemainder("mandatoryBodyAs", function);
if (remainder != null) {
String type = ObjectHelper.between(remainder, "(", ")");
- if (type == null) {
+ remainder = ObjectHelper.after(remainder, ")");
+ if (type == null || ObjectHelper.isNotEmpty(remainder)) {
throw new SimpleParserException("Valid syntax: ${mandatoryBodyAs(type)} was: " + function, token.getIndex());
}
type = StringHelper.removeQuotes(type);
http://git-wip-us.apache.org/repos/asf/camel/blob/e6fbbf04/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
index 32dec6e..88c00c1 100644
--- a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
@@ -446,7 +446,7 @@ public class SimpleTest extends LanguageTestSupport {
public void testBodyAs() throws Exception {
assertExpression("${bodyAs(String)}", "<hello id='m123'>world!</hello>");
assertExpression("${bodyAs('String')}", "<hello id='m123'>world!</hello>");
-
+
exchange.getIn().setBody(null);
assertExpression("${bodyAs('String')}", null);
@@ -461,6 +461,14 @@ public class SimpleTest extends LanguageTestSupport {
} catch (CamelExecutionException e) {
assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
}
+
+ exchange.getIn().setBody("hello");
+ try {
+ assertExpression("${bodyAs(String).test}", "hello.test");
+ fail("should have thrown an exception");
+ } catch (SimpleIllegalSyntaxException e) {
+ assertTrue("Get a wrong message", e.getMessage().indexOf("bodyAs(String).test") > 0);
+ }
}
public void testMandatoryBodyAs() throws Exception {
@@ -486,6 +494,13 @@ public class SimpleTest extends LanguageTestSupport {
} catch (CamelExecutionException e) {
assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
}
+
+ try {
+ assertExpression("${mandatoryBodyAs(String).test}", "hello.test");
+ fail("should have thrown an exception");
+ } catch (SimpleIllegalSyntaxException e) {
+ assertTrue("Get a wrong message", e.getMessage().indexOf("mandatoryBodyAs(String).test") > 0);
+ }
}
public void testHeaderEmptyBody() throws Exception {