DataBindingPropertyAccessor with factory methods (forReadOnlyAccess etc)

Includes configurable write support at ReflectivePropertyAccessor level.

Issue: SPR-16588
This commit is contained in:
Juergen Hoeller
2018-03-22 00:03:06 +01:00
parent 94c525cdc8
commit b5511645b8
3 changed files with 66 additions and 51 deletions

View File

@@ -32,7 +32,7 @@ import org.springframework.expression.PropertyAccessor;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.standard.SpelExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.SimplePropertyAccessor;
import org.springframework.expression.spel.support.DataBindingPropertyAccessor;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.expression.spel.testresources.Person;
@@ -194,14 +194,14 @@ public class PropertyAccessTests extends AbstractExpressionTests {
public void noGetClassAccess() {
Expression expr = parser.parseExpression("'a'.class.getName()");
StandardEvaluationContext context = new StandardEvaluationContext();
context.setPropertyAccessors(Collections.singletonList(new SimplePropertyAccessor()));
context.setPropertyAccessors(Collections.singletonList(DataBindingPropertyAccessor.forReadWriteAccess()));
expr.getValue(context);
}
@Test
public void propertyReadWrite() {
StandardEvaluationContext context = new StandardEvaluationContext();
context.setPropertyAccessors(Collections.singletonList(new SimplePropertyAccessor()));
context.setPropertyAccessors(Collections.singletonList(DataBindingPropertyAccessor.forReadWriteAccess()));
Expression expr = parser.parseExpression("name");
Person target = new Person("p1");
@@ -216,7 +216,7 @@ public class PropertyAccessTests extends AbstractExpressionTests {
@Test(expected = SpelEvaluationException.class)
public void propertyReadOnly() {
StandardEvaluationContext context = new StandardEvaluationContext();
context.setPropertyAccessors(Collections.singletonList(new SimplePropertyAccessor(false)));
context.setPropertyAccessors(Collections.singletonList(DataBindingPropertyAccessor.forReadOnlyAccess()));
Expression expr = parser.parseExpression("name");
Person target = new Person("p1");