2

I'm developing a Spring webflow, trying to use TDD so I've extended AbstractXmlFlowExecutionTests. I can't see an obvious way to assert what I would have thought would be a simple thing: that a view state has an associated view of a given name. For example, given this flow (excerpt):

<?xml version="1.0" encoding="UTF-8"?>
<flow ...>
    ...
    <view-state id="foo" view="barView">
    </view-state>
</flow>

and unit test

public void testAssertFooStateHasBarView() {
    ...
    assertCurrentStateEquals("foo");
    assertTrue( getFlowDefinition().getState("confirmation").isViewState());
    // Surely there's an easier way...?
    ViewState viewState = (ViewState)getFlowDefinition().getState("foo");
    View view = viewState.getViewFactory().getView(new MockRequestContext());
    // yuck!
    assertTrue(view.toString().contains("barView"));
}

Is there a simpler way to assert that state foo has view barView?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Scott Bale
  • 10,649
  • 5
  • 33
  • 36

3 Answers3

1

You can use this:

assertResponseWrittenEquals("barView", context);

Where context is your MockExternalContext.

This is how I always test this anyway.

TM.
  • 108,298
  • 33
  • 122
  • 127
1

If you are actually signaling events, you can get the ViewSelection and check the name via this method:

assertViewNameEquals("Your View Name", applicationView(viewSelection));
MetroidFan2002
  • 29,217
  • 16
  • 62
  • 80
-1

I can't speak to the rest of your tests, or how to use Webflow, but why are you using contains() to test for equality? I'm sure you don't want a view of "barViewBlah" to match your test, do you?

assertEquals("barView", view.toString());
matt b
  • 138,234
  • 66
  • 282
  • 345
  • I agree it's gross, that's why I'm looking for a better way. In this case the toString of the View object is [MockViewFactoryCreator.MockView@1b0889a viewId = 'barView'] so I can't do a straight compare and there's no (obvious) API to retrieve that 'barView' value. – Scott Bale Apr 28 '09 at 15:23
  • If you cast to MockView, does it give you an accessor for viewName? – matt b Apr 28 '09 at 15:52
  • Not an option - MockView is an inner class of MockViewFactoryCreator, which is only package-visible. I could use reflection but that sucks roughly the same amount. – Scott Bale Apr 28 '09 at 15:58