001 /*
002 * $Id: ProjectionSelectionTest.java 1104080 2011-05-17 09:22:09Z mcucchiara $
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 */
020 package org.apache.commons.ognl.test;
021
022 import org.apache.commons.ognl.test.objects.Root;
023 import org.junit.runner.RunWith;
024 import org.junit.runners.Parameterized;
025 import org.junit.runners.Parameterized.Parameters;
026
027 import java.math.BigInteger;
028 import java.util.ArrayList;
029 import java.util.Arrays;
030 import java.util.Collection;
031
032 @RunWith(value = Parameterized.class)
033 public class ProjectionSelectionTest
034 extends OgnlTestCase
035 {
036 private static Root ROOT = new Root();
037
038 private static Object[][] TESTS = {
039 // Projection, selection
040 { ROOT, "array.{class}",
041 Arrays.asList( new Class[] { Integer.class, Integer.class, Integer.class, Integer.class } ) },
042 { ROOT, "map.array.{? #this > 2 }", Arrays.asList( new Integer[] { new Integer( 3 ), new Integer( 4 ) } ) },
043 { ROOT, "map.array.{^ #this > 2 }", Arrays.asList( new Integer[] { new Integer( 3 ) } ) },
044 { ROOT, "map.array.{$ #this > 2 }", Arrays.asList( new Integer[] { new Integer( 4 ) } ) },
045 { ROOT, "map.array[*].{?true} instanceof java.util.Collection", Boolean.TRUE },
046 { null, "#fact=1, 30H.{? #fact = #fact * (#this+1), false }, #fact",
047 new BigInteger( "265252859812191058636308480000000" ) }, };
048
049 /*
050 * =================================================================== Public static methods
051 * ===================================================================
052 */
053 @Parameters
054 public static Collection<Object[]> data()
055 {
056 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
057 for ( int i = 0; i < TESTS.length; i++ )
058 {
059 Object[] tmp = new Object[6];
060 tmp[0] = TESTS[i][1];
061 tmp[1] = TESTS[i][0];
062 tmp[2] = TESTS[i][1];
063 tmp[3] = TESTS[i][2];
064
065 data.add( tmp );
066 }
067 return data;
068 }
069
070 /*
071 * =================================================================== Constructors
072 * ===================================================================
073 */
074 public ProjectionSelectionTest( String name, Object root, String expressionString, Object expectedResult,
075 Object setValue, Object expectedAfterSetResult )
076 {
077 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
078 }
079 }