View Javadoc

1   /*
2    * $Id: InheritedMethodsTest.java 1103095 2011-05-14 13:18:29Z simonetripodi $
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  /**
21   * 
22   */
23  package org.apache.commons.ognl.test;
24  
25  import junit.framework.TestCase;
26  import org.apache.commons.ognl.Node;
27  import org.apache.commons.ognl.Ognl;
28  import org.apache.commons.ognl.OgnlContext;
29  import org.apache.commons.ognl.test.objects.BaseBean;
30  import org.apache.commons.ognl.test.objects.FirstBean;
31  import org.apache.commons.ognl.test.objects.Root;
32  import org.apache.commons.ognl.test.objects.SecondBean;
33  
34  /**
35   * Tests functionality of casting inherited method expressions.
36   */
37  public class InheritedMethodsTest
38      extends TestCase
39  {
40  
41      private static Root ROOT = new Root();
42  
43      public void test_Base_Inheritance()
44          throws Exception
45      {
46          OgnlContext context = (OgnlContext) Ognl.createDefaultContext( null );
47          String expression = "map.bean.name";
48          BaseBean first = new FirstBean();
49          BaseBean second = new SecondBean();
50  
51          ROOT.getMap().put( "bean", first );
52  
53          Node node = Ognl.compileExpression( context, ROOT, expression );
54  
55          assertEquals( first.getName(), node.getAccessor().get( context, ROOT ) );
56  
57          ROOT.getMap().put( "bean", second );
58  
59          assertEquals( second.getName(), node.getAccessor().get( context, ROOT ) );
60      }
61  }