[jboss-user] [JBoss Seam] - Re: Problem testing seam using EntityManager

margonz do-not-reply at jboss.com
Thu Mar 15 13:21:59 EDT 2007


I had the same problem and fixed it by copying exactly how the dvdstore ProductUnitTest gets a handle on the EntityManager. Here is what my simple test UnitTest looked like:

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.jboss.seam.mock.SeamTest;
import org.testng.annotations.Configuration;
import org.testng.annotations.Test;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceException;
import org.jboss.seam.mock.SeamTest;
import org.testng.annotations.Test;
public class UnitTest extends SeamTest {
      EntityManager em() {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("dvdDatabase");
        EntityManager        em  = emf.createEntityManager();
        assertNotNull("entity manager", em);
        assertTrue("entity manager open", em.isOpen());
        return em;
    }
	 	@Test
	    public void testRegisterAction() throws Exception
	    {
	        EntityManager em = em();
	        System.out.println("em = "+em);
	        em.close();
	    }
}


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4028473#4028473

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4028473



More information about the jboss-user mailing list