AnsweredAssumed Answered

Mocking RestTemplate in listener in unit test

Question asked by activitinike on Jun 1, 2016
Latest reply on Jun 2, 2016 by martin.grofcik

We have RestTemplate class usage to make REST API calls, defined in Service tasks and listeners.

For unit testing, I would like to mock RestTemplate while running end to end process test.

I tried following, but it works only if I test listener class or JavaDelegate class directly, but not while executing process instance using ActivitiRule and InMemory config.

//Mock rest api calls
      RestTemplate restTemplate = new RestTemplate();
      MockRestServiceServer mockRestServer = MockRestServiceServer.createServer(restTemplate);
      //json response
      String responseString200_task = "{MyJsonStructure}";

When I run process in unit test using:


It execute the process instance, but it still makes actual call to REST API server, rather than mocking the call.

Is there a way to make it work?
Similar situation for and DAO dependency in Listeners or ServiceTask delegate.

Thanks for any help.