Results 1 to 7 of 7

Thread: Web Flow test to test RequestContext.

  1. #1

    Default Web Flow test to test RequestContext.

    How to write Junit -test for web flow , where
    in Flow action

    public Event createCRCProfile(RequestContext context){
    Users origUsers = (Users)context.getFlowScope().get("origParticipant ");

    if you write test , you need pass parameter "origParticipant"/
    as using externalContext, there is no way to set parameter in FlowScope.
    so if you use MockRequestContext, than you can't pass as parameter in startFlow() or signalEvent().

    Can you please give some way to do it.
    I already posted two time, i didn;t find any response from after i posted code.

  2. #2
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    What you need to understand is that testing an action in isolation is different from testing an entire flow.

    If you want to test the action in isolation, just configure it with the necessary mock dependencies and call it inside a unit test passing in a MockRequestContext where you setup the necessary data in all of the available scopes. Then verify if the action does what it needs to do.

    If you're testing an entire flow (e.g. in an AbstractFlowExecutionTests subclass), it's the responsability of the flow itself to prepare the necessary data in all of the available scopes, just like in a real life scenario. In this case you're testing the entire flow from a 'external client' point of view, so you need the pass in an ExternalContext with the necessary request parameters, just like would happen when the flow is running in a real webapp.

    Erwin
    Last edited by klr8; Nov 1st, 2006 at 01:41 PM.

  3. #3

    Default

    Quote Originally Posted by klr8 View Post
    What you need to understand is that testing an action in isolation is different from testing an entire flow.

    If you want to test the action in isolation, just configure it with the necessary mock dependencies and call it inside a unit test passing in a MockRequestContext where you setup the necessary data in all of the available scopes. Then verify if the action does what it needs to do.

    If you're testing an entire flow (e.g. in an AbstractFlowExecutionTests subclass), it's the responsability of the flow itself to prepare the necessary data in all of the available scopes, just like in a real life scenario. In this case you're testing the entire flow from a 'external client' point of view, so you need the pass in an ExternalContext with the necessary request parameters, just like would happen when the flow is running in a real webapp.

    Erwin
    I got your point, what you want say, that completely right.
    But if you think from integration testing point of view.
    Where when you signalEvent from JunitTest , it is calling API from ActionForm.
    in that API , you pass requestContext, which contain formObject, not a parameters.

    I want to do integration testing with out deploying application.

    I think this feature was there in SPringWebFlow PR5, what is reason for not having in 1.0 final?
    In PR 5 there is one feature that revert data after insert in database when run junit test, this feature is not in 1.0. What is reason for that?

  4. #4
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    I think this feature was there in SPringWebFlow PR5, what is reason for not having in 1.0 final?
    ??? What feature are you talking about? Can you give me an exact pointer?


    In PR 5 there is one feature that revert data after insert in database when run junit test, this feature is not in 1.0. What is reason for that?
    This is not a SWF feature, but a Spring feature (AbstractTransactionalDataSourceSpringContextTests ).

    Erwin

  5. #5

    Default

    Quote Originally Posted by klr8 View Post
    ??? What feature are you talking about? Can you give me an exact pointer?




    This is not a SWF feature, but a Spring feature (AbstractTransactionalDataSourceSpringContextTests ).

    Erwin
    I am taking about this feature.
    MockRequestContext context = new MockRequestContext();
    Map parameters = new HashMap();
    parameters.put("guess", "123");
    context.setSourceEvent(new Event(this, "submit", parameters));

  6. #6
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    MockRequestContext requestContext = new MockRequestContext()
    requestContext.getMockExternalContext().putRequest Parameter("guess", "123");
    requestContext.getMockExternalContext().putRequest Parameter("_eventId", "submit");

    So you can still do the equivalent thing in 1.0 final.

    Erwin

  7. #7

    Default

    Quote Originally Posted by klr8 View Post
    MockRequestContext requestContext = new MockRequestContext()
    requestContext.getMockExternalContext().putRequest Parameter("guess", "123");
    requestContext.getMockExternalContext().putRequest Parameter("_eventId", "submit");

    So you can still do the equivalent thing in 1.0 final.

    Erwin
    Thanks for reply.
    it works, but i have another problem when i use mockRequestContext.
    I am not able to set dependency injection for service layer in junit test.
    CRCParticipantFlowAction action = new CRCParticipantFlowAction();
    Event result = action.createCRCProfile(requestContext);
    it call API from FlowAction. which in turn call another aPI
    CRCProfile crcProfile = CRCParticipantDataHelper.doPrepareCRCParticipantDa ta(crcParticipant,roleService,userRoleMap,origUser s,cryptoService);

    in this parameters roleService, userRoleMap and CryptoService are service layer api, that need to instantiated. In FlowAction i used to setter for that.
    but when i execute Junit test. it give NPE.
    while getting userRoleId.
    Integer userRoleId = roleService.findUserRole(participantList);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •