Expert Spring MVC and Web Flow

(Dana P.) #1
ViewSelection selectedView = signalEvent("submit", parameters);
Purchase purchase = (Purchase)selectedView.getModel().get("purchase");
assertEquals("Wrong price" new MonetaryAmount("25"), purchase.getAmount());
assertEquals("Wrong quantity", 4, purchase.getQuantity());
assertFlowExecutionEnded();
}
}

The preceding test ensures that the controller logic implemented thus far within the flow
definition works as expected. The test can also serve as a convenient way to test the execution
of the use case from the web tier down. As additional states are added to the flow, you simply
add additional test methods that signal events that drive transitions to those states and verify
that the respective state behavior executes correctly.

Decision States


Recall that the next step in this sample flow is to optionally allow the user to enter product
shipping information. In other words, there exists some condition that determines whether or
not shipping information is required for a given flow execution.
The decision state (see Listing 11-9) is designed to handle this type of situation, where a
condition needs to be evaluated to drive a state transition. A decision state is a simple, indem-
potent routing state.

Listing 11-9./WEB-INF/flows/purchase-flow.xmlContaining a Decision State

<flow start-state="enterPurchaseInformation">
<view-state id="enterPurchaseInformation" view="purchaseForm">
<entry-actions>
<action bean="formAction" method="setupForm"/>
</entry-actions>
<transition on="submit" to="requiresShipping">
<action bean="formAction" method="bindAndValidate"/>
</transition>
<transition on="cancel" to="cancel"/>
</view-state>
<decision-state id="requiresShipping">
<if test="${flowScope.purchase.shipping}" then="enterShippingDetails" ➥
else="placeOrder"/>
</decision-state>
<view-state id="enterShippingDetails" view="shippingForm">
<transition on="submit" to="placeOrder">
<action bean="sellItemAction" method="bindAndValidate"/>
</transition>
</view-state>
<import resource="purchase-flow-context.xml"/>
</flow>

326 CHAPTER 11 ■INTRODUCTION TO SPRING WEB FLOW

Free download pdf