Hello,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}";
mockRestServer.expect(requestTo("RESTURLwkfl"))
.andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(responseString200_task));
When I run process in unit test using:
activitiRule.getRuntimeService().startProcessInstanceByKey("mykey");
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.