use of cn.taketoday.expression.spel.testresources.Person in project today-infrastructure by TAKETODAY.
the class PropertyAccessTests method propertyAccessWithInstanceMethodResolverAndTypedRootObject.
@Test
void propertyAccessWithInstanceMethodResolverAndTypedRootObject() {
Person rootObject = new Person("p1");
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().withInstanceMethods().withTypedRootObject(rootObject, TypeDescriptor.valueOf(Object.class)).build();
assertThat(parser.parseExpression("name.substring(1)").getValue(context)).isEqualTo("1");
assertThat(context.getRootObject().getValue()).isSameAs(rootObject);
assertThat(context.getRootObject().getTypeDescriptor().getType()).isSameAs(Object.class);
}
use of cn.taketoday.expression.spel.testresources.Person in project today-framework by TAKETODAY.
the class PropertyAccessTests method propertyAccessWithInstanceMethodResolverAndTypedRootObject.
@Test
void propertyAccessWithInstanceMethodResolverAndTypedRootObject() {
Person rootObject = new Person("p1");
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().withInstanceMethods().withTypedRootObject(rootObject, TypeDescriptor.valueOf(Object.class)).build();
assertThat(parser.parseExpression("name.substring(1)").getValue(context)).isEqualTo("1");
assertThat(context.getRootObject().getValue()).isSameAs(rootObject);
assertThat(context.getRootObject().getTypeDescriptor().getType()).isSameAs(Object.class);
}
use of cn.taketoday.expression.spel.testresources.Person in project today-framework by TAKETODAY.
the class PropertyAccessTests method propertyAccessWithInstanceMethodResolver.
@Test
void propertyAccessWithInstanceMethodResolver() {
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().withInstanceMethods().build();
Person target = new Person("p1");
assertThat(parser.parseExpression("name.substring(1)").getValue(context, target)).isEqualTo("1");
}
use of cn.taketoday.expression.spel.testresources.Person in project today-framework by TAKETODAY.
the class PropertyAccessTests method propertyReadOnly.
@Test
void propertyReadOnly() {
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
Expression expr = parser.parseExpression("name");
Person target = new Person("p1");
assertThat(expr.getValue(context, target)).isEqualTo("p1");
target.setName("p2");
assertThat(expr.getValue(context, target)).isEqualTo("p2");
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() -> parser.parseExpression("name='p3'").getValue(context, target));
}
use of cn.taketoday.expression.spel.testresources.Person in project today-framework by TAKETODAY.
the class PropertyAccessTests method propertyReadWrite.
@Test
void propertyReadWrite() {
EvaluationContext context = SimpleEvaluationContext.forReadWriteDataBinding().build();
Expression expr = parser.parseExpression("name");
Person target = new Person("p1");
assertThat(expr.getValue(context, target)).isEqualTo("p1");
target.setName("p2");
assertThat(expr.getValue(context, target)).isEqualTo("p2");
parser.parseExpression("name='p3'").getValue(context, target);
assertThat(target.getName()).isEqualTo("p3");
assertThat(expr.getValue(context, target)).isEqualTo("p3");
expr.setValue(context, target, "p4");
assertThat(target.getName()).isEqualTo("p4");
assertThat(expr.getValue(context, target)).isEqualTo("p4");
}
Aggregations