camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-9175: Simple random function - Should trim the min/max values
Date Thu, 08 Oct 2015 15:33:51 GMT
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 <ancosen@gmail.com>
Authored: Thu Oct 8 17:30:31 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
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");


Mime
View raw message