In this case, execution of the preceding purchase flow needs testing. Specifically, the fol-
lowing can be asserted:
- When the flow starts, it transitions to the correct start state: enterPurchaseInformation.
- After the enterPurchaseInformationstate has entered:
- The correct Viewis selected (purchaseForm).
- The model data the Viewneeds is provisioned correctly (an instance of a
purchase bean is present).
- After the enterPurchaseInformationstate has entered:
•On the occurrence of the cancel event, the flow execution ends.
•On the occurrence of the submit event data binding and validation logic executes
correctly.
This is accomplished by writing a test that extends AbstractFlowexecutionTests. Refer to
Listing 11-8.
Listing 11-8.Test Class to Test the Example Flow
public class PurchaseFlowExecutionTests extends AbstractXmlFlowExecutionTests {
@Override // the location of the flow definition in the file system
protected Resource getFlowLocation() {
File flowDir = new File("src/webapp/WEB-INF");
return new FileSystemResource(new File(flowDir, "purchaseflow.xml"));
}
.....
@Override // the location of the flow definition in the file system
protected Resource getFlowLocation() {
File flowDir = new File("src/webapp/WEB-INF");
return new FileSystemResource(new File(flowDir, "purchase-flow.xml"));
}
// test that the flow execution starts as expected
public void testStartFlow() {
ViewSelection selectedView = startFlow();
assertCurrentStateEquals("enterPurchaseInformation");
assertModelAttributeNotNull("purchase", selectedView);
assertViewNameEquals("purchaseForm", selectedView);
}
// test a successful submit, including data binding
public void testSubmitPurchaseInformation() {
testStartFlow();
Map parameters = new HashMap(2);
parameters.put("price", "25");
parameters.put("quantity", "4");
CHAPTER 11 ■INTRODUCTION TO SPRING WEB FLOW 325