lundi 7 septembre 2015

Grails 2.4.5 controller unit test verify transaction has rolled back

Here is a simple controller

class UserController {
   @Transactional
   def update() {
      try {
        ....
        throw new Exception("test transaction rollback")
        ...
      } catch( e ) {
        transactionStatus.setRollbackOnly()
        respond "{ "status":"error" }"
      }
   }
}

Here is a unit test spec

@TestFor(UserController)
class UserControllerSpec extends Specification {
   when:''
   controller.update()

   then:'verify that transaction has been rolled back'
   // it fails with missing property, whats the best way to check that it was rolled back ?
   controller.transactionManager.transactionRolledBack == true
}

whats the best way to test that the transaction has been rolled back ?

Aucun commentaire:

Enregistrer un commentaire