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.MethodFailedException;
23 import org.apache.commons.ognl.NoSuchPropertyException;
24 import org.apache.commons.ognl.test.objects.IndexedSetObject;
25 import org.apache.commons.ognl.test.objects.Root;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.Parameterized;
28 import org.junit.runners.Parameterized.Parameters;
29
30 import java.util.ArrayList;
31 import java.util.Collection;
32
33 @RunWith(value = Parameterized.class)
34 public class IndexAccessTest
35 extends OgnlTestCase
36 {
37
38 private static Root ROOT = new Root();
39
40 private static IndexedSetObject INDEXED_SET = new IndexedSetObject();
41
42 private static Object[][] TESTS =
43 {
44 { ROOT, "list[index]", ROOT.getList().get( ROOT.getIndex() ) },
45 { ROOT, "list[objectIndex]", ROOT.getList().get( ROOT.getObjectIndex().intValue() ) },
46 { ROOT, "array[objectIndex]", ROOT.getArray()[ROOT.getObjectIndex().intValue()] },
47 { ROOT, "array[getObjectIndex()]", ROOT.getArray()[ROOT.getObjectIndex().intValue()] },
48 { ROOT, "array[genericIndex]", ROOT.getArray()[( (Integer) ROOT.getGenericIndex() ).intValue()] },
49 { ROOT, "booleanArray[self.objectIndex]", Boolean.FALSE },
50 { ROOT, "booleanArray[getObjectIndex()]", Boolean.FALSE },
51 { ROOT, "booleanArray[nullIndex]", NoSuchPropertyException.class },
52 { ROOT, "list[size() - 1]", MethodFailedException.class },
53 { ROOT, "(index == (array.length - 3)) ? 'toggle toggleSelected' : 'toggle'", "toggle toggleSelected" },
54 { ROOT, "\"return toggleDisplay('excdisplay\"+index+\"', this)\"",
55 "return toggleDisplay('excdisplay1', this)" }, { ROOT, "map[mapKey].split('=')[0]", "StringStuff" },
56 { ROOT, "booleanValues[index1][index2]", Boolean.FALSE },
57 { ROOT, "tab.searchCriteria[index1].displayName", "Woodland creatures" },
58 { ROOT, "tab.searchCriteriaSelections[index1][index2]", Boolean.TRUE },
59 { ROOT, "tab.searchCriteriaSelections[index1][index2]", Boolean.TRUE, Boolean.FALSE, Boolean.FALSE },
60 { ROOT, "map['bar'].value", 100, 50, 50 }, { INDEXED_SET, "thing[\"x\"].val", 1, 2, 2 } };
61
62
63
64
65
66 @Parameters
67 public static Collection<Object[]> data()
68 {
69 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
70 for ( int i = 0; i < TESTS.length; i++ )
71 {
72 Object[] tmp = new Object[6];
73 tmp[0] = TESTS[i][1];
74 tmp[1] = TESTS[i][0];
75 tmp[2] = TESTS[i][1];
76 tmp[3] = TESTS[i][2];
77
78 if ( TESTS[i].length == 5 )
79 {
80 tmp[4] = TESTS[i][3];
81 tmp[5] = TESTS[i][4];
82 }
83
84 data.add( tmp );
85 }
86 return data;
87 }
88
89
90
91
92
93 public IndexAccessTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
94 Object expectedAfterSetResult )
95 {
96 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
97 }
98 }