Repository: camel Updated Branches: refs/heads/master c211ed2fb -> cc8126985
CAMEL-8316: Rename property language to exchangeProperty to avoid ambiguity, confusion and clash with properties as a general term. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ffd8beaa Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ffd8beaa Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ffd8beaa Branch: refs/heads/master Commit: ffd8beaac5c6a7db716d638e4dd88122b22b1450 Parents: 8864250 Author: Claus Ibsen <[email protected]> Authored: Thu Feb 5 11:56:34 2015 +0100 Committer: Claus Ibsen <[email protected]> Committed: Thu Feb 5 15:51:23 2015 +0100 ---------------------------------------------------------------------- .../simple/ast/SimpleFunctionExpression.java | 5 +- .../camel/language/simple/SimpleTest.java | 50 ++++++++++++++++---- 2 files changed, 44 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/ffd8beaa/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 8ea75a1..d05356d 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 @@ -90,6 +90,9 @@ public class SimpleFunctionExpression extends LiteralExpression { // property remainder = ifStartsWithReturnRemainder("property", function); + if (remainder == null) { + remainder = ifStartsWithReturnRemainder("exchangeProperty", function); + } if (remainder != null) { // remove leading character (dot or ?) if (remainder.startsWith(".") || remainder.startsWith("?")) { @@ -103,7 +106,7 @@ public class SimpleFunctionExpression extends LiteralExpression { // validate syntax boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder); if (invalid) { - throw new SimpleParserException("Valid syntax: ${property.OGNL} was: " + function, token.getIndex()); + throw new SimpleParserException("Valid syntax: ${exchangeProperty.OGNL} was: " + function, token.getIndex()); } if (OgnlHelper.isValidOgnlExpression(remainder)) { http://git-wip-us.apache.org/repos/asf/camel/blob/ffd8beaa/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 85d99cd..cce849d 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 @@ -198,6 +198,11 @@ public class SimpleTest extends LanguageTestSupport { assertExpression("property.medal", "gold"); } + public void testSimpleExchangePropertyExpressions() throws Exception { + exchange.setProperty("medal", "gold"); + assertExpression("exchangeProperty.medal", "gold"); + } + public void testSimpleSystemPropertyExpressions() throws Exception { System.setProperty("who", "I was here"); assertExpression("sys.who", "I was here"); @@ -272,16 +277,16 @@ public class SimpleTest extends LanguageTestSupport { lines.add("ActiveMQ in Action"); exchange.setProperty("wicket", lines); - assertExpression("${property.wicket[0]}", "Camel in Action"); - assertExpression("${property.wicket[1]}", "ActiveMQ in Action"); + assertExpression("${exchangeProperty.wicket[0]}", "Camel in Action"); + assertExpression("${exchangeProperty.wicket[1]}", "ActiveMQ in Action"); try { - assertExpression("${property.wicket[2]}", ""); + assertExpression("${exchangeProperty.wicket[2]}", ""); fail("Should have thrown an exception"); } catch (Exception e) { IndexOutOfBoundsException cause = assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause()); assertEquals("Index: 2, Size: 2", cause.getMessage()); } - assertExpression("${property.unknown[cool]}", null); + assertExpression("${exchangeProperty.unknown[cool]}", null); } public void testOGNLPropertyLinesList() throws Exception { @@ -290,10 +295,10 @@ public class SimpleTest extends LanguageTestSupport { lines.add(new OrderLine(456, "ActiveMQ in Action")); exchange.setProperty("wicket", lines); - assertExpression("${property.wicket[0].getId}", 123); - assertExpression("${property.wicket[1].getName}", "ActiveMQ in Action"); + assertExpression("${exchangeProperty.wicket[0].getId}", 123); + assertExpression("${exchangeProperty.wicket[1].getName}", "ActiveMQ in Action"); try { - assertExpression("${property.wicket[2]}", ""); + assertExpression("${exchangeProperty.wicket[2]}", ""); fail("Should have thrown an exception"); } catch (Exception e) { IndexOutOfBoundsException cause = assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause()); @@ -318,17 +323,33 @@ public class SimpleTest extends LanguageTestSupport { assertExpression("${property.unknown[cool]}", null); } + public void testOGNLExchangePropertyMap() throws Exception { + Map<String, Object> map = new HashMap<String, Object>(); + map.put("cool", "Camel rocks"); + map.put("dude", "Hey dude"); + map.put("code", 4321); + exchange.setProperty("wicket", map); + + assertExpression("${exchangeProperty.wicket[cool]}", "Camel rocks"); + assertExpression("${exchangeProperty.wicket[dude]}", "Hey dude"); + assertExpression("${exchangeProperty.wicket[unknown]}", null); + assertExpression("${exchangeProperty.wicket[code]}", 4321); + // no header named unknown + assertExpression("${exchangeProperty?.unknown[cool]}", null); + assertExpression("${exchangeProperty.unknown[cool]}", null); + } + public void testOGNLPropertyMapWithDot() throws Exception { Map<String, Object> map = new HashMap<String, Object>(); map.put("this.code", "This code"); exchange.setProperty("wicket", map); - assertExpression("${property.wicket[this.code]}", "This code"); + assertExpression("${exchangeProperty.wicket[this.code]}", "This code"); } public void testOGNLPropertyMapNotMap() throws Exception { try { - assertExpression("${property.foobar[bar]}", null); + assertExpression("${exchangeProperty.foobar[bar]}", null); fail("Should have thrown an exception"); } catch (RuntimeBeanExpressionException e) { IndexOutOfBoundsException cause = assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause()); @@ -341,7 +362,16 @@ public class SimpleTest extends LanguageTestSupport { assertExpression("${property.foobar[bar}", null); fail("Should have thrown an exception"); } catch (ExpressionIllegalSyntaxException e) { - assertTrue(e.getMessage().startsWith("Valid syntax: ${property.OGNL} was: property.foobar[bar at location 0")); + assertTrue(e.getMessage().startsWith("Valid syntax: ${exchangeProperty.OGNL} was: property.foobar[bar at location 0")); + } + } + + public void testOGNLExchangePropertyMapIllegalSyntax() throws Exception { + try { + assertExpression("${exchangeProperty.foobar[bar}", null); + fail("Should have thrown an exception"); + } catch (ExpressionIllegalSyntaxException e) { + assertTrue(e.getMessage().startsWith("Valid syntax: ${exchangeProperty.OGNL} was: exchangeProperty.foobar[bar at location 0")); } }
