use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR9486_floatLessThanDouble.
@Test
public void SPR9486_floatLessThanDouble() {
Boolean expectedNumber = -10.21f < -10.2;
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Expression expression = parser.parseExpression("-10.21f < -10.2");
Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals(expectedNumber, result);
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method checkTemplateParsingError.
private void checkTemplateParsingError(String expression, ParserContext context, String expectedMessage) throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
try {
parser.parseExpression(expression, context);
fail("Should have failed with message: " + expectedMessage);
} catch (Exception ex) {
String message = ex.getMessage();
if (ex instanceof ExpressionException) {
message = ((ExpressionException) ex).getSimpleMessage();
}
if (!message.equals(expectedMessage)) {
ex.printStackTrace();
}
assertThat(expectedMessage, equalTo(message));
}
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method array.
@Test
public void array() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Expression expression = null;
Object result = null;
expression = parser.parseExpression("new java.lang.Long[0].class");
result = expression.getValue(context, "");
assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());
expression = parser.parseExpression("T(java.lang.Long[])");
result = expression.getValue(context, "");
assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());
expression = parser.parseExpression("T(java.lang.String[][][])");
result = expression.getValue(context, "");
assertEquals("Equal assertion failed: ", "class [[[Ljava.lang.String;", result.toString());
assertEquals("T(java.lang.String[][][])", ((SpelExpression) expression).toStringAST());
expression = parser.parseExpression("new int[0].class");
result = expression.getValue(context, "");
assertEquals("Equal assertion failed: ", "class [I", result.toString());
expression = parser.parseExpression("T(int[][])");
result = expression.getValue(context, "");
assertEquals("class [[I", result.toString());
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method elvis_SPR7209_1.
// end bean resolver tests
@Test
public void elvis_SPR7209_1() {
StandardEvaluationContext eContext = new StandardEvaluationContext(new XX());
Expression expr = null;
// Different parts of elvis expression are null
expr = new SpelExpressionParser().parseRaw("(?:'default')");
assertEquals("default", expr.getValue());
expr = new SpelExpressionParser().parseRaw("?:'default'");
assertEquals("default", expr.getValue());
expr = new SpelExpressionParser().parseRaw("?:");
assertEquals(null, expr.getValue());
// Different parts of ternary expression are null
try {
expr = new SpelExpressionParser().parseRaw("(?'abc':'default')");
expr.getValue(eContext);
fail();
} catch (SpelEvaluationException see) {
assertEquals(SpelMessage.TYPE_CONVERSION_ERROR, see.getMessageCode());
}
expr = new SpelExpressionParser().parseRaw("(false?'abc':null)");
assertEquals(null, expr.getValue());
// Assignment
try {
expr = new SpelExpressionParser().parseRaw("(='default')");
expr.getValue(eContext);
fail();
} catch (SpelEvaluationException see) {
assertEquals(SpelMessage.SETVALUE_NOT_SUPPORTED, see.getMessageCode());
}
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR13055.
@Test
@SuppressWarnings("rawtypes")
public void SPR13055() throws Exception {
List<Map<String, Object>> myPayload = new ArrayList<>();
Map<String, Object> v1 = new HashMap<>();
Map<String, Object> v2 = new HashMap<>();
v1.put("test11", "test11");
v1.put("test12", "test12");
v2.put("test21", "test21");
v2.put("test22", "test22");
myPayload.add(v1);
myPayload.add(v2);
EvaluationContext context = new StandardEvaluationContext(myPayload);
ExpressionParser parser = new SpelExpressionParser();
String ex = "#root.![T(org.springframework.util.StringUtils).collectionToCommaDelimitedString(#this.values())]";
List res = parser.parseExpression(ex).getValue(context, List.class);
assertEquals("[test12,test11, test22,test21]", res.toString());
res = parser.parseExpression("#root.![#this.values()]").getValue(context, List.class);
assertEquals("[[test12, test11], [test22, test21]]", res.toString());
res = parser.parseExpression("#root.![values()]").getValue(context, List.class);
assertEquals("[[test12, test11], [test22, test21]]", res.toString());
}
Aggregations