camunda-community-hub / camunda-platform-7-mockito

Provides mock helpers to register delegate/listener mocks while testing processes
Apache License 2.0
45 stars 20 forks source link

Add spring test support for CallActivity mocking #104

Open ghost opened 4 years ago

ghost commented 4 years ago

Following code is not working for Spring tests: CallActivityMock deployFlowMock = ProcessExpressions.registerCallActivityMock(testDeployFlow).onExecutionAddVariable("var", "val"); deployFlowMock.deploy(processEngine); As I think it happens because of using different contexts for mocks. I went deep to the mocking code and saw that all stubs are registered with Mocks.register(name, instance); and it puts into static ThreadLocal map. But Spring doesn't see this things. Could you provide an API which will register mocks depends on current context (which we can define with annotation, for example)?

fml2 commented 4 years ago

Since I also think this would be a very useful feature, I hat a take at this. My intermediate result is in https://github.com/fml2/camunda-bpm-mockito/tree/feature/Mock-CallActivity-in-Spring-context.

The usage would be:

new CallActivityMockForSpringContext(processKey, springBeanRegistry).... (all the known methods from CallActivityMock)

Please gurus look at this and tell me whether the approach is a promising one.

For now, I can't figure out how to get a SingletonBeanRegistry (used in my class) given an ApplicationContext (usually available in a spring based test).

jangalinski commented 4 years ago

I appreciate your contribution. Unfortunately, I was having trouble reviewing this ... I am locally not able to build this ... I guess this is some problem on my machine, please give me a day or two to fix this.

fml2 commented 4 years ago

Have you had a chance to look at this?