dimanche 28 juin 2015

Unit testing Spring @Service bean wrapping Activiti RuntimeService

I'm trying to test my service that is underneath calling Activiti's RuntimeService. Looking at the blogs and posts the only thing Activiti exposes for testing is possibility to test Activiti engine itself by completing task, setting process variables, etc. I want to test my business logic above the engine by mocking Activiti's services like RuntimeService, TaskService. My service methods looks like this:

@Override
public String getNextActivationStepUri(String activationCode) {
    ProcessInstance processInstance =
            runtimeService.createProcessInstanceQuery().variableValueLike(ACTIVATION_CODE, activationCode)
                    .includeProcessVariables().singleResult();
    if (processInstance != null) {
        if (CLICK_ACTIVATION_LINK.equals(processInstance.getActivityId())) {
            return handleUserActionTask(processInstance);
        }
    }
    ...
}

private String handleUserActionTask(ProcessInstance processInstance) {
    Task task =
            taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId())
                    .active().singleResult();
    if (task != null) {
        taskService.complete(task.getId());
        Task nextTask =
                taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId())
                        .active().singleResult();
        if (nextTask != null) {
            return createActivationFormDataUri(processInstance, nextTask.getTaskDefinitionKey());
        } ...
}

Any suggestion how to mock these builder like service calls (createProcessInstanceQuery.variableValueLike.includeProcessVariables...) for both task and runtime service? I want to assert that valid URI is provided as a return of the method call.

Aucun commentaire:

Enregistrer un commentaire