Repository: camel Updated Branches: refs/heads/master 1d9dc6220 -> a7ac627a2
CAMEL-9175: Simple random function - Should trim the min/max values Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a7ac627a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a7ac627a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a7ac627a Branch: refs/heads/master Commit: a7ac627a2a1566a1021a0fe731c53f443786dfbe Parents: 1d9dc62 Author: Andrea Cosentino <anco...@gmail.com> Authored: Thu Oct 8 17:30:31 2015 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Thu Oct 8 17:30:31 2015 +0200 ---------------------------------------------------------------------- .../camel/language/simple/ast/SimpleFunctionExpression.java | 6 +++--- .../test/java/org/apache/camel/language/simple/SimpleTest.java | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a7ac627a/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 2653240..d2fd1ca 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 @@ -334,11 +334,11 @@ public class SimpleFunctionExpression extends LiteralExpression { if (tokens.length > 2) { throw new SimpleParserException("Valid syntax: ${random(min,max)} or ${random(max)} was: " + function, token.getIndex()); } - int min = Integer.parseInt(tokens[0]); - int max = Integer.parseInt(tokens[1]); + int min = Integer.parseInt(tokens[0].trim()); + int max = Integer.parseInt(tokens[1].trim()); return ExpressionBuilder.randomExpression(min, max); } else { - int max = Integer.parseInt(values); + int max = Integer.parseInt(values.trim()); return ExpressionBuilder.randomExpression(max); } } http://git-wip-us.apache.org/repos/asf/camel/blob/a7ac627a/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 28e6eca..95c7455 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 @@ -1453,6 +1453,12 @@ public class SimpleTest extends LanguageTestSupport { Expression expression = SimpleLanguage.simple("random(10)", Integer.class); assertTrue(0 <= expression.evaluate(exchange, Integer.class) && expression.evaluate(exchange, Integer.class) < max); } + Expression expression = SimpleLanguage.simple("random(1, 10)", Integer.class); + assertTrue(min <= expression.evaluate(exchange, Integer.class) && expression.evaluate(exchange, Integer.class) < max); + + Expression expression1 = SimpleLanguage.simple("random( 10)", Integer.class); + assertTrue(0 <= expression1.evaluate(exchange, Integer.class) && expression1.evaluate(exchange, Integer.class) < max); + try { assertExpression("random(10,21,30)", null); fail("Should have thrown exception");