001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.beanutils.bugs;
018:
019: import junit.framework.Test;
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022:
023: import org.apache.commons.beanutils.PropertyUtils;
024: import org.apache.commons.beanutils.bugs.other.Jira273BeanFactory;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: /**
029: * Public methods overriden in anonymous or private subclasses
030: * are not recognized by PropertyUtils - see issue# BEANUTILS-273.
031: * <p />
032: * See https://issues.apache.org/jira/browse/BEANUTILS-273
033: * <p />
034: *
035: * @version $Revision: 555172 $ $Date: 2007-07-11 06:18:17 +0100 (Wed, 11 Jul 2007) $
036: */
037: public class Jira273TestCase extends TestCase {
038:
039: private Log log = LogFactory.getLog(Jira273TestCase.class);
040:
041: /**
042: * Create a test case with the specified name.
043: *
044: * @param name The name of the test
045: */
046: public Jira273TestCase(String name) {
047: super (name);
048: }
049:
050: /**
051: * Run the Test.
052: *
053: * @param args Arguments
054: */
055: public static void main(String[] args) {
056: junit.textui.TestRunner.run(suite());
057: }
058:
059: /**
060: * Create a test suite for this test.
061: *
062: * @return a test suite
063: */
064: public static Test suite() {
065: return (new TestSuite(Jira273TestCase.class));
066: }
067:
068: /**
069: * Set up.
070: *
071: * @throws java.lang.Exception
072: */
073: protected void setUp() throws Exception {
074: super .setUp();
075: }
076:
077: /**
078: * Tear Down.
079: *
080: * @throws java.lang.Exception
081: */
082: protected void tearDown() throws Exception {
083: super .tearDown();
084: }
085:
086: /**
087: * Test with an annonymous class that overrides a public method
088: * of a public class.
089: */
090: public void testIssue_BEANUTILS_273_AnnonymousOverriden() {
091: Object bean = Jira273BeanFactory.createAnnonymousOverriden();
092: Object result = null;
093: try {
094: result = PropertyUtils.getProperty(bean, "beanValue");
095: } catch (Throwable t) {
096: log.error("AnnonymousOverriden: " + t.getMessage(), t);
097: fail("AnnonymousOverriden Threw exception: " + t);
098: }
099: assertEquals("AnnonymousOverriden", result);
100: }
101:
102: /**
103: * Test with an annonymous class that inherits a public method
104: * of a public class.
105: */
106: public void testIssue_BEANUTILS_273_AnnonymousNotOverriden() {
107: Object bean = Jira273BeanFactory.createAnnonymousNotOverriden();
108: Object result = null;
109: try {
110: result = PropertyUtils.getProperty(bean, "beanValue");
111: } catch (Throwable t) {
112: log.error("AnnonymousNotOverriden: " + t.getMessage(), t);
113: fail("AnnonymousNotOverriden Threw exception: " + t);
114: }
115: assertEquals("PublicBeanWithMethod", result);
116: }
117:
118: /**
119: * Test with an private class that inherits a public method
120: * of a public class.
121: */
122: public void testIssue_BEANUTILS_273_PrivatePublicNotOverriden() {
123: Object bean = Jira273BeanFactory
124: .createPrivatePublicNotOverriden();
125: Object result = null;
126: try {
127: result = PropertyUtils.getProperty(bean, "beanValue");
128: } catch (Throwable t) {
129: log
130: .error("PrivatePublicNotOverriden: "
131: + t.getMessage(), t);
132: fail("PrivatePublicNotOverriden Threw exception: " + t);
133: }
134: assertEquals("PublicBeanWithMethod", result);
135: }
136:
137: /**
138: * Test with an private class that overrides a public method
139: * of a public class.
140: */
141: public void testIssue_BEANUTILS_273_PrivatePublicOverriden() {
142: Object bean = Jira273BeanFactory.createPrivatePublicOverriden();
143: Object result = null;
144: try {
145: result = PropertyUtils.getProperty(bean, "beanValue");
146: } catch (Throwable t) {
147: log.error("PrivatePublicOverriden: " + t.getMessage(), t);
148: fail("PrivatePublicOverriden Threw exception: " + t);
149: }
150: assertEquals("PrivatePublicOverriden", result);
151: }
152:
153: /**
154: * Test with an private class that inherits a public method
155: * of a "grand parent" public class.
156: */
157: public void testIssue_BEANUTILS_273_PrivatePrivatePublicNotOverriden() {
158: Object bean = Jira273BeanFactory
159: .createPrivatePrivatePublicNotOverriden();
160: Object result = null;
161: try {
162: result = PropertyUtils.getProperty(bean, "beanValue");
163: } catch (Throwable t) {
164: log.error("PrivatePrivatePublicNotOverriden: "
165: + t.getMessage(), t);
166: fail("PrivatePrivatePublicNotOverriden Threw exception: "
167: + t);
168: }
169: assertEquals("PublicBeanWithMethod", result);
170: }
171:
172: /**
173: * Test with an private class that overrides a public method
174: * of a "grand parent" public class.
175: */
176: public void testIssue_BEANUTILS_273_PrivatePrivatePublicOverriden() {
177: Object bean = Jira273BeanFactory
178: .createPrivatePrivatePublicOverriden();
179: Object result = null;
180: try {
181: result = PropertyUtils.getProperty(bean, "beanValue");
182: } catch (Throwable t) {
183: log.error("PrivatePrivatePublicOverriden: "
184: + t.getMessage(), t);
185: fail("PrivatePrivatePublicOverriden Threw exception: " + t);
186: }
187: assertEquals("PrivatePrivatePublicOverriden", result);
188: }
189: }
|