0

I have a bunch of microservices written using Java and Spring Boot 2.

generation-service, creates an object with a bunch of info and sends it to the next service (in the body of a request pointing to the next service endpoint) that we'll call receiver-service.

Now, I want to test the object generated by generation-service.

Is there any way that I can intercept the request created by generation service and redirect it to a test object? (Spawning a service and pointing generation-service to this endpoint is not an option as I cannot spawn new services.)

Please notice that the post "How to mock RestTemplate in Java Spring?" doesn't solve my problem as I am not interested in testing the response, but the request to the next service. With Rest template I can instead check just the feed that is just OK/FAILED.

AR1
  • 4,507
  • 4
  • 26
  • 42
  • 1
    Possible duplicate of [How to mock RestTemplate in Java Spring?](https://stackoverflow.com/questions/42406625/how-to-mock-resttemplate-in-java-spring). That should really give a good idea of where you need to go. – Robert Moskal Jul 05 '18 at 14:42
  • Edited my answer to explain why this is not a duplicate of the one that you proposed – AR1 Jul 05 '18 at 15:49
  • I think you can just `@Mock` the ReceiverService instead of `@Autowired` ing it. Another way is to have `ReceiverService` interface. Then, in your test environment, create the `TestReceiverService` as a bean that implements the interface. By excluding the actual one, you can test this. – Edward Aung Jul 05 '18 at 15:57
  • You can always examine the arguments sent to a Mck. https://www.erol.si/2014/07/verify-a-method-was-called-with-certain-argument-using-mockito/ – Robert Moskal Jul 05 '18 at 16:06

0 Answers0