openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: svn commit: r501955 - /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
Date Wed, 31 Jan 2007 20:18:06 GMT
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!


Mime
View raw message