我目前正在尝试使用Spring 4.0中添加的WebSockets支持,如this guide所述。正如指南所示,使用
spring-test模块支持以非常简单流畅的方式编写
@MessageMapping
注释的方法可以添加到任何Spring MVC控制器中,该控制器还可以包含@RequestMapping
方法。spring-test模块支持以非常简单流畅的方式编写
@RequestMapping
方法的集成测试(如here所述)。@Test
public void getAccount() throws Exception {
this.mockMvc.perform(get("/accounts/1").accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
.andExpect(jsonPath("$.name").value("Lee"));
}
是否有类似的支持使用WebSockets测试@MessageMapping
方法的功能?我在任何Spring模块中都没有找到任何内容,也没有任何WebSocket指南包含任何测试。如果没有,我需要实际部署应用程序并使用{{link1:WebSocketConnectionManager
}}连接测试客户端吗?或者是否有一些API可以从spring-test构建?
此示例项目包含这样一个小型测试客户端,但我更喜欢将其集成到实际测试中,而不需要我部署应用程序并在测试中硬编码已部署的路径。