View Javadoc

1   /*
2    * $Id: PropertyArithmeticAndLogicalOperatorsTest.java 1104080 2011-05-17 09:22:09Z mcucchiara $
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   * http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
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       * =================================================================== Constructors
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 }