I am trying to write tests for my JavaDelegates. I am following the advice on this link:
I am not sure I can use constructor injection (which I would prefer over auto wired) given that the BPMN engine does not know what to inject. I notice that in the example the
@Inject
and
@Named
Attributes are used, but I am not sure which frameworks this is referring to. There is no indication in the documentation about which frameworks are used or supported and makes a lot of assumptions.
- Is there any worked examples as to how I can do this?
- I am using Unit with Mockito. Which IOC framework is recommended for this stack?
Thank you.
EDIT:
I have the testing working as such, but I am still unclear if the @AutoWired works in the ProcessEngine:
@RunWith(MockitoJUnitRunner.class)
public class SendWelcomeLetterDelegateTest {
@InjectMocks
SendWelcomeLetterDelegate sendWelcomeLetterDelegate;
@Mock
DelegateExecution executionMock;
@Mock
ConfigService configService;
@Test
public void executeTest() {
try {
sendWelcomeLetterDelegate.execute(executionMock);
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
}
@Component
public class SendWelcomeLetterDelegate implements JavaDelegate {
@Autowired
ConfigService configService;
...
EDIT 2:
I am finding that the Tomcat Camunda version does not wire up the Spring @Autowired components and am getting a SendWelcomeLetterDelegate.configService is null error when the process task executes.
java.lang.NullPointerException: Cannot invoke "za.co.services.ConfigService.getVpServerURL()" because "this.configService" is null
at za.co.flow.delegates.SendWelcomeLetterDelegate.execute(SendWelcomeLetterDelegate.java:45)
at org.camunda.bpm.engine.impl.bpmn.delegate.JavaDelegateInvocation.invoke(JavaDelegateInvocation.java:40)
at org.camunda.bpm.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:58)
at org.camunda.bpm.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocationInContext(DefaultDelegateInterceptor.java:92)
...