Hello @jonathan.lukas,
thank you for your reply. This helps a little bit.
I’m currently trying out the normal mock of the service task, but it doesn’t work. Just to don’t miss anything, here is what I’ve done:
I work with JUnit5 and Camunda Version 7.17 and used therefore:
- junit-jupiter-api
- mockito-junit-jupiter
- camunda-bpm-junit5
- assertj-core
Added the MockExpressionManager in the camunda.cfg.xml file. In there I have also the StandaloneInMemProcessEngineConfiguration for the test deployment of camunda.
I have this annotation @ExtendWith(ProcessEngineExtension.class). Do I need this one @ExtendWith(MockitoExtension.class) as well? (tried it out, didn’t change anything)
This is my little test process:
I connected the Java Delegate via Java class.
Here is my implementation:
package com.process;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
public class ExampleServiceImpl implements JavaDelegate {
private static final Logger LOG = LogManager.getLogger(ExampleActivity.class);
@Override
public void execute(DelegateExecution execution) throws Exception {
// Do something...
LOG.info("Hello I'm here in the wonderful ExampleServiceImpl and do stuff!");
}
}
I can run the process and everything works, even in the test case below.
@Test
@Deployment(resources = { "test-process-files/test-diagram.bpmn" })
public void shouldExecuteExampleActivityTest() {
ProcessInstance processInstance = runtimeService().createProcessInstanceByKey("TestProcessID").execute();
assertThat(processInstance).isStarted();
assertThat(processInstance).isWaitingAt("ExampleActivityID");
execute(job());
assertThat(processInstance).hasPassed("ExampleActivityID");
assertThat(processInstance).isWaitingAt("EndEvent");
execute(job());
assertThat(processInstance).isEnded();
}
That’s great, but as I said, I have two use cases and want a) to mock the JavaDelegate Impl (and set some process vars) and b) mock only parts of the JavaDelegate Impl, like a call to another service.
I tried to mock the service task but I don’t think the MockExpressionManager is working in my environment, because it says the Mock is never touched.
Wanted but not invoked:
exampleActivityTask.execute(<any>);
-> at com.test.ProcessTestCase.shouldExecuteExampleActivityTest(ProcessTestCase.java:130)
Actually, there were zero interactions with this mock.
I created it like this:
@Mock
private ExampleServiceImpl exampleActivityTask;
@BeforeEach
public void defineHappyScenario() {
MockitoAnnotations.openMocks(this);
Mocks.register("ExampleServiceImpl", exampleActivityTask);
}
Did I miss anything? Did I do something wrong?
I hope you don’t get scared off by all this text