Unit test a flow

I try to follow this example flowable-engine/modules/flowable-engine/src/test/java/org/flowable/examples/bpmn/executionlistener/ExecutionListenerTest.java at main · flowable/flowable-engine · GitHub to test a flow. This is my unit test.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {“/testApplicationContext.xml”})
public class TestWasCustomerUpdated extends PluggableFlowableTestCase {

@Autowired
private RuntimeService runtimeService;
private String customerUID = "118045";

@Test
public void simpleProcessTest() throws IOException, SOAPException {

    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put( Constants.CUSTOMER_UID, customerUID);

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("checkCustomerFlow", variables);
    String varSetInExecutionListener = (String) runtimeService.getVariable(processInstance.getId(), Constants.IS_CUSTOMER_UPDATED);
    Assert.assertNotNull(varSetInExecutionListener);
    Assert.assertEquals("firstValue", varSetInExecutionListener);
 }

}

The flow runs all right, but at the line with “getVariable” I get

org.flowable.common.engine.api.FlowableObjectNotFoundException: execution 120001 doesn’t exist

The flow has ended and isn’t available any more to check on its results, or so it seems. Is there anything I can do to check the variables my flow has set after it ended?

Hi Christine,

All runtime data are deleted, when process instance is finished.
You can check the history (HistoryService) when you want to make assertions on the already finished process instance.

Regards
Martin

Does that mean the example I use does not work out of the box? I’ll try HistoryService. Thanks.

The example you mentioned works fine because there is a wait state in the process and that’s why process is not finished.

1 Like

Historylog, brilliant. Thank you.