openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r881381 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetamodel.java openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties
Date Tue, 17 Nov 2009 17:13:49 GMT
Author: ppoddar
Date: Tue Nov 17 17:13:48 2009
New Revision: 881381

URL: http://svn.apache.org/viewvc?rev=881381&view=rev
Log:
Add error messages for attribute not found exceptions.

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetamodel.java
    openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetamodel.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetamodel.java?rev=881381&r1=881380&r2=881381&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetamodel.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetamodel.java
Tue Nov 17 17:13:48 2009
@@ -20,6 +20,8 @@
 package org.apache.openjpa.persistence.meta;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
 import javax.persistence.metamodel.Attribute;
@@ -311,6 +313,66 @@
         assertEquals(PersistentAttributeType.BASIC, pInt.getPersistentAttributeType());
     }
     
+    public void testNotFoundErrorMessage() {
+        IdentifiableType<ImplicitFieldAccessBase> e0 = model.entity(ImplicitFieldAccessBase.class);
+        String name = "unknown";
+        try {
+          Method[] getters = {
+            e0.getClass().getMethod("getAttribute",          new Class<?>[]{String.class}),
+            e0.getClass().getMethod("getCollection",         new Class<?>[]{String.class}),
+            e0.getClass().getMethod("getList",               new Class<?>[]{String.class}),
+            e0.getClass().getMethod("getSet",                new Class<?>[]{String.class}),
+            e0.getClass().getMethod("getSingularAttribute",  new Class<?>[]{String.class}),
+            
+            e0.getClass().getMethod("getDeclaredAttribute",  new Class<?>[]{String.class}),
+            e0.getClass().getMethod("getDeclaredCollection", new Class<?>[]{String.class}),
+            e0.getClass().getMethod("getDeclaredList",       new Class<?>[]{String.class}),
+            e0.getClass().getMethod("getDeclaredSet",        new Class<?>[]{String.class}),
+            e0.getClass().getMethod("getDeclaredSingularAttribute", new Class<?>[]{String.class}),
+            
+            e0.getClass().getMethod("getAttribute",          new Class<?>[]{String.class,
Class.class}),
+            e0.getClass().getMethod("getCollection",         new Class<?>[]{String.class,
Class.class}),
+            e0.getClass().getMethod("getList",               new Class<?>[]{String.class,
Class.class}),
+            e0.getClass().getMethod("getSet",                new Class<?>[]{String.class,
Class.class}),
+            e0.getClass().getMethod("getSingularAttribute",  new Class<?>[]{String.class,
Class.class}),
+            
+            e0.getClass().getMethod("getDeclaredAttribute",  new Class<?>[]{String.class,
Class.class}),
+            e0.getClass().getMethod("getDeclaredCollection", new Class<?>[]{String.class,
Class.class}),
+            e0.getClass().getMethod("getDeclaredList",       new Class<?>[]{String.class,
Class.class}),
+            e0.getClass().getMethod("getDeclaredSet",        new Class<?>[]{String.class,
Class.class}),
+            e0.getClass().getMethod("getDeclaredSingularAttribute", new Class<?>[]{String.class,
Class.class}),
+
+            e0.getClass().getMethod("getMap",          new Class<?>[]{String.class}),
+            e0.getClass().getMethod("getMap",          new Class<?>[]{String.class,
Class.class, Class.class}),
+            e0.getClass().getMethod("getDeclaredMap",  new Class<?>[]{String.class}),
+            e0.getClass().getMethod("getDeclaredMap",  new Class<?>[]{String.class,
Class.class, Class.class}),
+          };
+//                 e0.getClass().getMethod("getDeclaredVersion", new Class<?>[]{Class.class}),
+        
+        for (int i = 0; i < getters.length; i++) {
+            Object[] args;
+            if (i < 10) {
+                args = new Object[]{name};
+            } else if (i < 20) {
+                args = new Object[]{name, Object.class};
+            } else if (i%2 == 0) {
+                args = new Object[]{name};
+            } else {
+                args = new Object[]{name, Object.class, String.class};
+            }
+            try {
+                getters[i].invoke(e0, args);
+                fail();
+            }  catch (InvocationTargetException e) {
+               System.err.println("Expeceted:" + e.getTargetException());
+            }
+        }
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+    
     void assertFails(ManagedType<?> type, String name, boolean dec) {
         try {
             Attribute<?,?> a = dec ? type.getDeclaredAttribute(name) 

Modified: openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties?rev=881381&r1=881380&r2=881381&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties
Tue Nov 17 17:13:48 2009
@@ -67,3 +67,16 @@
 	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.
+attr-not-found: Attribute "{0}" of {1} not found in {2}
+attr-not-found-single: Singular attribute "{0}" of {1} type not found in {2}
+attr-not-found-decl-single: Declared singular attribute "{0}" of {1} type not found in {2}
+attr-not-found-coll: Collection attribute "{0}" of {1} element type not found in {2}
+attr-not-found-decl-coll: Declared Collection attribute "{0}" of {1} element type not found
in {2}
+attr-not-found-list: List attribute "{0}" of {1} element type not found in {2}
+attr-not-found-decl-list: Declared List attribute "{0}" of {1} element type not found in
{2}
+attr-not-found-set: Set attribute "{0}" of {1} element type not found in {2}
+attr-not-found-decl-set: Declared Set attribute "{0}" of {1} element type not found in {2}
+attr-not-found-map: Map attribute "{0}" of {1} key type and {2} value type not found in {3}
+attr-not-found-decl-map: Declared Map attribute "{0}" of {1} key type and {2} value type
not found in {3}
+decl-version-not-found: Declared version attribute of {1} type not found in {2} 
+version-not-found: Version attribute of {1} type not found in {2}
\ No newline at end of file



Mime
View raw message