Announcement Announcement Module
No announcement yet.
Testing a flow using input mapping Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Testing a flow using input mapping

    Hi - new to SWF so excuse the possible obvious question!

    I am currently writing a simple webflow that uses an input mapper and trying to write some tests for it.

    i.e. something like:
    <flow start-state="enterCardDetails">
            <mapping source="accountID" target="flowScope.accountID"/>
            <mapping source="totalAmount" target="flowScope.totalAmount"/>
        <view-state id="enterCardDetails" view="cardDetailsForm">
        parameters mapped will get bound to a form object using an action bean
    I have looked through all the samples/forums for examples of how to test mapping of parameters into a workflow, but apart from the phonebook application (which maps values passed from a subflow back to a flow) cannot find anything that points me in the right direction.

    Eventually the webflow that I am creating will be used as a subflow within other flows, but I want to write tests for this flow first to prove it works, before embarking on creation of any 'parent' flows that will call this.

    Can anyone provide me with a simple example of how to write a unit test for a webflow that mocks mapped in parameters, so that when I run tests, I can validate that parameters are mapped into this flow correctly?

    Thanks in advance!
    Last edited by alpower; Jun 29th, 2006, 09:51 AM.

  • #2
    I'd really like to know this too! I have subflows that I'd like to test - they return values using the output mapper and so far my integration tests (extends AbstractXmlFlowExecutionTests) don't have any way of checking the result of the flow.

    Thanks for any help


    • #3
      Surely there must be a way to test a subflow on it's own?

      ...Surely there must be a way of unit testing a flow by passing in input mappings?

      At the moment my unit test just starts with:

          public void testStartFlow() throws Exception {
              ApplicationView view = applicationView(startFlow());
      but there must be a way of passing in values when testing so that they are bound to input mappings?

      I tried passing in an attribute map to the ExternalizedFlowDefiinition, but this just passes attributes in, without linking them to the flow input mapping (see original post for the XML input mapping)

          protected ExternalizedFlowDefinition getFlowDefinition() {
              String id = "payment-flow";
              AttributeMap attributes = new AttributeMap();
              attributes.put("accountID", new Integer(123));
              attributes.put("totalAmount", new Float(54.50));
              File flowDir = new File("web-resources/WEB-INF/flows");
              Resource resource = new FileSystemResource(new File(flowDir, "payment-flow.xml"));
              return new ExternalizedFlowDefinition(id, resource, attributes);
      I realise that this isn't correct (as it isn't working!) but if someone has done this, or this cannot be done please let me know, as I am pulling my hair out!

      At this point, the only way I can see to test this is to write parent flows and then test them calling this flow, but that is more along the lines of integration testing.

      Surely there must be a way of testing a flow's input mappings in a standalone/more granular way?


      • #4
        Alpower and Matt,

        Yes, there is.

        Take a look at the AbstractFlowExecutionTests.startFlow(AttributeMap ...) related methods--this allows you to pass an input attribute map to your starting flow. You can also use the startFlow variant that accepts a flow execution listener and verify in the listener's sessionStarted method the attributes get mapped correctly by your input mapper.



        • #5

          Many thanks for the response - got that working fine now.

          Once one has mapped values in using the AbstractFlowExecutionTests.startFlow(AttributeMap) method, how would one bind an attribute present in flowScope (say flowScope.totalAmount) to be set as a value on the form object, which also has a totalAmount?

          Would this be done by the use of an entry action on the view along with a suitable method to set this??

          <action bean="setupFormFields" method="setAmount(${flowscope.totalAmount})" result-name="myForm.totalAmount"/>
          I think I am missing something obvious, or do not understand how input mappings get bound to the form object.

          Last edited by alpower; Jul 4th, 2006, 09:03 AM.


          • #6
            Solved it by overriding setupForm (as below). Thanks for your help previously anyway.


             public Event setupForm(RequestContext context) throws Exception {
                    return super.setupForm(context);   
                public Event addInputParams(RequestContext context) throws Exception {
                    Form myForm = myForm(context);
                    myForm.setTotalAmount((Float)context.getFlowScope().getNumber("totalAmount", Float.class));
                    return success();