I'm struggling with creating contract for multipart/mixed controller method, which looks like this below:
@PostMapping("/posts")
public Json createNew(@RequestPart MultipartFile header,
@RequestPart MultipartFile photo,
@RequestPart Json info) {
// logic
return new Json("ok");
}
Problem is, using Groovy DSL, i can't(or didn't find a method to) specify request part's content-type. Without it, autogenerated test would look like this:
// given:
MockMvcRequestSpecification request = given()
.header("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryBTX23kTw0Z5a5bsF")
.multiPart("header", "filename1", "content1".getBytes())
.multiPart("photo", "filename1", "content1".getBytes())
.multiPart("info", "filename1", "{\r\n \"status\" : \"new upload\"\r\n}".getBytes());
Which fails, because "info" part would not be deserialized to Json object without content-type specified.
I've tried this code below but it didn't work:
request {
method 'POST'
url '/posts'
multipart(
[
...
...
info : named(
name: value(consumer(regex(nonEmpty())), producer('filename1')),
content: value(consumer(regex(nonEmpty())), new ServerDslProperty(file("info.json"),
headers {contentType(applicationJson())})))
]
)
headers {
contentType('multipart/form-data; boundary=----WebKitFormBoundaryBTX23kTw0Z5a5bsF')
}
}
So, my question is: how i can specify a multipart request's part content-type?
Edit As @Marcin said, this is a bug Issue on github