new SimpleFlowExecutionSnapshotFactory(executionFactory, newMockFlowLocator(flow)));
keyFactory.setAlwaysGenerateNewNextKey(true);
executionFactory.setExecutionKeyFactory(keyFactory);
final FlowExecution execution = executionFactory.createFlowExecution(flow);
execution.start(null, new MockExternalContext());
// Flow state: rendered subflow view
assertTrue(execution.isActive());
assertEquals("view", execution.getActiveSession().getScope().get("renderCalled"));
final FlowExecutionKey key1 = execution.getKey();
assertNotNull(key1);
assertEquals(key1, keyFactory.parseFlowExecutionKey(key1.toString()));
final MockExternalContext context1 = new MockExternalContext();
context1.setEventId("submit");
execution.resume(context1);
// Flow state: rendered parent view (following subflow termination)
assertTrue(execution.isActive());
assertEquals("parentview", execution.getActiveSession().getScope().get("renderCalled"));
final FlowExecutionKey key2 = execution.getKey();
assertNotNull(key2);
assertFalse(key1.equals(key2));
assertEquals(key2, keyFactory.parseFlowExecutionKey(key2.toString()));
final MockExternalContext context2 = new MockExternalContext();
context2.setEventId("submit");
execution.resume(context2);
// Flow state: completed
assertTrue(execution.hasEnded());
}