I need to mock a post request with multipart form body as given below. I tried with a regex pattern for the unique string in the body --Z5KfGboCdJvPl4VsEq74AeK7PZN4EyN , but it didn't work. Can some one guide me on this?
BODY :
"body":"--Z5KfGboCdJvPl4VsEq74AeK7PZN4EyN
Content-Disposition: form-data; name="dataset"
Content-Type: text/plain;charset=UTF-8
Content-Length: 14 drugs --Z5KfGboCdJvPl4VsEq74AeK7PZN4EyN
Content-Disposition: form-data; name="searchQuery"
Content-Type: text/plain;charset=UTF-8
Content-Length: 6 cancer --Z5KfGboCdJvPl4VsEq74AeK7PZN4EyN
Content-Disposition: form-data; name="queryLanguage"
Content-Type: text/plain;charset=UTF-8
Content-Length: 4 ssql --Z5KfGboCdJvPl4VsEq74AeK7PZN4EyN
Content-Disposition: form-data; name="returnFields"
Content-Type: text/plain;charset=UTF-8
Content-Length: 22 Id,name --Z5KfGboCdJvPl4VsEq74AeK7PZN4EyN
Content-Disposition: form-data; name="returnLimit"
Content-Type: text/plain;charset=UTF-8
Content-Length: 1 1 --Z5KfGboCdJvPl4VsEq74AeK7PZN4EyN
Content-Disposition: form-data; name="offset"
Content-Type: text/plain;charset=UTF-8
Content-Length: 1 0 --Z5KfGboCdJvPl4VsEq74AeK7PZN4EyN-- "
I tried like -
mockServerClient
.when(
request()
.withMethod("POST")
.withHeaders(
new Header("Content-Type", "multipart/form-data"))
.withPath("abc/xyz")
.withBody(**regex("[\n.\w\W]***
Content-Disposition: form-data; name="dataset"
Content-Type: text/plain;charset=UTF-8
Content-Length: 14 drugs [\n.\w\W]*
Content-Disposition: form-data; name="searchQuery"
Content-Type: text/plain;charset=UTF-8
Content-Length: 6 cancer [\n.\w\W]*
Content-Disposition: form-data; name="queryLanguage"
Content-Type: text/plain;charset=UTF-8
Content-Length: 4 ssql [\n.\w\W]*
Content-Disposition: form-data; name="returnFields"
Content-Type: text/plain;charset=UTF-8
Content-Length: 22 Id,name [\n.\w\W]*
Content-Disposition: form-data; name="returnLimit"
Content-Type: text/plain;charset=UTF-8
Content-Length: 1 1 [\n.\w\W]*
Content-Disposition: form-data; name="offset"
Content-Type: text/plain;charset=UTF-8
Content-Length: 1 0 [\n.\w\W]*-- "))
)