View Javadoc

1   /*
2    * $Id: ProjectionSelectionTest.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.junit.runner.RunWith;
24  import org.junit.runners.Parameterized;
25  import org.junit.runners.Parameterized.Parameters;
26  
27  import java.math.BigInteger;
28  import java.util.ArrayList;
29  import java.util.Arrays;
30  import java.util.Collection;
31  
32  @RunWith(value = Parameterized.class)
33  public class ProjectionSelectionTest
34      extends OgnlTestCase
35  {
36      private static Root ROOT = new Root();
37  
38      private static Object[][] TESTS = {
39          // Projection, selection
40          { ROOT, "array.{class}",
41              Arrays.asList( new Class[] { Integer.class, Integer.class, Integer.class, Integer.class } ) },
42          { ROOT, "map.array.{? #this > 2 }", Arrays.asList( new Integer[] { new Integer( 3 ), new Integer( 4 ) } ) },
43          { ROOT, "map.array.{^ #this > 2 }", Arrays.asList( new Integer[] { new Integer( 3 ) } ) },
44          { ROOT, "map.array.{$ #this > 2 }", Arrays.asList( new Integer[] { new Integer( 4 ) } ) },
45          { ROOT, "map.array[*].{?true} instanceof java.util.Collection", Boolean.TRUE },
46          { null, "#fact=1, 30H.{? #fact = #fact * (#this+1), false }, #fact",
47              new BigInteger( "265252859812191058636308480000000" ) }, };
48  
49      /*
50       * =================================================================== Public static methods
51       * ===================================================================
52       */
53      @Parameters
54      public static Collection<Object[]> data()
55      {
56          Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
57          for ( int i = 0; i < TESTS.length; i++ )
58          {
59              Object[] tmp = new Object[6];
60              tmp[0] = TESTS[i][1];
61              tmp[1] = TESTS[i][0];
62              tmp[2] = TESTS[i][1];
63              tmp[3] = TESTS[i][2];
64  
65              data.add( tmp );
66          }
67          return data;
68      }
69  
70      /*
71       * =================================================================== Constructors
72       * ===================================================================
73       */
74      public ProjectionSelectionTest( String name, Object root, String expressionString, Object expectedResult,
75                                      Object setValue, Object expectedAfterSetResult )
76      {
77          super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
78      }
79  }