Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3EA42187EA for ; Thu, 8 Oct 2015 15:31:49 +0000 (UTC) Received: (qmail 30557 invoked by uid 500); 8 Oct 2015 15:31:36 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 30508 invoked by uid 500); 8 Oct 2015 15:31:36 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 30499 invoked by uid 99); 8 Oct 2015 15:31:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Oct 2015 15:31:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 02E03E0BCE; Thu, 8 Oct 2015 15:31:36 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: acosentino@apache.org To: commits@camel.apache.org Message-Id: <861bb50303f54d38a5f574164b274574@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: camel git commit: CAMEL-9175: Simple random function - Should trim the min/max values Date: Thu, 8 Oct 2015 15:31:36 +0000 (UTC) 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 Authored: Thu Oct 8 17:30:31 2015 +0200 Committer: Andrea Cosentino 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");