001 /*
002 * $Id: ContextVariableTest.java 1188000 2011-10-23 23:10:24Z 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.Simple;
023 import org.junit.runner.RunWith;
024 import org.junit.runners.Parameterized;
025 import org.junit.runners.Parameterized.Parameters;
026
027 import java.util.ArrayList;
028 import java.util.Collection;
029
030 @RunWith(value = Parameterized.class)
031 public class ContextVariableTest
032 extends OgnlTestCase
033 {
034
035 private static Object ROOT = new Simple();
036
037 private static Object[][] TESTS = {
038 // Naming and referring to names
039 { "#root", ROOT }, // Special root reference
040 { "#this", ROOT }, // Special this reference
041 { "#f=5, #s=6, #f + #s", new Integer( 11 ) }, { "#six=(#five=5, 6), #five + #six", new Integer( 11 ) }, };
042
043 /*
044 * =================================================================== Public static methods
045 * ===================================================================
046 */
047 @Parameters
048 public static Collection<Object[]> data()
049 {
050 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
051 for ( int i = 0; i < TESTS.length; i++ )
052 {
053 Object[] tmp = new Object[6];
054 tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")";
055 tmp[1] = ROOT;
056 tmp[2] = TESTS[i][0];
057 tmp[3] = TESTS[i][1];
058 tmp[4] = null;
059 tmp[5] = null;
060
061 data.add( tmp );
062 }
063 return data;
064 }
065
066 /*
067 * =================================================================== Constructors
068 * ===================================================================
069 */
070 public ContextVariableTest( String name, Object root, String expressionString, Object expectedResult,
071 Object setValue, Object expectedAfterSetResult )
072 {
073 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
074 }
075 }