rearranged spel subpackages in order to avoid package dependency cycle; introduced SpelParserConfiguration object to replace bit flags
This commit is contained in:
@@ -20,15 +20,15 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.ParseException;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParserConfiguration;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.support.StandardTypeLocator;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class EvaluationTests extends ExpressionTestCase {
|
||||
|
||||
@Test
|
||||
public void testCreateListsOnAttemptToIndexNull01() throws EvaluationException, ParseException {
|
||||
ExpressionParser parser = new SpelExpressionParser(SpelExpressionParserConfiguration.CreateObjectIfAttemptToReferenceNull | SpelExpressionParserConfiguration.GrowListsOnIndexBeyondSize);
|
||||
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
||||
Expression expression = parser.parseExpression("list[0]");
|
||||
TestClass testClass = new TestClass();
|
||||
Object o = null;
|
||||
@@ -67,7 +67,7 @@ public class EvaluationTests extends ExpressionTestCase {
|
||||
public void testCreateMapsOnAttemptToIndexNull01() throws EvaluationException, ParseException {
|
||||
TestClass testClass = new TestClass();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext(testClass);
|
||||
ExpressionParser parser = new SpelExpressionParser(SpelExpressionParserConfiguration.CreateObjectIfAttemptToReferenceNull | SpelExpressionParserConfiguration.GrowListsOnIndexBeyondSize);
|
||||
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
||||
Object o = null;
|
||||
o = parser.parseExpression("map['a']").getValue(ctx);
|
||||
Assert.assertNull(o);
|
||||
@@ -87,7 +87,7 @@ public class EvaluationTests extends ExpressionTestCase {
|
||||
public void testCreateObjectsOnAttemptToReferenceNull() throws EvaluationException, ParseException {
|
||||
TestClass testClass = new TestClass();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext(testClass);
|
||||
ExpressionParser parser = new SpelExpressionParser(SpelExpressionParserConfiguration.CreateObjectIfAttemptToReferenceNull | SpelExpressionParserConfiguration.GrowListsOnIndexBeyondSize);
|
||||
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
||||
Object o = null;
|
||||
o = parser.parseExpression("wibble.bar").getValue(ctx);
|
||||
Assert.assertEquals("hello",o);
|
||||
@@ -236,7 +236,7 @@ public class EvaluationTests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testPropertiesNested03() throws ParseException {
|
||||
try {
|
||||
new SpelExpressionParser().parse("placeOfBirth.23");
|
||||
new SpelExpressionParser().parseRaw("placeOfBirth.23");
|
||||
Assert.fail();
|
||||
} catch (SpelParseException spe) {
|
||||
Assert.assertEquals(spe.getMessageCode(), SpelMessage.UNEXPECTED_DATA_AFTER_DOT);
|
||||
@@ -507,4 +507,5 @@ public class EvaluationTests extends ExpressionTestCase {
|
||||
Class stringClass = parser.parseExpression("T(String)").getValue(Class.class);
|
||||
Assert.assertEquals(String.class,stringClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
// Create a parser
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
// Parse an expression
|
||||
Expression expr = parser.parseExpression("new String('hello world')");
|
||||
Expression expr = parser.parseRaw("new String('hello world')");
|
||||
// Evaluate it using a 'standard' context
|
||||
Object value = expr.getValue();
|
||||
// They are reusable
|
||||
@@ -102,16 +102,16 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
primes.addAll(Arrays.asList(2,3,5,7,11,13,17));
|
||||
ctx.setVariable("primes",primes);
|
||||
|
||||
Expression expr = parser.parseExpression("#favouriteColour");
|
||||
Expression expr = parser.parseRaw("#favouriteColour");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals("blue", value);
|
||||
|
||||
expr = parser.parseExpression("#primes.get(1)");
|
||||
expr = parser.parseRaw("#primes.get(1)");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals(3, value);
|
||||
|
||||
// all prime numbers > 10 from the list (using selection ?{...})
|
||||
expr = parser.parseExpression("#primes.?[#this>10]");
|
||||
expr = parser.parseRaw("#primes.?[#this>10]");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals("[11, 13, 17]", value.toString());
|
||||
}
|
||||
@@ -140,30 +140,30 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
ctx.setRootObject(tc);
|
||||
|
||||
// read it, set it, read it again
|
||||
Expression expr = parser.parseExpression("str");
|
||||
Expression expr = parser.parseRaw("str");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals("wibble", value);
|
||||
expr = parser.parseExpression("str");
|
||||
expr = parser.parseRaw("str");
|
||||
expr.setValue(ctx, "wobble");
|
||||
expr = parser.parseExpression("str");
|
||||
expr = parser.parseRaw("str");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals("wobble", value);
|
||||
// or using assignment within the expression
|
||||
expr = parser.parseExpression("str='wabble'");
|
||||
expr = parser.parseRaw("str='wabble'");
|
||||
value = expr.getValue(ctx);
|
||||
expr = parser.parseExpression("str");
|
||||
expr = parser.parseRaw("str");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals("wabble", value);
|
||||
|
||||
// private property will be accessed through getter()
|
||||
expr = parser.parseExpression("property");
|
||||
expr = parser.parseRaw("property");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals(42, value);
|
||||
|
||||
// ... and set through setter
|
||||
expr = parser.parseExpression("property=4");
|
||||
expr = parser.parseRaw("property=4");
|
||||
value = expr.getValue(ctx);
|
||||
expr = parser.parseExpression("property");
|
||||
expr = parser.parseRaw("property");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals(4,value);
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
ctx.registerFunction("repeat",ExpressionLanguageScenarioTests.class.getDeclaredMethod("repeat",String.class));
|
||||
|
||||
Expression expr = parser.parseExpression("#repeat('hello')");
|
||||
Expression expr = parser.parseRaw("#repeat('hello')");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals("hellohello", value);
|
||||
|
||||
@@ -206,7 +206,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
ctx.addPropertyAccessor(new FruitColourAccessor());
|
||||
Expression expr = parser.parseExpression("orange");
|
||||
Expression expr = parser.parseRaw("orange");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals(Color.orange, value);
|
||||
|
||||
@@ -226,7 +226,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
ctx.addPropertyAccessor(new VegetableColourAccessor());
|
||||
Expression expr = parser.parseExpression("pea");
|
||||
Expression expr = parser.parseRaw("pea");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals(Color.green, value);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.ParseException;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
/**
|
||||
@@ -39,7 +40,7 @@ public abstract class ExpressionTestCase {
|
||||
protected final static boolean SHOULD_BE_WRITABLE = true;
|
||||
protected final static boolean SHOULD_NOT_BE_WRITABLE = false;
|
||||
|
||||
protected final static ExpressionParser parser = SpelExpressionParserFactory.getParser();
|
||||
protected final static ExpressionParser parser = new SpelExpressionParser();
|
||||
protected final static StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,10 +30,11 @@ import org.springframework.expression.PropertyAccessor;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.ast.FormatHelper;
|
||||
import org.springframework.expression.spel.support.ReflectionHelper;
|
||||
import org.springframework.expression.spel.support.ReflectivePropertyResolver;
|
||||
import org.springframework.expression.spel.support.ReflectivePropertyAccessor;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.support.StandardTypeConverter;
|
||||
import org.springframework.expression.spel.support.ReflectionHelper.ArgsMatchKind;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
/**
|
||||
* Tests for any helper code.
|
||||
@@ -274,7 +275,7 @@ public class HelperTests extends ExpressionTestCase {
|
||||
|
||||
@Test
|
||||
public void testReflectivePropertyResolver() throws Exception {
|
||||
ReflectivePropertyResolver rpr = new ReflectivePropertyResolver();
|
||||
ReflectivePropertyAccessor rpr = new ReflectivePropertyAccessor();
|
||||
Tester t = new Tester();
|
||||
t.setProperty("hello");
|
||||
EvaluationContext ctx = new StandardEvaluationContext(t);
|
||||
@@ -313,7 +314,7 @@ public class HelperTests extends ExpressionTestCase {
|
||||
|
||||
@Test
|
||||
public void testOptimalReflectivePropertyResolver() throws Exception {
|
||||
ReflectivePropertyResolver rpr = new ReflectivePropertyResolver();
|
||||
ReflectivePropertyAccessor rpr = new ReflectivePropertyAccessor();
|
||||
Tester t = new Tester();
|
||||
t.setProperty("hello");
|
||||
EvaluationContext ctx = new StandardEvaluationContext(t);
|
||||
|
||||
@@ -21,6 +21,7 @@ import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
/**
|
||||
* These are tests for language features that are not yet considered 'live'. Either missing implementation or documentation.
|
||||
|
||||
@@ -20,6 +20,7 @@ import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
/**
|
||||
* Tests the evaluation of basic literals: boolean, integer, hex integer, long, real, null, date
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Operation;
|
||||
import org.springframework.expression.OperatorOverloader;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
/**
|
||||
* Test providing operator support
|
||||
|
||||
@@ -20,6 +20,7 @@ import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.spel.ast.Operator;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
/**
|
||||
* Tests the evaluation of expressions using relational operators.
|
||||
|
||||
@@ -21,6 +21,7 @@ import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.ParseException;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
/**
|
||||
* Parse some expressions and check we get the AST we expect. Rather than inspecting each node in the AST, we ask it to
|
||||
@@ -451,7 +452,7 @@ public class ParsingTests {
|
||||
*/
|
||||
public void parseCheck(String expression, String expectedStringFormOfAST) {
|
||||
try {
|
||||
SpelExpression e = (SpelExpression) parser.parseExpression(expression);
|
||||
SpelExpression e = (SpelExpression) parser.parseRaw(expression);
|
||||
if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) {
|
||||
SpelUtilities.printAbstractSyntaxTree(System.err, e);
|
||||
}
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
||||
///CLOVER:OFF
|
||||
|
||||
@@ -35,7 +36,7 @@ public class PerformanceTests {
|
||||
public static final int ITERATIONS = 10000;
|
||||
public static final boolean report = true;
|
||||
|
||||
private static ExpressionParser parser = SpelExpressionParserFactory.getParser();
|
||||
private static ExpressionParser parser = new SpelExpressionParser();
|
||||
private static EvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.PropertyAccessor;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
///CLOVER:OFF
|
||||
@@ -104,16 +105,16 @@ public class PropertyAccessTests extends ExpressionTestCase {
|
||||
// names the String class as the type it is interested in so is chosen in preference to
|
||||
// any 'default' ones
|
||||
ctx.addPropertyAccessor(new StringyPropertyAccessor());
|
||||
Expression expr = parser.parseExpression("new String('hello').flibbles");
|
||||
Expression expr = parser.parseRaw("new String('hello').flibbles");
|
||||
Integer i = expr.getValue(ctx, Integer.class);
|
||||
Assert.assertEquals((int) i, 7);
|
||||
|
||||
// The reflection one will be used for other properties...
|
||||
expr = parser.parseExpression("new String('hello').CASE_INSENSITIVE_ORDER");
|
||||
expr = parser.parseRaw("new String('hello').CASE_INSENSITIVE_ORDER");
|
||||
Object o = expr.getValue(ctx);
|
||||
Assert.assertNotNull(o);
|
||||
|
||||
expr = parser.parseExpression("new String('hello').flibbles");
|
||||
expr = parser.parseRaw("new String('hello').flibbles");
|
||||
expr.setValue(ctx, 99);
|
||||
i = expr.getValue(ctx, Integer.class);
|
||||
Assert.assertEquals((int) i, 99);
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
Expression expr = parser.parseExpression("hasAnyRole('MANAGER','TELLER')");
|
||||
Expression expr = parser.parseRaw("hasAnyRole('MANAGER','TELLER')");
|
||||
|
||||
ctx.setRootObject(new Person("Ben"));
|
||||
Boolean value = expr.getValue(ctx,Boolean.class);
|
||||
@@ -74,7 +74,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
|
||||
// Multiple options for supporting this expression: "p.name == principal.name"
|
||||
// (1) If the right person is the root context object then "name==principal.name" is good enough
|
||||
Expression expr = parser.parseExpression("name == principal.name");
|
||||
Expression expr = parser.parseRaw("name == principal.name");
|
||||
|
||||
ctx.setRootObject(new Person("Andy"));
|
||||
Boolean value = expr.getValue(ctx,Boolean.class);
|
||||
@@ -85,7 +85,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
Assert.assertFalse(value);
|
||||
|
||||
// (2) Or register an accessor that can understand 'p' and return the right person
|
||||
expr = parser.parseExpression("p.name == principal.name");
|
||||
expr = parser.parseRaw("p.name == principal.name");
|
||||
|
||||
PersonAccessor pAccessor = new PersonAccessor();
|
||||
ctx.addPropertyAccessor(pAccessor);
|
||||
@@ -107,7 +107,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
|
||||
// Might be better with a as a variable although it would work as a property too...
|
||||
// Variable references using a '#'
|
||||
Expression expr = parser.parseExpression("(hasRole('SUPERVISOR') or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
|
||||
Expression expr = parser.parseRaw("(hasRole('SUPERVISOR') or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
|
||||
|
||||
Boolean value = null;
|
||||
|
||||
@@ -134,7 +134,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
// Might be better with a as a variable although it would work as a property too...
|
||||
// Variable references using a '#'
|
||||
// SpelExpression expr = parser.parseExpression("(hasRole('SUPERVISOR') or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
|
||||
Expression expr = parser.parseExpression("(hasRole(3) or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
|
||||
Expression expr = parser.parseRaw("(hasRole(3) or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
|
||||
|
||||
Boolean value = null;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
public void selectionWithList() throws Exception {
|
||||
Expression expression = new SpelExpressionParser().parse("integers.?[#this<5]");
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof List);
|
||||
@@ -53,7 +53,7 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
public void selectFirstItemInList() throws Exception {
|
||||
Expression expression = new SpelExpressionParser().parse("integers.^[#this<5]");
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
@@ -62,7 +62,7 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
public void selectLastItemInList() throws Exception {
|
||||
Expression expression = new SpelExpressionParser().parse("integers.$[#this<5]");
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
@@ -71,7 +71,7 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
public void selectionWithArray() throws Exception {
|
||||
Expression expression = new SpelExpressionParser().parse("integers.?[#this<5]");
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value.getClass().isArray());
|
||||
@@ -88,7 +88,7 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
public void selectFirstItemInArray() throws Exception {
|
||||
Expression expression = new SpelExpressionParser().parse("integers.^[#this<5]");
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
@@ -97,7 +97,7 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
public void selectLastItemInArray() throws Exception {
|
||||
Expression expression = new SpelExpressionParser().parse("integers.$[#this<5]");
|
||||
Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
@@ -106,7 +106,7 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
public void selectionWithPrimitiveArray() throws Exception {
|
||||
Expression expression = new SpelExpressionParser().parse("ints.?[#this<5]");
|
||||
Expression expression = new SpelExpressionParser().parseRaw("ints.?[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value.getClass().isArray());
|
||||
@@ -123,7 +123,7 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
public void selectFirstItemInPrimitiveArray() throws Exception {
|
||||
Expression expression = new SpelExpressionParser().parse("ints.^[#this<5]");
|
||||
Expression expression = new SpelExpressionParser().parseRaw("ints.^[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
@@ -132,7 +132,7 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
public void selectLastItemInPrimitiveArray() throws Exception {
|
||||
Expression expression = new SpelExpressionParser().parse("ints.$[#this<5]");
|
||||
Expression expression = new SpelExpressionParser().parseRaw("ints.$[#this<5]");
|
||||
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
|
||||
Object value = expression.getValue(context);
|
||||
assertTrue(value instanceof Integer);
|
||||
@@ -141,7 +141,7 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
public void projectionWithList() throws Exception {
|
||||
Expression expression = new SpelExpressionParser().parse("#testList.![wrapper.value]");
|
||||
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]");
|
||||
EvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("testList", IntegerTestBean.createList());
|
||||
Object value = expression.getValue(context);
|
||||
@@ -155,7 +155,7 @@ public class SelectionAndProjectionTests {
|
||||
|
||||
@Test
|
||||
public void projectionWithArray() throws Exception {
|
||||
Expression expression = new SpelExpressionParser().parse("#testArray.![wrapper.value]");
|
||||
Expression expression = new SpelExpressionParser().parseRaw("#testArray.![wrapper.value]");
|
||||
EvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("testArray", IntegerTestBean.createArray());
|
||||
Object value = expression.getValue(context);
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.expression.spel;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
/**
|
||||
* Utilities for working with Spring Expressions.
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.expression.ParserContext;
|
||||
import org.springframework.expression.PropertyAccessor;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.ReflectivePropertyResolver;
|
||||
import org.springframework.expression.spel.support.ReflectivePropertyAccessor;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.support.StandardTypeLocator;
|
||||
|
||||
@@ -56,12 +56,12 @@ public class SpringEL300Tests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testSPR5899() throws Exception {
|
||||
StandardEvaluationContext eContext = new StandardEvaluationContext(new Spr5899Class());
|
||||
Expression expr = new SpelExpressionParser().parse("tryToInvokeWithNull(12)");
|
||||
Expression expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull(12)");
|
||||
Assert.assertEquals(12,expr.getValue(eContext));
|
||||
expr = new SpelExpressionParser().parse("tryToInvokeWithNull(null)");
|
||||
expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull(null)");
|
||||
Assert.assertEquals(null,expr.getValue(eContext));
|
||||
try {
|
||||
expr = new SpelExpressionParser().parse("tryToInvokeWithNull2(null)");
|
||||
expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull2(null)");
|
||||
expr.getValue();
|
||||
Assert.fail("Should have failed to find a method to which it could pass null");
|
||||
} catch (EvaluationException see) {
|
||||
@@ -70,26 +70,26 @@ public class SpringEL300Tests extends ExpressionTestCase {
|
||||
eContext.setTypeLocator(new MyTypeLocator());
|
||||
|
||||
// varargs
|
||||
expr = new SpelExpressionParser().parse("tryToInvokeWithNull3(null,'a','b')");
|
||||
expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull3(null,'a','b')");
|
||||
Assert.assertEquals("ab",expr.getValue(eContext));
|
||||
|
||||
// varargs 2 - null is packed into the varargs
|
||||
expr = new SpelExpressionParser().parse("tryToInvokeWithNull3(12,'a',null,'c')");
|
||||
expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull3(12,'a',null,'c')");
|
||||
Assert.assertEquals("anullc",expr.getValue(eContext));
|
||||
|
||||
// check we can find the ctor ok
|
||||
expr = new SpelExpressionParser().parse("new Spr5899Class().toString()");
|
||||
expr = new SpelExpressionParser().parseRaw("new Spr5899Class().toString()");
|
||||
Assert.assertEquals("instance",expr.getValue(eContext));
|
||||
|
||||
expr = new SpelExpressionParser().parse("new Spr5899Class(null).toString()");
|
||||
expr = new SpelExpressionParser().parseRaw("new Spr5899Class(null).toString()");
|
||||
Assert.assertEquals("instance",expr.getValue(eContext));
|
||||
|
||||
// ctor varargs
|
||||
expr = new SpelExpressionParser().parse("new Spr5899Class(null,'a','b').toString()");
|
||||
expr = new SpelExpressionParser().parseRaw("new Spr5899Class(null,'a','b').toString()");
|
||||
Assert.assertEquals("instance",expr.getValue(eContext));
|
||||
|
||||
// ctor varargs 2
|
||||
expr = new SpelExpressionParser().parse("new Spr5899Class(null,'a', null, 'b').toString()");
|
||||
expr = new SpelExpressionParser().parseRaw("new Spr5899Class(null,'a', null, 'b').toString()");
|
||||
Assert.assertEquals("instance",expr.getValue(eContext));
|
||||
}
|
||||
|
||||
@@ -133,13 +133,13 @@ public class SpringEL300Tests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testSPR5905_InnerTypeReferences() throws Exception {
|
||||
StandardEvaluationContext eContext = new StandardEvaluationContext(new Spr5899Class());
|
||||
Expression expr = new SpelExpressionParser().parse("T(java.util.Map$Entry)");
|
||||
Expression expr = new SpelExpressionParser().parseRaw("T(java.util.Map$Entry)");
|
||||
Assert.assertEquals(Map.Entry.class,expr.getValue(eContext));
|
||||
|
||||
expr = new SpelExpressionParser().parse("T(org.springframework.expression.spel.SpringEL300Tests$Outer$Inner).run()");
|
||||
expr = new SpelExpressionParser().parseRaw("T(org.springframework.expression.spel.SpringEL300Tests$Outer$Inner).run()");
|
||||
Assert.assertEquals(12,expr.getValue(eContext));
|
||||
|
||||
expr = new SpelExpressionParser().parse("new org.springframework.expression.spel.SpringEL300Tests$Outer$Inner().run2()");
|
||||
expr = new SpelExpressionParser().parseRaw("new org.springframework.expression.spel.SpringEL300Tests$Outer$Inner().run2()");
|
||||
Assert.assertEquals(13,expr.getValue(eContext));
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class SpringEL300Tests extends ExpressionTestCase {
|
||||
m.put("foo", "bar");
|
||||
StandardEvaluationContext eContext = new StandardEvaluationContext(m); // root is a map instance
|
||||
eContext.addPropertyAccessor(new MapAccessor());
|
||||
Expression expr = new SpelExpressionParser().parseExpression("['foo']");
|
||||
Expression expr = new SpelExpressionParser().parseRaw("['foo']");
|
||||
Assert.assertEquals("bar", expr.getValue(eContext));
|
||||
}
|
||||
|
||||
@@ -172,16 +172,16 @@ public class SpringEL300Tests extends ExpressionTestCase {
|
||||
String name = null;
|
||||
Expression expr = null;
|
||||
|
||||
expr = new SpelExpressionParser().parse("jdbcProperties['username']");
|
||||
expr = new SpelExpressionParser().parseRaw("jdbcProperties['username']");
|
||||
name = expr.getValue(eContext,String.class);
|
||||
Assert.assertEquals("Dave",name);
|
||||
|
||||
expr = new SpelExpressionParser().parse("jdbcProperties[username]");
|
||||
expr = new SpelExpressionParser().parseRaw("jdbcProperties[username]");
|
||||
name = expr.getValue(eContext,String.class);
|
||||
Assert.assertEquals("Dave",name);
|
||||
|
||||
// MapAccessor required for this to work
|
||||
expr = new SpelExpressionParser().parse("jdbcProperties.username");
|
||||
expr = new SpelExpressionParser().parseRaw("jdbcProperties.username");
|
||||
eContext.addPropertyAccessor(new MapAccessor());
|
||||
name = expr.getValue(eContext,String.class);
|
||||
Assert.assertEquals("Dave",name);
|
||||
@@ -189,13 +189,13 @@ public class SpringEL300Tests extends ExpressionTestCase {
|
||||
// --- dotted property names
|
||||
|
||||
// lookup foo on the root, then bar on that, then use that as the key into jdbcProperties
|
||||
expr = new SpelExpressionParser().parse("jdbcProperties[foo.bar]");
|
||||
expr = new SpelExpressionParser().parseRaw("jdbcProperties[foo.bar]");
|
||||
eContext.addPropertyAccessor(new MapAccessor());
|
||||
name = expr.getValue(eContext,String.class);
|
||||
Assert.assertEquals("Dave2",name);
|
||||
|
||||
// key is foo.bar
|
||||
expr = new SpelExpressionParser().parse("jdbcProperties['foo.bar']");
|
||||
expr = new SpelExpressionParser().parseRaw("jdbcProperties['foo.bar']");
|
||||
eContext.addPropertyAccessor(new MapAccessor());
|
||||
name = expr.getValue(eContext,String.class);
|
||||
Assert.assertEquals("Elephant",name);
|
||||
@@ -274,7 +274,7 @@ public class SpringEL300Tests extends ExpressionTestCase {
|
||||
|
||||
@Test
|
||||
public void testAccessingNullPropertyViaReflection_SPR5663() throws AccessException {
|
||||
PropertyAccessor propertyAccessor = new ReflectivePropertyResolver();
|
||||
PropertyAccessor propertyAccessor = new ReflectivePropertyAccessor();
|
||||
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
||||
Assert.assertFalse(propertyAccessor.canRead(context, null, "abc"));
|
||||
Assert.assertFalse(propertyAccessor.canWrite(context, null, "abc"));
|
||||
|
||||
@@ -76,7 +76,7 @@ public class VariableAndFunctionTests extends ExpressionTestCase {
|
||||
ctx.setVariable("notStatic", this.getClass().getMethod("nonStatic"));
|
||||
try {
|
||||
@SuppressWarnings("unused")
|
||||
Object v = parser.parseExpression("#notStatic()").getValue(ctx);
|
||||
Object v = parser.parseRaw("#notStatic()").getValue(ctx);
|
||||
Assert.fail("Should have failed with exception - cannot call non static method that way");
|
||||
} catch (SpelEvaluationException se) {
|
||||
if (se.getMessageCode() != SpelMessage.FUNCTION_MUST_BE_STATIC) {
|
||||
|
||||
@@ -13,30 +13,33 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.expression.spel.standard.internal;
|
||||
import junit.framework.Assert;
|
||||
|
||||
package org.springframework.expression.spel.standard;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.ExpressionException;
|
||||
import org.springframework.expression.ParseException;
|
||||
import org.springframework.expression.spel.SpelExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.SpelMessage;
|
||||
import org.springframework.expression.spel.SpelNode;
|
||||
import org.springframework.expression.spel.SpelParseException;
|
||||
import org.springframework.expression.spel.ast.OpAnd;
|
||||
import org.springframework.expression.spel.ast.OpOr;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
|
||||
/**
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class SpelParserTests {
|
||||
|
||||
@Test
|
||||
public void theMostBasic() throws EvaluationException,ParseException {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parse("2");
|
||||
SpelExpression expr = parser.parseRaw("2");
|
||||
Assert.assertNotNull(expr);
|
||||
Assert.assertNotNull(expr.getAST());
|
||||
Assert.assertEquals(2,expr.getValue());
|
||||
@@ -48,35 +51,35 @@ public class SpelParserTests {
|
||||
public void valueType() throws Exception {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
EvaluationContext ctx = new StandardEvaluationContext();
|
||||
Class c = parser.parse("2").getValueType();
|
||||
Class c = parser.parseRaw("2").getValueType();
|
||||
Assert.assertEquals(Integer.class,c);
|
||||
c = parser.parse("12").getValueType(ctx);
|
||||
c = parser.parseRaw("12").getValueType(ctx);
|
||||
Assert.assertEquals(Integer.class,c);
|
||||
c = parser.parse("null").getValueType();
|
||||
c = parser.parseRaw("null").getValueType();
|
||||
Assert.assertNull(c);
|
||||
c = parser.parse("null").getValueType(ctx);
|
||||
c = parser.parseRaw("null").getValueType(ctx);
|
||||
Assert.assertNull(c);
|
||||
Object o = parser.parse("null").getValue(ctx,Integer.class);
|
||||
Object o = parser.parseRaw("null").getValue(ctx,Integer.class);
|
||||
Assert.assertNull(o);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whitespace() throws EvaluationException,ParseException {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parse("2 + 3");
|
||||
SpelExpression expr = parser.parseRaw("2 + 3");
|
||||
Assert.assertEquals(5,expr.getValue());
|
||||
expr = parser.parse("2 + 3");
|
||||
expr = parser.parseRaw("2 + 3");
|
||||
Assert.assertEquals(5,expr.getValue());
|
||||
expr = parser.parse("2\n+ 3");
|
||||
expr = parser.parseRaw("2\n+ 3");
|
||||
Assert.assertEquals(5,expr.getValue());
|
||||
expr = parser.parse("2\r\n+\t3");
|
||||
expr = parser.parseRaw("2\r\n+\t3");
|
||||
Assert.assertEquals(5,expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPlus1() throws EvaluationException,ParseException {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parse("2+2");
|
||||
SpelExpression expr = parser.parseRaw("2+2");
|
||||
Assert.assertNotNull(expr);
|
||||
Assert.assertNotNull(expr.getAST());
|
||||
Assert.assertEquals(4,expr.getValue());
|
||||
@@ -85,14 +88,14 @@ public class SpelParserTests {
|
||||
@Test
|
||||
public void arithmeticPlus2() throws EvaluationException,ParseException {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parse("37+41");
|
||||
SpelExpression expr = parser.parseRaw("37+41");
|
||||
Assert.assertEquals(78,expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticMultiply1() throws EvaluationException,ParseException {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parse("2*3");
|
||||
SpelExpression expr = parser.parseRaw("2*3");
|
||||
Assert.assertNotNull(expr);
|
||||
Assert.assertNotNull(expr.getAST());
|
||||
// printAst(expr.getAST(),0);
|
||||
@@ -102,7 +105,7 @@ public class SpelParserTests {
|
||||
@Test
|
||||
public void arithmeticPrecedence1() throws EvaluationException,ParseException {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parse("2*3+5");
|
||||
SpelExpression expr = parser.parseRaw("2*3+5");
|
||||
Assert.assertEquals(11,expr.getValue());
|
||||
}
|
||||
|
||||
@@ -110,7 +113,7 @@ public class SpelParserTests {
|
||||
public void generalExpressions() throws Exception {
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
parser.parse("new String[3]");
|
||||
parser.parseRaw("new String[3]");
|
||||
Assert.fail();
|
||||
} catch (ParseException e) {
|
||||
Assert.assertTrue(e instanceof SpelParseException);
|
||||
@@ -120,7 +123,7 @@ public class SpelParserTests {
|
||||
}
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
parser.parse("new String");
|
||||
parser.parseRaw("new String");
|
||||
Assert.fail();
|
||||
} catch (ParseException e) {
|
||||
Assert.assertTrue(e instanceof SpelParseException);
|
||||
@@ -130,7 +133,7 @@ public class SpelParserTests {
|
||||
}
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
parser.parse("new String(3,");
|
||||
parser.parseRaw("new String(3,");
|
||||
Assert.fail();
|
||||
} catch (ParseException e) {
|
||||
Assert.assertTrue(e instanceof SpelParseException);
|
||||
@@ -140,7 +143,7 @@ public class SpelParserTests {
|
||||
}
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
parser.parse("new String(3");
|
||||
parser.parseRaw("new String(3");
|
||||
Assert.fail();
|
||||
} catch (ParseException e) {
|
||||
Assert.assertTrue(e instanceof SpelParseException);
|
||||
@@ -150,7 +153,7 @@ public class SpelParserTests {
|
||||
}
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
parser.parse("new String(");
|
||||
parser.parseRaw("new String(");
|
||||
Assert.fail();
|
||||
} catch (ParseException e) {
|
||||
Assert.assertTrue(e instanceof SpelParseException);
|
||||
@@ -160,7 +163,7 @@ public class SpelParserTests {
|
||||
}
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
parser.parse("\"abc");
|
||||
parser.parseRaw("\"abc");
|
||||
Assert.fail();
|
||||
} catch (ParseException e) {
|
||||
Assert.assertTrue(e instanceof SpelParseException);
|
||||
@@ -170,7 +173,7 @@ public class SpelParserTests {
|
||||
}
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
parser.parse("'abc");
|
||||
parser.parseRaw("'abc");
|
||||
Assert.fail();
|
||||
} catch (ParseException e) {
|
||||
Assert.assertTrue(e instanceof SpelParseException);
|
||||
@@ -184,69 +187,69 @@ public class SpelParserTests {
|
||||
@Test
|
||||
public void arithmeticPrecedence2() throws EvaluationException,ParseException {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parse("2+3*5");
|
||||
SpelExpression expr = parser.parseRaw("2+3*5");
|
||||
Assert.assertEquals(17,expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence3() throws EvaluationException,ParseException {
|
||||
SpelExpression expr = new SpelExpressionParser().parse("3+10/2");
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("3+10/2");
|
||||
Assert.assertEquals(8,expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence4() throws EvaluationException,ParseException {
|
||||
SpelExpression expr = new SpelExpressionParser().parse("10/2+3");
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("10/2+3");
|
||||
Assert.assertEquals(8,expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence5() throws EvaluationException,ParseException {
|
||||
SpelExpression expr = new SpelExpressionParser().parse("(4+10)/2");
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("(4+10)/2");
|
||||
Assert.assertEquals(7,expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence6() throws EvaluationException,ParseException {
|
||||
SpelExpression expr = new SpelExpressionParser().parse("(3+2)*2");
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("(3+2)*2");
|
||||
Assert.assertEquals(10,expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void booleanOperators() throws EvaluationException,ParseException {
|
||||
SpelExpression expr = new SpelExpressionParser().parse("true");
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("true");
|
||||
Assert.assertEquals(Boolean.TRUE,expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parse("false");
|
||||
expr = new SpelExpressionParser().parseRaw("false");
|
||||
Assert.assertEquals(Boolean.FALSE,expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parse("false and false");
|
||||
expr = new SpelExpressionParser().parseRaw("false and false");
|
||||
Assert.assertEquals(Boolean.FALSE,expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parse("true and (true or false)");
|
||||
expr = new SpelExpressionParser().parseRaw("true and (true or false)");
|
||||
Assert.assertEquals(Boolean.TRUE,expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parse("true and true or false");
|
||||
expr = new SpelExpressionParser().parseRaw("true and true or false");
|
||||
Assert.assertEquals(Boolean.TRUE,expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parse("!true");
|
||||
expr = new SpelExpressionParser().parseRaw("!true");
|
||||
Assert.assertEquals(Boolean.FALSE,expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parse("!(false or true)");
|
||||
expr = new SpelExpressionParser().parseRaw("!(false or true)");
|
||||
Assert.assertEquals(Boolean.FALSE,expr.getValue(Boolean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringLiterals() throws EvaluationException,ParseException {
|
||||
SpelExpression expr = new SpelExpressionParser().parse("'howdy'");
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("'howdy'");
|
||||
Assert.assertEquals("howdy",expr.getValue());
|
||||
expr = new SpelExpressionParser().parse("'hello '' world'");
|
||||
expr = new SpelExpressionParser().parseRaw("'hello '' world'");
|
||||
Assert.assertEquals("hello ' world",expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringLiterals2() throws EvaluationException,ParseException {
|
||||
SpelExpression expr = new SpelExpressionParser().parse("'howdy'.substring(0,2)");
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("'howdy'.substring(0,2)");
|
||||
Assert.assertEquals("ho",expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPositionalInformation() throws EvaluationException, ParseException {
|
||||
SpelExpression expr = new SpelExpressionParser().parse("true and true or false");
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("true and true or false");
|
||||
SpelNode rootAst = expr.getAST();
|
||||
OpOr operatorOr = (OpOr)rootAst;
|
||||
OpAnd operatorAnd = (OpAnd)operatorOr.getLeftOperand();
|
||||
@@ -354,7 +357,7 @@ public class SpelParserTests {
|
||||
private void checkNumber(String expression, Object value, Class<?> type) {
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parse(expression);
|
||||
SpelExpression expr = parser.parseRaw(expression);
|
||||
Object o = expr.getValue();
|
||||
Assert.assertEquals(value,o);
|
||||
Assert.assertEquals(type,o.getClass());
|
||||
@@ -367,7 +370,7 @@ public class SpelParserTests {
|
||||
private void checkNumberError(String expression, SpelMessage expectedMessage) {
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
parser.parse(expression);
|
||||
parser.parseRaw(expression);
|
||||
Assert.fail();
|
||||
} catch (ParseException e) {
|
||||
Assert.assertTrue(e instanceof SpelParseException);
|
||||
Reference in New Issue
Block a user