mercredi 5 octobre 2016

Reset a RestTemplate after MockRestServiceServer is applied

I have declared a RestTemplate as a bean in my Spring project to centralise some custom config. Judging by the source code, if I use MockRestServiceServer.createServer() on it, the bean will be "polluted" with a mock RequestFactory.

This fact is also not documented so even if I manually save and restore the Factory, it may stop working when the implementation of MockRestServiceServer changes.

I am wondering is there any clean workaround/pattern that would

  1. make sure all RestTemplates go through a central config process, and
  2. allow RestTemplate calls in a bean to be mocked without having to manually instantiate bean and wire it

(Of course, none of these would be needed if the author of MockRestServiceServer provided a way to undo the changes... I will raise a ticket if no satisfactory solution can be found.)

Aucun commentaire:

Enregistrer un commentaire