String defaultAfterPage1 = "default-after-page-for-"+FLOW_TYPE_1;
String defaultPage1 = "page-of-"+FLOW_TYPE_1;
mainFlow.setPageName(defaultPage1);
mainFlow.setDefaultAfterPage(defaultAfterPage1);
FlowActivityImpl fa1 = new FlowActivityImpl().initInvisible(false);
FlowPropertyDefinitionImpl copiedBackProperty = new FlowPropertyDefinitionImpl("copiedBackProperty").initAccess(PropertyScope.flowLocal, PropertyUsage.io);
fa1.addPropertyDefinition(copiedBackProperty);
mainFlow.addActivity(fa1);
FlowImpl subFlow = new FlowImpl(FLOW_TYPE_2);
String defaultAfterPage2 = "default-after-page-for-"+FLOW_TYPE_2;
String defaultPage2 = "page-of-"+FLOW_TYPE_2;
subFlow.setPageName(defaultPage2);
subFlow.setDefaultAfterPage(defaultAfterPage2);
FlowActivityImpl fa2_1 = new FlowActivityImpl().initInvisible(false);
fa2_1.addPropertyDefinition(copiedBackProperty.clone());
subFlow.addActivity(fa2_1);
subFlow.addActivity(new TransitionFlowActivity());
FlowImpl continuedFlow = new FlowImpl(FLOW_TYPE_3);
String defaultAfterPage3 = "default-after-page-for-"+FLOW_TYPE_3;
String defaultPage3 = "page-of-"+FLOW_TYPE_3;
continuedFlow.setPageName(defaultPage3);
continuedFlow.setDefaultAfterPage(defaultAfterPage3);
FlowActivityImpl fa3_1 = new FlowActivityImpl().initInvisible(false);
continuedFlow.addActivity(fa3_1);
Object returnToFlowLookupKey = true;
FlowManagement baseFlowManagement = getFlowManagement(mainFlow, subFlow, continuedFlow);
FlowState flowState1 = baseFlowManagement.startFlowState(FLOW_TYPE_1, true, null, returnToFlowLookupKey);
assertEquals(flowState1.getCurrentPage(), defaultPage1);
FlowState flowState2 = baseFlowManagement.startFlowState(FLOW_TYPE_2, true, null, true);
flowState2.setProperty(copiedBackProperty.getName(), A_VALUE_THAT_IS_COPIED_BACK);
assertEquals(flowState2.getCurrentPage(), defaultPage2);
String lookupKey1 = flowState2.getProperty(FSRETURN_TO_FLOW);
assertEquals(flowState1.getLookupKey(), lookupKey1, "the child flow does not have the parent flow as the return-to-flow ");
flowState2.setProperty(FSNEXT_FLOW, FLOW_TYPE_3);
String pageName = flowState2.finishFlow();
FlowState flowState3 = baseFlowManagement.getCurrentFlowState();
assertEquals(flowState3.getFlowTypeName(), FLOW_TYPE_3);
assertEquals(flowState3.getProperty(copiedBackProperty.getName()), A_VALUE_THAT_IS_COPIED_BACK);
assertEquals(pageName, defaultPage3, "the child flow when it completed did not redirect to the parent flow's page. flowState2="+flowState2);
lookupKey1 = flowState3.getProperty(FSRETURN_TO_FLOW);
assertEquals(flowState1.getLookupKey(), lookupKey1, "the child flow does not have the parent flow as the return-to-flow ");
pageName = flowState3.finishFlow();
assertEquals(pageName, defaultPage1, "the child flow when it completed did not redirect to the parent flow's page. flowState2="+flowState2);
FlowState flowState1_again = baseFlowManagement.getCurrentFlowState();
assertEquals(flowState1_again.getLookupKey(), flowState1.getLookupKey());
assertEquals(flowState1_again.getProperty(copiedBackProperty.getName()), A_VALUE_THAT_IS_COPIED_BACK);
flowState1_again.finishFlow();
FlowState nothing = baseFlowManagement.getCurrentFlowState();
assertNull(nothing);
}