|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
org.springframework.webflow.test.execution.AbstractFlowExecutionTests
public abstract class AbstractFlowExecutionTests
Base class for integration tests that verify a flow executes as expected. Flow execution tests captured by subclasses should test that a flow responds to all supported transition criteria correctly, transitioning to the correct states and producing the expected results on the occurence of possible external (user) events.
More specifically, a typical flow execution test case will test:
startFlow(MutableAttributeMap, ExternalContext)
variants).
signalEvent(String, ExternalContext)
variants). A test case should be coded for each logical event that can
occur, where an event drives a possible path through the flow. The goal should be to exercise all possible paths of
the flow. Use a test coverage tool like Clover or Emma to assist with measuring your test's effectiveness.
A flow execution test can effectively automate and validate the orchestration required to drive an end-to-end business task that spans several steps involving the user to complete. Such tests are a good way to test your system top-down starting at the web-tier and pushing through all the way to the DB without having to deploy to a servlet or portlet container. In addition, they can be used to effectively test a flow's execution (the web layer) standalone, typically with a mock service layer. Both styles of testing are valuable and supported.
Constructor Summary | |
---|---|
AbstractFlowExecutionTests()
Constructs a default flow execution test. |
|
AbstractFlowExecutionTests(java.lang.String name)
Constructs a flow execution test with given name. |
Method Summary | |
---|---|
protected ApplicationView |
applicationView(ViewSelection viewSelection)
Assert that the returned view selection is an instance of ApplicationView . |
protected void |
assertActiveFlowEquals(java.lang.String expectedActiveFlowId)
Assert that the active flow session is for the flow with the provided id. |
protected void |
assertCurrentStateEquals(java.lang.String expectedCurrentStateId)
Assert that the current state of the flow execution equals the provided state id. |
protected void |
assertFlowExecutionActive()
Assert that the entire flow execution is active; that is, it has not ended and has been started. |
protected void |
assertFlowExecutionEnded()
Assert that the entire flow execution has ended; that is, it is no longer active. |
protected void |
assertModelAttributeCollectionSize(int expectedSize,
java.lang.String attributeName,
ApplicationView viewSelection)
Assert that the selected view contains the specified collection model attribute with the provided expected size. |
protected void |
assertModelAttributeEquals(java.lang.Object expectedValue,
java.lang.String attributeName,
ApplicationView viewSelection)
Assert that the selected view contains the specified model attribute with the provided expected value. |
protected void |
assertModelAttributeNotNull(java.lang.String attributeName,
ApplicationView viewSelection)
Assert that the selected view contains the specified model attribute. |
protected void |
assertModelAttributeNull(java.lang.String attributeName,
ApplicationView viewSelection)
Assert that the selected view does not contain the specified model attribute. |
protected void |
assertViewNameEquals(java.lang.String expectedViewName,
ApplicationView viewSelection)
Assert that the view name equals the provided value. |
protected ExternalContext |
createExternalContext(ParameterMap requestParameters)
Creates an ExternalContext instance. |
protected FlowExecutionFactory |
createFlowExecutionFactory()
Factory method to create the flow execution factory. |
protected java.lang.Object |
evaluateModelAttributeExpression(java.lang.String attributeName,
java.util.Map model)
Evaluates a model attribute expression. |
protected ExternalRedirect |
externalRedirect(ViewSelection viewSelection)
Assert that the returned view selection is an instance of ExternalRedirect . |
protected FlowDefinitionRedirect |
flowDefinitionRedirect(ViewSelection viewSelection)
Assert that the returned view selection is an instance of FlowDefinitionRedirect . |
protected FlowExecutionRedirect |
flowExecutionRedirect(ViewSelection viewSelection)
Assert that the returned view selection is an instance of FlowExecutionRedirect . |
protected java.lang.Object |
getConversationAttribute(java.lang.String attributeName)
Returns the attribute in conversation scope. |
protected java.lang.Object |
getFlashAttribute(java.lang.String attributeName)
Returns the attribute in flash scope. |
protected java.lang.Object |
getFlowAttribute(java.lang.String attributeName)
Returns the attribute in flow scope. |
protected abstract FlowDefinition |
getFlowDefinition()
Returns the flow definition to be tested. |
protected FlowExecution |
getFlowExecution()
Returns the flow execution being tested. |
protected FlowExecutionFactory |
getFlowExecutionFactory()
Gets the factory that will create the flow execution to test. |
protected java.lang.Object |
getRequiredConversationAttribute(java.lang.String attributeName)
Returns the required attribute in conversation scope; asserts the attribute is present. |
protected java.lang.Object |
getRequiredConversationAttribute(java.lang.String attributeName,
java.lang.Class requiredType)
Returns the required attribute in conversation scope; asserts the attribute is present and of the required type. |
protected java.lang.Object |
getRequiredFlashAttribute(java.lang.String attributeName)
Returns the required attribute in flash scope; asserts the attribute is present. |
protected java.lang.Object |
getRequiredFlashAttribute(java.lang.String attributeName,
java.lang.Class requiredType)
Returns the required attribute in flash scope; asserts the attribute is present and of the correct type. |
protected java.lang.Object |
getRequiredFlowAttribute(java.lang.String attributeName)
Returns the required attribute in flow scope; asserts the attribute is present. |
protected java.lang.Object |
getRequiredFlowAttribute(java.lang.String attributeName,
java.lang.Class requiredType)
Returns the required attribute in flow scope; asserts the attribute is present and of the correct type. |
protected void |
nullView(ViewSelection viewSelection)
Assert that the returned view selection is the ViewSelection.NULL_VIEW . |
protected ViewSelection |
refresh()
Refresh the flow execution being tested, asking the current view state to make a "refresh" view selection. |
protected ViewSelection |
refresh(ExternalContext context)
Refresh the flow execution being tested, asking the current view state state to make a "refresh" view selection. |
void |
setExpressionParser(org.springframework.binding.expression.ExpressionParser expressionParser)
Set the expression parser responsible for parsing expression strings into evaluatable expression objects. |
protected ViewSelection |
signalEvent(java.lang.String eventId)
Signal an occurence of an event in the current state of the flow execution being tested. |
protected ViewSelection |
signalEvent(java.lang.String eventId,
ExternalContext context)
Signal an occurence of an event in the current state of the flow execution being tested. |
protected ViewSelection |
signalEvent(java.lang.String eventId,
ParameterMap requestParameters)
Signal an occurence of an event in the current state of the flow execution being tested. |
protected ViewSelection |
startFlow()
Start the flow execution to be tested. |
protected ViewSelection |
startFlow(MutableAttributeMap input)
Start the flow execution to be tested. |
protected ViewSelection |
startFlow(MutableAttributeMap input,
ExternalContext context)
Start the flow execution to be tested. |
protected void |
updateFlowExecution(FlowExecution flowExecution)
Directly update the flow execution used by the test by setting it to given flow execution. |
Methods inherited from class junit.framework.TestCase |
---|
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString |
Methods inherited from class junit.framework.Assert |
---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public AbstractFlowExecutionTests()
TestCase.setName(String)
public AbstractFlowExecutionTests(java.lang.String name)
name
- the name of the testMethod Detail |
---|
public void setExpressionParser(org.springframework.binding.expression.ExpressionParser expressionParser)
protected FlowExecutionFactory getFlowExecutionFactory()
createFlowExecutionFactory()
protected ExternalContext createExternalContext(ParameterMap requestParameters)
MockExternalContext
. Subclasses can override if
they which to use another external context implementation.
requestParameters
- request parameters to put into the external context (optional)
protected ViewSelection startFlow() throws FlowExecutionException
Convenience operation that starts the execution with:
ExternalContext
with no environmental request parameters set
FlowExecutionException
- if an exception was thrown while starting the flow executionprotected ViewSelection startFlow(MutableAttributeMap input) throws FlowExecutionException
Convenience operation that starts the execution with:
ExternalContext
with no environmental request parameters set
input
- the flow execution input attributes eligible for mapping by the root flow
FlowExecutionException
- if an exception was thrown while starting the flow executionprotected ViewSelection startFlow(MutableAttributeMap input, ExternalContext context) throws FlowExecutionException
This is the most flexible of the start methods. It allows you to specify:
input
- the flow execution input attributes eligible for mapping by the root flowcontext
- the external context providing information about the caller's environment, used by the flow
execution during the start operation
FlowExecutionException
- if an exception was thrown while starting the flow executionprotected ViewSelection signalEvent(java.lang.String eventId) throws FlowExecutionException
eventId
- the event that occured
FlowExecutionException
- if an exception was thrown within a state of the resumed flow execution during
event processingprotected ViewSelection signalEvent(java.lang.String eventId, ParameterMap requestParameters) throws FlowExecutionException
eventId
- the event that occuredrequestParameters
- request parameters needed by the flow execution to complete event processing
FlowExecutionException
- if an exception was thrown within a state of the resumed flow execution during
event processingprotected ViewSelection signalEvent(java.lang.String eventId, ExternalContext context) throws FlowExecutionException
Note: signaling an event will cause state transitions to occur in a chain until control is returned to the
caller. Control is returned once an "interactive" state type is entered: either a view state when the flow is
paused or an end state when the flow terminates. Action states are executed without returning control, as their
result always triggers another state transition, executed internally. Action states can also be executed in a
chain like fashion (e.g. action state 1 (result), action state 2 (result), action state 3 (result), view state
If you wish to verify expected behavior on each state transition (and not just when the view state triggers
return of control back to the client), you have a few options:
First, you may implement standalone unit tests for your
Second, you can attach one or more FlowExecutionListeners to the flow execution at start time within your test
code, which will allow you to receive a callback on each state transition (among other points). It is recommended
you extend
Action
implementations. There you can verify that an Action executes its logic properly in isolation. When you do this,
you may mock or stub out services the Action implementation needs that are expensive to initialize. You can also
verify there that the action puts everything in the flow or request scope it was expected to (to meet its
contract with the view it is prepping for display, for example).
FlowExecutionListenerAdapter
and only override the
callback methods you are interested in.
eventId
- the event that occuredcontext
- the external context providing information about the caller's environment, used by the flow
execution during the signal event operation
FlowExecutionException
- if an exception was thrown within a state of the resumed flow execution during
event processing
protected ViewSelection refresh() throws FlowExecutionException
FlowExecutionException
- if an exception was thrown during refreshprotected ViewSelection refresh(ExternalContext context) throws FlowExecutionException
context
- the external context providing information about the caller's environment, used by the flow
execution during the refresh operation
FlowExecutionException
- if an exception was thrown during refreshprotected FlowExecution getFlowExecution() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- the execution has not been startedprotected java.lang.Object getConversationAttribute(java.lang.String attributeName)
attributeName
- the name of the attribute
protected java.lang.Object getRequiredConversationAttribute(java.lang.String attributeName) throws java.lang.IllegalStateException
attributeName
- the name of the attribute
java.lang.IllegalStateException
- if the attribute was not presentprotected java.lang.Object getRequiredConversationAttribute(java.lang.String attributeName, java.lang.Class requiredType) throws java.lang.IllegalStateException
attributeName
- the name of the attribute
java.lang.IllegalStateException
- if the attribute was not present or not of the required typeprotected java.lang.Object getFlowAttribute(java.lang.String attributeName)
attributeName
- the name of the attribute
protected java.lang.Object getRequiredFlowAttribute(java.lang.String attributeName) throws java.lang.IllegalStateException
attributeName
- the name of the attribute
java.lang.IllegalStateException
- if the attribute was not presentprotected java.lang.Object getRequiredFlowAttribute(java.lang.String attributeName, java.lang.Class requiredType) throws java.lang.IllegalStateException
attributeName
- the name of the attribute
java.lang.IllegalStateException
- if the attribute was not present or was of the wrong typeprotected java.lang.Object getFlashAttribute(java.lang.String attributeName)
attributeName
- the name of the attribute
protected java.lang.Object getRequiredFlashAttribute(java.lang.String attributeName) throws java.lang.IllegalStateException
attributeName
- the name of the attribute
java.lang.IllegalStateException
- if the attribute was not presentprotected java.lang.Object getRequiredFlashAttribute(java.lang.String attributeName, java.lang.Class requiredType) throws java.lang.IllegalStateException
attributeName
- the name of the attribute
java.lang.IllegalStateException
- if the attribute was not present or was of the wrong typeprotected void assertActiveFlowEquals(java.lang.String expectedActiveFlowId)
expectedActiveFlowId
- the flow id that should have a session active in the tested flow executionprotected void assertFlowExecutionActive()
protected void assertFlowExecutionEnded()
protected void assertCurrentStateEquals(java.lang.String expectedCurrentStateId)
expectedCurrentStateId
- the expected current stateprotected void assertViewNameEquals(java.lang.String expectedViewName, ApplicationView viewSelection)
expectedViewName
- the expected nameviewSelection
- the selected viewprotected void assertModelAttributeEquals(java.lang.Object expectedValue, java.lang.String attributeName, ApplicationView viewSelection)
expectedValue
- the expected valueattributeName
- the attribute name (can be an expression)viewSelection
- the selected view with a model attribute map to assert againstprotected void assertModelAttributeCollectionSize(int expectedSize, java.lang.String attributeName, ApplicationView viewSelection)
expectedSize
- the expected sizeattributeName
- the collection attribute name (can be an expressionviewSelection
- the selected view with a model attribute map to assert againstprotected void assertModelAttributeNotNull(java.lang.String attributeName, ApplicationView viewSelection)
attributeName
- the attribute name (can be an expression)viewSelection
- the selected view with a model attribute map to assert againstprotected void assertModelAttributeNull(java.lang.String attributeName, ApplicationView viewSelection)
attributeName
- the attribute name (can be an expression)viewSelection
- the selected view with a model attribute map to assert againstprotected ApplicationView applicationView(ViewSelection viewSelection)
ApplicationView
.
viewSelection
- the view selectionprotected FlowExecutionRedirect flowExecutionRedirect(ViewSelection viewSelection)
FlowExecutionRedirect
.
viewSelection
- the view selectionprotected FlowDefinitionRedirect flowDefinitionRedirect(ViewSelection viewSelection)
FlowDefinitionRedirect
.
viewSelection
- the view selectionprotected ExternalRedirect externalRedirect(ViewSelection viewSelection)
ExternalRedirect
.
viewSelection
- the view selectionprotected void nullView(ViewSelection viewSelection)
ViewSelection.NULL_VIEW
.
viewSelection
- the view selectionprotected java.lang.Object evaluateModelAttributeExpression(java.lang.String attributeName, java.util.Map model)
attributeName
- the attribute expressionmodel
- the model map
protected FlowExecutionFactory createFlowExecutionFactory()
FlowExecutionImplFactory
instance.
protected void updateFlowExecution(FlowExecution flowExecution)
flowExecution
- the flow execution to useprotected abstract FlowDefinition getFlowDefinition()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |