Hi,
I modeled a simple process to find out how call activities work and I have trouble unit testing the subtask.
So basically my sample.bpmn
is start => choose-action (user task) => subprocess-task (call activity) =>after-subprocess (user task) => last-task (user task) => end
with a call to
subprocess.bpmn
which is start => anytask (service|usertask) => end
subprocess-task
has a DelegateVariableMapping
that logs and sets variable anytext
. If I use a service task in the subprocess, my unit test runs fine, if I use a simple user task, it does not as task()
is null. So I suppose I have to retrieve the subprocess instance task - how can I do that?
Regards,
Janina
import static org.camunda.bpm.engine.test.assertions.ProcessEngineAssertions.*;
import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.*;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.test.*;
import org.camunda.bpm.extension.process_test_coverage.junit.rules.TestCoverageProcessEngineRuleBuilder;
import org.junit.*;
public class SampleProcessTest {
private ProcessInstance processInstance;
@ClassRule
@Rule
public static ProcessEngineRule rule = TestCoverageProcessEngineRuleBuilder.create().build();
@Before
public void before() {
init(rule.getProcessEngine());
processInstance = processEngine().getRuntimeService()
.startProcessInstanceByKey("sample");
assertThat(processInstance).isActive();
}
@Test
@Deployment(resources = { "sample.bpmn", "subprocess.bpmn" })
public void shouldPassSubprocess() {
// choose "action"
complete(task(), withVariables("action", "subprocess",
"anytext", "set by unit test"));
// subprocess-task
ProcessInstance subProcessInstance = processEngine().getRuntimeService().createProcessInstanceQuery().processDefinitionKey("subprocess").singleResult();
assertThat(subProcessInstance).isActive();
assertThat(task()).isNotNull();
if ("demo".equals(task().getAssignee())) {
complete(task());
}
assertThat(processInstance).hasVariables("anytext");
// after-subprocess
complete(task(), withVariables("anytext", "I ran through after-subprocess"));
// choose-"action"
complete(task(), withVariables("action", null));
// last-task
complete(task());
assertThat(processInstance).hasPassed("choose-"action"", "subprocess-task", "after-subprocess", "last-task").isEnded();
}
}