我正在使用Sprint Boot 2.x和Spring Cloud Contract验证程序。 现在,我无法通过合同成功进行测试。
我无法获得合同,因为Wiremock不接受我的多方通话请求。
这是我的例子:
CONTROLLER :
@PostMapping(value = "/import", headers = {"content-type=multipart/form-data"}, produces = APPLICATION_JSON_VALUE)
public ResponseEntity importXbrl(@RequestPart("xml") MultipartFile xml) throws IOException {
return new ResponseEntity<>(new SomeResponse, HttpStatus.OK);
}
合同:
request:
method: "POST"
url: "/14/import"
multipart:
named:
- paramName: "xml"
fileName: 'xml'
fileContent: "file content"
contentType: 'application/octet-stream'
matchers:
headers:
- key: 'Content-Type'
regex: 'multipart/form-data;'
multipart:
named:
- paramName: xml
fileName:
predefined: non_empty
fileContent:
predefined: non_empty
contentType:
predefined: non_empty
response:
status: 200
matchers:
headers:
- key: 'Content-Type'
regex: 'application/json.*'
测试:
@Test public void test() throws Exception {
MockMultipartFile xml = new MockMultipartFile("xml", "xml", MediaType.APPLICATION_OCTET_STREAM_VALUE, getClass().getResourceAsStream("/xml"));
mockMvc.perform(MockMvcRequestBuilders.multipart(REQUEST_URI)
.file(xml)
.andExpect(status().is(200));
}
WIREMOCK
-----------------------------------------------------------------------------------------------------------------------
| Closest stub | Request |
-----------------------------------------------------------------------------------------------------------------------
|
POST | POST
/14/import | /14/import
|
<<<<< Body does not match
"cursor" : 12 | Content-Disposition: form-data; name="xml"
} | Content-Type: application/octet-stream
| Content-Length: 0
|
|
| --0ZaonQTGe0xcK6YOS2D8T0R28KIFML7M--
|
-----------------------------------------------------------------------------------------------------------------------
任何帮助都会很棒!