You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Quite some Mock-Mvc requests configuration could be automatized. Additionally, The framework could provide with finer grained MockHttpServletRequestBuilder factories and even shortcuts to issue MockMvc requests in one call.
Most of these is not security related and if this request is ever accepted, you might split what is pure security from what is just MVC related (every-thing but Authorization header). But as security is involved and the solution I propose is part of set of OAuth2 unit testing improvements I request, here it is...
Actual Behavior
Content-type, Accept and Authorization headers are to be manually added to each MockMvc request. This is boring and error-prone (you can easily forget Authorization header or miss-match Content-type and actual body serialization mechanism).
Authorization and Accept headers are transparently added
MockHttpServletRequestBuilder is created, configured, build and performed in one call
you can browse my source for additional samples involving further request builder configuration (cookies or additional headers)
P.S.
SerializationHelper, used in MockMvcHelper, quite eases requests body serializing using registered message converters. It might be worth being contributed to the framework too but don't quite know where...
The text was updated successfully, but these errors were encountered:
Summary
Quite some Mock-Mvc requests configuration could be automatized. Additionally, The framework could provide with finer grained
MockHttpServletRequestBuilder
factories and even shortcuts to issue MockMvc requests in one call.Most of these is not security related and if this request is ever accepted, you might split what is pure security from what is just MVC related (every-thing but Authorization header). But as security is involved and the solution I propose is part of set of OAuth2 unit testing improvements I request, here it is...
Actual Behavior
Content-type, Accept and Authorization headers are to be manually added to each MockMvc request. This is boring and error-prone (you can easily forget Authorization header or miss-match Content-type and actual body serialization mechanism).
Expected Behavior
As done in
MockMvcHelper
andOAuth2MockMvcHelper
:linked requests
Sample
Overall result in controller unit tests:
In this sample:
api
is aMockMvc
wrapper instanceMockHttpServletRequestBuilder
is created, configured, build and performed in one callP.S.
SerializationHelper
, used inMockMvcHelper
, quite eases requests body serializing using registered message converters. It might be worth being contributed to the framework too but don't quite know where...The text was updated successfully, but these errors were encountered: