use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class ExpressionEvaluatorTests method withoutReturnValue.
@Test
public void withoutReturnValue() throws Exception {
EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.NO_RESULT);
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value, nullValue());
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class ExpressionEvaluatorTests method withNullReturn.
@Test
public void withNullReturn() throws Exception {
EvaluationContext context = createEvaluationContext(null);
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value, nullValue());
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class ExpressionEvaluatorTests method withReturnValue.
@Test
public void withReturnValue() throws Exception {
EvaluationContext context = createEvaluationContext("theResult");
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value, equalTo("theResult"));
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class ExpressionEvaluatorTests method resolveBeanReference.
@Test
public void resolveBeanReference() throws Exception {
StaticApplicationContext applicationContext = new StaticApplicationContext();
BeanDefinition beanDefinition = new RootBeanDefinition(String.class);
applicationContext.registerBeanDefinition("myBean", beanDefinition);
applicationContext.refresh();
EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.NO_RESULT, applicationContext);
Object value = new SpelExpressionParser().parseExpression("@myBean.class.getName()").getValue(context);
assertThat(value, is(String.class.getName()));
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class EvaluationTests method initializingCollectionElementsOnWrite.
/**
* SPR-6984: attempting to index a collection on write using an index that
* doesn't currently exist in the collection (address.crossStreets[0] below)
*/
@Test
public void initializingCollectionElementsOnWrite() throws Exception {
TestPerson person = new TestPerson();
EvaluationContext context = new StandardEvaluationContext(person);
SpelParserConfiguration config = new SpelParserConfiguration(true, true);
ExpressionParser parser = new SpelExpressionParser(config);
Expression expression = parser.parseExpression("name");
expression.setValue(context, "Oleg");
assertEquals("Oleg", person.getName());
expression = parser.parseExpression("address.street");
expression.setValue(context, "123 High St");
assertEquals("123 High St", person.getAddress().getStreet());
expression = parser.parseExpression("address.crossStreets[0]");
expression.setValue(context, "Blah");
assertEquals("Blah", person.getAddress().getCrossStreets().get(0));
expression = parser.parseExpression("address.crossStreets[3]");
expression.setValue(context, "Wibble");
assertEquals("Blah", person.getAddress().getCrossStreets().get(0));
assertEquals("Wibble", person.getAddress().getCrossStreets().get(3));
}
Aggregations