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

    Expecting a RollbackException in a Persistence test?

    Cesar Ricardez Newbie

      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();

          }

       

       

      }