Announcement Announcement Module
Collapse
No announcement yet.
AbstractXmlFlowExecutionTests with real subflow Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AbstractXmlFlowExecutionTests with real subflow

    In SWF 2.0.7, I am trying to use AbstractXmlFlowExecutionTests to test a flow that starts with a subflow. Examples and documentation show how to register a mock subflow, and this post and JIRA (http://forum.springsource.org/showthread.php?p=232506) offer some description, but I can't get anything to work. Has anyone done this?

    My main flow, signup-Member-flow.xml, starts
    Code:
            <subflow-state id="common-signup" subflow="common-signup">
    		<input name="siteMemberForm" value="siteMemberForm"/>
    		<transition on="endCollect" to="review"/>
    	</subflow-state>
    	
    	<view-state id="review" model="siteMemberForm">
           // .... do more stuff in the main flow
    The subflow, common-signup-flow.xml, looks like:
    Code:
            <input name="siteMemberForm" required="true"/>
    	<!--  form to add members -->
    	<view-state id="signup" model="siteMemberForm">
    		<!-- set required fields and white-list -->
    		<binder>
    			//...bunch of bindings
    		</binder>
    		<transition on="signupMember" to="collectMemberData"/>
    		<transition on="cancel" to="end" bind="false" validate="false"/>
    	</view-state>
    	
    	<action-state id="collectMemberData">
    		<evaluate expression="signupMemberActions.collectMemberData"/>
    		<transition on="success" to="endCollect"/>
    		<transition on="error" to="signup"/>
    	</action-state>
    	
    	<end-state id="endCollect"/>
    And my test class that extends AbstractXmlFlowExecutionTests has these lines:
    Code:
            @Override
    	protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory) {
    		return resourceFactory.createFileResource("src/main/webapp/WEB-INF/signup/signupMember-flow.xml");
    	}
    
    
            @Test
    	public void testStart() throws Exception {
    		startFlow(new MockExternalContext());
    		assertCurrentStateEquals(COMMON_SIGNUP);
    		assertNotNull(getRequiredFlowAttribute("siteMemberForm"));
    	}
    The line startFlow(new MockExternalContext()); throws a NoSuchFlowDefinitionException: No flow definition 'common-signup' found. I've tried to override configureFlowBuilderContext, but I don't think I'm doing it right. It looks like:

    Code:
            @Override
    	protected void configureFlowBuilderContext(MockFlowBuilderContext builderContext) {
    		Flow theFlow = createSubFlow(builderContext);
    		builderContext.registerSubflow(theFlow);
    	}
    	
    	protected Flow createSubFlow(MockFlowBuilderContext builderContext){
    		FlowBuilder builder = createFlowBuilder(getResourceFactory().createFileResource("src/main/webapp/WEB-INF/common-signup/common-signup-flow.xml"));
    		FlowAssembler assembler = new FlowAssembler(builder, builderContext);
    		Flow theFlow = assembler.assembleFlow();
    		return theFlow;
    	}
    That clunky attempt at creating the flow was based off of other examples I've found through searching the web.

    Thanks in advance for the pointers and correction.

  • #2
    You should probably override the getModelResources() method. Refer to "14.4. Registering flow dependencies" of the reference manual.

    Comment


    • #3
      I've already tried overriding getModelResources (with different permutations of flow creating the file resources), but it hasn't worked. From the title of 14.4, you would think a subflow would be a "flow dependency," but then subflows are not mentioned in the text - so I guess maybe I shouldn't expect that to work.

      Code:
      @Override
      	protected FlowDefinitionResource[] getModelResources(FlowDefinitionResourceFactory resourceFactory) {
      		FlowDefinitionResource[] resources = new FlowDefinitionResource[] {
      				resourceFactory.createFileResource("src/main/webapp/WEB-INF/common-signup/common-signup-flow.xml"),
      				resourceFactory.createFileResource("src/main/webapp/WEB-INF/signup/signupMember-flow.xml")
      			   };
      		return resources;
      	}
      I think I'm in the same position as gmatthews here:
      http://forum.springsource.org/showth...nTests+subflow

      Comment

      Working...
      X