You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2008/08/08 10:53:36 UTC
svn commit: r683914 -
/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/TestException.java
Author: ppoddar
Date: Fri Aug 8 01:53:35 2008
New Revision: 683914
URL: http://svn.apache.org/viewvc?rev=683914&view=rev
Log:
OPENJPA-678: Adding test case for query/named query
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/TestException.java
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/TestException.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/TestException.java?rev=683914&r1=683913&r2=683914&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/TestException.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/exception/TestException.java Fri Aug 8 01:53:35 2008
@@ -26,11 +26,13 @@
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.OptimisticLockException;
+import javax.persistence.Query;
import javax.persistence.TransactionRequiredException;
import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.jdbc.sql.SQLErrorCodeReader;
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.util.UserException;
/**
* Tests proper JPA exceptions are raised by the implementation.
@@ -158,6 +160,40 @@
}
/**
+ * Invalid query does not throw IllegalArgumentException on construction
+ * as per JPA spec. The exception is thrown during execution.
+ *
+ * A patch
+ * <A HREF="http://issues.apache.org/jira/browse/OPENJPA-678">OPENJPA-678</A>
+ * by Xiaoqin Feng has proposed eager compilation of the query to raise the
+ * error before execution and as per JPA spec.
+ * However, this patch has not yet been applied as eagerly compiling query
+ * has other side-effects.
+ *
+ */
+ public void testIllegalArgumennExceptionOnInvalidQuery() {
+ EntityManager em = emf.createEntityManager();
+ Query query = em.createQuery("This is not a valid JPQL query");
+ try {
+ query.getResultList();
+ } catch (Throwable t) {
+ assertException(t, IllegalArgumentException.class);
+ }
+ }
+
+ /**
+ * Invalid named query fails as per spec on factory based construction.
+ */
+ public void testIllegalArgumennExceptionOnInvalidNamedQuery() {
+ EntityManager em = emf.createEntityManager();
+ try {
+ Query query = em.createNamedQuery("This is invalid Named query");
+ } catch (Throwable t) {
+ assertException(t, IllegalArgumentException.class);
+ }
+ }
+
+ /**
* Asserts that the given expected type of the exception is equal to or a
* subclass of the given throwable or any of its nested exception.
* Otherwise fails assertion and prints the given throwable and its nested