2 Replies Latest reply on May 16, 2009 1:33 AM by Emir Calabuch

    TestNG fails in by Seam Web Project generated eclipse Project

    Ashley Williams Newbie

      I generated a "Seam Web Project" in Eclipse, e.g. "MySeam". The plugin generated four projects in eclipse:



      • MySeam

      • MySeam-ear

      • MySeam-ejb

      • Myseam-test



      After solving problems i can deploy now. So far everything is fine except testing. I wanted to test db connection thus i have written a small test:


      ...
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("ops2")
      ...


      Running the test class within TestNG-Plugin results an error:


      ...


      Caused by: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager


      ...


      Has anyone an idea?


      Thanks.
                




        • 1. Re: TestNG fails in by Seam Web Project generated eclipse Project
          Juergen B. Newbie

          I'm facing the same problem.


          Please can anybody give a hint?!


          Thank you!

          • 2. Re: TestNG fails in by Seam Web Project generated eclipse Project
            Emir Calabuch Newbie

            This error is caused by the fact that your persistence.xml is configured to use a JTA transaction manager and you're instantiating the EntityManager directly.


            SeamTest is perhaps too smart... it configures your application to be tested inside a container (JBoss Embedded), so if you create the EntityManager by hand you'll be conflicting with your persistence unit configuration (probably your persistence.xml uses JBossTransactionManagerLookup or has transaction-type="JTA"), which expects you to use the container's transaction manager.


            So, instead of hand creating the EntityManager, just inject it as you would inside the container (because you're actually using it inside a container). If your unit tests are not being run from within the container (i.e., you're not using SeamTest but directly derive your test classes from TestCase), then you need to create a separate persistence.xml for testing purposes, in which you use transaction-type="RESOURCE_LOCAL" and refrain from using several features of hibernate that only work with JTA transaction managers (such as second level cache). But if you're creating EJBs, they are best tested within an EJB container.


            Ideally, you would want to use SeamTest's added features, such as testing from within a full-featured container, which tests your EJBs in the same ecosystem they'll find in production... You can bypass SeamTest in other contexts, for example if you're testing POJOs that don't use the database, seam injection, jndi lookups or other container-specific features.


            For database-specific testing, SeamTest also provides support for DBUnit, which lets you easily populate your database with sample data. I use this setup very effectively with an HSQLDB memory database.