1

I have a service which connects to a set of api's which i want to test.

I would like to make a Fake Service for my integration tests (to simulate failure situations)

I cannot simply use @RestController as they are not loaded during a test, and I looked into mockserver but I am unsure if it is what I am looking for, as I do not want my test to trigger a mock call, but rather my code should trigger the api call normally, simply using the mock server rather than an actual server (the base url is configurable so i can make my service point to a mock server)

UPDATE 1:

The only alternative I am seeing is possibly launching Cargo and deploying my service inside it?

UPDATE 2: I just found out about Wiremock. Could this be usable here?

mangusbrother
  • 3,988
  • 11
  • 51
  • 103

2 Answers2

2

I went with WireMock http://wiremock.org/

Setting the ClassRule in a junit test will have the fake server up and running before your test starts.

mangusbrother
  • 3,988
  • 11
  • 51
  • 103
1

Mockito(http://docs.mockito.googlecode.com/hg/1.9.5/org/mockito/Mockito.html) is a good library for mocking method calls. It can return a certain value given a certain input. With this library you could mock a REST client to simulate the communication between your application and the REST api.

John K
  • 462
  • 2
  • 11
  • Unfortunatley my api calls are triggered on context startup so trying to mock them in BeforeClass will be useless as stuff has not been loaded, whereas in Before is too late – mangusbrother Apr 18 '16 at 19:19