I'm trying to assert previously stubbed endpoint that is being called during the OAuth2 flow:
stubFor(
post(urlPathEqualTo("/token"))
.withHeader(AUTHORIZATION, equalTo("Basic cGluLmFwaS5jbGllbnRJZDpwaW4uYXBpLmNsaWVudFNlY3JldA=="))
.withHeader(CONTENT_TYPE, equalTo("application/x-www-form-urlencoded;charset=UTF-8"))
.withHeader(ACCEPT, equalTo(APPLICATION_JSON_VALUE + "," + APPLICATION_FORM_URLENCODED_VALUE))
.willReturn(aResponse()
.withStatus(HttpStatus.OK.value())
.withHeader(CONTENT_TYPE, "application/json")
.withHeader(CONNECTION, "Close")
.withBody("{\n" +
" \"access_token\": \"62466f2c-ff9e-4c6c-a866-b8296cf78041\",\n" +
" \"scope\": \"trust read write\",\n" +
" \"token_type\": \"bearer\",\n" +
" \"expires_in\": 20300,\n" +
"}")));
and
verify(postRequestedFor(urlPathEqualTo("/token")));
There is a piece of log, stubbed/actual requests look equals, but Wiremock says Header does not match
:
Could someone, please, suggest what can be wrong here? Thank you in advance!
To me it looks like an issue with a space after comma, try:
.withHeader(ACCEPT, equalTo(APPLICATION_JSON_VALUE + ", " + APPLICATION_FORM_URLENCODED_VALUE))
By the way, comparing headers with equalTo
might be flaky. You might consider using containing
:
post(urlPathEqualTo("/token"))
.withHeader(ACCEPT, containing(APPLICATION_JSON_VALUE))
.withHeader(ACCEPT, containing(APPLICATION_FORM_URLENCODED_VALUE))