Consistent ExpressionException-style quoting of expression string and position
Issue: SPR-14942
This commit is contained in:
@@ -1663,15 +1663,15 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void SPR10146_malformedExpressions() throws Exception {
|
||||
doTestSpr10146("/foo", "EL1070E:(pos 0): Problem parsing left operand");
|
||||
doTestSpr10146("*foo", "EL1070E:(pos 0): Problem parsing left operand");
|
||||
doTestSpr10146("%foo", "EL1070E:(pos 0): Problem parsing left operand");
|
||||
doTestSpr10146("<foo", "EL1070E:(pos 0): Problem parsing left operand");
|
||||
doTestSpr10146(">foo", "EL1070E:(pos 0): Problem parsing left operand");
|
||||
doTestSpr10146("&&foo", "EL1070E:(pos 0): Problem parsing left operand");
|
||||
doTestSpr10146("||foo", "EL1070E:(pos 0): Problem parsing left operand");
|
||||
doTestSpr10146("&foo", "EL1069E:(pos 0): missing expected character '&'");
|
||||
doTestSpr10146("|foo", "EL1069E:(pos 0): missing expected character '|'");
|
||||
doTestSpr10146("/foo", "EL1070E: Problem parsing left operand");
|
||||
doTestSpr10146("*foo", "EL1070E: Problem parsing left operand");
|
||||
doTestSpr10146("%foo", "EL1070E: Problem parsing left operand");
|
||||
doTestSpr10146("<foo", "EL1070E: Problem parsing left operand");
|
||||
doTestSpr10146(">foo", "EL1070E: Problem parsing left operand");
|
||||
doTestSpr10146("&&foo", "EL1070E: Problem parsing left operand");
|
||||
doTestSpr10146("||foo", "EL1070E: Problem parsing left operand");
|
||||
doTestSpr10146("&foo", "EL1069E: missing expected character '&'");
|
||||
doTestSpr10146("|foo", "EL1069E: missing expected character '|'");
|
||||
}
|
||||
|
||||
private void doTestSpr10146(String expression, String expectedMessage) {
|
||||
@@ -1702,7 +1702,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void SPR10328() throws Exception {
|
||||
thrown.expect(SpelParseException.class);
|
||||
thrown.expectMessage("EL1071E:(pos 2): A required selection expression has not been specified");
|
||||
thrown.expectMessage("EL1071E: A required selection expression has not been specified");
|
||||
Expression exp = parser.parseExpression("$[]");
|
||||
exp.getValue(Arrays.asList("foo", "bar", "baz"));
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.expression.spel.standard;
|
||||
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.SpelMessage;
|
||||
@@ -33,11 +32,12 @@ import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Andy Clement
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class SpelParserTests {
|
||||
|
||||
@Test
|
||||
public void theMostBasic() throws EvaluationException, ParseException {
|
||||
public void theMostBasic() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2");
|
||||
assertNotNull(expr);
|
||||
@@ -48,7 +48,7 @@ public class SpelParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueType() throws Exception {
|
||||
public void valueType() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
EvaluationContext ctx = new StandardEvaluationContext();
|
||||
Class<?> c = parser.parseRaw("2").getValueType();
|
||||
@@ -64,7 +64,7 @@ public class SpelParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whitespace() throws EvaluationException, ParseException {
|
||||
public void whitespace() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2 + 3");
|
||||
assertEquals(5, expr.getValue());
|
||||
@@ -77,7 +77,7 @@ public class SpelParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPlus1() throws EvaluationException, ParseException {
|
||||
public void arithmeticPlus1() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2+2");
|
||||
assertNotNull(expr);
|
||||
@@ -86,14 +86,14 @@ public class SpelParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPlus2() throws EvaluationException, ParseException {
|
||||
public void arithmeticPlus2() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("37+41");
|
||||
assertEquals(78, expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticMultiply1() throws EvaluationException, ParseException {
|
||||
public void arithmeticMultiply1() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2*3");
|
||||
assertNotNull(expr);
|
||||
@@ -103,15 +103,14 @@ public class SpelParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence1() throws EvaluationException, ParseException {
|
||||
public void arithmeticPrecedence1() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2*3+5");
|
||||
assertEquals(11, expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generalExpressions() throws Exception {
|
||||
|
||||
public void generalExpressions() {
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
parser.parseRaw("new String");
|
||||
@@ -122,6 +121,7 @@ public class SpelParserTests {
|
||||
SpelParseException spe = (SpelParseException) ex;
|
||||
assertEquals(SpelMessage.MISSING_CONSTRUCTOR_ARGS, spe.getMessageCode());
|
||||
assertEquals(10, spe.getPosition());
|
||||
assertTrue(ex.getMessage().contains(ex.getExpressionString()));
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -134,6 +134,7 @@ public class SpelParserTests {
|
||||
SpelParseException spe = (SpelParseException) ex;
|
||||
assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode());
|
||||
assertEquals(10, spe.getPosition());
|
||||
assertTrue(ex.getMessage().contains(ex.getExpressionString()));
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -146,6 +147,7 @@ public class SpelParserTests {
|
||||
SpelParseException spe = (SpelParseException) ex;
|
||||
assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode());
|
||||
assertEquals(10, spe.getPosition());
|
||||
assertTrue(ex.getMessage().contains(ex.getExpressionString()));
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -158,6 +160,7 @@ public class SpelParserTests {
|
||||
SpelParseException spe = (SpelParseException) ex;
|
||||
assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode());
|
||||
assertEquals(10, spe.getPosition());
|
||||
assertTrue(ex.getMessage().contains(ex.getExpressionString()));
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -170,6 +173,7 @@ public class SpelParserTests {
|
||||
SpelParseException spe = (SpelParseException) ex;
|
||||
assertEquals(SpelMessage.NON_TERMINATING_DOUBLE_QUOTED_STRING, spe.getMessageCode());
|
||||
assertEquals(0, spe.getPosition());
|
||||
assertTrue(ex.getMessage().contains(ex.getExpressionString()));
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -182,43 +186,44 @@ public class SpelParserTests {
|
||||
SpelParseException spe = (SpelParseException) ex;
|
||||
assertEquals(SpelMessage.NON_TERMINATING_QUOTED_STRING, spe.getMessageCode());
|
||||
assertEquals(0, spe.getPosition());
|
||||
assertTrue(ex.getMessage().contains(ex.getExpressionString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence2() throws EvaluationException, ParseException {
|
||||
public void arithmeticPrecedence2() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw("2+3*5");
|
||||
assertEquals(17, expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence3() throws EvaluationException, ParseException {
|
||||
public void arithmeticPrecedence3() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("3+10/2");
|
||||
assertEquals(8, expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence4() throws EvaluationException, ParseException {
|
||||
public void arithmeticPrecedence4() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("10/2+3");
|
||||
assertEquals(8, expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence5() throws EvaluationException, ParseException {
|
||||
public void arithmeticPrecedence5() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("(4+10)/2");
|
||||
assertEquals(7, expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arithmeticPrecedence6() throws EvaluationException, ParseException {
|
||||
public void arithmeticPrecedence6() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("(3+2)*2");
|
||||
assertEquals(10, expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void booleanOperators() throws EvaluationException, ParseException {
|
||||
public void booleanOperators() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("true");
|
||||
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parseRaw("false");
|
||||
@@ -236,7 +241,7 @@ public class SpelParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void booleanOperators_symbolic_spr9614() throws EvaluationException, ParseException {
|
||||
public void booleanOperators_symbolic_spr9614() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("true");
|
||||
assertEquals(Boolean.TRUE, expr.getValue(Boolean.class));
|
||||
expr = new SpelExpressionParser().parseRaw("false");
|
||||
@@ -254,7 +259,7 @@ public class SpelParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringLiterals() throws EvaluationException, ParseException {
|
||||
public void stringLiterals() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("'howdy'");
|
||||
assertEquals("howdy", expr.getValue());
|
||||
expr = new SpelExpressionParser().parseRaw("'hello '' world'");
|
||||
@@ -262,13 +267,13 @@ public class SpelParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringLiterals2() throws EvaluationException, ParseException {
|
||||
public void stringLiterals2() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("'howdy'.substring(0,2)");
|
||||
assertEquals("ho", expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringLiterals_DoubleQuotes_spr9620() throws Exception {
|
||||
public void testStringLiterals_DoubleQuotes_spr9620() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("\"double quote: \"\".\"");
|
||||
assertEquals("double quote: \".", expr.getValue());
|
||||
expr = new SpelExpressionParser().parseRaw("\"hello \"\" world\"");
|
||||
@@ -276,7 +281,7 @@ public class SpelParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringLiterals_DoubleQuotes_spr9620_2() throws Exception {
|
||||
public void testStringLiterals_DoubleQuotes_spr9620_2() {
|
||||
try {
|
||||
new SpelExpressionParser().parseRaw("\"double quote: \\\"\\\".\"");
|
||||
fail("Should have failed");
|
||||
@@ -288,7 +293,7 @@ public class SpelParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void positionalInformation() throws EvaluationException, ParseException {
|
||||
public void positionalInformation() {
|
||||
SpelExpression expr = new SpelExpressionParser().parseRaw("true and true or false");
|
||||
SpelNode rootAst = expr.getAST();
|
||||
OpOr operatorOr = (OpOr) rootAst;
|
||||
@@ -355,13 +360,13 @@ public class SpelParserTests {
|
||||
|
||||
exprEx = new ExpressionException("wibble", "test");
|
||||
assertEquals("test", exprEx.getSimpleMessage());
|
||||
assertEquals("Expression 'wibble': test", exprEx.toDetailedString());
|
||||
assertEquals("Expression 'wibble': test", exprEx.getMessage());
|
||||
assertEquals("Expression [wibble]: test", exprEx.toDetailedString());
|
||||
assertEquals("Expression [wibble]: test", exprEx.getMessage());
|
||||
|
||||
exprEx = new ExpressionException("wibble", 3, "test");
|
||||
assertEquals("test", exprEx.getSimpleMessage());
|
||||
assertEquals("Expression 'wibble' @ 3: test", exprEx.toDetailedString());
|
||||
assertEquals("Expression 'wibble' @ 3: test", exprEx.getMessage());
|
||||
assertEquals("Expression [wibble] @3: test", exprEx.toDetailedString());
|
||||
assertEquals("Expression [wibble] @3: test", exprEx.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -401,16 +406,16 @@ public class SpelParserTests {
|
||||
checkNumber("1e+3", 1e3d, Double.class);
|
||||
}
|
||||
|
||||
|
||||
private void checkNumber(String expression, Object value, Class<?> type) {
|
||||
try {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
SpelExpression expr = parser.parseRaw(expression);
|
||||
Object o = expr.getValue();
|
||||
assertEquals(value, o);
|
||||
assertEquals(type, o.getClass());
|
||||
Object exprVal = expr.getValue();
|
||||
assertEquals(value, exprVal);
|
||||
assertEquals(type, exprVal.getClass());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user