Search code examples
javaspringunit-testingspring-webflowspring-webflow-2

How to assert in a unit test that Spring Webflow exited through the specific end state?


I'm researching the means of unit testing a Spring Webflow. The webflow under test has multiple end states. Is there a way to determine, through which of those end states did the workflow exit?

My current code is:

    @Test
    public void flow_ends_on_cancel_from_start_state() {
        startFlow(context);
        context.setEventId("cancel");
        resumeFlow(context);
        assertFlowExecutionEnded();
    }

I tried asserting for the current state being equal to the id of the end state in question, but the assertion was failing because the workflow had already terminated.

Any advice?


Solution

  • You can use assertFlowExecutionOutcomeEquals to check that, your test method should be something like this:

    @Test
    public void flow_ends_on_cancel_from_start_state() {
        startFlow(context);
        context.setEventId("cancel");
        resumeFlow(context);
        assertFlowExecutionEnded();
        assertFlowExecutionOutcomeEquals("endStateId");
    }