grails - how to override gorm delete method for testing? -
i writing simple integration test intend simulate delete failure.
the controller pulls record database , deletes shown below.
def deleteitem(id){ def item = item.get(id) item.delete() }
now, want simulate delete failure following code
void testdeleteitem_faildeleteflushsavefail(){ item.metaclass.delete = { map params -> throw new validationexception("failed!!") } def model = controller.deleteitem(mp.id) assertequals controller.flash.message, "sorry error occured when deleting!!" groovysystem.metaclassregistry.removemetaclass(item.class) }
but test fails because method not replaced. i.e exception not thrown on delete. guessing problem in metaclass formulation. how can make exception thrown when delete called? appreciate help! thanks!
this because should use
item.metaclass.delete = { throw new validationexception("failed!!") }
rather
item.metaclass.delete = { map params -> throw new validationexception("failed!!") }
Comments
Post a Comment