001 /*
002 * $Id: SimpleNavigationChainTreeTest.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 static junit.framework.Assert.assertTrue;
023
024 import java.util.ArrayList;
025 import java.util.Collection;
026
027 import org.apache.commons.ognl.Ognl;
028 import org.junit.Test;
029 import org.junit.runner.RunWith;
030 import org.junit.runners.Parameterized;
031 import org.junit.runners.Parameterized.Parameters;
032
033 @RunWith(value = Parameterized.class)
034 public class SimpleNavigationChainTreeTest
035 extends OgnlTestCase
036 {
037
038 private static Object[][] TESTS = { { "name", Boolean.TRUE }, { "name[i]", Boolean.FALSE },
039 { "name + foo", Boolean.FALSE }, { "name.foo", Boolean.TRUE } };
040
041 /*
042 * =================================================================== Public static methods
043 * ===================================================================
044 */
045 @Parameters
046 public static Collection<Object[]> data()
047 {
048 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
049 for ( int i = 0; i < TESTS.length; i++ )
050 {
051 Object[] tmp = new Object[6];
052 tmp[0] = TESTS[i][0] + " (" + TESTS[i][1] + ")";
053 tmp[1] = null;
054 tmp[2] = TESTS[i][0];
055 tmp[3] = TESTS[i][1];
056
057 data.add( tmp );
058 }
059 return data;
060 }
061
062 /*
063 * =================================================================== Constructors
064 * ===================================================================
065 */
066 public SimpleNavigationChainTreeTest( String name, Object root, String expressionString, Object expectedResult,
067 Object setValue, Object expectedAfterSetResult )
068 {
069 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
070 }
071
072 /*
073 * =================================================================== Overridden methods
074 * ===================================================================
075 */
076 @Test
077 @Override
078 public void runTest()
079 throws Exception
080 {
081 assertTrue( Ognl.isSimpleNavigationChain( getExpression(), _context ) == ( (Boolean) getExpectedResult() ).booleanValue() );
082 }
083 }