3 Replies Latest reply on Apr 15, 2015 7:30 AM by awizenm

    Persistence configuration for JUnit tests based on JbpmJUnitBaseTestCase

    awizenm

      Hi everybody,

       

      how to set-up the JUnit test environment to make persistent entities available for all test methods?

       

      Please take a look at this small test. The set-up method persists a new user using  the helper methods from JbpmJUnitBaseTestCase. Unfortunately the user can not be found in the test method.

       

      public class EntityManagerTest extends JbpmJUnitBaseTestCase {
      
          @Test
          public void testEvaluationProcess() {
      
              EntityManager entityManager = getEmf().createEntityManager();
              UserImpl user = entityManager.find(UserImpl.class, "newUserId");
      
              assertNotNull("User not found!", user);
          }
      
          public EntityManagerTest() {
              super(true, true);
          }
      
          @Override
          @Before
          public void setUp() throws Exception{
              super.setUp();
      
              EntityManager entityManager = getEmf().createEntityManager();
              entityManager.persist(new UserImpl("newUserId"));
          }
      }
      
      
      
      
      
      
      
      
      

       

      Any suggestions?

        • 1. Re: Persistence configuration for JUnit tests
          jimmy001

          Hi!

           

          Have you considered to use Arquillian for integration testing ?

          • 2. Re: Persistence configuration for JUnit tests
            awizenm

            Hi Jimmy,

            thank you for your suggestion.

             

            For the time being, in the process design and process development phase I'm looking for a lightweight solution for testing only the bpmn2 process. For this purpose a minimal environment consisting of jBPM runtime and a database should be sufficient. I assumed JbpmJUnitBaseTestCase will provide this environment.

             

            There should be a way to set up the in memory database for the tests based on JbpmJUnitBaseTestCase. Isn't it?

             

            In the case of no success with JbpmJUnitBaseTestCase I will move to Arquillian.

             

            Thx

            • 3. Re: Persistence configuration for JUnit tests based on JbpmJUnitBaseTestCase
              awizenm

              OK, what helps in this testing scenario is just the usage of a transaction in the set-up method:

               

               

              @Override
              @Before
              public void setUp() throws Exception{
              
                  super.setUp();
              
                  BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
                  tm.begin();
                  
                  EntityManager entityManager = getEmf().createEntityManager();
                  entityManager.persist(new UserImpl("newUserId"));
                  
                  tm.commit();
              }