UNIT TEST ERROR
An update action calls save on a domain object DataCenter that has been mocked. All methods like .get(), .hasErrors() work on the DataCenter during the test but the save() method throws NullPointerException.
Can anyone tell me why this problem is occurring and how to solve it?
Heres a sniplet from the code:
<--------------------------ACTION BEING TESTED------------------------------->
def myaction = {
def Instance = data.get( params.id )
if(Instance) {
if(!Instance.hasErrors()) {
Instance.save(flush:true)
flash.message = "Instance ${params.id} updated"
redirect(action:show,id:Instance.id)
}
}
}
<------------------------------------------------------------------------------>
<--------------------------TEST CODE USED----------------------------------->
void testActionWhenInstanceFoundSaveSuccess() {
def testInstances = [ new Instance('InstanceId': 1, 'name':"I_1", 'city': "TEST_CITY" ) ]
mockDomain(Instance,testInstances)
this.controller.params.id = 1
this.controller.myaction()//Fails Here
}
<----------------------------------------------------------------------------->
An update action calls save on a domain object DataCenter that has been mocked. All methods like .get(), .hasErrors() work on the DataCenter during the test but the save() method throws NullPointerException.
Can anyone tell me why this problem is occurring and how to solve it?
Heres a sniplet from the code:
<--------------------------ACTION BEING TESTED------------------------------->
def myaction = {
def Instance = data.get( params.id )
if(Instance) {
if(!Instance.hasErrors()) {
Instance.save(flush:true)
flash.message = "Instance ${params.id} updated"
redirect(action:show,id:Instance.id)
}
}
}
<------------------------------------------------------------------------------>
<--------------------------TEST CODE USED----------------------------------->
void testActionWhenInstanceFoundSaveSuccess() {
def testInstances = [ new Instance('InstanceId': 1, 'name':"I_1", 'city': "TEST_CITY" ) ]
mockDomain(Instance,testInstances)
this.controller.params.id = 1
this.controller.myaction()//Fails Here
}
<----------------------------------------------------------------------------->
Last edited: