2 Replies Latest reply on Apr 23, 2013 3:39 PM by xiumeteo

    Expecting a RollbackException in a Persistence test?

    xiumeteo

      Hi, i'm using Arquillian with Persistence Extension 1.0.0alpha6 and i trying to test a double insertion on database, so when i persist an entity i must receive a RollbackException cause there is an object previously inserted, but since the insertion is using the same transaction as APE when i call persist the Rollback is catched by APE and i never chatch any exception...

      My question is...is there another approach to do this, o is there imposible with APE??

       

      Greets

       

      Here is my test-code

      @RunWith( Arquillian.class )

       

      public class AppTestIssue6 {

       

          @Inject

          App app1;

       

       

          @PersistenceContext

          EntityManager manager;

         

          @javax.annotation.Resource

          UserTransaction transaction;

         

        

       

       

          @Deployment(  )

          public static Archive<?> createDeployment() {

              return ShrinkWrap.create(WebArchive.class, "test.war")

                      .addPackage(App.class.getPackage())              

                      .addAsResource("persistence_local.xml", "META-INF/persistence.xml")

                      .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

             

          }

               

        

          @Cleanup( phase = TestExecutionPhase.BEFORE )

          @UsingDataSet( "applications_populate.yml" )

          @Test( expected = RollbackException.class )

          public void testpersistWithaUsingDataSet() {       

             

                  

              //transaction.begin();

              App app = new App();

              app.setAppName("prueba1");

              app.setDescription("prueba-java");

              app.setCreatedAt(new Date());

              app.setModifiedAt(new Date());       

             

             

              manager.persist(app);

            

              //transaction.commit();

              //transaction.commit();

          }

       

       

      }

        • 1. Re: Expecting a RollbackException in a Persistence test?
          bmajsak

          You can always use programmatic transaction demarcation. Simply @Inject UserTransaction and turn off APE-provided by using @Transactional(NONE).

           

          However I don't personally see a lot of value in such a test case, because what you are effectively testing is if ORM/DB code works with transactions and guarantees data consistency, which is not really your application responsibility anyway (that's what container provides).

          • 2. Re: Expecting a RollbackException in a Persistence test?
            xiumeteo

            Thnks! a lot! Bartosz...the Alpha6 seems like its better than Alpha5 jaja!...and whatever in i can help with APE it will be wonderful, especially in summer!!