Search in sources :

Example 1 with ReflectivePropertyAccessor

use of cn.taketoday.expression.spel.support.ReflectivePropertyAccessor in project today-infrastructure by TAKETODAY.

the class SpelReproTests method propertyAccessOnNullTarget_SPR5663.

@Test
void propertyAccessOnNullTarget_SPR5663() throws AccessException {
    PropertyAccessor accessor = new ReflectivePropertyAccessor();
    EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
    assertThat(accessor.canRead(context, null, "abc")).isFalse();
    assertThat(accessor.canWrite(context, null, "abc")).isFalse();
    assertThatIllegalStateException().isThrownBy(() -> accessor.read(context, null, "abc"));
    assertThatIllegalStateException().isThrownBy(() -> accessor.write(context, null, "abc", "foo"));
}
Also used : PropertyAccessor(cn.taketoday.expression.PropertyAccessor) ReflectivePropertyAccessor(cn.taketoday.expression.spel.support.ReflectivePropertyAccessor) EvaluationContext(cn.taketoday.expression.EvaluationContext) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) ReflectivePropertyAccessor(cn.taketoday.expression.spel.support.ReflectivePropertyAccessor) Test(org.junit.jupiter.api.Test)

Example 2 with ReflectivePropertyAccessor

use of cn.taketoday.expression.spel.support.ReflectivePropertyAccessor in project today-infrastructure by TAKETODAY.

the class SpelReproTests method SPR9994_bridgeMethods.

@Test
void SPR9994_bridgeMethods() throws Exception {
    ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
    StandardEvaluationContext context = new StandardEvaluationContext();
    GenericImplementation target = new GenericImplementation();
    accessor.write(context, target, "property", "1");
    assertThat(target.value).isEqualTo(1);
    TypedValue value = accessor.read(context, target, "property");
    assertThat(value.getValue()).isEqualTo(1);
    assertThat(value.getTypeDescriptor().getType()).isEqualTo(Integer.class);
    assertThat(value.getTypeDescriptor().getAnnotations()).isNotEmpty();
}
Also used : StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) ReflectivePropertyAccessor(cn.taketoday.expression.spel.support.ReflectivePropertyAccessor) TypedValue(cn.taketoday.expression.TypedValue) Test(org.junit.jupiter.api.Test)

Example 3 with ReflectivePropertyAccessor

use of cn.taketoday.expression.spel.support.ReflectivePropertyAccessor in project today-framework by TAKETODAY.

the class SpelReproTests method SPR9994_bridgeMethods.

@Test
void SPR9994_bridgeMethods() throws Exception {
    ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
    StandardEvaluationContext context = new StandardEvaluationContext();
    GenericImplementation target = new GenericImplementation();
    accessor.write(context, target, "property", "1");
    assertThat(target.value).isEqualTo(1);
    TypedValue value = accessor.read(context, target, "property");
    assertThat(value.getValue()).isEqualTo(1);
    assertThat(value.getTypeDescriptor().getType()).isEqualTo(Integer.class);
    assertThat(value.getTypeDescriptor().getAnnotations()).isNotEmpty();
}
Also used : StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) ReflectivePropertyAccessor(cn.taketoday.expression.spel.support.ReflectivePropertyAccessor) TypedValue(cn.taketoday.expression.TypedValue) Test(org.junit.jupiter.api.Test)

Example 4 with ReflectivePropertyAccessor

use of cn.taketoday.expression.spel.support.ReflectivePropertyAccessor in project today-framework by TAKETODAY.

the class SpelReproTests method propertyAccessOnNullTarget_SPR5663.

@Test
void propertyAccessOnNullTarget_SPR5663() throws AccessException {
    PropertyAccessor accessor = new ReflectivePropertyAccessor();
    EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
    assertThat(accessor.canRead(context, null, "abc")).isFalse();
    assertThat(accessor.canWrite(context, null, "abc")).isFalse();
    assertThatIllegalStateException().isThrownBy(() -> accessor.read(context, null, "abc"));
    assertThatIllegalStateException().isThrownBy(() -> accessor.write(context, null, "abc", "foo"));
}
Also used : PropertyAccessor(cn.taketoday.expression.PropertyAccessor) ReflectivePropertyAccessor(cn.taketoday.expression.spel.support.ReflectivePropertyAccessor) EvaluationContext(cn.taketoday.expression.EvaluationContext) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) ReflectivePropertyAccessor(cn.taketoday.expression.spel.support.ReflectivePropertyAccessor) Test(org.junit.jupiter.api.Test)

Example 5 with ReflectivePropertyAccessor

use of cn.taketoday.expression.spel.support.ReflectivePropertyAccessor in project today-framework by TAKETODAY.

the class SpelReproTests method SPR10162_onlyBridgeMethod.

@Test
void SPR10162_onlyBridgeMethod() throws Exception {
    ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Object target = new OnlyBridgeMethod();
    TypedValue value = accessor.read(context, target, "property");
    assertThat(value.getValue()).isNull();
    assertThat(value.getTypeDescriptor().getType()).isEqualTo(Integer.class);
}
Also used : StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) ReflectivePropertyAccessor(cn.taketoday.expression.spel.support.ReflectivePropertyAccessor) TypedValue(cn.taketoday.expression.TypedValue) Test(org.junit.jupiter.api.Test)

Aggregations

ReflectivePropertyAccessor (cn.taketoday.expression.spel.support.ReflectivePropertyAccessor)6 StandardEvaluationContext (cn.taketoday.expression.spel.support.StandardEvaluationContext)6 Test (org.junit.jupiter.api.Test)6 TypedValue (cn.taketoday.expression.TypedValue)4 EvaluationContext (cn.taketoday.expression.EvaluationContext)2 PropertyAccessor (cn.taketoday.expression.PropertyAccessor)2