1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.commons.ognl.test;
21
22 import junit.framework.TestCase;
23 import org.apache.commons.ognl.Node;
24 import org.apache.commons.ognl.Ognl;
25 import org.apache.commons.ognl.OgnlContext;
26
27 import java.util.Map;
28
29
30
31
32 public class PropertySetterTest
33 extends TestCase
34 {
35
36 private Map map;
37
38 private TestObject testObject = new TestObject( "propertyValue" );
39
40 private String propertyKey = "property";
41
42 public interface TestInterface
43 {
44 public String getProperty();
45 }
46
47 public class TestObject
48 implements TestInterface
49 {
50
51 private String property;
52
53 private Integer integerProperty = 1;
54
55 public TestObject( String property )
56 {
57 this.property = property;
58 }
59
60 public String getProperty()
61 {
62 return property;
63 }
64
65 public void setProperty( String property )
66 {
67 this.property = property;
68 }
69
70 public Integer getIntegerProperty()
71 {
72 return integerProperty;
73 }
74 }
75
76 public Map getMap()
77 {
78 return map;
79 }
80
81 public String getKey()
82 {
83 return "key";
84 }
85
86 public TestObject getObject()
87 {
88 return testObject;
89 }
90
91 public TestInterface getInterfaceObject()
92 {
93 return testObject;
94 }
95
96 public String getPropertyKey()
97 {
98 return propertyKey;
99 }
100
101 public void testEnhancedOgnl()
102 throws Exception
103 {
104 OgnlContext context = (OgnlContext) Ognl.createDefaultContext( null );
105 Node expression = Ognl.compileExpression( context, this, "interfaceObject.property" );
106 Ognl.setValue( expression, context, this, "hello" );
107 assertEquals( "hello", getObject().getProperty() );
108
109
110 context.clear();
111
112 expression = Ognl.compileExpression( context, this.getObject(), "property" );
113 Ognl.setValue( expression, context, this.getObject(), "hello" );
114 assertEquals( "hello", getObject().getProperty() );
115 }
116 }