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.test.objects.Root;
23 import org.apache.commons.ognl.test.objects.SimpleNumeric;
24 import org.apache.commons.ognl.test.objects.TestModel;
25 import org.junit.runner.RunWith;
26 import org.junit.runners.Parameterized;
27 import org.junit.runners.Parameterized.Parameters;
28
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.Collection;
32
33
34
35
36 @RunWith(value = Parameterized.class)
37 public class PropertyArithmeticAndLogicalOperatorsTest
38 extends OgnlTestCase
39 {
40
41 private static Root ROOT = new Root();
42
43 private static TestModel MODEL = new TestModel();
44
45 private static SimpleNumeric NUMERIC = new SimpleNumeric();
46
47 private static Object[][] TESTS = {
48 { ROOT, "objectIndex > 0", Boolean.TRUE },
49 { ROOT, "false", Boolean.FALSE },
50 { ROOT, "!false || true", Boolean.TRUE },
51 { ROOT, "property.bean3.value >= 24", Boolean.TRUE },
52 { ROOT, "genericIndex-1", new Integer( 1 ) },
53 { ROOT, "((renderNavigation ? 0 : 1) + map.size) * theInt",
54 new Integer( ( ( ROOT.getRenderNavigation() ? 0 : 1 ) + ROOT.getMap().size() ) * ROOT.getTheInt() ) },
55 { ROOT, "{theInt + 1}", Arrays.asList( new Integer( ROOT.getTheInt() + 1 ) ) },
56 { MODEL, "(unassignedCopyModel.optionCount > 0 && canApproveCopy) || entry.copy.size() > 0", Boolean.TRUE },
57 { ROOT, " !(printDelivery || @Boolean@FALSE)", Boolean.FALSE },
58 { ROOT, "(getIndexedProperty('nested').size - 1) > genericIndex", Boolean.FALSE },
59 { ROOT, "(getIndexedProperty('nested').size + 1) >= genericIndex", Boolean.TRUE },
60 { ROOT, "(getIndexedProperty('nested').size + 1) == genericIndex", Boolean.TRUE },
61 { ROOT, "(getIndexedProperty('nested').size + 1) < genericIndex", Boolean.FALSE },
62 { ROOT, "map.size * genericIndex",
63 new Integer( ROOT.getMap().size() * ( (Integer) ROOT.getGenericIndex() ).intValue() ) },
64 { ROOT, "property == property", Boolean.TRUE }, { ROOT, "property.bean3.value % 2 == 0", Boolean.TRUE },
65 { ROOT, "genericIndex % 3 == 0", Boolean.FALSE },
66 { ROOT, "genericIndex % theInt == property.bean3.value", Boolean.FALSE },
67 { ROOT, "theInt / 100.0", ROOT.getTheInt() / 100.0 },
68 { ROOT, "@java.lang.Long@valueOf('100') == @java.lang.Long@valueOf('100')", Boolean.TRUE },
69 { NUMERIC, "budget - timeBilled", new Double( NUMERIC.getBudget() - NUMERIC.getTimeBilled() ) },
70 { NUMERIC, "(budget % tableSize) == 0", Boolean.TRUE } };
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 tmp[3] = TESTS[i][2];
84
85 if ( TESTS[i].length == 5 )
86 {
87 tmp[4] = TESTS[i][3];
88 tmp[5] = TESTS[i][4];
89 }
90
91 data.add( tmp );
92 }
93 return data;
94 }
95
96
97
98
99
100 public PropertyArithmeticAndLogicalOperatorsTest( String name, Object root, String expressionString,
101 Object expectedResult, Object setValue,
102 Object expectedAfterSetResult )
103 {
104 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
105 }
106 }