001    /*
002     * $Id: NestedMethodTest.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.Component;
023    import org.junit.Test;
024    import org.junit.runner.RunWith;
025    import org.junit.runners.Parameterized;
026    import org.junit.runners.Parameterized.Parameters;
027    
028    import java.util.ArrayList;
029    import java.util.Collection;
030    
031    @RunWith(value = Parameterized.class)
032    public class NestedMethodTest
033        extends OgnlTestCase
034    {
035    
036        private static Component COMPONENT = new Component();
037    
038        private static Object[][] TESTS = {
039            // Expression in a method call argument
040            { COMPONENT, "toDisplay.pictureUrl", COMPONENT.getToDisplay().getPictureUrl() },
041            { COMPONENT, "page.createRelativeAsset(toDisplay.pictureUrl)",
042                COMPONENT.getPage().createRelativeAsset( COMPONENT.getToDisplay().getPictureUrl() ) }, };
043    
044        /*
045         * =================================================================== Public static methods
046         * ===================================================================
047         */
048        @Parameters
049        public static Collection<Object[]> data()
050        {
051            Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
052            for ( int i = 0; i < TESTS.length; i++ )
053            {
054                Object[] tmp = new Object[6];
055                tmp[0] = TESTS[i][1];
056                tmp[1] = TESTS[i][0];
057                tmp[2] = TESTS[i][1];
058    
059                switch ( TESTS[i].length )
060                {
061                    case 3:
062                        tmp[3] = TESTS[i][2];
063                        break;
064    
065                    case 4:
066                        tmp[3] = TESTS[i][2];
067                        tmp[4] = TESTS[i][3];
068                        break;
069    
070                    case 5:
071                        tmp[3] = TESTS[i][2];
072                        tmp[4] = TESTS[i][3];
073                        tmp[5] = TESTS[i][4];
074                        break;
075    
076                    default:
077                        throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length );
078                }
079    
080                data.add( tmp );
081            }
082            return data;
083        }
084    
085        /*
086         * =================================================================== Constructors
087         * ===================================================================
088         */
089        public NestedMethodTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
090                                 Object expectedAfterSetResult )
091        {
092            super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
093        }
094    
095        @Test
096    
097        @Override
098        public void runTest()
099            throws Exception
100        {
101            super.runTest();
102        }
103    
104    }