1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.beanutils.bugs;
18  
19  import org.apache.commons.beanutils.PropertyUtils;
20  import org.apache.commons.beanutils.bugs.other.Jira87BeanFactory;
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import junit.framework.Test;
24  import junit.framework.TestCase;
25  import junit.framework.TestSuite;
26  
27  /***
28   * Test case for Jiar issue# BEANUTILS-87.
29   * <p />
30   * See https://issues.apache.org/jira/browse/BEANUTILS-87
31   * <p />
32   * In BeanUtils 1.7.0 a "package friendly" implementation
33   * of a public interface with defined a "mapped property"
34   * caused an {@link IllegalAccessException} to be thrown by
35   * PropertyUtils's getMappedProperty method.
36   * <p />
37   * This test case demonstrates the issue.
38   *
39   * @version $Revision: 541308 $ $Date: 2007-05-24 15:31:50 +0100 (Thu, 24 May 2007) $
40   */
41  public class Jira87TestCase extends TestCase {
42  
43      private Log log = LogFactory.getLog(Jira87TestCase.class);
44  
45      /***
46       * Create a test case with the specified name.
47       *
48       * @param name The name of the test
49       */
50      public Jira87TestCase(String name) {
51          super(name);
52      }
53  
54      /***
55       * Run the Test.
56       *
57       * @param args Arguments
58       */
59      public static void main(String[] args) {
60          junit.textui.TestRunner.run(suite());
61      }
62  
63      /***
64       * Create a test suite for this test.
65       *
66       * @return a test suite
67       */
68      public static Test suite() {
69          return (new TestSuite(Jira87TestCase.class));
70      }
71  
72      /***
73       * Set up.
74       *
75       * @throws java.lang.Exception
76       */
77      protected void setUp() throws Exception {
78          super.setUp();
79      }
80  
81      /***
82       * Tear Down.
83       *
84       * @throws java.lang.Exception
85       */
86      protected void tearDown() throws Exception {
87          super.tearDown();
88      }
89  
90      /***
91       * Interface definition with a mapped property
92       */
93      public void testJira87() {
94  
95          Jira87BeanFactory.PublicMappedInterface bean = Jira87BeanFactory.createMappedPropertyBean();
96          try {
97              // N.B. The test impl. returns the key value
98              assertEquals("foo", PropertyUtils.getMappedProperty(bean, "value(foo)"));
99          } catch (Throwable t) {
100             log.error("ERROR " + t, t);
101             fail("Threw exception: " + t);
102         }
103     }
104 }