You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by kw...@apache.org on 2007/01/31 20:27:12 UTC

svn commit: r501955 - /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java

Author: kwsutter
Date: Wed Jan 31 11:27:11 2007
New Revision: 501955

URL: http://svn.apache.org/viewvc?view=rev&rev=501955
Log:
Simple test for OPENJPA-116.  Just modified the simple TestPersistence testcase with a new variation for testing the exception on getDelegate() when the EM is closed.

Modified:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java?view=diff&rev=501955&r1=501954&r2=501955
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java Wed Jan 31 11:27:11 2007
@@ -1,114 +1,134 @@
-/*
- * Copyright 2006 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.openjpa.persistence.simple;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Persistence;
-
-import junit.framework.TestCase;
-import junit.textui.TestRunner;
-import org.apache.openjpa.persistence.OpenJPAEntityManager;
-
-/**
- * Simple test case to get an EntityManager and perform some basic operations.
- *
- * @author Marc Prud'hommeaux
- */
-public class TestPersistence
-    extends TestCase {
-
-    private EntityManagerFactory emf;
-
-    public void setUp() {
-        Map props = new HashMap(System.getProperties());
-        props.put("openjpa.MetaDataFactory",
-            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
-        emf = Persistence.createEntityManagerFactory("test", props);
-    }
-
-    public void tearDown() {
-        if (emf == null)
-            return;
-        try {
-            EntityManager em = emf.createEntityManager();
-            em.getTransaction().begin();
-            em.createQuery("delete from AllFieldTypes").executeUpdate();
-            em.getTransaction().commit();
-            em.close();
-            emf.close();
-        } catch (Exception e) {
-        }
-    }
-
-    public void testCreateEntityManager() {
-        EntityManager em = emf.createEntityManager();
-
-        EntityTransaction t = em.getTransaction();
-        assertNotNull(t);
-        t.begin();
-        t.setRollbackOnly();
-        t.rollback();
-
-        // openjpa-facade test
-        assertTrue(em instanceof OpenJPAEntityManager);
-        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
-        ojem.getFetchPlan().setMaxFetchDepth(1);
-        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
-        em.close();
-    }
-
-    public void testPersist() {
-        EntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-        em.persist(new AllFieldTypes());
-        em.getTransaction().commit();
-        em.close();
-    }
-
-    public void testQuery() {
-        EntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-        AllFieldTypes aft = new AllFieldTypes();
-        aft.setStringField("foo");
-        aft.setIntField(10);
-        em.persist(aft);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        em.getTransaction().begin();
-        assertEquals(1, em.createQuery
-            ("select x from AllFieldTypes x where x.stringField = 'foo'").
-            getResultList().size());
-        assertEquals(0, em.createQuery
-            ("select x from AllFieldTypes x where x.stringField = 'bar'").
-            getResultList().size());
-        assertEquals(1, em.createQuery
-            ("select x from AllFieldTypes x where x.intField >= 10").
-            getResultList().size());
-        em.getTransaction().rollback();
-        em.close();
-    }
-
-    public static void main(String[] args) {
-        TestRunner.run(TestPersistence.class);
-    }
-}
-
+/*
+ * Copyright 2006 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.openjpa.persistence.simple;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+/**
+ * Simple test case to get an EntityManager and perform some basic operations.
+ *
+ * @author Marc Prud'hommeaux
+ */
+public class TestPersistence
+    extends TestCase {
+
+    private EntityManagerFactory emf;
+
+    public void setUp() {
+        Map props = new HashMap(System.getProperties());
+        props.put("openjpa.MetaDataFactory",
+            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
+        emf = Persistence.createEntityManagerFactory("test", props);
+    }
+
+    public void tearDown() {
+        if (emf == null)
+            return;
+        try {
+            EntityManager em = emf.createEntityManager();
+            em.getTransaction().begin();
+            em.createQuery("delete from AllFieldTypes").executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+            emf.close();
+        } catch (Exception e) {
+        }
+    }
+
+    public void testCreateEntityManager() {
+        EntityManager em = emf.createEntityManager();
+
+        EntityTransaction t = em.getTransaction();
+        assertNotNull(t);
+        t.begin();
+        t.setRollbackOnly();
+        t.rollback();
+
+        // openjpa-facade test
+        assertTrue(em instanceof OpenJPAEntityManager);
+        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
+        ojem.getFetchPlan().setMaxFetchDepth(1);
+        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
+        em.close();
+    }
+
+    public void testPersist() {
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.persist(new AllFieldTypes());
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    public void testQuery() {
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        AllFieldTypes aft = new AllFieldTypes();
+        aft.setStringField("foo");
+        aft.setIntField(10);
+        em.persist(aft);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        em.getTransaction().begin();
+        assertEquals(1, em.createQuery
+            ("select x from AllFieldTypes x where x.stringField = 'foo'").
+            getResultList().size());
+        assertEquals(0, em.createQuery
+            ("select x from AllFieldTypes x where x.stringField = 'bar'").
+            getResultList().size());
+        assertEquals(1, em.createQuery
+            ("select x from AllFieldTypes x where x.intField >= 10").
+            getResultList().size());
+        em.getTransaction().rollback();
+        em.close();
+    }
+
+    /**
+     * Ensures that an IllegalStateException is thrown if getDelegate is called
+     * after closing the EntityManager.
+     */
+    public void testGetDelegateAfterClose() {
+        EntityManager em = emf.createEntityManager();
+
+        em.close();
+
+        try {
+            Object o = em.getDelegate();
+            fail();
+        }
+        catch(IllegalStateException ise) {
+            /*
+             * An IllegalStateException is expected. Nothing to do here.
+             */
+        }
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(TestPersistence.class);
+    }
+}
+



RE: svn commit: r501955 - /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java

Posted by Patrick Linskey <pl...@bea.com>.
I seem to recall deciding to not use the SVN eclipse integration a few
months ago -- I do all my svn work from the command line. Maybe this was
why I made that decision.

-Patrick

-- 
Patrick Linskey
BEA Systems, Inc. 

_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it. 

> -----Original Message-----
> From: Kevin Sutter [mailto:kwsutter@gmail.com] 
> Sent: Wednesday, January 31, 2007 11:40 AM
> To: open-jpa-commits@incubator.apache.org
> Subject: Re: svn commit: r501955 - 
> /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/jav
a/org/apache/openjpa/persistence/simple/TestPersistence.java
> 
> Sorry about the "whole changed file" thing again.  I thought 
> I had found the
> problem with a doubly defined [miscellany] section in my svn 
> config file.
> But, I changed that and I still have the problem.  Like I 
> mentioned before,
> this only seems to happen after using the SVN Eclipse plugin 
> to do a merge
> of a patch.  Maybe I should just use the SVN command line to 
> do the commit?
> Or, maybe I have to manually do the Windows->Linux line 
> ending conversion
> before committing any changes?  Seems kind of error prone, 
> especially as my
> memory continues to grow older...  :-)
> 
> I looked back in our dev mailing list and Craig had performed 
> an operation
> on two of the OpenJPA sub-projects that supposedly helps with this
> situation.  Is this operation "permanent"?  That is, if I run 
> this on each
> sub-project and push the changes out, will that clean up this 
> line ending
> thing?  The problem with this approach is that it seems to 
> only work with
> existing files.  Any new files and we would have to remember 
> to run this
> operation again.
> 
> Any other ideas?  I would like to get this cleaned up so that 
> my commits
> look consistent with everybody else's.   When I do my diffs before
> committing, only the changed lines show up.  It's the commit 
> processing that
> picks up the whole file.
> 
> Thank you and, again, my apologies!
> Kevin
> 
> On 1/31/07, kwsutter@apache.org <kw...@apache.org> wrote:
> >
> > Author: kwsutter
> > Date: Wed Jan 31 11:27:11 2007
> > New Revision: 501955
> >
> > URL: http://svn.apache.org/viewvc?view=rev&rev=501955
> > Log:
> > Simple test for OPENJPA-116.  Just modified the simple 
> TestPersistence
> > testcase with a new variation for testing the exception on 
> getDelegate()
> > when the EM is closed.
> >
> > Modified:
> >
> >     
> incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java
/org/apache/openjpa/persistence/simple/TestPersistence.java
> >
> > Modified:
> > 
> incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java
/org/apache/openjpa/persistence/simple/TestPersistence.java
> > URL:
> > 
> http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-p
ersistence->
jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestP
> ersistence.java?view=diff&rev=501955&r1=501954&r2=501955
> >
> > 
> ==============================================================
> ================
> > ---
> > 
> incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java
/org/apache/openjpa/persistence/simple/TestPersistence.java
> > (original)
> > +++
> > 
> incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java
/org/apache/openjpa/persistence/simple/TestPersistence.java
> > Wed Jan 31 11:27:11 2007
> > @@ -1,114 +1,134 @@
> > -/*
> > - * Copyright 2006 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.openjpa.persistence.simple;
> > -
> > -import java.util.HashMap;
> > -import java.util.Map;
> > -import javax.persistence.EntityManager;
> > -import javax.persistence.EntityManagerFactory;
> > -import javax.persistence.EntityTransaction;
> > -import javax.persistence.Persistence;
> > -
> > -import junit.framework.TestCase;
> > -import junit.textui.TestRunner;
> > -import org.apache.openjpa.persistence.OpenJPAEntityManager;
> > -
> > -/**
> > - * Simple test case to get an EntityManager and perform some basic
> > operations.
> > - *
> > - * @author Marc Prud'hommeaux
> > - */
> > -public class TestPersistence
> > -    extends TestCase {
> > -
> > -    private EntityManagerFactory emf;
> > -
> > -    public void setUp() {
> > -        Map props = new HashMap(System.getProperties());
> > -        props.put("openjpa.MetaDataFactory",
> > -            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> > -        emf = 
> Persistence.createEntityManagerFactory("test", props);
> > -    }
> > -
> > -    public void tearDown() {
> > -        if (emf == null)
> > -            return;
> > -        try {
> > -            EntityManager em = emf.createEntityManager();
> > -            em.getTransaction().begin();
> > -            em.createQuery("delete from 
> AllFieldTypes").executeUpdate();
> > -            em.getTransaction().commit();
> > -            em.close();
> > -            emf.close();
> > -        } catch (Exception e) {
> > -        }
> > -    }
> > -
> > -    public void testCreateEntityManager() {
> > -        EntityManager em = emf.createEntityManager();
> > -
> > -        EntityTransaction t = em.getTransaction();
> > -        assertNotNull(t);
> > -        t.begin();
> > -        t.setRollbackOnly();
> > -        t.rollback();
> > -
> > -        // openjpa-facade test
> > -        assertTrue(em instanceof OpenJPAEntityManager);
> > -        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> > -        ojem.getFetchPlan().setMaxFetchDepth(1);
> > -        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> > -        em.close();
> > -    }
> > -
> > -    public void testPersist() {
> > -        EntityManager em = emf.createEntityManager();
> > -        em.getTransaction().begin();
> > -        em.persist(new AllFieldTypes());
> > -        em.getTransaction().commit();
> > -        em.close();
> > -    }
> > -
> > -    public void testQuery() {
> > -        EntityManager em = emf.createEntityManager();
> > -        em.getTransaction().begin();
> > -        AllFieldTypes aft = new AllFieldTypes();
> > -        aft.setStringField("foo");
> > -        aft.setIntField(10);
> > -        em.persist(aft);
> > -        em.getTransaction().commit();
> > -        em.close();
> > -
> > -        em = emf.createEntityManager();
> > -        em.getTransaction().begin();
> > -        assertEquals(1, em.createQuery
> > -            ("select x from AllFieldTypes x where x.stringField =
> > 'foo'").
> > -            getResultList().size());
> > -        assertEquals(0, em.createQuery
> > -            ("select x from AllFieldTypes x where x.stringField =
> > 'bar'").
> > -            getResultList().size());
> > -        assertEquals(1, em.createQuery
> > -            ("select x from AllFieldTypes x where 
> x.intField >= 10").
> > -            getResultList().size());
> > -        em.getTransaction().rollback();
> > -        em.close();
> > -    }
> > -
> > -    public static void main(String[] args) {
> > -        TestRunner.run(TestPersistence.class);
> > -    }
> > -}
> > -
> > +/*
> > + * Copyright 2006 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.openjpa.persistence.simple;
> > +
> > +import java.util.HashMap;
> > +import java.util.Map;
> > +import javax.persistence.EntityManager;
> > +import javax.persistence.EntityManagerFactory;
> > +import javax.persistence.EntityTransaction;
> > +import javax.persistence.Persistence;
> > +
> > +import junit.framework.TestCase;
> > +import junit.textui.TestRunner;
> > +import org.apache.openjpa.persistence.OpenJPAEntityManager;
> > +
> > +/**
> > + * Simple test case to get an EntityManager and perform some basic
> > operations.
> > + *
> > + * @author Marc Prud'hommeaux
> > + */
> > +public class TestPersistence
> > +    extends TestCase {
> > +
> > +    private EntityManagerFactory emf;
> > +
> > +    public void setUp() {
> > +        Map props = new HashMap(System.getProperties());
> > +        props.put("openjpa.MetaDataFactory",
> > +            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> > +        emf = 
> Persistence.createEntityManagerFactory("test", props);
> > +    }
> > +
> > +    public void tearDown() {
> > +        if (emf == null)
> > +            return;
> > +        try {
> > +            EntityManager em = emf.createEntityManager();
> > +            em.getTransaction().begin();
> > +            em.createQuery("delete from 
> AllFieldTypes").executeUpdate();
> > +            em.getTransaction().commit();
> > +            em.close();
> > +            emf.close();
> > +        } catch (Exception e) {
> > +        }
> > +    }
> > +
> > +    public void testCreateEntityManager() {
> > +        EntityManager em = emf.createEntityManager();
> > +
> > +        EntityTransaction t = em.getTransaction();
> > +        assertNotNull(t);
> > +        t.begin();
> > +        t.setRollbackOnly();
> > +        t.rollback();
> > +
> > +        // openjpa-facade test
> > +        assertTrue(em instanceof OpenJPAEntityManager);
> > +        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> > +        ojem.getFetchPlan().setMaxFetchDepth(1);
> > +        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> > +        em.close();
> > +    }
> > +
> > +    public void testPersist() {
> > +        EntityManager em = emf.createEntityManager();
> > +        em.getTransaction().begin();
> > +        em.persist(new AllFieldTypes());
> > +        em.getTransaction().commit();
> > +        em.close();
> > +    }
> > +
> > +    public void testQuery() {
> > +        EntityManager em = emf.createEntityManager();
> > +        em.getTransaction().begin();
> > +        AllFieldTypes aft = new AllFieldTypes();
> > +        aft.setStringField("foo");
> > +        aft.setIntField(10);
> > +        em.persist(aft);
> > +        em.getTransaction().commit();
> > +        em.close();
> > +
> > +        em = emf.createEntityManager();
> > +        em.getTransaction().begin();
> > +        assertEquals(1, em.createQuery
> > +            ("select x from AllFieldTypes x where x.stringField =
> > 'foo'").
> > +            getResultList().size());
> > +        assertEquals(0, em.createQuery
> > +            ("select x from AllFieldTypes x where x.stringField =
> > 'bar'").
> > +            getResultList().size());
> > +        assertEquals(1, em.createQuery
> > +            ("select x from AllFieldTypes x where 
> x.intField >= 10").
> > +            getResultList().size());
> > +        em.getTransaction().rollback();
> > +        em.close();
> > +    }
> > +
> > +    /**
> > +     * Ensures that an IllegalStateException is thrown if 
> getDelegate is
> > called
> > +     * after closing the EntityManager.
> > +     */
> > +    public void testGetDelegateAfterClose() {
> > +        EntityManager em = emf.createEntityManager();
> > +
> > +        em.close();
> > +
> > +        try {
> > +            Object o = em.getDelegate();
> > +            fail();
> > +        }
> > +        catch(IllegalStateException ise) {
> > +            /*
> > +             * An IllegalStateException is expected. 
> Nothing to do here.
> > +             */
> > +        }
> > +    }
> > +
> > +    public static void main(String[] args) {
> > +        TestRunner.run(TestPersistence.class);
> > +    }
> > +}
> > +
> >
> >
> >
> 

Re: svn commit: r501955 - /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Kevin,

Sorry for commenting before reading this...

On Jan 31, 2007, at 11:39 AM, Kevin Sutter wrote:

> Sorry about the "whole changed file" thing again.  I thought I had  
> found the
> problem with a doubly defined [miscellany] section in my svn config  
> file.
> But, I changed that and I still have the problem.  Like I mentioned  
> before,
> this only seems to happen after using the SVN Eclipse plugin to do  
> a merge
> of a patch.

Do you review the diff in Eclipse before committing?

> Maybe I should just use the SVN command line to do the commit?

That works.

> Or, maybe I have to manually do the Windows->Linux line ending  
> conversion
> before committing any changes?  Seems kind of error prone,  
> especially as my
> memory continues to grow older...  :-)

This also works.
>
> I looked back in our dev mailing list and Craig had performed an  
> operation
> on two of the OpenJPA sub-projects that supposedly helps with this
> situation.  Is this operation "permanent"?

Yes. For existing files that should have the eol-style, svn  
automatically normalizes the files upon commit.

> That is, if I run this on each
> sub-project and push the changes out, will that clean up this line  
> ending
> thing?

Yes. When you first apply the property to a file, it might give you  
one of those 100% changed commits, but that will not happen on  
subsequent commits.

> The problem with this approach is that it seems to only work with
> existing files.  Any new files and we would have to remember to run  
> this
> operation again.

Yes, IIRC this is true. New files need to have the property added.  
There is a property that you can set in your environment but there's  
nothing that I can recall to set an entire directory tree permanently  
to this status.

Craig
>
> Any other ideas?  I would like to get this cleaned up so that my  
> commits
> look consistent with everybody else's.   When I do my diffs before
> committing, only the changed lines show up.  It's the commit  
> processing that
> picks up the whole file.
>
> Thank you and, again, my apologies!
> Kevin
>
> On 1/31/07, kwsutter@apache.org <kw...@apache.org> wrote:
>>
>> Author: kwsutter
>> Date: Wed Jan 31 11:27:11 2007
>> New Revision: 501955
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=501955
>> Log:
>> Simple test for OPENJPA-116.  Just modified the simple  
>> TestPersistence
>> testcase with a new variation for testing the exception on  
>> getDelegate()
>> when the EM is closed.
>>
>> Modified:
>>
>>     incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
>> org/apache/openjpa/persistence/simple/TestPersistence.java
>>
>> Modified:
>> incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/ 
>> apache/openjpa/persistence/simple/TestPersistence.java
>> URL:
>> http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa- 
>> persistence-jdbc/src/test/java/org/apache/openjpa/persistence/ 
>> simple/TestPersistence.java?view=diff&rev=501955&r1=501954&r2=501955
>>
>> ===================================================================== 
>> =========
>> ---
>> incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/ 
>> apache/openjpa/persistence/simple/TestPersistence.java
>> (original)
>> +++
>> incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/ 
>> apache/openjpa/persistence/simple/TestPersistence.java
>> Wed Jan 31 11:27:11 2007
>> @@ -1,114 +1,134 @@
>> -/*
>> - * Copyright 2006 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.openjpa.persistence.simple;
>> -
>> -import java.util.HashMap;
>> -import java.util.Map;
>> -import javax.persistence.EntityManager;
>> -import javax.persistence.EntityManagerFactory;
>> -import javax.persistence.EntityTransaction;
>> -import javax.persistence.Persistence;
>> -
>> -import junit.framework.TestCase;
>> -import junit.textui.TestRunner;
>> -import org.apache.openjpa.persistence.OpenJPAEntityManager;
>> -
>> -/**
>> - * Simple test case to get an EntityManager and perform some basic
>> operations.
>> - *
>> - * @author Marc Prud'hommeaux
>> - */
>> -public class TestPersistence
>> -    extends TestCase {
>> -
>> -    private EntityManagerFactory emf;
>> -
>> -    public void setUp() {
>> -        Map props = new HashMap(System.getProperties());
>> -        props.put("openjpa.MetaDataFactory",
>> -            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
>> -        emf = Persistence.createEntityManagerFactory("test", props);
>> -    }
>> -
>> -    public void tearDown() {
>> -        if (emf == null)
>> -            return;
>> -        try {
>> -            EntityManager em = emf.createEntityManager();
>> -            em.getTransaction().begin();
>> -            em.createQuery("delete from  
>> AllFieldTypes").executeUpdate();
>> -            em.getTransaction().commit();
>> -            em.close();
>> -            emf.close();
>> -        } catch (Exception e) {
>> -        }
>> -    }
>> -
>> -    public void testCreateEntityManager() {
>> -        EntityManager em = emf.createEntityManager();
>> -
>> -        EntityTransaction t = em.getTransaction();
>> -        assertNotNull(t);
>> -        t.begin();
>> -        t.setRollbackOnly();
>> -        t.rollback();
>> -
>> -        // openjpa-facade test
>> -        assertTrue(em instanceof OpenJPAEntityManager);
>> -        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
>> -        ojem.getFetchPlan().setMaxFetchDepth(1);
>> -        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
>> -        em.close();
>> -    }
>> -
>> -    public void testPersist() {
>> -        EntityManager em = emf.createEntityManager();
>> -        em.getTransaction().begin();
>> -        em.persist(new AllFieldTypes());
>> -        em.getTransaction().commit();
>> -        em.close();
>> -    }
>> -
>> -    public void testQuery() {
>> -        EntityManager em = emf.createEntityManager();
>> -        em.getTransaction().begin();
>> -        AllFieldTypes aft = new AllFieldTypes();
>> -        aft.setStringField("foo");
>> -        aft.setIntField(10);
>> -        em.persist(aft);
>> -        em.getTransaction().commit();
>> -        em.close();
>> -
>> -        em = emf.createEntityManager();
>> -        em.getTransaction().begin();
>> -        assertEquals(1, em.createQuery
>> -            ("select x from AllFieldTypes x where x.stringField =
>> 'foo'").
>> -            getResultList().size());
>> -        assertEquals(0, em.createQuery
>> -            ("select x from AllFieldTypes x where x.stringField =
>> 'bar'").
>> -            getResultList().size());
>> -        assertEquals(1, em.createQuery
>> -            ("select x from AllFieldTypes x where x.intField >=  
>> 10").
>> -            getResultList().size());
>> -        em.getTransaction().rollback();
>> -        em.close();
>> -    }
>> -
>> -    public static void main(String[] args) {
>> -        TestRunner.run(TestPersistence.class);
>> -    }
>> -}
>> -
>> +/*
>> + * Copyright 2006 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.openjpa.persistence.simple;
>> +
>> +import java.util.HashMap;
>> +import java.util.Map;
>> +import javax.persistence.EntityManager;
>> +import javax.persistence.EntityManagerFactory;
>> +import javax.persistence.EntityTransaction;
>> +import javax.persistence.Persistence;
>> +
>> +import junit.framework.TestCase;
>> +import junit.textui.TestRunner;
>> +import org.apache.openjpa.persistence.OpenJPAEntityManager;
>> +
>> +/**
>> + * Simple test case to get an EntityManager and perform some basic
>> operations.
>> + *
>> + * @author Marc Prud'hommeaux
>> + */
>> +public class TestPersistence
>> +    extends TestCase {
>> +
>> +    private EntityManagerFactory emf;
>> +
>> +    public void setUp() {
>> +        Map props = new HashMap(System.getProperties());
>> +        props.put("openjpa.MetaDataFactory",
>> +            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
>> +        emf = Persistence.createEntityManagerFactory("test", props);
>> +    }
>> +
>> +    public void tearDown() {
>> +        if (emf == null)
>> +            return;
>> +        try {
>> +            EntityManager em = emf.createEntityManager();
>> +            em.getTransaction().begin();
>> +            em.createQuery("delete from  
>> AllFieldTypes").executeUpdate();
>> +            em.getTransaction().commit();
>> +            em.close();
>> +            emf.close();
>> +        } catch (Exception e) {
>> +        }
>> +    }
>> +
>> +    public void testCreateEntityManager() {
>> +        EntityManager em = emf.createEntityManager();
>> +
>> +        EntityTransaction t = em.getTransaction();
>> +        assertNotNull(t);
>> +        t.begin();
>> +        t.setRollbackOnly();
>> +        t.rollback();
>> +
>> +        // openjpa-facade test
>> +        assertTrue(em instanceof OpenJPAEntityManager);
>> +        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
>> +        ojem.getFetchPlan().setMaxFetchDepth(1);
>> +        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
>> +        em.close();
>> +    }
>> +
>> +    public void testPersist() {
>> +        EntityManager em = emf.createEntityManager();
>> +        em.getTransaction().begin();
>> +        em.persist(new AllFieldTypes());
>> +        em.getTransaction().commit();
>> +        em.close();
>> +    }
>> +
>> +    public void testQuery() {
>> +        EntityManager em = emf.createEntityManager();
>> +        em.getTransaction().begin();
>> +        AllFieldTypes aft = new AllFieldTypes();
>> +        aft.setStringField("foo");
>> +        aft.setIntField(10);
>> +        em.persist(aft);
>> +        em.getTransaction().commit();
>> +        em.close();
>> +
>> +        em = emf.createEntityManager();
>> +        em.getTransaction().begin();
>> +        assertEquals(1, em.createQuery
>> +            ("select x from AllFieldTypes x where x.stringField =
>> 'foo'").
>> +            getResultList().size());
>> +        assertEquals(0, em.createQuery
>> +            ("select x from AllFieldTypes x where x.stringField =
>> 'bar'").
>> +            getResultList().size());
>> +        assertEquals(1, em.createQuery
>> +            ("select x from AllFieldTypes x where x.intField >=  
>> 10").
>> +            getResultList().size());
>> +        em.getTransaction().rollback();
>> +        em.close();
>> +    }
>> +
>> +    /**
>> +     * Ensures that an IllegalStateException is thrown if  
>> getDelegate is
>> called
>> +     * after closing the EntityManager.
>> +     */
>> +    public void testGetDelegateAfterClose() {
>> +        EntityManager em = emf.createEntityManager();
>> +
>> +        em.close();
>> +
>> +        try {
>> +            Object o = em.getDelegate();
>> +            fail();
>> +        }
>> +        catch(IllegalStateException ise) {
>> +            /*
>> +             * An IllegalStateException is expected. Nothing to  
>> do here.
>> +             */
>> +        }
>> +    }
>> +
>> +    public static void main(String[] args) {
>> +        TestRunner.run(TestPersistence.class);
>> +    }
>> +}
>> +
>>
>>
>>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: svn commit: r501955 - /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java

Posted by Kevin Sutter <kw...@gmail.com>.
Sorry about the "whole changed file" thing again.  I thought I had found the
problem with a doubly defined [miscellany] section in my svn config file.
But, I changed that and I still have the problem.  Like I mentioned before,
this only seems to happen after using the SVN Eclipse plugin to do a merge
of a patch.  Maybe I should just use the SVN command line to do the commit?
Or, maybe I have to manually do the Windows->Linux line ending conversion
before committing any changes?  Seems kind of error prone, especially as my
memory continues to grow older...  :-)

I looked back in our dev mailing list and Craig had performed an operation
on two of the OpenJPA sub-projects that supposedly helps with this
situation.  Is this operation "permanent"?  That is, if I run this on each
sub-project and push the changes out, will that clean up this line ending
thing?  The problem with this approach is that it seems to only work with
existing files.  Any new files and we would have to remember to run this
operation again.

Any other ideas?  I would like to get this cleaned up so that my commits
look consistent with everybody else's.   When I do my diffs before
committing, only the changed lines show up.  It's the commit processing that
picks up the whole file.

Thank you and, again, my apologies!
Kevin

On 1/31/07, kwsutter@apache.org <kw...@apache.org> wrote:
>
> Author: kwsutter
> Date: Wed Jan 31 11:27:11 2007
> New Revision: 501955
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=501955
> Log:
> Simple test for OPENJPA-116.  Just modified the simple TestPersistence
> testcase with a new variation for testing the exception on getDelegate()
> when the EM is closed.
>
> Modified:
>
>     incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
>
> Modified:
> incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
> URL:
> http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java?view=diff&rev=501955&r1=501954&r2=501955
>
> ==============================================================================
> ---
> incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
> (original)
> +++
> incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
> Wed Jan 31 11:27:11 2007
> @@ -1,114 +1,134 @@
> -/*
> - * Copyright 2006 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.openjpa.persistence.simple;
> -
> -import java.util.HashMap;
> -import java.util.Map;
> -import javax.persistence.EntityManager;
> -import javax.persistence.EntityManagerFactory;
> -import javax.persistence.EntityTransaction;
> -import javax.persistence.Persistence;
> -
> -import junit.framework.TestCase;
> -import junit.textui.TestRunner;
> -import org.apache.openjpa.persistence.OpenJPAEntityManager;
> -
> -/**
> - * Simple test case to get an EntityManager and perform some basic
> operations.
> - *
> - * @author Marc Prud'hommeaux
> - */
> -public class TestPersistence
> -    extends TestCase {
> -
> -    private EntityManagerFactory emf;
> -
> -    public void setUp() {
> -        Map props = new HashMap(System.getProperties());
> -        props.put("openjpa.MetaDataFactory",
> -            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> -        emf = Persistence.createEntityManagerFactory("test", props);
> -    }
> -
> -    public void tearDown() {
> -        if (emf == null)
> -            return;
> -        try {
> -            EntityManager em = emf.createEntityManager();
> -            em.getTransaction().begin();
> -            em.createQuery("delete from AllFieldTypes").executeUpdate();
> -            em.getTransaction().commit();
> -            em.close();
> -            emf.close();
> -        } catch (Exception e) {
> -        }
> -    }
> -
> -    public void testCreateEntityManager() {
> -        EntityManager em = emf.createEntityManager();
> -
> -        EntityTransaction t = em.getTransaction();
> -        assertNotNull(t);
> -        t.begin();
> -        t.setRollbackOnly();
> -        t.rollback();
> -
> -        // openjpa-facade test
> -        assertTrue(em instanceof OpenJPAEntityManager);
> -        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> -        ojem.getFetchPlan().setMaxFetchDepth(1);
> -        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> -        em.close();
> -    }
> -
> -    public void testPersist() {
> -        EntityManager em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        em.persist(new AllFieldTypes());
> -        em.getTransaction().commit();
> -        em.close();
> -    }
> -
> -    public void testQuery() {
> -        EntityManager em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        AllFieldTypes aft = new AllFieldTypes();
> -        aft.setStringField("foo");
> -        aft.setIntField(10);
> -        em.persist(aft);
> -        em.getTransaction().commit();
> -        em.close();
> -
> -        em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        assertEquals(1, em.createQuery
> -            ("select x from AllFieldTypes x where x.stringField =
> 'foo'").
> -            getResultList().size());
> -        assertEquals(0, em.createQuery
> -            ("select x from AllFieldTypes x where x.stringField =
> 'bar'").
> -            getResultList().size());
> -        assertEquals(1, em.createQuery
> -            ("select x from AllFieldTypes x where x.intField >= 10").
> -            getResultList().size());
> -        em.getTransaction().rollback();
> -        em.close();
> -    }
> -
> -    public static void main(String[] args) {
> -        TestRunner.run(TestPersistence.class);
> -    }
> -}
> -
> +/*
> + * Copyright 2006 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.openjpa.persistence.simple;
> +
> +import java.util.HashMap;
> +import java.util.Map;
> +import javax.persistence.EntityManager;
> +import javax.persistence.EntityManagerFactory;
> +import javax.persistence.EntityTransaction;
> +import javax.persistence.Persistence;
> +
> +import junit.framework.TestCase;
> +import junit.textui.TestRunner;
> +import org.apache.openjpa.persistence.OpenJPAEntityManager;
> +
> +/**
> + * Simple test case to get an EntityManager and perform some basic
> operations.
> + *
> + * @author Marc Prud'hommeaux
> + */
> +public class TestPersistence
> +    extends TestCase {
> +
> +    private EntityManagerFactory emf;
> +
> +    public void setUp() {
> +        Map props = new HashMap(System.getProperties());
> +        props.put("openjpa.MetaDataFactory",
> +            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> +        emf = Persistence.createEntityManagerFactory("test", props);
> +    }
> +
> +    public void tearDown() {
> +        if (emf == null)
> +            return;
> +        try {
> +            EntityManager em = emf.createEntityManager();
> +            em.getTransaction().begin();
> +            em.createQuery("delete from AllFieldTypes").executeUpdate();
> +            em.getTransaction().commit();
> +            em.close();
> +            emf.close();
> +        } catch (Exception e) {
> +        }
> +    }
> +
> +    public void testCreateEntityManager() {
> +        EntityManager em = emf.createEntityManager();
> +
> +        EntityTransaction t = em.getTransaction();
> +        assertNotNull(t);
> +        t.begin();
> +        t.setRollbackOnly();
> +        t.rollback();
> +
> +        // openjpa-facade test
> +        assertTrue(em instanceof OpenJPAEntityManager);
> +        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> +        ojem.getFetchPlan().setMaxFetchDepth(1);
> +        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> +        em.close();
> +    }
> +
> +    public void testPersist() {
> +        EntityManager em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        em.persist(new AllFieldTypes());
> +        em.getTransaction().commit();
> +        em.close();
> +    }
> +
> +    public void testQuery() {
> +        EntityManager em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        AllFieldTypes aft = new AllFieldTypes();
> +        aft.setStringField("foo");
> +        aft.setIntField(10);
> +        em.persist(aft);
> +        em.getTransaction().commit();
> +        em.close();
> +
> +        em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        assertEquals(1, em.createQuery
> +            ("select x from AllFieldTypes x where x.stringField =
> 'foo'").
> +            getResultList().size());
> +        assertEquals(0, em.createQuery
> +            ("select x from AllFieldTypes x where x.stringField =
> 'bar'").
> +            getResultList().size());
> +        assertEquals(1, em.createQuery
> +            ("select x from AllFieldTypes x where x.intField >= 10").
> +            getResultList().size());
> +        em.getTransaction().rollback();
> +        em.close();
> +    }
> +
> +    /**
> +     * Ensures that an IllegalStateException is thrown if getDelegate is
> called
> +     * after closing the EntityManager.
> +     */
> +    public void testGetDelegateAfterClose() {
> +        EntityManager em = emf.createEntityManager();
> +
> +        em.close();
> +
> +        try {
> +            Object o = em.getDelegate();
> +            fail();
> +        }
> +        catch(IllegalStateException ise) {
> +            /*
> +             * An IllegalStateException is expected. Nothing to do here.
> +             */
> +        }
> +    }
> +
> +    public static void main(String[] args) {
> +        TestRunner.run(TestPersistence.class);
> +    }
> +}
> +
>
>
>

Re: svn commit: r501955 - /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java

Posted by Craig L Russell <Cr...@Sun.COM>.
This commit is way too big for its changes.

I recommend that everyone do an svn diff prior to commit to make sure  
that you don't have a line-end problem, such as this appears to have.

Craig

On Jan 31, 2007, at 11:27 AM, kwsutter@apache.org wrote:

> Author: kwsutter
> Date: Wed Jan 31 11:27:11 2007
> New Revision: 501955
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=501955
> Log:
> Simple test for OPENJPA-116.  Just modified the simple  
> TestPersistence testcase with a new variation for testing the  
> exception on getDelegate() when the EM is closed.
>
> Modified:
>     incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java
>
> Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/ 
> java/org/apache/openjpa/persistence/simple/TestPersistence.java
> URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa- 
> persistence-jdbc/src/test/java/org/apache/openjpa/persistence/ 
> simple/TestPersistence.java?view=diff&rev=501955&r1=501954&r2=501955
> ====================================================================== 
> ========
> --- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java (original)
> +++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java Wed Jan  
> 31 11:27:11 2007
> @@ -1,114 +1,134 @@
> -/*
> - * Copyright 2006 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.openjpa.persistence.simple;
> -
> -import java.util.HashMap;
> -import java.util.Map;
> -import javax.persistence.EntityManager;
> -import javax.persistence.EntityManagerFactory;
> -import javax.persistence.EntityTransaction;
> -import javax.persistence.Persistence;
> -
> -import junit.framework.TestCase;
> -import junit.textui.TestRunner;
> -import org.apache.openjpa.persistence.OpenJPAEntityManager;
> -
> -/**
> - * Simple test case to get an EntityManager and perform some basic  
> operations.
> - *
> - * @author Marc Prud'hommeaux
> - */
> -public class TestPersistence
> -    extends TestCase {
> -
> -    private EntityManagerFactory emf;
> -
> -    public void setUp() {
> -        Map props = new HashMap(System.getProperties());
> -        props.put("openjpa.MetaDataFactory",
> -            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> -        emf = Persistence.createEntityManagerFactory("test", props);
> -    }
> -
> -    public void tearDown() {
> -        if (emf == null)
> -            return;
> -        try {
> -            EntityManager em = emf.createEntityManager();
> -            em.getTransaction().begin();
> -            em.createQuery("delete from  
> AllFieldTypes").executeUpdate();
> -            em.getTransaction().commit();
> -            em.close();
> -            emf.close();
> -        } catch (Exception e) {
> -        }
> -    }
> -
> -    public void testCreateEntityManager() {
> -        EntityManager em = emf.createEntityManager();
> -
> -        EntityTransaction t = em.getTransaction();
> -        assertNotNull(t);
> -        t.begin();
> -        t.setRollbackOnly();
> -        t.rollback();
> -
> -        // openjpa-facade test
> -        assertTrue(em instanceof OpenJPAEntityManager);
> -        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> -        ojem.getFetchPlan().setMaxFetchDepth(1);
> -        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> -        em.close();
> -    }
> -
> -    public void testPersist() {
> -        EntityManager em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        em.persist(new AllFieldTypes());
> -        em.getTransaction().commit();
> -        em.close();
> -    }
> -
> -    public void testQuery() {
> -        EntityManager em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        AllFieldTypes aft = new AllFieldTypes();
> -        aft.setStringField("foo");
> -        aft.setIntField(10);
> -        em.persist(aft);
> -        em.getTransaction().commit();
> -        em.close();
> -
> -        em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        assertEquals(1, em.createQuery
> -            ("select x from AllFieldTypes x where x.stringField =  
> 'foo'").
> -            getResultList().size());
> -        assertEquals(0, em.createQuery
> -            ("select x from AllFieldTypes x where x.stringField =  
> 'bar'").
> -            getResultList().size());
> -        assertEquals(1, em.createQuery
> -            ("select x from AllFieldTypes x where x.intField >= 10").
> -            getResultList().size());
> -        em.getTransaction().rollback();
> -        em.close();
> -    }
> -
> -    public static void main(String[] args) {
> -        TestRunner.run(TestPersistence.class);
> -    }
> -}
> -
> +/*
> + * Copyright 2006 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.openjpa.persistence.simple;
> +
> +import java.util.HashMap;
> +import java.util.Map;
> +import javax.persistence.EntityManager;
> +import javax.persistence.EntityManagerFactory;
> +import javax.persistence.EntityTransaction;
> +import javax.persistence.Persistence;
> +
> +import junit.framework.TestCase;
> +import junit.textui.TestRunner;
> +import org.apache.openjpa.persistence.OpenJPAEntityManager;
> +
> +/**
> + * Simple test case to get an EntityManager and perform some basic  
> operations.
> + *
> + * @author Marc Prud'hommeaux
> + */
> +public class TestPersistence
> +    extends TestCase {
> +
> +    private EntityManagerFactory emf;
> +
> +    public void setUp() {
> +        Map props = new HashMap(System.getProperties());
> +        props.put("openjpa.MetaDataFactory",
> +            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> +        emf = Persistence.createEntityManagerFactory("test", props);
> +    }
> +
> +    public void tearDown() {
> +        if (emf == null)
> +            return;
> +        try {
> +            EntityManager em = emf.createEntityManager();
> +            em.getTransaction().begin();
> +            em.createQuery("delete from  
> AllFieldTypes").executeUpdate();
> +            em.getTransaction().commit();
> +            em.close();
> +            emf.close();
> +        } catch (Exception e) {
> +        }
> +    }
> +
> +    public void testCreateEntityManager() {
> +        EntityManager em = emf.createEntityManager();
> +
> +        EntityTransaction t = em.getTransaction();
> +        assertNotNull(t);
> +        t.begin();
> +        t.setRollbackOnly();
> +        t.rollback();
> +
> +        // openjpa-facade test
> +        assertTrue(em instanceof OpenJPAEntityManager);
> +        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> +        ojem.getFetchPlan().setMaxFetchDepth(1);
> +        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> +        em.close();
> +    }
> +
> +    public void testPersist() {
> +        EntityManager em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        em.persist(new AllFieldTypes());
> +        em.getTransaction().commit();
> +        em.close();
> +    }
> +
> +    public void testQuery() {
> +        EntityManager em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        AllFieldTypes aft = new AllFieldTypes();
> +        aft.setStringField("foo");
> +        aft.setIntField(10);
> +        em.persist(aft);
> +        em.getTransaction().commit();
> +        em.close();
> +
> +        em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        assertEquals(1, em.createQuery
> +            ("select x from AllFieldTypes x where x.stringField =  
> 'foo'").
> +            getResultList().size());
> +        assertEquals(0, em.createQuery
> +            ("select x from AllFieldTypes x where x.stringField =  
> 'bar'").
> +            getResultList().size());
> +        assertEquals(1, em.createQuery
> +            ("select x from AllFieldTypes x where x.intField >= 10").
> +            getResultList().size());
> +        em.getTransaction().rollback();
> +        em.close();
> +    }
> +
> +    /**
> +     * Ensures that an IllegalStateException is thrown if  
> getDelegate is called
> +     * after closing the EntityManager.
> +     */
> +    public void testGetDelegateAfterClose() {
> +        EntityManager em = emf.createEntityManager();
> +
> +        em.close();
> +
> +        try {
> +            Object o = em.getDelegate();
> +            fail();
> +        }
> +        catch(IllegalStateException ise) {
> +            /*
> +             * An IllegalStateException is expected. Nothing to do  
> here.
> +             */
> +        }
> +    }
> +
> +    public static void main(String[] args) {
> +        TestRunner.run(TestPersistence.class);
> +    }
> +}
> +
>
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: svn commit: r501955 - /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java

Posted by Kevin Sutter <kw...@gmail.com>.
Yeah, I tend to agree.  Just wanted to get something out there for the fix
that was provided...  And, doing it this way allows me to experiment more
with getting these line ending characters correct...  :-)  JK!

On 1/31/07, Craig L Russell <Cr...@sun.com> wrote:
>
> I'd prefer to see a separate test that tests all of the em methods
> that are supposed to throw an exception (all of them except isOpen
> and getTransaction). Putting this new test here is awkward.
>
> Craig
>
> On Jan 31, 2007, at 11:27 AM, kwsutter@apache.org wrote:
>
> > Author: kwsutter
> > Date: Wed Jan 31 11:27:11 2007
> > New Revision: 501955
> >
> > URL: http://svn.apache.org/viewvc?view=rev&rev=501955
> > Log:
> > Simple test for OPENJPA-116.  Just modified the simple
> > TestPersistence testcase with a new variation for testing the
> > exception on getDelegate() when the EM is closed.
> >
> > Modified:
> >     incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/
> > org/apache/openjpa/persistence/simple/TestPersistence.java
> >
> > Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/
> > java/org/apache/openjpa/persistence/simple/TestPersistence.java
> > URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-
> > persistence-jdbc/src/test/java/org/apache/openjpa/persistence/
> > simple/TestPersistence.java?view=diff&rev=501955&r1=501954&r2=501955
> > ======================================================================
> > ========
> > --- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/
> > org/apache/openjpa/persistence/simple/TestPersistence.java (original)
> > +++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/
> > org/apache/openjpa/persistence/simple/TestPersistence.java Wed Jan
> > 31 11:27:11 2007
> > @@ -1,114 +1,134 @@
> > -/*
> > - * Copyright 2006 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.openjpa.persistence.simple;
> > -
> > -import java.util.HashMap;
> > -import java.util.Map;
> > -import javax.persistence.EntityManager;
> > -import javax.persistence.EntityManagerFactory;
> > -import javax.persistence.EntityTransaction;
> > -import javax.persistence.Persistence;
> > -
> > -import junit.framework.TestCase;
> > -import junit.textui.TestRunner;
> > -import org.apache.openjpa.persistence.OpenJPAEntityManager;
> > -
> > -/**
> > - * Simple test case to get an EntityManager and perform some basic
> > operations.
> > - *
> > - * @author Marc Prud'hommeaux
> > - */
> > -public class TestPersistence
> > -    extends TestCase {
> > -
> > -    private EntityManagerFactory emf;
> > -
> > -    public void setUp() {
> > -        Map props = new HashMap(System.getProperties());
> > -        props.put("openjpa.MetaDataFactory",
> > -            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> > -        emf = Persistence.createEntityManagerFactory("test", props);
> > -    }
> > -
> > -    public void tearDown() {
> > -        if (emf == null)
> > -            return;
> > -        try {
> > -            EntityManager em = emf.createEntityManager();
> > -            em.getTransaction().begin();
> > -            em.createQuery("delete from
> > AllFieldTypes").executeUpdate();
> > -            em.getTransaction().commit();
> > -            em.close();
> > -            emf.close();
> > -        } catch (Exception e) {
> > -        }
> > -    }
> > -
> > -    public void testCreateEntityManager() {
> > -        EntityManager em = emf.createEntityManager();
> > -
> > -        EntityTransaction t = em.getTransaction();
> > -        assertNotNull(t);
> > -        t.begin();
> > -        t.setRollbackOnly();
> > -        t.rollback();
> > -
> > -        // openjpa-facade test
> > -        assertTrue(em instanceof OpenJPAEntityManager);
> > -        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> > -        ojem.getFetchPlan().setMaxFetchDepth(1);
> > -        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> > -        em.close();
> > -    }
> > -
> > -    public void testPersist() {
> > -        EntityManager em = emf.createEntityManager();
> > -        em.getTransaction().begin();
> > -        em.persist(new AllFieldTypes());
> > -        em.getTransaction().commit();
> > -        em.close();
> > -    }
> > -
> > -    public void testQuery() {
> > -        EntityManager em = emf.createEntityManager();
> > -        em.getTransaction().begin();
> > -        AllFieldTypes aft = new AllFieldTypes();
> > -        aft.setStringField("foo");
> > -        aft.setIntField(10);
> > -        em.persist(aft);
> > -        em.getTransaction().commit();
> > -        em.close();
> > -
> > -        em = emf.createEntityManager();
> > -        em.getTransaction().begin();
> > -        assertEquals(1, em.createQuery
> > -            ("select x from AllFieldTypes x where x.stringField =
> > 'foo'").
> > -            getResultList().size());
> > -        assertEquals(0, em.createQuery
> > -            ("select x from AllFieldTypes x where x.stringField =
> > 'bar'").
> > -            getResultList().size());
> > -        assertEquals(1, em.createQuery
> > -            ("select x from AllFieldTypes x where x.intField >= 10").
> > -            getResultList().size());
> > -        em.getTransaction().rollback();
> > -        em.close();
> > -    }
> > -
> > -    public static void main(String[] args) {
> > -        TestRunner.run(TestPersistence.class);
> > -    }
> > -}
> > -
> > +/*
> > + * Copyright 2006 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.openjpa.persistence.simple;
> > +
> > +import java.util.HashMap;
> > +import java.util.Map;
> > +import javax.persistence.EntityManager;
> > +import javax.persistence.EntityManagerFactory;
> > +import javax.persistence.EntityTransaction;
> > +import javax.persistence.Persistence;
> > +
> > +import junit.framework.TestCase;
> > +import junit.textui.TestRunner;
> > +import org.apache.openjpa.persistence.OpenJPAEntityManager;
> > +
> > +/**
> > + * Simple test case to get an EntityManager and perform some basic
> > operations.
> > + *
> > + * @author Marc Prud'hommeaux
> > + */
> > +public class TestPersistence
> > +    extends TestCase {
> > +
> > +    private EntityManagerFactory emf;
> > +
> > +    public void setUp() {
> > +        Map props = new HashMap(System.getProperties());
> > +        props.put("openjpa.MetaDataFactory",
> > +            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> > +        emf = Persistence.createEntityManagerFactory("test", props);
> > +    }
> > +
> > +    public void tearDown() {
> > +        if (emf == null)
> > +            return;
> > +        try {
> > +            EntityManager em = emf.createEntityManager();
> > +            em.getTransaction().begin();
> > +            em.createQuery("delete from
> > AllFieldTypes").executeUpdate();
> > +            em.getTransaction().commit();
> > +            em.close();
> > +            emf.close();
> > +        } catch (Exception e) {
> > +        }
> > +    }
> > +
> > +    public void testCreateEntityManager() {
> > +        EntityManager em = emf.createEntityManager();
> > +
> > +        EntityTransaction t = em.getTransaction();
> > +        assertNotNull(t);
> > +        t.begin();
> > +        t.setRollbackOnly();
> > +        t.rollback();
> > +
> > +        // openjpa-facade test
> > +        assertTrue(em instanceof OpenJPAEntityManager);
> > +        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> > +        ojem.getFetchPlan().setMaxFetchDepth(1);
> > +        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> > +        em.close();
> > +    }
> > +
> > +    public void testPersist() {
> > +        EntityManager em = emf.createEntityManager();
> > +        em.getTransaction().begin();
> > +        em.persist(new AllFieldTypes());
> > +        em.getTransaction().commit();
> > +        em.close();
> > +    }
> > +
> > +    public void testQuery() {
> > +        EntityManager em = emf.createEntityManager();
> > +        em.getTransaction().begin();
> > +        AllFieldTypes aft = new AllFieldTypes();
> > +        aft.setStringField("foo");
> > +        aft.setIntField(10);
> > +        em.persist(aft);
> > +        em.getTransaction().commit();
> > +        em.close();
> > +
> > +        em = emf.createEntityManager();
> > +        em.getTransaction().begin();
> > +        assertEquals(1, em.createQuery
> > +            ("select x from AllFieldTypes x where x.stringField =
> > 'foo'").
> > +            getResultList().size());
> > +        assertEquals(0, em.createQuery
> > +            ("select x from AllFieldTypes x where x.stringField =
> > 'bar'").
> > +            getResultList().size());
> > +        assertEquals(1, em.createQuery
> > +            ("select x from AllFieldTypes x where x.intField >= 10").
> > +            getResultList().size());
> > +        em.getTransaction().rollback();
> > +        em.close();
> > +    }
> > +
> > +    /**
> > +     * Ensures that an IllegalStateException is thrown if
> > getDelegate is called
> > +     * after closing the EntityManager.
> > +     */
> > +    public void testGetDelegateAfterClose() {
> > +        EntityManager em = emf.createEntityManager();
> > +
> > +        em.close();
> > +
> > +        try {
> > +            Object o = em.getDelegate();
> > +            fail();
> > +        }
> > +        catch(IllegalStateException ise) {
> > +            /*
> > +             * An IllegalStateException is expected. Nothing to do
> > here.
> > +             */
> > +        }
> > +    }
> > +
> > +    public static void main(String[] args) {
> > +        TestRunner.run(TestPersistence.class);
> > +    }
> > +}
> > +
> >
> >
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>
>
>

Re: svn commit: r501955 - /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java

Posted by Craig L Russell <Cr...@Sun.COM>.
I'd prefer to see a separate test that tests all of the em methods  
that are supposed to throw an exception (all of them except isOpen  
and getTransaction). Putting this new test here is awkward.

Craig

On Jan 31, 2007, at 11:27 AM, kwsutter@apache.org wrote:

> Author: kwsutter
> Date: Wed Jan 31 11:27:11 2007
> New Revision: 501955
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=501955
> Log:
> Simple test for OPENJPA-116.  Just modified the simple  
> TestPersistence testcase with a new variation for testing the  
> exception on getDelegate() when the EM is closed.
>
> Modified:
>     incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java
>
> Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/ 
> java/org/apache/openjpa/persistence/simple/TestPersistence.java
> URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa- 
> persistence-jdbc/src/test/java/org/apache/openjpa/persistence/ 
> simple/TestPersistence.java?view=diff&rev=501955&r1=501954&r2=501955
> ====================================================================== 
> ========
> --- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java (original)
> +++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java Wed Jan  
> 31 11:27:11 2007
> @@ -1,114 +1,134 @@
> -/*
> - * Copyright 2006 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.openjpa.persistence.simple;
> -
> -import java.util.HashMap;
> -import java.util.Map;
> -import javax.persistence.EntityManager;
> -import javax.persistence.EntityManagerFactory;
> -import javax.persistence.EntityTransaction;
> -import javax.persistence.Persistence;
> -
> -import junit.framework.TestCase;
> -import junit.textui.TestRunner;
> -import org.apache.openjpa.persistence.OpenJPAEntityManager;
> -
> -/**
> - * Simple test case to get an EntityManager and perform some basic  
> operations.
> - *
> - * @author Marc Prud'hommeaux
> - */
> -public class TestPersistence
> -    extends TestCase {
> -
> -    private EntityManagerFactory emf;
> -
> -    public void setUp() {
> -        Map props = new HashMap(System.getProperties());
> -        props.put("openjpa.MetaDataFactory",
> -            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> -        emf = Persistence.createEntityManagerFactory("test", props);
> -    }
> -
> -    public void tearDown() {
> -        if (emf == null)
> -            return;
> -        try {
> -            EntityManager em = emf.createEntityManager();
> -            em.getTransaction().begin();
> -            em.createQuery("delete from  
> AllFieldTypes").executeUpdate();
> -            em.getTransaction().commit();
> -            em.close();
> -            emf.close();
> -        } catch (Exception e) {
> -        }
> -    }
> -
> -    public void testCreateEntityManager() {
> -        EntityManager em = emf.createEntityManager();
> -
> -        EntityTransaction t = em.getTransaction();
> -        assertNotNull(t);
> -        t.begin();
> -        t.setRollbackOnly();
> -        t.rollback();
> -
> -        // openjpa-facade test
> -        assertTrue(em instanceof OpenJPAEntityManager);
> -        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> -        ojem.getFetchPlan().setMaxFetchDepth(1);
> -        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> -        em.close();
> -    }
> -
> -    public void testPersist() {
> -        EntityManager em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        em.persist(new AllFieldTypes());
> -        em.getTransaction().commit();
> -        em.close();
> -    }
> -
> -    public void testQuery() {
> -        EntityManager em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        AllFieldTypes aft = new AllFieldTypes();
> -        aft.setStringField("foo");
> -        aft.setIntField(10);
> -        em.persist(aft);
> -        em.getTransaction().commit();
> -        em.close();
> -
> -        em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        assertEquals(1, em.createQuery
> -            ("select x from AllFieldTypes x where x.stringField =  
> 'foo'").
> -            getResultList().size());
> -        assertEquals(0, em.createQuery
> -            ("select x from AllFieldTypes x where x.stringField =  
> 'bar'").
> -            getResultList().size());
> -        assertEquals(1, em.createQuery
> -            ("select x from AllFieldTypes x where x.intField >= 10").
> -            getResultList().size());
> -        em.getTransaction().rollback();
> -        em.close();
> -    }
> -
> -    public static void main(String[] args) {
> -        TestRunner.run(TestPersistence.class);
> -    }
> -}
> -
> +/*
> + * Copyright 2006 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.openjpa.persistence.simple;
> +
> +import java.util.HashMap;
> +import java.util.Map;
> +import javax.persistence.EntityManager;
> +import javax.persistence.EntityManagerFactory;
> +import javax.persistence.EntityTransaction;
> +import javax.persistence.Persistence;
> +
> +import junit.framework.TestCase;
> +import junit.textui.TestRunner;
> +import org.apache.openjpa.persistence.OpenJPAEntityManager;
> +
> +/**
> + * Simple test case to get an EntityManager and perform some basic  
> operations.
> + *
> + * @author Marc Prud'hommeaux
> + */
> +public class TestPersistence
> +    extends TestCase {
> +
> +    private EntityManagerFactory emf;
> +
> +    public void setUp() {
> +        Map props = new HashMap(System.getProperties());
> +        props.put("openjpa.MetaDataFactory",
> +            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> +        emf = Persistence.createEntityManagerFactory("test", props);
> +    }
> +
> +    public void tearDown() {
> +        if (emf == null)
> +            return;
> +        try {
> +            EntityManager em = emf.createEntityManager();
> +            em.getTransaction().begin();
> +            em.createQuery("delete from  
> AllFieldTypes").executeUpdate();
> +            em.getTransaction().commit();
> +            em.close();
> +            emf.close();
> +        } catch (Exception e) {
> +        }
> +    }
> +
> +    public void testCreateEntityManager() {
> +        EntityManager em = emf.createEntityManager();
> +
> +        EntityTransaction t = em.getTransaction();
> +        assertNotNull(t);
> +        t.begin();
> +        t.setRollbackOnly();
> +        t.rollback();
> +
> +        // openjpa-facade test
> +        assertTrue(em instanceof OpenJPAEntityManager);
> +        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> +        ojem.getFetchPlan().setMaxFetchDepth(1);
> +        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> +        em.close();
> +    }
> +
> +    public void testPersist() {
> +        EntityManager em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        em.persist(new AllFieldTypes());
> +        em.getTransaction().commit();
> +        em.close();
> +    }
> +
> +    public void testQuery() {
> +        EntityManager em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        AllFieldTypes aft = new AllFieldTypes();
> +        aft.setStringField("foo");
> +        aft.setIntField(10);
> +        em.persist(aft);
> +        em.getTransaction().commit();
> +        em.close();
> +
> +        em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        assertEquals(1, em.createQuery
> +            ("select x from AllFieldTypes x where x.stringField =  
> 'foo'").
> +            getResultList().size());
> +        assertEquals(0, em.createQuery
> +            ("select x from AllFieldTypes x where x.stringField =  
> 'bar'").
> +            getResultList().size());
> +        assertEquals(1, em.createQuery
> +            ("select x from AllFieldTypes x where x.intField >= 10").
> +            getResultList().size());
> +        em.getTransaction().rollback();
> +        em.close();
> +    }
> +
> +    /**
> +     * Ensures that an IllegalStateException is thrown if  
> getDelegate is called
> +     * after closing the EntityManager.
> +     */
> +    public void testGetDelegateAfterClose() {
> +        EntityManager em = emf.createEntityManager();
> +
> +        em.close();
> +
> +        try {
> +            Object o = em.getDelegate();
> +            fail();
> +        }
> +        catch(IllegalStateException ise) {
> +            /*
> +             * An IllegalStateException is expected. Nothing to do  
> here.
> +             */
> +        }
> +    }
> +
> +    public static void main(String[] args) {
> +        TestRunner.run(TestPersistence.class);
> +    }
> +}
> +
>
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: svn commit: r501955 - /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java

Posted by Craig L Russell <Cr...@Sun.COM>.
I'd prefer to see a separate test that tests all of the em methods  
that are supposed to throw an exception (all of them except isOpen  
and getTransaction). Putting this new test here is awkward.

Craig

On Jan 31, 2007, at 11:27 AM, kwsutter@apache.org wrote:

> Author: kwsutter
> Date: Wed Jan 31 11:27:11 2007
> New Revision: 501955
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=501955
> Log:
> Simple test for OPENJPA-116.  Just modified the simple  
> TestPersistence testcase with a new variation for testing the  
> exception on getDelegate() when the EM is closed.
>
> Modified:
>     incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java
>
> Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/ 
> java/org/apache/openjpa/persistence/simple/TestPersistence.java
> URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa- 
> persistence-jdbc/src/test/java/org/apache/openjpa/persistence/ 
> simple/TestPersistence.java?view=diff&rev=501955&r1=501954&r2=501955
> ====================================================================== 
> ========
> --- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java (original)
> +++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java Wed Jan  
> 31 11:27:11 2007
> @@ -1,114 +1,134 @@
> -/*
> - * Copyright 2006 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.openjpa.persistence.simple;
> -
> -import java.util.HashMap;
> -import java.util.Map;
> -import javax.persistence.EntityManager;
> -import javax.persistence.EntityManagerFactory;
> -import javax.persistence.EntityTransaction;
> -import javax.persistence.Persistence;
> -
> -import junit.framework.TestCase;
> -import junit.textui.TestRunner;
> -import org.apache.openjpa.persistence.OpenJPAEntityManager;
> -
> -/**
> - * Simple test case to get an EntityManager and perform some basic  
> operations.
> - *
> - * @author Marc Prud'hommeaux
> - */
> -public class TestPersistence
> -    extends TestCase {
> -
> -    private EntityManagerFactory emf;
> -
> -    public void setUp() {
> -        Map props = new HashMap(System.getProperties());
> -        props.put("openjpa.MetaDataFactory",
> -            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> -        emf = Persistence.createEntityManagerFactory("test", props);
> -    }
> -
> -    public void tearDown() {
> -        if (emf == null)
> -            return;
> -        try {
> -            EntityManager em = emf.createEntityManager();
> -            em.getTransaction().begin();
> -            em.createQuery("delete from  
> AllFieldTypes").executeUpdate();
> -            em.getTransaction().commit();
> -            em.close();
> -            emf.close();
> -        } catch (Exception e) {
> -        }
> -    }
> -
> -    public void testCreateEntityManager() {
> -        EntityManager em = emf.createEntityManager();
> -
> -        EntityTransaction t = em.getTransaction();
> -        assertNotNull(t);
> -        t.begin();
> -        t.setRollbackOnly();
> -        t.rollback();
> -
> -        // openjpa-facade test
> -        assertTrue(em instanceof OpenJPAEntityManager);
> -        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> -        ojem.getFetchPlan().setMaxFetchDepth(1);
> -        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> -        em.close();
> -    }
> -
> -    public void testPersist() {
> -        EntityManager em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        em.persist(new AllFieldTypes());
> -        em.getTransaction().commit();
> -        em.close();
> -    }
> -
> -    public void testQuery() {
> -        EntityManager em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        AllFieldTypes aft = new AllFieldTypes();
> -        aft.setStringField("foo");
> -        aft.setIntField(10);
> -        em.persist(aft);
> -        em.getTransaction().commit();
> -        em.close();
> -
> -        em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        assertEquals(1, em.createQuery
> -            ("select x from AllFieldTypes x where x.stringField =  
> 'foo'").
> -            getResultList().size());
> -        assertEquals(0, em.createQuery
> -            ("select x from AllFieldTypes x where x.stringField =  
> 'bar'").
> -            getResultList().size());
> -        assertEquals(1, em.createQuery
> -            ("select x from AllFieldTypes x where x.intField >= 10").
> -            getResultList().size());
> -        em.getTransaction().rollback();
> -        em.close();
> -    }
> -
> -    public static void main(String[] args) {
> -        TestRunner.run(TestPersistence.class);
> -    }
> -}
> -
> +/*
> + * Copyright 2006 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.openjpa.persistence.simple;
> +
> +import java.util.HashMap;
> +import java.util.Map;
> +import javax.persistence.EntityManager;
> +import javax.persistence.EntityManagerFactory;
> +import javax.persistence.EntityTransaction;
> +import javax.persistence.Persistence;
> +
> +import junit.framework.TestCase;
> +import junit.textui.TestRunner;
> +import org.apache.openjpa.persistence.OpenJPAEntityManager;
> +
> +/**
> + * Simple test case to get an EntityManager and perform some basic  
> operations.
> + *
> + * @author Marc Prud'hommeaux
> + */
> +public class TestPersistence
> +    extends TestCase {
> +
> +    private EntityManagerFactory emf;
> +
> +    public void setUp() {
> +        Map props = new HashMap(System.getProperties());
> +        props.put("openjpa.MetaDataFactory",
> +            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> +        emf = Persistence.createEntityManagerFactory("test", props);
> +    }
> +
> +    public void tearDown() {
> +        if (emf == null)
> +            return;
> +        try {
> +            EntityManager em = emf.createEntityManager();
> +            em.getTransaction().begin();
> +            em.createQuery("delete from  
> AllFieldTypes").executeUpdate();
> +            em.getTransaction().commit();
> +            em.close();
> +            emf.close();
> +        } catch (Exception e) {
> +        }
> +    }
> +
> +    public void testCreateEntityManager() {
> +        EntityManager em = emf.createEntityManager();
> +
> +        EntityTransaction t = em.getTransaction();
> +        assertNotNull(t);
> +        t.begin();
> +        t.setRollbackOnly();
> +        t.rollback();
> +
> +        // openjpa-facade test
> +        assertTrue(em instanceof OpenJPAEntityManager);
> +        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> +        ojem.getFetchPlan().setMaxFetchDepth(1);
> +        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> +        em.close();
> +    }
> +
> +    public void testPersist() {
> +        EntityManager em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        em.persist(new AllFieldTypes());
> +        em.getTransaction().commit();
> +        em.close();
> +    }
> +
> +    public void testQuery() {
> +        EntityManager em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        AllFieldTypes aft = new AllFieldTypes();
> +        aft.setStringField("foo");
> +        aft.setIntField(10);
> +        em.persist(aft);
> +        em.getTransaction().commit();
> +        em.close();
> +
> +        em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        assertEquals(1, em.createQuery
> +            ("select x from AllFieldTypes x where x.stringField =  
> 'foo'").
> +            getResultList().size());
> +        assertEquals(0, em.createQuery
> +            ("select x from AllFieldTypes x where x.stringField =  
> 'bar'").
> +            getResultList().size());
> +        assertEquals(1, em.createQuery
> +            ("select x from AllFieldTypes x where x.intField >= 10").
> +            getResultList().size());
> +        em.getTransaction().rollback();
> +        em.close();
> +    }
> +
> +    /**
> +     * Ensures that an IllegalStateException is thrown if  
> getDelegate is called
> +     * after closing the EntityManager.
> +     */
> +    public void testGetDelegateAfterClose() {
> +        EntityManager em = emf.createEntityManager();
> +
> +        em.close();
> +
> +        try {
> +            Object o = em.getDelegate();
> +            fail();
> +        }
> +        catch(IllegalStateException ise) {
> +            /*
> +             * An IllegalStateException is expected. Nothing to do  
> here.
> +             */
> +        }
> +    }
> +
> +    public static void main(String[] args) {
> +        TestRunner.run(TestPersistence.class);
> +    }
> +}
> +
>
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: svn commit: r501955 - /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java

Posted by Craig L Russell <Cr...@Sun.COM>.
This commit is way too big for its changes.

I recommend that everyone do an svn diff prior to commit to make sure  
that you don't have a line-end problem, such as this appears to have.

Craig

On Jan 31, 2007, at 11:27 AM, kwsutter@apache.org wrote:

> Author: kwsutter
> Date: Wed Jan 31 11:27:11 2007
> New Revision: 501955
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=501955
> Log:
> Simple test for OPENJPA-116.  Just modified the simple  
> TestPersistence testcase with a new variation for testing the  
> exception on getDelegate() when the EM is closed.
>
> Modified:
>     incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java
>
> Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/ 
> java/org/apache/openjpa/persistence/simple/TestPersistence.java
> URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa- 
> persistence-jdbc/src/test/java/org/apache/openjpa/persistence/ 
> simple/TestPersistence.java?view=diff&rev=501955&r1=501954&r2=501955
> ====================================================================== 
> ========
> --- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java (original)
> +++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/ 
> org/apache/openjpa/persistence/simple/TestPersistence.java Wed Jan  
> 31 11:27:11 2007
> @@ -1,114 +1,134 @@
> -/*
> - * Copyright 2006 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.openjpa.persistence.simple;
> -
> -import java.util.HashMap;
> -import java.util.Map;
> -import javax.persistence.EntityManager;
> -import javax.persistence.EntityManagerFactory;
> -import javax.persistence.EntityTransaction;
> -import javax.persistence.Persistence;
> -
> -import junit.framework.TestCase;
> -import junit.textui.TestRunner;
> -import org.apache.openjpa.persistence.OpenJPAEntityManager;
> -
> -/**
> - * Simple test case to get an EntityManager and perform some basic  
> operations.
> - *
> - * @author Marc Prud'hommeaux
> - */
> -public class TestPersistence
> -    extends TestCase {
> -
> -    private EntityManagerFactory emf;
> -
> -    public void setUp() {
> -        Map props = new HashMap(System.getProperties());
> -        props.put("openjpa.MetaDataFactory",
> -            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> -        emf = Persistence.createEntityManagerFactory("test", props);
> -    }
> -
> -    public void tearDown() {
> -        if (emf == null)
> -            return;
> -        try {
> -            EntityManager em = emf.createEntityManager();
> -            em.getTransaction().begin();
> -            em.createQuery("delete from  
> AllFieldTypes").executeUpdate();
> -            em.getTransaction().commit();
> -            em.close();
> -            emf.close();
> -        } catch (Exception e) {
> -        }
> -    }
> -
> -    public void testCreateEntityManager() {
> -        EntityManager em = emf.createEntityManager();
> -
> -        EntityTransaction t = em.getTransaction();
> -        assertNotNull(t);
> -        t.begin();
> -        t.setRollbackOnly();
> -        t.rollback();
> -
> -        // openjpa-facade test
> -        assertTrue(em instanceof OpenJPAEntityManager);
> -        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> -        ojem.getFetchPlan().setMaxFetchDepth(1);
> -        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> -        em.close();
> -    }
> -
> -    public void testPersist() {
> -        EntityManager em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        em.persist(new AllFieldTypes());
> -        em.getTransaction().commit();
> -        em.close();
> -    }
> -
> -    public void testQuery() {
> -        EntityManager em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        AllFieldTypes aft = new AllFieldTypes();
> -        aft.setStringField("foo");
> -        aft.setIntField(10);
> -        em.persist(aft);
> -        em.getTransaction().commit();
> -        em.close();
> -
> -        em = emf.createEntityManager();
> -        em.getTransaction().begin();
> -        assertEquals(1, em.createQuery
> -            ("select x from AllFieldTypes x where x.stringField =  
> 'foo'").
> -            getResultList().size());
> -        assertEquals(0, em.createQuery
> -            ("select x from AllFieldTypes x where x.stringField =  
> 'bar'").
> -            getResultList().size());
> -        assertEquals(1, em.createQuery
> -            ("select x from AllFieldTypes x where x.intField >= 10").
> -            getResultList().size());
> -        em.getTransaction().rollback();
> -        em.close();
> -    }
> -
> -    public static void main(String[] args) {
> -        TestRunner.run(TestPersistence.class);
> -    }
> -}
> -
> +/*
> + * Copyright 2006 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.openjpa.persistence.simple;
> +
> +import java.util.HashMap;
> +import java.util.Map;
> +import javax.persistence.EntityManager;
> +import javax.persistence.EntityManagerFactory;
> +import javax.persistence.EntityTransaction;
> +import javax.persistence.Persistence;
> +
> +import junit.framework.TestCase;
> +import junit.textui.TestRunner;
> +import org.apache.openjpa.persistence.OpenJPAEntityManager;
> +
> +/**
> + * Simple test case to get an EntityManager and perform some basic  
> operations.
> + *
> + * @author Marc Prud'hommeaux
> + */
> +public class TestPersistence
> +    extends TestCase {
> +
> +    private EntityManagerFactory emf;
> +
> +    public void setUp() {
> +        Map props = new HashMap(System.getProperties());
> +        props.put("openjpa.MetaDataFactory",
> +            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
> +        emf = Persistence.createEntityManagerFactory("test", props);
> +    }
> +
> +    public void tearDown() {
> +        if (emf == null)
> +            return;
> +        try {
> +            EntityManager em = emf.createEntityManager();
> +            em.getTransaction().begin();
> +            em.createQuery("delete from  
> AllFieldTypes").executeUpdate();
> +            em.getTransaction().commit();
> +            em.close();
> +            emf.close();
> +        } catch (Exception e) {
> +        }
> +    }
> +
> +    public void testCreateEntityManager() {
> +        EntityManager em = emf.createEntityManager();
> +
> +        EntityTransaction t = em.getTransaction();
> +        assertNotNull(t);
> +        t.begin();
> +        t.setRollbackOnly();
> +        t.rollback();
> +
> +        // openjpa-facade test
> +        assertTrue(em instanceof OpenJPAEntityManager);
> +        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
> +        ojem.getFetchPlan().setMaxFetchDepth(1);
> +        assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
> +        em.close();
> +    }
> +
> +    public void testPersist() {
> +        EntityManager em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        em.persist(new AllFieldTypes());
> +        em.getTransaction().commit();
> +        em.close();
> +    }
> +
> +    public void testQuery() {
> +        EntityManager em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        AllFieldTypes aft = new AllFieldTypes();
> +        aft.setStringField("foo");
> +        aft.setIntField(10);
> +        em.persist(aft);
> +        em.getTransaction().commit();
> +        em.close();
> +
> +        em = emf.createEntityManager();
> +        em.getTransaction().begin();
> +        assertEquals(1, em.createQuery
> +            ("select x from AllFieldTypes x where x.stringField =  
> 'foo'").
> +            getResultList().size());
> +        assertEquals(0, em.createQuery
> +            ("select x from AllFieldTypes x where x.stringField =  
> 'bar'").
> +            getResultList().size());
> +        assertEquals(1, em.createQuery
> +            ("select x from AllFieldTypes x where x.intField >= 10").
> +            getResultList().size());
> +        em.getTransaction().rollback();
> +        em.close();
> +    }
> +
> +    /**
> +     * Ensures that an IllegalStateException is thrown if  
> getDelegate is called
> +     * after closing the EntityManager.
> +     */
> +    public void testGetDelegateAfterClose() {
> +        EntityManager em = emf.createEntityManager();
> +
> +        em.close();
> +
> +        try {
> +            Object o = em.getDelegate();
> +            fail();
> +        }
> +        catch(IllegalStateException ise) {
> +            /*
> +             * An IllegalStateException is expected. Nothing to do  
> here.
> +             */
> +        }
> +    }
> +
> +    public static void main(String[] args) {
> +        TestRunner.run(TestPersistence.class);
> +    }
> +}
> +
>
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!