The last working example is not very good because for every @Test method we 
have to createEntityManagerFactory. I don't think it's a good idea.
So i found a better solution:


  | public class MyTest extends SeamTest {
  |     private EntityManagerFactory emf;
  |     
  |     @Override
  |     @BeforeClass
  |     public void init() throws Exception {
  |             super.init();
  |             emf = Persistence.createEntityManagerFactory("ezapp");
  |     }
  |     
  |     @Override
  |     @AfterClass
  |     public void cleanup() throws Exception {
  |             emf.close();
  |             super.cleanup();
  |     }
  | 
  |     @Test
  |     public void testFindByUsername() {      
  |             EntityManager em = emf.createEntityManager();
  |             em.getTransaction().begin();
  |             
  |             em.getTransaction().rollback();
  |             em.close();
  |     }
  | }
  | 

First we have to extend SeamTest even if we are not going to use it's 
functionality in our unit test. But we need to initialize embedded container 
which is started in SeamTest.init(). So we override this method, call 
super.init() to initialize container and next we create our 
EntityManagerFactory. We close EntityManagerFactory in overrided cleanup() 
method.


Regards

Jarek


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

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117392
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to