我正在使用下面列出的代码对我的休息服务进行单元测试,并且请求已成功命中该服务。
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
private MockMvc mvc;
private URI = "/order/1"
this.mvc.perform(
post(URI).headers(headers)
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(mapper.writeValueAsString(request))
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(result -> {
response[0] = result.getResponse().getContentAsString();
statusCode[0] = result.getResponse().getStatus();
});
我正在尝试使用类似的代码测试我的 SOAP 服务( http://localhost:8080/OrderService/13.08.wsdl )。当我通过浏览器点击时,端点似乎已启动,但在结果中看到 404 -
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
private MockMvc mvc;
private URI = "http://localhost:8080/OrderService/13.08.wsdl";
this.mvc.perform(
post(URI).headers(headers)
.contentType(MediaType.TEXT_XML)
.content(request.toString())
.accept(MediaType.TEXT_XML))
.andExpect(result -> {
response[0] = result.getResponse().getContentAsString();
statusCode[0] = result.getResponse().getStatus();
});
最佳答案
@WebMvcTest
注释将仅加载应用程序的 Controller 层。这将仅扫描 @Controller
/@RestController
注释,并且不会加载完整的 ApplicationContext
。
关于java - 单元测试-如何使用Spring MockMVC调用soap服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48310929/