Mocking RestTemplate in listener in unit test
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2016 03:49 PM
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.
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.
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.
Labels:
- Labels:
-
Archive
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2016 03:39 AM
Hi,
if you want to completely omit rest service call, you can hook into process parsing and replace the rest calls with mocks.
Or you can have a look on
regards
Martin
if you want to completely omit rest service call, you can hook into process parsing and replace the rest calls with mocks.
Or you can have a look on
org.activiti.engine.test.bpmn.servicetask.WebServiceTaskTest
.regards
Martin
