Skip to content

Is it possible to have integration tests with TestRestTemplate and these annotations? #209

Answered by ch4mpy
gillouche asked this question in Q&A
Discussion options

You must be logged in to vote

May I ask what exactly you can test on responses from TestRestTemplate that you can't with those from MockMvc?

To my knowledge, no, you can't force the security context with TestRestTemplate as the request is an actual request and the security context is populated by the actual security filter-chain.

You can hardly create a "valid" JWT bearer yourself because it requires to sign it with the actual authorization server private key. It also requires the authorization server to be reachable for the resource server to fetch the public key.

If you want to stick with actual requests (instead of MockMvc ones), I'd advise that you define an OAuth2 client with client-credentials on the authorizati…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by gillouche
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants