3
I는 JSON 응답에 도메인 클래스를 렌더링하는 Grails의 컨트롤러 유닛 테스트를 쓰고 ControllerUnitTestCase의 도메인 객체 실패 도메인 개체 :JSON 렌더링
class MyControllerTests extends ControllerUnitTestCase {
@Before
void setUp() {
super.setUp()
mockDomain(MyDomainClass, [new MyDomainClass(id: 7)])
}
@Test
void testFind() {
def inst = MyDomainClass.get(7)
controller.params.id = inst.id
controller.find()
assert(controller.response.json.data.id == inst.id)
}
모두가 불쾌한 스택 추적을 토해내 json으로 렌더링을 제외하고 잘 작동하는 것 같군이 :
| Failure: testFind(MyControllerTests)
| org.apache.commons.lang.UnhandledException:
org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Error converting Bean with class MyDomainClass
Caused by: org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Error converting Bean with class MyDomainClass
at grails.converters.JSON.value(JSON.java:199)
at grails.converters.JSON.convertAnother(JSON.java:162)
at grails.converters.JSON.value(JSON.java:199)
at grails.converters.JSON.render(JSON.java:134)
... 5 more
Caused by: java.lang.reflect.InvocationTargetException
... 9 more
Caused by: groovy.lang.MissingMethodException: No signature of method: MyDomainClass.isAttached() is applicable for argument types:() values: []
Possible solutions: isAttached(), attach()
... 9 more
를 지도 대신 도메인 클래스에 반환을 변경
작동 : 도메인 클래스에 죽을 JSON 마샬의 원인은 무엇
render ([data: [id: domainInst.id]] as JSON)
? 그것은 정상적인 환경에서 작동하지만 모의 테스트 환경에서는 작동하지 않습니다. 이 테스트를 수행 할 수있는 방법이 있습니까?
해결 방법으로 내 대답보기 - 향후 버전에서 해결할 요청을 열었습니다. –