You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ni...@apache.org on 2005/09/01 20:12:40 UTC
svn commit: r265760 - in /jakarta/commons/proper/beanutils/trunk: ./
src/java/org/apache/commons/beanutils/ src/test/org/apache/commons/beanutils/
Author: niallp
Date: Thu Sep 1 11:12:19 2005
New Revision: 265760
URL: http://svn.apache.org/viewcvs?rev=265760&view=rev
Log:
Bug 36445 Replace copied code and add mapped property tests - reported by Sam Ruby
Added:
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildBean.java (with props)
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildInterface.java (with props)
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java (with props)
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestInterface.java (with props)
Modified:
jakarta/commons/proper/beanutils/trunk/build.xml
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestBean.java
Modified: jakarta/commons/proper/beanutils/trunk/build.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/build.xml?rev=265760&r1=265759&r2=265760&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/build.xml (original)
+++ jakarta/commons/proper/beanutils/trunk/build.xml Thu Sep 1 11:12:19 2005
@@ -285,7 +285,8 @@
test.lazy.dynaclass,
test.lazy.dynabean,
test.lazy.dynamap,
- test.indexed.properties
+ test.indexed.properties,
+ test.mapped.properties
"
description="Run all unit test cases">
</target>
@@ -541,6 +542,20 @@
</java>
</target>
+ <target name="test.mapped.properties" depends="compile.tests">
+ <echo message="Running Mapped Property tests ..."/>
+ <java classname="${test.runner}" fork="yes"
+ failonerror="${test.failonerror}">
+ <sysproperty key="org.apache.commons.logging.LogFactory"
+ value="${test.factory}"/>
+ <sysproperty key="org.apache.commons.logging.Log"
+ value="${test.log}"/>
+ <sysproperty key="org.apache.commons.logging.simplelog.defaultlog"
+ value="${test.level}"/>
+ <arg value="org.apache.commons.beanutils.MappedPropertyTestCase"/>
+ <classpath refid="test.classpath"/>
+ </java>
+ </target>
<!-- ========== Microbenchmark Cases ===================================== -->
Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java?rev=265760&r1=265759&r2=265760&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java (original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java Thu Sep 1 11:12:19 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -100,17 +100,17 @@
// Look for mapped read method and matching write method
try {
- mappedReadMethod = findMethod(beanClass, "get" + base, 1,
+ mappedReadMethod = getMethod(beanClass, "get" + base,
stringClassArray);
Class params[] = { String.class, mappedReadMethod.getReturnType() };
- mappedWriteMethod = findMethod(beanClass, "set" + base, 2, params);
+ mappedWriteMethod = getMethod(beanClass, "set" + base, params);
} catch (IntrospectionException e) {
;
}
// If there's no read method, then look for just a write method
if (mappedReadMethod == null) {
- mappedWriteMethod = findMethod(beanClass, "set" + base, 2);
+ mappedWriteMethod = getMethod(beanClass, "set" + base, 2);
}
if ((mappedReadMethod == null) && (mappedWriteMethod == null)) {
@@ -154,15 +154,15 @@
// search the mapped get and set methods
mappedReadMethod =
- findMethod(beanClass, mappedGetterName, 1, stringClassArray);
+ getMethod(beanClass, mappedGetterName, stringClassArray);
if (mappedReadMethod != null) {
Class params[] = { String.class, mappedReadMethod.getReturnType() };
mappedWriteMethod =
- findMethod(beanClass, mappedSetterName, 2, params);
+ getMethod(beanClass, mappedSetterName, params);
} else {
mappedWriteMethod =
- findMethod(beanClass, mappedSetterName, 2);
+ getMethod(beanClass, mappedSetterName, 2);
}
findMappedPropertyType();
@@ -313,86 +313,15 @@
return new String(chars);
}
- //======================================================================
- // Package private support methods (copied from java.beans.Introspector).
- //======================================================================
-
- // Cache of Class.getDeclaredMethods.
- //
- // This static variable is safe even when this code is deployed via a
- // shared classloader because it is keyed via a Class object. The same
- // class loaded via two different classloaders will result in different
- // entries in this map.
- //
- // Note, however, that this Hashtable can result in a memory leak. When
- // this class is in a shared classloader it will retain references to
- // classes loaded via a webapp classloader even after the webapp has been
- // undeployed.
- private static java.util.Hashtable
- declaredMethodCache = new java.util.Hashtable();
-
- /*
- * Internal method to return *public* methods within a class.
- */
- private static synchronized Method[] getPublicDeclaredMethods(Class clz) {
- // Looking up Class.getDeclaredMethods is relatively expensive,
- // so we cache the results.
- final Class fclz = clz;
- Method[] result = (Method[]) declaredMethodCache.get(fclz);
- if (result != null) {
- return result;
- }
-
- // We have to raise privilege for getDeclaredMethods
- result = (Method[])
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- try{
-
- return fclz.getDeclaredMethods();
-
- } catch (SecurityException ex) {
- // this means we're in a limited security environment
- // so let's try going through the public methods
- // and null those those that are not from the declaring
- // class
- Method[] methods = fclz.getMethods();
- for (int i = 0, size = methods.length; i < size; i++) {
- Method method = methods[i];
- if (!(fclz.equals(method.getDeclaringClass()))) {
- methods[i] = null;
- }
- }
- return methods;
- }
- }
- });
-
- // Null out any non-public methods.
- for (int i = 0; i < result.length; i++) {
- Method method = result[i];
- if (method != null) {
- int mods = method.getModifiers();
- if (!Modifier.isPublic(mods)) {
- result[i] = null;
- }
- }
- }
-
- // Add it to the cache.
- declaredMethodCache.put(clz, result);
- return result;
- }
-
/**
- * Internal support for finding a target methodName on a given class.
+ * Find a method on a class with a specified number of parameters.
*/
- private static Method internalFindMethod(Class start, String methodName,
- int argCount) {
+ private static Method internalGetMethod(Class initial, String methodName,
+ int parameterCount) {
// For overridden methods we need to find the most derived version.
// So we start with the given class and walk up the superclass chain.
- for (Class cl = start; cl != null; cl = cl.getSuperclass()) {
- Method methods[] = getPublicDeclaredMethods(cl);
+ for (Class clazz = initial; clazz != null; clazz = clazz.getSuperclass()) {
+ Method methods[] = clazz.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method == null) {
@@ -400,11 +329,12 @@
}
// skip static methods.
int mods = method.getModifiers();
- if (Modifier.isStatic(mods)) {
+ if (!Modifier.isPublic(mods) ||
+ Modifier.isStatic(mods)) {
continue;
}
if (method.getName().equals(methodName) &&
- method.getParameterTypes().length == argCount) {
+ method.getParameterTypes().length == parameterCount) {
return method;
}
}
@@ -413,160 +343,55 @@
// Now check any inherited interfaces. This is necessary both when
// the argument class is itself an interface, and when the argument
// class is an abstract class.
- Class ifcs[] = start.getInterfaces();
- for (int i = 0; i < ifcs.length; i++) {
- Method m = internalFindMethod(ifcs[i], methodName, argCount);
- if (m != null) {
- return m;
- }
- }
-
- return null;
- }
-
- /**
- * Internal support for finding a target methodName with a given
- * parameter list on a given class.
- */
- private static Method internalFindMethod(Class start, String methodName,
- int argCount, Class args[]) {
- // For overriden methods we need to find the most derived version.
- // So we start with the given class and walk up the superclass chain.
- for (Class cl = start; cl != null; cl = cl.getSuperclass()) {
- Method methods[] = getPublicDeclaredMethods(cl);
- for (int i = 0; i < methods.length; i++) {
- Method method = methods[i];
- if (method == null) {
- continue;
- }
- // skip static methods.
- int mods = method.getModifiers();
- if (Modifier.isStatic(mods)) {
- continue;
- }
- // make sure method signature matches.
- Class params[] = method.getParameterTypes();
- if (method.getName().equals(methodName) &&
- params.length == argCount) {
- boolean different = false;
- if (argCount > 0) {
- for (int j = 0; j < argCount; j++) {
- if (params[j] != args[j]) {
- different = true;
- continue;
- }
- }
- if (different) {
- continue;
- }
- }
- return method;
- }
+ Class[] interfaces = initial.getInterfaces();
+ for (int i = 0; i < interfaces.length; i++) {
+ Method method = internalGetMethod(interfaces[i], methodName, parameterCount);
+ if (method != null) {
+ return method;
}
}
- // Now check any inherited interfaces. This is necessary both when
- // the argument class is itself an interface, and when the argument
- // class is an abstract class.
- Class ifcs[] = start.getInterfaces();
- for (int i = 0; i < ifcs.length; i++) {
- Method m = internalFindMethod(ifcs[i], methodName, argCount);
- if (m != null) {
- return m;
- }
- }
-
return null;
}
/**
- * Find a target methodName on a given class.
+ * Find a method on a class with a specified number of parameters.
*/
- static Method findMethod(Class cls, String methodName, int argCount)
+ private static Method getMethod(Class clazz, String methodName, int parameterCount)
throws IntrospectionException {
if (methodName == null) {
return null;
}
- Method m = internalFindMethod(cls, methodName, argCount);
- if (m != null) {
- return m;
+ Method method = internalGetMethod(clazz, methodName, parameterCount);
+ if (method != null) {
+ return method;
}
- // We failed to find a suitable method
+ // No Method found
throw new IntrospectionException("No method \"" + methodName +
- "\" with " + argCount + " arg(s)");
+ "\" with " + parameterCount + " parameter(s)");
}
/**
- * Find a target methodName with specific parameter list on a given class.
+ * Find a method on a class with a specified parameter list.
*/
- static Method findMethod(Class cls, String methodName, int argCount,
- Class args[]) throws IntrospectionException {
+ private static Method getMethod(Class clazz, String methodName, Class[] parameterTypes)
+ throws IntrospectionException {
if (methodName == null) {
return null;
}
- Method m = internalFindMethod(cls, methodName, argCount, args);
- if (m != null) {
- return m;
- }
-
- // We failed to find a suitable method
- throw new IntrospectionException("No method \"" + methodName +
- "\" with " + argCount + " arg(s) of matching types.");
- }
-
- /**
- * Return true if class a is either equivalent to class b, or
- * if class a is a subclass of class b, ie if a either "extends"
- * or "implements" b.
- * Note tht either or both "Class" objects may represent interfaces.
- */
- static boolean isSubclass(Class a, Class b) {
- // We rely on the fact that for any given java class or
- // primtitive type there is a unqiue Class object, so
- // we can use object equivalence in the comparisons.
- if (a == b) {
- return true;
- }
-
- if (a == null || b == null) {
- return false;
+ Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, parameterTypes);
+ if (method != null) {
+ return method;
}
- for (Class x = a; x != null; x = x.getSuperclass()) {
- if (x == b) {
- return true;
- }
-
- if (b.isInterface()) {
- Class interfaces[] = x.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- if (isSubclass(interfaces[i], b)) {
- return true;
- }
- }
- }
- }
+ int parameterCount = (parameterTypes == null) ? 0 : parameterTypes.length;
- return false;
+ // No Method found
+ throw new IntrospectionException("No method \"" + methodName +
+ "\" with " + parameterCount + " parameter(s) of matching types.");
}
-
- /**
- * Return true iff the given method throws the given exception.
- */
-
- private boolean throwsException(Method method, Class exception) {
-
- Class exs[] = method.getExceptionTypes();
- for (int i = 0; i < exs.length; i++) {
- if (exs[i] == exception) {
- return true;
- }
- }
-
- return false;
- }
}
Added: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildBean.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildBean.java?rev=265760&view=auto
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildBean.java (added)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildBean.java Thu Sep 1 11:12:19 2005
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.beanutils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Inherited Mapped property test bean.
+ *
+ * @author Niall pemberton
+ * @version $Revision$ $Date$
+ */
+
+public class MappedPropertyChildBean extends MappedPropertyTestBean{
+
+}
Propchange: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildInterface.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildInterface.java?rev=265760&view=auto
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildInterface.java (added)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildInterface.java Thu Sep 1 11:12:19 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.beanutils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test Child Interface
+ *
+ * @author Niall Pemberton
+ * @version $Revision$ $Date$
+ */
+
+public interface MappedPropertyChildInterface extends MappedPropertyTestInterface {
+
+
+}
+
Propchange: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildInterface.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyChildInterface.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestBean.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestBean.java?rev=265760&r1=265759&r2=265760&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestBean.java (original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestBean.java Thu Sep 1 11:12:19 2005
@@ -40,4 +40,42 @@
public void setMapproperty(String key, String value) {
map.put(key, value);
}
+
+ protected String getProtectedMapped(String key) {
+ return (String) map.get(key);
+ }
+
+ protected void setProtectedMapped(String key, String value) {
+ map.put(key, value);
+ }
+
+ public void setMappedPrimitive(int key, int value) {
+ map.put(new Integer(key), new Integer(value));
+ }
+
+ public void setAnyMapped(MappedPropertyTestBean key, MappedPropertyTestBean value) {
+ map.put(key, value);
+ }
+
+ public void setMappedSetterOnly(String key, String value) {
+ map.put(key, value);
+ }
+
+ public String getMappedGetterOnly(String key) {
+ return (String) map.get(key);
+ }
+
+ public String getInvalidGetter(String key, String other) {
+ return (String) map.get(key);
+ }
+
+ public void setInvalidGetter(String key, String value) {
+ map.put(key, value);
+ }
+ public String getInvalidSetter(String key) {
+ return (String) map.get(key);
+ }
+ public void setInvalidSetter(String key, String value, String other) {
+ }
+
}
Added: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java?rev=265760&view=auto
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java (added)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java Thu Sep 1 11:12:19 2005
@@ -0,0 +1,295 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.beanutils;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import java.lang.reflect.Method;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * <p>Test Case for the <code>MappedPropertyDescriptor</code>.</p>
+ *
+ * @author Niall Pemberton
+ */
+public class MappedPropertyTestCase extends TestCase {
+
+ private static final Log log = LogFactory.getLog(MappedPropertyTestCase.class);
+
+
+ // ---------------------------------------------------------- Constructors
+
+ /**
+ * Construct a new instance of this test case.
+ *
+ * @param name Name of the test case
+ */
+ public MappedPropertyTestCase(String name) {
+ super(name);
+ }
+
+ // -------------------------------------------------- Overall Test Methods
+
+ /**
+ * Run this Test
+ */
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * Return the tests included in this test suite.
+ */
+ public static Test suite() {
+ return (new TestSuite(MappedPropertyTestCase.class));
+ }
+
+ /**
+ * Tear down instance variables required by this test case.
+ */
+ public void tearDown() {
+ }
+
+ // ------------------------------------------------ Individual Test Methods
+
+ /**
+ * Test valid method name
+ */
+ public void testFound() {
+ String property = "mapproperty";
+ Class clazz = MappedPropertyTestBean.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ assertNotNull("Getter is missing", desc.getMappedReadMethod());
+ assertNotNull("Setter is missing", desc.getMappedWriteMethod());
+ } catch (Exception ex) {
+ fail("Property '" + property + "' Not Found in " + clazz.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Test invalid method name
+ */
+ public void testNotFound() {
+ String property = "xxxxxxx";
+ Class clazz = MappedPropertyTestBean.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ fail("Property '" + property + "' found in " + clazz.getName());
+ } catch (Exception ex) {
+ // expected result
+ }
+ }
+
+ /**
+ * Test Mapped Property - Getter only
+ */
+ public void testMappedGetterOnly() {
+ String property = "mappedGetterOnly";
+ Class clazz = MappedPropertyTestBean.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ assertNotNull("Getter is missing", desc.getMappedReadMethod());
+ assertNull("Setter is found", desc.getMappedWriteMethod());
+ } catch (Exception ex) {
+ fail("Property '" + property + "' Not Found in " + clazz.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Test Mapped Property - Setter Only
+ */
+ public void testMappedSetterOnly() {
+ String property = "mappedSetterOnly";
+ Class clazz = MappedPropertyTestBean.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ assertNull("Getter is found", desc.getMappedReadMethod());
+ assertNotNull("Setter is missing", desc.getMappedWriteMethod());
+ } catch (Exception ex) {
+ fail("Property '" + property + "' Not Found in " + clazz.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Test Mapped Property - Invalid Setter
+ */
+ public void testInvalidSetter() {
+ String property = "invalidSetter";
+ Class clazz = MappedPropertyTestBean.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ assertNotNull("Getter is missing", desc.getMappedReadMethod());
+ assertNull("Setter is found", desc.getMappedWriteMethod());
+ } catch (Exception ex) {
+ fail("Property '" + property + "' Not Found in " + clazz.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Test Mapped Property - Invalid Getter
+ */
+ public void testInvalidGetter() {
+ String property = "invalidGetter";
+ Class clazz = MappedPropertyTestBean.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ assertNull("Getter is found", desc.getMappedReadMethod());
+ assertNotNull("Setter is missing", desc.getMappedWriteMethod());
+ } catch (Exception ex) {
+ fail("Property '" + property + "' Not Found in " + clazz.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Test property with any two args
+ */
+ public void testAnyArgsProperty() {
+ String property = "anyMapped";
+ Class clazz = MappedPropertyTestBean.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ assertNull("Getter is found", desc.getMappedReadMethod());
+ assertNotNull("Setter is missing", desc.getMappedWriteMethod());
+ } catch (Exception ex) {
+ fail("Property '" + property + "' Not Found in " + clazz.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Test property with two primitve args
+ */
+ public void testPrimitiveArgsProperty() {
+ String property = "mappedPrimitive";
+ Class clazz = MappedPropertyTestBean.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ assertNull("Getter is found", desc.getMappedReadMethod());
+ assertNotNull("Setter is missing", desc.getMappedWriteMethod());
+ } catch (Exception ex) {
+ fail("Property '" + property + "' Not Found in " + clazz.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Test 'protected' mapped property
+ */
+ public void testProtected() {
+ String property = "protectedProperty";
+ Class clazz = MappedPropertyTestBean.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ fail("Property '" + property + "' found in " + clazz.getName());
+ } catch (Exception ex) {
+ // expected result
+ }
+ }
+
+
+ /**
+ * Test 'public' method in parent
+ */
+ public void testPublicParentMethod() {
+ String property = "mapproperty";
+ Class clazz = MappedPropertyChildBean.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ assertNotNull("Getter is missing", desc.getMappedReadMethod());
+ assertNotNull("Setter is missing", desc.getMappedWriteMethod());
+ } catch (Exception ex) {
+ fail("Property '" + property + "' Not Found in " + clazz.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Test 'protected' method in parent
+ */
+ public void testProtectedParentMethod() {
+ String property = "protectedMapped";
+ Class clazz = MappedPropertyChildBean.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ fail("Property '" + property + "' found in " + clazz.getName());
+ } catch (Exception ex) {
+ }
+ }
+
+
+ /**
+ * Test Interface with mapped property
+ */
+ public void testInterfaceMapped() {
+ String property = "mapproperty";
+ Class clazz = MappedPropertyTestInterface.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ assertNotNull("Getter is missing", desc.getMappedReadMethod());
+ assertNotNull("Setter is missing", desc.getMappedWriteMethod());
+ } catch (Exception ex) {
+ fail("Property '" + property + "' Not Found in " + clazz.getName() + ": " + ex);
+ }
+ }
+
+ /**
+ * Test property not found in interface
+ */
+ public void testInterfaceNotFound() {
+ String property = "XXXXXX";
+ Class clazz = MappedPropertyTestInterface.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ fail("Property '" + property + "' found in " + clazz.getName());
+ } catch (Exception ex) {
+ }
+ }
+
+ /**
+ * Test Interface Inherited mapped property
+ */
+ public void testChildInterfaceMapped() {
+ String property = "mapproperty";
+ Class clazz = MappedPropertyChildInterface.class;
+ try {
+ MappedPropertyDescriptor desc
+ = new MappedPropertyDescriptor(property, clazz);
+ assertNotNull("Getter is missing", desc.getMappedReadMethod());
+ assertNotNull("Setter is missing", desc.getMappedWriteMethod());
+ } catch (Exception ex) {
+ fail("Property '" + property + "' Not Found in " + clazz.getName() + ": " + ex);
+ }
+ }
+}
\ No newline at end of file
Propchange: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestInterface.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestInterface.java?rev=265760&view=auto
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestInterface.java (added)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestInterface.java Thu Sep 1 11:12:19 2005
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.beanutils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test Interface
+ *
+ * @author Niall Pemberton
+ * @version $Revision$ $Date$
+ */
+
+public interface MappedPropertyTestInterface {
+
+
+ public String getMapproperty(String key);
+
+ public void setMapproperty(String key, String value);
+
+}
Propchange: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestInterface.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestInterface.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org