Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法实现Grails jaxrs多部分文件上载集成测试_Grails_File Upload_Jax Rs_Integration Testing - Fatal编程技术网

无法实现Grails jaxrs多部分文件上载集成测试

无法实现Grails jaxrs多部分文件上载集成测试,grails,file-upload,jax-rs,integration-testing,Grails,File Upload,Jax Rs,Integration Testing,我使用它来公开一个接受多部分/表单数据的api @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(['application/json']) @Path('/addMessage') ChatMessage addChatMessageWithAttachment(@Context HttpServletRequest req) { log.debug "> addCha

我使用它来公开一个接受多部分/表单数据的api

    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(['application/json'])
    @Path('/addMessage')
    ChatMessage addChatMessageWithAttachment(@Context HttpServletRequest req) {
        log.debug "> addChatMessageWithAttachment"
        def fileStores = []
        def chatMessage
        GrailsWebRequest request = WebUtils.retrieveGrailsWebRequest()
        def params = request.getParams()
        if (!(params.messageBody.length() > 0)) {
            log.error("Empty message body")
            throw new LocalisedException(ErrorCode.CHAT_MESSAGE_CREATE_FAILED)
        }
      }
实现工作正常,正如预期的那样。我能够成功发送表单数据(包括文件和其他参数)

现在我正试图实现上述逻辑的集成测试

我正在使用IntegrationTestCase来实现这一点。因此,我的代码片段如下所示:

class ChatMessageResourceV1Tests extends IntegrationTestCase{
    //other implementation and setup ommited    

    @Test
    void "Create new chat message for event id - customer user"() {
        def headers = ['Content-Type': 'multipart/form-data', 'Accept': 'application/json']

        def data = "My message..."
        def cm = new ChatMessage(messageBody: data)

        def content = "{'eventId':'$event.id','messageBody':'My message...'}"
        sendRequest("/api/v1/chatMessage/addMessage", 'POST', headers, content.bytes)

        assertEquals(200, response.status)
        }    

}
当我运行测试时..我可以看到调用到达API方法内部..但是,参数messageBody为null,并且抛出异常

我已经尝试了所有可能的测试组合,但没有运气

任何帮助都将不胜感激