There are a few things wrong with the way the controller code is written here, fixing these should get your code to work:
.1. You are returning ResponseEntity
explicitly here, which means that you don't have to annotate your response with @ResponseBody
. ResponseEntity
already encapsulate this behavior.
.2. Your method is not taking in a JSON, it is simply accepting a Form post, yet you are saying that the Content-Type is json, which it is not. Since you are expecting a response of json, you should be setting the Accept
header to json instead and remove the Content-Type
altogether.
I think changing these should fix your test.