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

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -