Search in sources :

Example 1 with RecordPerson

use of cn.taketoday.expression.spel.testresources.RecordPerson in project today-infrastructure by TAKETODAY.

the class PropertyAccessTests method propertyReadOnlyWithRecordStyle.

@Test
void propertyReadOnlyWithRecordStyle() {
    EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
    Expression expr = parser.parseExpression("name");
    RecordPerson target1 = new RecordPerson("p1");
    assertThat(expr.getValue(context, target1)).isEqualTo("p1");
    RecordPerson target2 = new RecordPerson("p2");
    assertThat(expr.getValue(context, target2)).isEqualTo("p2");
    assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() -> parser.parseExpression("name='p3'").getValue(context, target2));
}
Also used : RecordPerson(cn.taketoday.expression.spel.testresources.RecordPerson) Expression(cn.taketoday.expression.Expression) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) SimpleEvaluationContext(cn.taketoday.expression.spel.support.SimpleEvaluationContext) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) EvaluationContext(cn.taketoday.expression.EvaluationContext) Test(org.junit.jupiter.api.Test)

Example 2 with RecordPerson

use of cn.taketoday.expression.spel.testresources.RecordPerson in project today-framework by TAKETODAY.

the class PropertyAccessTests method propertyReadOnlyWithRecordStyle.

@Test
void propertyReadOnlyWithRecordStyle() {
    EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
    Expression expr = parser.parseExpression("name");
    RecordPerson target1 = new RecordPerson("p1");
    assertThat(expr.getValue(context, target1)).isEqualTo("p1");
    RecordPerson target2 = new RecordPerson("p2");
    assertThat(expr.getValue(context, target2)).isEqualTo("p2");
    assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() -> parser.parseExpression("name='p3'").getValue(context, target2));
}
Also used : RecordPerson(cn.taketoday.expression.spel.testresources.RecordPerson) Expression(cn.taketoday.expression.Expression) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) SimpleEvaluationContext(cn.taketoday.expression.spel.support.SimpleEvaluationContext) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) EvaluationContext(cn.taketoday.expression.EvaluationContext) Test(org.junit.jupiter.api.Test)

Aggregations

EvaluationContext (cn.taketoday.expression.EvaluationContext)2 Expression (cn.taketoday.expression.Expression)2 SpelExpression (cn.taketoday.expression.spel.standard.SpelExpression)2 SimpleEvaluationContext (cn.taketoday.expression.spel.support.SimpleEvaluationContext)2 StandardEvaluationContext (cn.taketoday.expression.spel.support.StandardEvaluationContext)2 RecordPerson (cn.taketoday.expression.spel.testresources.RecordPerson)2 Test (org.junit.jupiter.api.Test)2