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 org.apache.commons.ognl.InappropriateExpressionException;
23 import org.apache.commons.ognl.NoSuchPropertyException;
24 import org.apache.commons.ognl.test.objects.Root;
25 import org.junit.runner.RunWith;
26 import org.junit.runners.Parameterized;
27 import org.junit.runners.Parameterized.Parameters;
28
29 import java.util.*;
30
31 @RunWith(value = Parameterized.class)
32 public class SetterTest
33 extends OgnlTestCase
34 {
35 private static Root ROOT = new Root();
36
37 static Set _list = new HashSet();
38 static
39 {
40 _list.add( "Test1" );
41 }
42
43 private static Object[][] TESTS = {
44
45 { ROOT.getMap(), "newValue", null, new Integer( 101 ) },
46 { ROOT, "settableList[0]", "foo", "quux" },
47 { ROOT, "settableList[0]", "quux" },
48 { ROOT, "settableList[2]", "baz", "quux" },
49 { ROOT, "settableList[2]", "quux" },
50 { ROOT, "settableList[$]", "quux", "oompa" },
51 { ROOT, "settableList[$]", "oompa" },
52 { ROOT, "settableList[^]", "quux", "oompa" },
53 { ROOT, "settableList[^]", "oompa" },
54 { ROOT, "settableList[|]", "bar", "oompa" },
55 { ROOT, "settableList[|]", "oompa" },
56 { ROOT, "map.newValue", new Integer( 101 ), new Integer( 555 ) },
57 { ROOT, "map", ROOT.getMap(), new HashMap(), NoSuchPropertyException.class },
58 { ROOT.getMap(), "newValue2 || put(\"newValue2\",987), newValue2", new Integer( 987 ), new Integer( 1002 ) },
59 { ROOT, "map.(someMissingKey || newValue)", new Integer( 555 ), new Integer( 666 ) },
60 { ROOT.getMap(), "newValue || someMissingKey", new Integer( 666 ), new Integer( 666 ) },
61 { ROOT, "map.(newValue && aKey)", null, new Integer( 54321 ) },
62 { ROOT, "map.(someMissingKey && newValue)", null, null },
63 { null, "0", new Integer( 0 ), null, InappropriateExpressionException.class },
64
65 { ROOT, "map[0]=\"map.newValue\", map[0](#this)", new Integer( 666 ), new Integer( 888 ) },
66 { ROOT, "selectedList", null, _list, IllegalArgumentException.class },
67 { ROOT, "openTransitionWin", Boolean.FALSE, Boolean.TRUE } };
68
69
70
71
72
73 @Parameters
74 public static Collection<Object[]> data()
75 {
76 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
77 for ( int i = 0; i < TESTS.length; i++ )
78 {
79 Object[] tmp = new Object[6];
80 tmp[0] = TESTS[i][1];
81 tmp[1] = TESTS[i][0];
82 tmp[2] = TESTS[i][1];
83
84 switch ( TESTS[i].length )
85 {
86 case 3:
87 tmp[3] = TESTS[i][2];
88 break;
89
90 case 4:
91 tmp[3] = TESTS[i][2];
92 tmp[4] = TESTS[i][3];
93 break;
94
95 case 5:
96 tmp[3] = TESTS[i][2];
97 tmp[4] = TESTS[i][3];
98 tmp[5] = TESTS[i][4];
99 break;
100
101 default:
102 throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length );
103 }
104
105 data.add( tmp );
106 }
107 return data;
108 }
109
110
111
112
113
114 public SetterTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
115 Object expectedAfterSetResult )
116 {
117 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
118 }
119 }