[jboss-user] [JBoss Seam] - Re: Uni testing and datasource problem

jagin do-not-reply at jboss.com
Sun Jan 6 13:52:40 EST 2008


OK, I resolved this mystery.

The unit test should look like this:


  | public class MyTest extends SeamTest {
  | 	
  | 	private EntityManagerFactory emf;
  | 
  | 	@Test
  | 	public void testFindByUsername() {
  | 		emf = Persistence.createEntityManagerFactory("ezapp");
  | 	
  | 		EntityManager em = emf.createEntityManager();
  | 		em.getTransaction().begin();
  | 		
  | 		//...		
  | 		
  | 		em.getTransaction().rollback();
  | 		em.close();
  | 		
  | 		emf.close();
  | 	}
  | 
  | }
  | 

The problem was with


  | 	@BeforeClass
  | 	public void init() {
  | 		emf = Persistence.createEntityManagerFactory("project_name");
  | 	}
  | 

It seems that createEntityManagerFactory is called before JBoss Embedded is initialized. Is it bug? In the reference book there is an example of unit test with BeforeClass.

Regards

Jarek

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

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



More information about the jboss-user mailing list