grails - peculiar behaviour of mockDomain -


hi have below unit test,

 class bookunitspec extends unitspec  { def "person_roleof() able retrive person role based on roletype enum"(){     setup: "mock person object"     mockdomain(person); //if move line 3 lines below ... //otherwise test passes     def person = new person()     def employee = new employee(id:1)     def employees = [employee]            //       mockdomain(person);    on here below error     mockdomain(personrole,employees);     mockdomain(employee,employees);     when: "add employee role person"     person.addtopersonroles(employee);     person.save()     then: "check if role can correctly retrieved"     person!=null     person.roleof(roletypes.employee)!=null;     person.roleof(roletypes.author)==null; } } 

throws

groovy.lang.missingmethodexception: no signature of method: com.nthdimenzion.domain.base.person.addtopersonroles() applicable argument types: (com.nthdimenzion.domain.employee) values: [com.nthdimenzion.domain.employee@a6cbf7[empid=<null>]] possible solutions: addtopersonroles(java.lang.object), getpersonroles()     @ org.nthdimenzion.domain.bookunitspec.person_roleof() able retrive person role based on roletype enum(bookunitspec.groovy:21)  groovy.lang.missingmethodexception: no signature of method: com.nthdimenzion.domain.base.person.addtopersonroles() applicable argument types: (com.nthdimenzion.domain.employee) values: [com.nthdimenzion.domain.employee@a6cbf7[empid=<null>]] possible solutions: addtopersonroles(java.lang.object), getpersonroles()     @ org.nthdimenzion.domain.bookunitspec.person_roleof() able retrive person role based on roletype enum(bookunitspec.groovy:21)  groovy.lang.missingmethodexception: no signature of method: com.nthdimenzion.domain.base.person.addtopersonroles() applicable argument types: (com.nthdimenzion.domain.employee) values: [com.nthdimenzion.domain.employee@a6cbf7[empid=<null>]] possible solutions: addtopersonroles(java.lang.object), getpersonroles()     @ org.nthdimenzion.domain.bookunitspec.person_roleof() able retrive person role based on roletype enum(bookunitspec.groovy:21) 

any ideas ?

if change line causes error:

       //       mockdomain(person);    on here below error 

to

       mockdomain( person, [ person ] ) 

does work again? think either need mock domain object before create instance, or need pass instances mockdomain call metaclass can set correctly.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -