use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class SpelDocumentationTests method testEqualityCheck.
@Test
public void testEqualityCheck() throws Exception {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(tesla);
Expression exp = parser.parseExpression("name == 'Nikola Tesla'");
// evaluates to true
boolean isEqual = exp.getValue(context, Boolean.class);
assertTrue(isEqual);
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class SpelReproTests method SPR10486.
@Test
public void SPR10486() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Spr10486 rootObject = new Spr10486();
Expression classNameExpression = parser.parseExpression("class.name");
Expression nameExpression = parser.parseExpression("name");
assertThat(classNameExpression.getValue(context, rootObject), equalTo((Object) Spr10486.class.getName()));
assertThat(nameExpression.getValue(context, rootObject), equalTo((Object) "name"));
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class SpelReproTests method SPR11142.
@Test
public void SPR11142() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Spr11142 rootObject = new Spr11142();
Expression expression = parser.parseExpression("something");
thrown.expect(SpelEvaluationException.class);
thrown.expectMessage("'something' cannot be found");
expression.getValue(context, rootObject);
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class SpelReproTests method AccessingFactoryBean_spr9511.
@Test
public void AccessingFactoryBean_spr9511() {
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new MyBeanResolver());
Expression expr = new SpelExpressionParser().parseRaw("@foo");
assertEquals("custard", expr.getValue(context));
expr = new SpelExpressionParser().parseRaw("&foo");
assertEquals("foo factory", expr.getValue(context));
try {
expr = new SpelExpressionParser().parseRaw("&@foo");
fail("Illegal syntax, error expected");
} catch (SpelParseException spe) {
assertEquals(SpelMessage.INVALID_BEAN_REFERENCE, spe.getMessageCode());
assertEquals(0, spe.getPosition());
}
try {
expr = new SpelExpressionParser().parseRaw("@&foo");
fail("Illegal syntax, error expected");
} catch (SpelParseException spe) {
assertEquals(SpelMessage.INVALID_BEAN_REFERENCE, spe.getMessageCode());
assertEquals(0, spe.getPosition());
}
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class SpelReproTests method projectionTypeDescriptors_2.
@Test
public void projectionTypeDescriptors_2() throws Exception {
StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
SpelExpressionParser parser = new SpelExpressionParser();
String el1 = "as.![#this.equals('abc')]";
SpelExpression exp = parser.parseRaw(el1);
Object[] value = (Object[]) exp.getValue(ctx);
// value is array containing [true,false]
assertEquals(Boolean.class, value[0].getClass());
TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
assertEquals(Boolean.class, evaluated.getElementTypeDescriptor().getType());
}
Aggregations