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 7A63C18803 for ; Thu, 8 Oct 2015 15:33:58 +0000 (UTC) Received: (qmail 43294 invoked by uid 500); 8 Oct 2015 15:33:52 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 43249 invoked by uid 500); 8 Oct 2015 15:33:52 -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 43237 invoked by uid 99); 8 Oct 2015 15:33:52 -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:33:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id ECB05E0BC6; Thu, 8 Oct 2015 15:33:51 +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: <5510a422e14d4cc0a145b0e8e53c5ca4@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:33:51 +0000 (UTC) Repository: camel Updated Branches: refs/heads/camel-2.16.x 27a2ee7cd -> 2d6fcb484 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/2d6fcb48 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2d6fcb48 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2d6fcb48 Branch: refs/heads/camel-2.16.x Commit: 2d6fcb4840d7e8283e2537851833f2121e4fcd08 Parents: 27a2ee7 Author: Andrea Cosentino Authored: Thu Oct 8 17:30:31 2015 +0200 Committer: Andrea Cosentino Committed: Thu Oct 8 17:33:10 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/2d6fcb48/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/2d6fcb48/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");