1 /*
2 * $Id: NestedMethodTest.java 1188000 2011-10-23 23:10:24Z 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.Component;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.junit.runners.Parameterized;
26 import org.junit.runners.Parameterized.Parameters;
27
28 import java.util.ArrayList;
29 import java.util.Collection;
30
31 @RunWith(value = Parameterized.class)
32 public class NestedMethodTest
33 extends OgnlTestCase
34 {
35
36 private static Component COMPONENT = new Component();
37
38 private static Object[][] TESTS = {
39 // Expression in a method call argument
40 { COMPONENT, "toDisplay.pictureUrl", COMPONENT.getToDisplay().getPictureUrl() },
41 { COMPONENT, "page.createRelativeAsset(toDisplay.pictureUrl)",
42 COMPONENT.getPage().createRelativeAsset( COMPONENT.getToDisplay().getPictureUrl() ) }, };
43
44 /*
45 * =================================================================== Public static methods
46 * ===================================================================
47 */
48 @Parameters
49 public static Collection<Object[]> data()
50 {
51 Collection<Object[]> data = new ArrayList<Object[]>(TESTS.length);
52 for ( int i = 0; i < TESTS.length; i++ )
53 {
54 Object[] tmp = new Object[6];
55 tmp[0] = TESTS[i][1];
56 tmp[1] = TESTS[i][0];
57 tmp[2] = TESTS[i][1];
58
59 switch ( TESTS[i].length )
60 {
61 case 3:
62 tmp[3] = TESTS[i][2];
63 break;
64
65 case 4:
66 tmp[3] = TESTS[i][2];
67 tmp[4] = TESTS[i][3];
68 break;
69
70 case 5:
71 tmp[3] = TESTS[i][2];
72 tmp[4] = TESTS[i][3];
73 tmp[5] = TESTS[i][4];
74 break;
75
76 default:
77 throw new RuntimeException( "don't understand TEST format with length " + TESTS[i].length );
78 }
79
80 data.add( tmp );
81 }
82 return data;
83 }
84
85 /*
86 * =================================================================== Constructors
87 * ===================================================================
88 */
89 public NestedMethodTest( String name, Object root, String expressionString, Object expectedResult, Object setValue,
90 Object expectedAfterSetResult )
91 {
92 super( name, root, expressionString, expectedResult, setValue, expectedAfterSetResult );
93 }
94
95 @Test
96
97 @Override
98 public void runTest()
99 throws Exception
100 {
101 super.runTest();
102 }
103
104 }