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 * 30 * <p> 31 * In BeanUtils 1.7.0 a "package friendly" implementation 32 * of a public interface with defined a "mapped property" 33 * caused an {@link IllegalAccessException} to be thrown by 34 * PropertyUtils's getMappedProperty method. 35 * 36 * <p> 37 * This test case demonstrates the issue. 38 * 39 * @version $Id$ 40 * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-87">https://issues.apache.org/jira/browse/BEANUTILS-87</a> 41 */ 42 public class Jira87TestCase extends TestCase { 43 44 private final Log log = LogFactory.getLog(Jira87TestCase.class); 45 46 /** 47 * Create a test case with the specified name. 48 * 49 * @param name The name of the test 50 */ 51 public Jira87TestCase(final String name) { 52 super(name); 53 } 54 55 /** 56 * Run the Test. 57 * 58 * @param args Arguments 59 */ 60 public static void main(final String[] args) { 61 junit.textui.TestRunner.run(suite()); 62 } 63 64 /** 65 * Create a test suite for this test. 66 * 67 * @return a test suite 68 */ 69 public static Test suite() { 70 return (new TestSuite(Jira87TestCase.class)); 71 } 72 73 /** 74 * Set up. 75 * 76 * @throws java.lang.Exception 77 */ 78 @Override 79 protected void setUp() throws Exception { 80 super.setUp(); 81 } 82 83 /** 84 * Tear Down. 85 * 86 * @throws java.lang.Exception 87 */ 88 @Override 89 protected void tearDown() throws Exception { 90 super.tearDown(); 91 } 92 93 /** 94 * Interface definition with a mapped property 95 */ 96 public void testJira87() { 97 98 final Jira87BeanFactory.PublicMappedInterface bean = Jira87BeanFactory.createMappedPropertyBean(); 99 try { 100 // N.B. The test impl. returns the key value 101 assertEquals("foo", PropertyUtils.getMappedProperty(bean, "value(foo)")); 102 } catch (final Throwable t) { 103 log.error("ERROR " + t, t); 104 fail("Threw exception: " + t); 105 } 106 } 107 }