use of org.springframework.expression.spel.standard.SpelExpression in project spring-framework by spring-projects.
the class ParsingTests method parseCheck.
/**
* Parse the supplied expression and then create a string representation of the resultant AST, it should be the
* expected value.
*
* @param expression the expression to parse
* @param expectedStringFormOfAST the expected string form of the AST
*/
public void parseCheck(String expression, String expectedStringFormOfAST) {
SpelExpression e = parser.parseRaw(expression);
assertThat(e).isNotNull();
assertThat(e.toStringAST()).isEqualTo(expectedStringFormOfAST);
}
use of org.springframework.expression.spel.standard.SpelExpression in project spring-framework by spring-projects.
the class EvaluationTests method testConstructorInvocation06.
@Test
public void testConstructorInvocation06() {
// repeated evaluation to drive use of cached executor
SpelExpression e = (SpelExpression) parser.parseExpression("new String('wibble')");
String newString = e.getValue(String.class);
assertThat(newString).isEqualTo("wibble");
newString = e.getValue(String.class);
assertThat(newString).isEqualTo("wibble");
// not writable
assertThat(e.isWritable(new StandardEvaluationContext())).isFalse();
// ast
assertThat(e.toStringAST()).isEqualTo("new String('wibble')");
}
use of org.springframework.expression.spel.standard.SpelExpression in project spring-framework by spring-projects.
the class MethodInvocationTests method testMethodFiltering_SPR6764.
@Test
public void testMethodFiltering_SPR6764() {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(new TestObject());
LocalFilter filter = new LocalFilter();
context.registerMethodFilter(TestObject.class, filter);
// Filter will be called but not do anything, so first doit() will be invoked
SpelExpression expr = (SpelExpression) parser.parseExpression("doit(1)");
String result = expr.getValue(context, String.class);
assertThat(result).isEqualTo("1");
assertThat(filter.filterCalled).isTrue();
// Filter will now remove non @Anno annotated methods
filter.removeIfNotAnnotated = true;
filter.filterCalled = false;
expr = (SpelExpression) parser.parseExpression("doit(1)");
result = expr.getValue(context, String.class);
assertThat(result).isEqualTo("double 1.0");
assertThat(filter.filterCalled).isTrue();
// check not called for other types
filter.filterCalled = false;
context.setRootObject(new String("abc"));
expr = (SpelExpression) parser.parseExpression("charAt(0)");
result = expr.getValue(context, String.class);
assertThat(result).isEqualTo("a");
assertThat(filter.filterCalled).isFalse();
// check de-registration works
filter.filterCalled = false;
// clear filter
context.registerMethodFilter(TestObject.class, null);
context.setRootObject(new TestObject());
expr = (SpelExpression) parser.parseExpression("doit(1)");
result = expr.getValue(context, String.class);
assertThat(result).isEqualTo("1");
assertThat(filter.filterCalled).isFalse();
}
use of org.springframework.expression.spel.standard.SpelExpression in project spring-framework by spring-projects.
the class EvaluationTests method operatorVariants.
@Test
public void operatorVariants() {
SpelExpression e = (SpelExpression) parser.parseExpression("#a < #b");
EvaluationContext ctx = new StandardEvaluationContext();
ctx.setVariable("a", (short) 3);
ctx.setVariable("b", (short) 6);
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
ctx.setVariable("b", (byte) 6);
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
ctx.setVariable("a", (byte) 9);
ctx.setVariable("b", (byte) 6);
assertThat(e.getValue(ctx, Boolean.class)).isFalse();
ctx.setVariable("a", 10L);
ctx.setVariable("b", (short) 30);
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
ctx.setVariable("a", (byte) 3);
ctx.setVariable("b", (short) 30);
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
ctx.setVariable("a", (byte) 3);
ctx.setVariable("b", 30L);
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
ctx.setVariable("a", (byte) 3);
ctx.setVariable("b", 30f);
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
ctx.setVariable("a", new BigInteger("10"));
ctx.setVariable("b", new BigInteger("20"));
assertThat(e.getValue(ctx, Boolean.class)).isTrue();
}
use of org.springframework.expression.spel.standard.SpelExpression in project spring-framework by spring-projects.
the class InProgressTests method testProjection06.
@Test
public void testProjection06() throws Exception {
SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.![true]");
assertThat(expr.toStringAST()).isEqualTo("'abc'.![true]");
}
Aggregations