Spring Webflow: Unit testing with Parent flows

Recently I had to test a webflow that extended a parent webflow. The documentation didn't offer much in the way of help but did suggest that you use getModelResources() method to register additional flows from the AbstractXmlFlowExecutionTests class
    @Override
    protected FlowDefinitionResource[] getModelResources(FlowDefinitionResourceFactory resourceFactory) {
        FlowDefinitionResource[] flowDefinitionResources = new FlowDefinitionResource[1];
        flowDefinitionResources[0] = resourceFactory.createFileResource("src/main/webapp/WEB-INF/flows/base-flow.xml");
        return flowDefinitionResources;
    }   
Great! Or so I thought... Below is how I extended the flow to use the base parent flow.




I registered the base-flow.xml in the flowRegistry like below and I assumed that the AbstractXmlFlowExecutionTests class would register the flow as id="base"
  
    
    ...
  
This was the wrong assumption, after debugging I noticed that the flow was getting an id of id="base-flow". So to fix this I used the method below.
    @Override
    protected FlowDefinitionResource[] getModelResources(FlowDefinitionResourceFactory resourceFactory) {
        FlowDefinitionResource[] flowDefinitionResources = new FlowDefinitionResource[1];
        flowDefinitionResources[0] = resourceFactory.createResource("src/main/webapp/WEB-INF/flows/base-flow.xml", null, "base");
        return flowDefinitionResources;
    }   

Comments

Popular posts from this blog

Angular Testing child component inputs