You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mi...@wellsfargo.com on 2004/08/26 18:05:22 UTC

Help with Cactus StrutsTestCase

I am trying to write test cases for my Struts app, but can't seem to figure it out.
I have used the examples, but I don't seem to get the correct outcome when I run them.

I am using LookupDispatchAction's exclusively. 

So here is the method I am testing:
==========================
    public void productSelectionAction( ActionMapping mapping
                                        , ActionForm form
                                        , HttpServletRequest request
                                        , HttpServletResponse response ) {
        log.info( "Process CreditApplicationActions productSelectionAction(...)" );

        NavigationBean navigationBean = ( NavigationBean )request.getSession().getAttribute( "navigationBean" );
        if( navigationBean == null ) {
            navigationBean = new NavigationBean();
        }

        if( Constants.TRUE.equals( request.getParameter( Constants.BUS_LINE_SELECTED ) ) ) {
            navigationBean.setHasBusinessLine( true );
        } else {
            request.getSession().setAttribute( "businessLineForm", null );
            navigationBean.setHasBusinessLine( false );
        }

        if( Constants.TRUE.equals( request.getParameter( Constants.BUS_CARD_SELECTED ) ) ) {
            navigationBean.setHasBusinessCard( true );
        } else {
            request.getSession().setAttribute( "businessCardForm", null );
            navigationBean.setHasBusinessCard( false );
        }

        if( Constants.TRUE.equals( request.getParameter( Constants.BUS_SEC_CARD_SELECTED ) ) ) {
            navigationBean.setHasSecuredCard( true );
        } else {
            request.getSession().setAttribute( "securedCardForm", null );
            navigationBean.setHasSecuredCard( false );
        }

        if( Constants.TRUE.equals( request.getParameter( Constants.EQUIP_EXPRESS_SELECTED ) ) ) {
            navigationBean.setHasEquipExpress( true );
        } else {
            request.getSession().setAttribute( "equipExpressForm", null );
            navigationBean.setHasEquipExpress( false );
        }

        request.getSession().setAttribute( "navigationBean", navigationBean );
    };




Here is the action in the struts-config.xml:
===============================
        <!-- Product selection action -->
        <action path="/productSelection"
                input=".productSelection"
                name="productSelectionForm"
                parameter="action"
                scope="session"               
                type="com.wf.bd.ice.creditapplication.CreditApplicationActions" 
                validate="true">
            <forward name="error" path=".productSelection" redirect="true" />
            <forward name="continue" path=".business" redirect="true" />
            <forward name="productSelection" path=".productSelection" redirect="true" />
            <forward name="business" path=".business" redirect="true" />
            <forward name="firstOwner" path=".firstOwner" redirect="true" />
            <forward name="secondOwner" path=".secondOwner" redirect="true" />
            <forward name="businessLine" path=".businessLine" redirect="true" />
            <forward name="businessCard" path=".businessCard" redirect="true" />
            <forward name="securedCard" path=".securedCard" redirect="true" />
            <forward name="equipExpress" path=".equipExpress" redirect="true" />
            <forward name="noSecondOwner" path=".noSecondOwner" redirect="true" />
            <forward name="noBusinessLine" path=".noBusinessLine" redirect="true" />
            <forward name="noBusinessCard" path=".noBusinessCard" redirect="true" />
            <forward name="noSecuredCard" path=".noSecuredCard" redirect="true" />
            <forward name="noEquipExpress" path=".noEquipExpress" redirect="true" />
            <forward name="conclude" path=".acceptanceAgreement" redirect="true" />
        </action>





Here is the test method:
==================
  public void testProductSelection() throws Exception {
    // JUnitDoclet begin method productSelection

        setRequestPathInfo( "/productSelection" );

        addRequestParameter( "action", "nextPage" );

        addRequestParameter( "businessLineSelected", "true" );
        addRequestParameter( "businessCardSelected", "true" );
        addRequestParameter( "businessSecuredCardSelected", "true" );
        addRequestParameter( "equipmentExpressSelected", "true" );

        actionPerform();

        verifyForward( Constants.ERROR_FWD );
        verifyForward( Constants.PRODUCTSELECTION_FWD );

        //verifyActionErrors(new String[] {"error.nodefault.implementation" } );
        //verifyActionErrors(new String[] { "error.noaction.specified"} );

        //NavigationBean navigationBean = (NavigationBean)getSession().getAttribute( "navigationBean" );
        //assertTrue( "NavigationBean is null", navigationBean == null);
        verifyNoActionErrors();

    // JUnitDoclet end method productSelection
  }





And I get zero errors at all...




---
> Thanks...
> Mick Knutson
> 
> 525 Market Street, SF, CA  94103
> (415) 222-1020
> Mick.Knutson@WellsFargo.com
> MAC A0103-223
---



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Help with Cactus StrutsTestCase

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Is your LookupDispatchAction implementing getKeyMethodMap()?


Mick.Knutson@wellsfargo.com wrote:

> I am trying to write test cases for my Struts app, but can't seem to figure it out.
> I have used the examples, but I don't seem to get the correct outcome when I run them.
> 
> I am using LookupDispatchAction's exclusively. 
> 
> So here is the method I am testing:
> ==========================
>     public void productSelectionAction( ActionMapping mapping
>                                         , ActionForm form
>                                         , HttpServletRequest request
>                                         , HttpServletResponse response ) {
>         log.info( "Process CreditApplicationActions productSelectionAction(...)" );
> 
>         NavigationBean navigationBean = ( NavigationBean )request.getSession().getAttribute( "navigationBean" );
>         if( navigationBean == null ) {
>             navigationBean = new NavigationBean();
>         }
> 
>         if( Constants.TRUE.equals( request.getParameter( Constants.BUS_LINE_SELECTED ) ) ) {
>             navigationBean.setHasBusinessLine( true );
>         } else {
>             request.getSession().setAttribute( "businessLineForm", null );
>             navigationBean.setHasBusinessLine( false );
>         }
> 
>         if( Constants.TRUE.equals( request.getParameter( Constants.BUS_CARD_SELECTED ) ) ) {
>             navigationBean.setHasBusinessCard( true );
>         } else {
>             request.getSession().setAttribute( "businessCardForm", null );
>             navigationBean.setHasBusinessCard( false );
>         }
> 
>         if( Constants.TRUE.equals( request.getParameter( Constants.BUS_SEC_CARD_SELECTED ) ) ) {
>             navigationBean.setHasSecuredCard( true );
>         } else {
>             request.getSession().setAttribute( "securedCardForm", null );
>             navigationBean.setHasSecuredCard( false );
>         }
> 
>         if( Constants.TRUE.equals( request.getParameter( Constants.EQUIP_EXPRESS_SELECTED ) ) ) {
>             navigationBean.setHasEquipExpress( true );
>         } else {
>             request.getSession().setAttribute( "equipExpressForm", null );
>             navigationBean.setHasEquipExpress( false );
>         }
> 
>         request.getSession().setAttribute( "navigationBean", navigationBean );
>     };
> 
> 
> 
> 
> Here is the action in the struts-config.xml:
> ===============================
>         <!-- Product selection action -->
>         <action path="/productSelection"
>                 input=".productSelection"
>                 name="productSelectionForm"
>                 parameter="action"
>                 scope="session"               
>                 type="com.wf.bd.ice.creditapplication.CreditApplicationActions" 
>                 validate="true">
>             <forward name="error" path=".productSelection" redirect="true" />
>             <forward name="continue" path=".business" redirect="true" />
>             <forward name="productSelection" path=".productSelection" redirect="true" />
>             <forward name="business" path=".business" redirect="true" />
>             <forward name="firstOwner" path=".firstOwner" redirect="true" />
>             <forward name="secondOwner" path=".secondOwner" redirect="true" />
>             <forward name="businessLine" path=".businessLine" redirect="true" />
>             <forward name="businessCard" path=".businessCard" redirect="true" />
>             <forward name="securedCard" path=".securedCard" redirect="true" />
>             <forward name="equipExpress" path=".equipExpress" redirect="true" />
>             <forward name="noSecondOwner" path=".noSecondOwner" redirect="true" />
>             <forward name="noBusinessLine" path=".noBusinessLine" redirect="true" />
>             <forward name="noBusinessCard" path=".noBusinessCard" redirect="true" />
>             <forward name="noSecuredCard" path=".noSecuredCard" redirect="true" />
>             <forward name="noEquipExpress" path=".noEquipExpress" redirect="true" />
>             <forward name="conclude" path=".acceptanceAgreement" redirect="true" />
>         </action>
> 
> 
> 
> 
> 
> Here is the test method:
> ==================
>   public void testProductSelection() throws Exception {
>     // JUnitDoclet begin method productSelection
> 
>         setRequestPathInfo( "/productSelection" );
> 
>         addRequestParameter( "action", "nextPage" );
> 
>         addRequestParameter( "businessLineSelected", "true" );
>         addRequestParameter( "businessCardSelected", "true" );
>         addRequestParameter( "businessSecuredCardSelected", "true" );
>         addRequestParameter( "equipmentExpressSelected", "true" );
> 
>         actionPerform();
> 
>         verifyForward( Constants.ERROR_FWD );
>         verifyForward( Constants.PRODUCTSELECTION_FWD );
> 
>         //verifyActionErrors(new String[] {"error.nodefault.implementation" } );
>         //verifyActionErrors(new String[] { "error.noaction.specified"} );
> 
>         //NavigationBean navigationBean = (NavigationBean)getSession().getAttribute( "navigationBean" );
>         //assertTrue( "NavigationBean is null", navigationBean == null);
>         verifyNoActionErrors();
> 
>     // JUnitDoclet end method productSelection
>   }
> 
> 
> 
> 
> 
> And I get zero errors at all...
> 
> 
> 
> 
> ---
> 
>>Thanks...
>>Mick Knutson
>>
>>525 Market Street, SF, CA  94103
>>(415) 222-1020
>>Mick.Knutson@WellsFargo.com
>>MAC A0103-223
> 
> ---


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Help with Cactus StrutsTestCase

Posted by Leandro Melo <lt...@yahoo.com.br>.
Thanks Duncan, i`ll check it out!


 --- Duncan Mills <du...@oracle.com> escreveu: 
> Leandro - a good article has just been published on
> the Oracle 
> Technology Network on using JUnit, Cactus and
> StrutsTestCase - the setup 
> portions relate to setting up these up with
> JDeveloper, but the basic 
> flow and tutorial portions provide a good kickstart
> even if you use 
> another IDE - check it out:
>
http://www.oracle.com/technology/pub/articles/server_side_unit_tests.html
> 
> Regards
> 
> Duncan Mills
> http://www.groundside.com/blog
> 
> 
> 
> Leandro Melo wrote:
> 
> >Doesn`t know the answer, where can i find a good
> >tutorial do test struts applications?
> >Is it true that for good testing the actions must
> >delegate their work to POJOs ??
> >
> >
> >
> > --- Mick.Knutson@wellsfargo.com escreveu: 
> >  
> >
> >>I am trying to write test cases for my Struts app,
> >>but can't seem to figure it out.
> >>I have used the examples, but I don't seem to get
> >>the correct outcome when I run them.
> >>
> >>I am using LookupDispatchAction's exclusively. 
> >>
> >>So here is the method I am testing:
> >>==========================
> >>    public void productSelectionAction(
> >>ActionMapping mapping
> >>                                        ,
> ActionForm
> >>form
> >>                                        ,
> >>HttpServletRequest request
> >>                                        ,
> >>HttpServletResponse response ) {
> >>        log.info( "Process
> CreditApplicationActions
> >>productSelectionAction(...)" );
> >>
> >>        NavigationBean navigationBean = (
> >>NavigationBean )request.getSession().getAttribute(
> >>"navigationBean" );
> >>        if( navigationBean == null ) {
> >>            navigationBean = new NavigationBean();
> >>        }
> >>
> >>        if( Constants.TRUE.equals(
> >>request.getParameter( Constants.BUS_LINE_SELECTED
> )
> >>) ) {
> >>            navigationBean.setHasBusinessLine(
> true
> >>);
> >>        } else {
> >>            request.getSession().setAttribute(
> >>"businessLineForm", null );
> >>            navigationBean.setHasBusinessLine(
> false
> >>);
> >>        }
> >>
> >>        if( Constants.TRUE.equals(
> >>request.getParameter( Constants.BUS_CARD_SELECTED
> )
> >>) ) {
> >>            navigationBean.setHasBusinessCard(
> true
> >>);
> >>        } else {
> >>            request.getSession().setAttribute(
> >>"businessCardForm", null );
> >>            navigationBean.setHasBusinessCard(
> false
> >>);
> >>        }
> >>
> >>        if( Constants.TRUE.equals(
> >>request.getParameter(
> >>Constants.BUS_SEC_CARD_SELECTED ) ) ) {
> >>            navigationBean.setHasSecuredCard( true
> >>);
> >>        } else {
> >>            request.getSession().setAttribute(
> >>"securedCardForm", null );
> >>            navigationBean.setHasSecuredCard(
> false
> >>);
> >>        }
> >>
> >>        if( Constants.TRUE.equals(
> >>request.getParameter(
> >>Constants.EQUIP_EXPRESS_SELECTED ) ) ) {
> >>            navigationBean.setHasEquipExpress(
> true
> >>);
> >>        } else {
> >>            request.getSession().setAttribute(
> >>"equipExpressForm", null );
> >>            navigationBean.setHasEquipExpress(
> false
> >>);
> >>        }
> >>
> >>        request.getSession().setAttribute(
> >>"navigationBean", navigationBean );
> >>    };
> >>
> >>
> >>
> >>
> >>Here is the action in the struts-config.xml:
> >>===============================
> >>        <!-- Product selection action -->
> >>        <action path="/productSelection"
> >>                input=".productSelection"
> >>                name="productSelectionForm"
> >>                parameter="action"
> >>                scope="session"               
> >>               
> >>
> >>    
> >>
>
>type="com.wf.bd.ice.creditapplication.CreditApplicationActions"
> >  
> >
> >>                validate="true">
> >>            <forward name="error"
> >>path=".productSelection" redirect="true" />
> >>            <forward name="continue"
> >>path=".business" redirect="true" />
> >>            <forward name="productSelection"
> >>path=".productSelection" redirect="true" />
> >>            <forward name="business"
> >>path=".business" redirect="true" />
> >>            <forward name="firstOwner"
> >>path=".firstOwner" redirect="true" />
> >>            <forward name="secondOwner"
> >>path=".secondOwner" redirect="true" />
> >>            <forward name="businessLine"
> >>path=".businessLine" redirect="true" />
> >>            <forward name="businessCard"
> >>path=".businessCard" redirect="true" />
> >>            <forward name="securedCard"
> >>path=".securedCard" redirect="true" />
> >>            <forward name="equipExpress"
> >>path=".equipExpress" redirect="true" />
> >>            <forward name="noSecondOwner"
> >>path=".noSecondOwner" redirect="true" />
> >>            <forward name="noBusinessLine"
> >>path=".noBusinessLine" redirect="true" />
> >>            <forward name="noBusinessCard"
> >>path=".noBusinessCard" redirect="true" />
> >>            <forward name="noSecuredCard"
> >>path=".noSecuredCard" redirect="true" />
> >>            <forward name="noEquipExpress"
> >>path=".noEquipExpress" redirect="true" />
> >>            <forward name="conclude"
> >>path=".acceptanceAgreement" redirect="true" />
> >>        </action>
> >>
> >>
> >>
> >>
> >>
> >>Here is the test method:
> >>==================
> >>  public void testProductSelection() throws
> >>Exception {
> >>    // JUnitDoclet begin method productSelection
> >>
> >>        setRequestPathInfo( "/productSelection" );
> >>
> >>        addRequestParameter( "action", "nextPage"
> );
> >>
> >>        addRequestParameter(
> "businessLineSelected",
> >>"true" );
> >>        addRequestParameter(
> "businessCardSelected",
> >>"true" );
> >>        addRequestParameter(
> >>"businessSecuredCardSelected", "true" );
> >>        addRequestParameter(
> >>"equipmentExpressSelected", "true" );
> >>
> >>        actionPerform();
> >>
> 
=== message truncated === 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Help with Cactus StrutsTestCase

Posted by Duncan Mills <du...@oracle.com>.
Leandro - a good article has just been published on the Oracle 
Technology Network on using JUnit, Cactus and StrutsTestCase - the setup 
portions relate to setting up these up with JDeveloper, but the basic 
flow and tutorial portions provide a good kickstart even if you use 
another IDE - check it out:
http://www.oracle.com/technology/pub/articles/server_side_unit_tests.html

Regards

Duncan Mills
http://www.groundside.com/blog



Leandro Melo wrote:

>Doesn`t know the answer, where can i find a good
>tutorial do test struts applications?
>Is it true that for good testing the actions must
>delegate their work to POJOs ??
>
>
>
> --- Mick.Knutson@wellsfargo.com escreveu: 
>  
>
>>I am trying to write test cases for my Struts app,
>>but can't seem to figure it out.
>>I have used the examples, but I don't seem to get
>>the correct outcome when I run them.
>>
>>I am using LookupDispatchAction's exclusively. 
>>
>>So here is the method I am testing:
>>==========================
>>    public void productSelectionAction(
>>ActionMapping mapping
>>                                        , ActionForm
>>form
>>                                        ,
>>HttpServletRequest request
>>                                        ,
>>HttpServletResponse response ) {
>>        log.info( "Process CreditApplicationActions
>>productSelectionAction(...)" );
>>
>>        NavigationBean navigationBean = (
>>NavigationBean )request.getSession().getAttribute(
>>"navigationBean" );
>>        if( navigationBean == null ) {
>>            navigationBean = new NavigationBean();
>>        }
>>
>>        if( Constants.TRUE.equals(
>>request.getParameter( Constants.BUS_LINE_SELECTED )
>>) ) {
>>            navigationBean.setHasBusinessLine( true
>>);
>>        } else {
>>            request.getSession().setAttribute(
>>"businessLineForm", null );
>>            navigationBean.setHasBusinessLine( false
>>);
>>        }
>>
>>        if( Constants.TRUE.equals(
>>request.getParameter( Constants.BUS_CARD_SELECTED )
>>) ) {
>>            navigationBean.setHasBusinessCard( true
>>);
>>        } else {
>>            request.getSession().setAttribute(
>>"businessCardForm", null );
>>            navigationBean.setHasBusinessCard( false
>>);
>>        }
>>
>>        if( Constants.TRUE.equals(
>>request.getParameter(
>>Constants.BUS_SEC_CARD_SELECTED ) ) ) {
>>            navigationBean.setHasSecuredCard( true
>>);
>>        } else {
>>            request.getSession().setAttribute(
>>"securedCardForm", null );
>>            navigationBean.setHasSecuredCard( false
>>);
>>        }
>>
>>        if( Constants.TRUE.equals(
>>request.getParameter(
>>Constants.EQUIP_EXPRESS_SELECTED ) ) ) {
>>            navigationBean.setHasEquipExpress( true
>>);
>>        } else {
>>            request.getSession().setAttribute(
>>"equipExpressForm", null );
>>            navigationBean.setHasEquipExpress( false
>>);
>>        }
>>
>>        request.getSession().setAttribute(
>>"navigationBean", navigationBean );
>>    };
>>
>>
>>
>>
>>Here is the action in the struts-config.xml:
>>===============================
>>        <!-- Product selection action -->
>>        <action path="/productSelection"
>>                input=".productSelection"
>>                name="productSelectionForm"
>>                parameter="action"
>>                scope="session"               
>>               
>>
>>    
>>
>type="com.wf.bd.ice.creditapplication.CreditApplicationActions"
>  
>
>>                validate="true">
>>            <forward name="error"
>>path=".productSelection" redirect="true" />
>>            <forward name="continue"
>>path=".business" redirect="true" />
>>            <forward name="productSelection"
>>path=".productSelection" redirect="true" />
>>            <forward name="business"
>>path=".business" redirect="true" />
>>            <forward name="firstOwner"
>>path=".firstOwner" redirect="true" />
>>            <forward name="secondOwner"
>>path=".secondOwner" redirect="true" />
>>            <forward name="businessLine"
>>path=".businessLine" redirect="true" />
>>            <forward name="businessCard"
>>path=".businessCard" redirect="true" />
>>            <forward name="securedCard"
>>path=".securedCard" redirect="true" />
>>            <forward name="equipExpress"
>>path=".equipExpress" redirect="true" />
>>            <forward name="noSecondOwner"
>>path=".noSecondOwner" redirect="true" />
>>            <forward name="noBusinessLine"
>>path=".noBusinessLine" redirect="true" />
>>            <forward name="noBusinessCard"
>>path=".noBusinessCard" redirect="true" />
>>            <forward name="noSecuredCard"
>>path=".noSecuredCard" redirect="true" />
>>            <forward name="noEquipExpress"
>>path=".noEquipExpress" redirect="true" />
>>            <forward name="conclude"
>>path=".acceptanceAgreement" redirect="true" />
>>        </action>
>>
>>
>>
>>
>>
>>Here is the test method:
>>==================
>>  public void testProductSelection() throws
>>Exception {
>>    // JUnitDoclet begin method productSelection
>>
>>        setRequestPathInfo( "/productSelection" );
>>
>>        addRequestParameter( "action", "nextPage" );
>>
>>        addRequestParameter( "businessLineSelected",
>>"true" );
>>        addRequestParameter( "businessCardSelected",
>>"true" );
>>        addRequestParameter(
>>"businessSecuredCardSelected", "true" );
>>        addRequestParameter(
>>"equipmentExpressSelected", "true" );
>>
>>        actionPerform();
>>
>>        verifyForward( Constants.ERROR_FWD );
>>        verifyForward(
>>Constants.PRODUCTSELECTION_FWD );
>>
>>        //verifyActionErrors(new String[]
>>{"error.nodefault.implementation" } );
>>        //verifyActionErrors(new String[] {
>>"error.noaction.specified"} );
>>
>>        //NavigationBean navigationBean =
>>(NavigationBean)getSession().getAttribute(
>>"navigationBean" );
>>        //assertTrue( "NavigationBean is null",
>>navigationBean == null);
>>        verifyNoActionErrors();
>>
>>    // JUnitDoclet end method productSelection
>>  }
>>
>>
>>
>>
>>
>>And I get zero errors at all...
>>
>>
>>
>>
>>---
>>    
>>
>>>Thanks...
>>>Mick Knutson
>>>
>>>525 Market Street, SF, CA  94103
>>>(415) 222-1020
>>>Mick.Knutson@WellsFargo.com
>>>MAC A0103-223
>>>      
>>>
>>---
>>
>>
>>
>>
>>    
>>
>---------------------------------------------------------------------
>  
>
>>To unsubscribe, e-mail:
>>user-unsubscribe@struts.apache.org
>>For additional commands, e-mail:
>>user-help@struts.apache.org
>>
>> 
>>    
>>
>
>
>	
>	
>		
>_______________________________________________________
>Yahoo! Acesso Grátis - navegue de graça com conexão de qualidade! 
>http://br.acesso.yahoo.com/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Help with Cactus StrutsTestCase

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Check out "Struts The Complete Reference" by James Holmes -- I hear the 
chapter on Testing absolutely ROCKS ;)

Bill Siggelkow

Leandro Melo wrote:

> Sorry for the confusing sentence. 
> I meant to say that i don`t know the answer, but i`d
> like to use the opportunity and also ask a basic
> question.
> 
> Where can i find a good
> tutorial do test struts applications?
> Is it true that for good testing the actions must
> delegate their work to POJOs ??
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Help with Cactus StrutsTestCase

Posted by Leandro Melo <lt...@yahoo.com.br>.
Sorry for the confusing sentence. 
I meant to say that i don`t know the answer, but i`d
like to use the opportunity and also ask a basic
question.

Where can i find a good
tutorial do test struts applications?
Is it true that for good testing the actions must
delegate their work to POJOs ??



 --- Leandro Melo <lt...@yahoo.com.br>
escreveu: 
> Doesn`t know the answer, where can i find a good
> tutorial do test struts applications?
> Is it true that for good testing the actions must
> delegate their work to POJOs ??
> 
> 
> 
>  --- Mick.Knutson@wellsfargo.com escreveu: 
> > I am trying to write test cases for my Struts app,
> > but can't seem to figure it out.
> > I have used the examples, but I don't seem to get
> > the correct outcome when I run them.
> > 
> > I am using LookupDispatchAction's exclusively. 
> > 
> > So here is the method I am testing:
> > ==========================
> >     public void productSelectionAction(
> > ActionMapping mapping
> >                                         ,
> ActionForm
> > form
> >                                         ,
> > HttpServletRequest request
> >                                         ,
> > HttpServletResponse response ) {
> >         log.info( "Process
> CreditApplicationActions
> > productSelectionAction(...)" );
> > 
> >         NavigationBean navigationBean = (
> > NavigationBean )request.getSession().getAttribute(
> > "navigationBean" );
> >         if( navigationBean == null ) {
> >             navigationBean = new NavigationBean();
> >         }
> > 
> >         if( Constants.TRUE.equals(
> > request.getParameter( Constants.BUS_LINE_SELECTED
> )
> > ) ) {
> >             navigationBean.setHasBusinessLine(
> true
> > );
> >         } else {
> >             request.getSession().setAttribute(
> > "businessLineForm", null );
> >             navigationBean.setHasBusinessLine(
> false
> > );
> >         }
> > 
> >         if( Constants.TRUE.equals(
> > request.getParameter( Constants.BUS_CARD_SELECTED
> )
> > ) ) {
> >             navigationBean.setHasBusinessCard(
> true
> > );
> >         } else {
> >             request.getSession().setAttribute(
> > "businessCardForm", null );
> >             navigationBean.setHasBusinessCard(
> false
> > );
> >         }
> > 
> >         if( Constants.TRUE.equals(
> > request.getParameter(
> > Constants.BUS_SEC_CARD_SELECTED ) ) ) {
> >             navigationBean.setHasSecuredCard( true
> > );
> >         } else {
> >             request.getSession().setAttribute(
> > "securedCardForm", null );
> >             navigationBean.setHasSecuredCard(
> false
> > );
> >         }
> > 
> >         if( Constants.TRUE.equals(
> > request.getParameter(
> > Constants.EQUIP_EXPRESS_SELECTED ) ) ) {
> >             navigationBean.setHasEquipExpress(
> true
> > );
> >         } else {
> >             request.getSession().setAttribute(
> > "equipExpressForm", null );
> >             navigationBean.setHasEquipExpress(
> false
> > );
> >         }
> > 
> >         request.getSession().setAttribute(
> > "navigationBean", navigationBean );
> >     };
> > 
> > 
> > 
> > 
> > Here is the action in the struts-config.xml:
> > ===============================
> >         <!-- Product selection action -->
> >         <action path="/productSelection"
> >                 input=".productSelection"
> >                 name="productSelectionForm"
> >                 parameter="action"
> >                 scope="session"               
> >                
> >
>
type="com.wf.bd.ice.creditapplication.CreditApplicationActions"
> > 
> >                 validate="true">
> >             <forward name="error"
> > path=".productSelection" redirect="true" />
> >             <forward name="continue"
> > path=".business" redirect="true" />
> >             <forward name="productSelection"
> > path=".productSelection" redirect="true" />
> >             <forward name="business"
> > path=".business" redirect="true" />
> >             <forward name="firstOwner"
> > path=".firstOwner" redirect="true" />
> >             <forward name="secondOwner"
> > path=".secondOwner" redirect="true" />
> >             <forward name="businessLine"
> > path=".businessLine" redirect="true" />
> >             <forward name="businessCard"
> > path=".businessCard" redirect="true" />
> >             <forward name="securedCard"
> > path=".securedCard" redirect="true" />
> >             <forward name="equipExpress"
> > path=".equipExpress" redirect="true" />
> >             <forward name="noSecondOwner"
> > path=".noSecondOwner" redirect="true" />
> >             <forward name="noBusinessLine"
> > path=".noBusinessLine" redirect="true" />
> >             <forward name="noBusinessCard"
> > path=".noBusinessCard" redirect="true" />
> >             <forward name="noSecuredCard"
> > path=".noSecuredCard" redirect="true" />
> >             <forward name="noEquipExpress"
> > path=".noEquipExpress" redirect="true" />
> >             <forward name="conclude"
> > path=".acceptanceAgreement" redirect="true" />
> >         </action>
> > 
> > 
> > 
> > 
> > 
> > Here is the test method:
> > ==================
> >   public void testProductSelection() throws
> > Exception {
> >     // JUnitDoclet begin method productSelection
> > 
> >         setRequestPathInfo( "/productSelection" );
> > 
> >         addRequestParameter( "action", "nextPage"
> );
> > 
> >         addRequestParameter(
> "businessLineSelected",
> > "true" );
> >         addRequestParameter(
> "businessCardSelected",
> > "true" );
> >         addRequestParameter(
> > "businessSecuredCardSelected", "true" );
> >         addRequestParameter(
> > "equipmentExpressSelected", "true" );
> > 
> >         actionPerform();
> > 
> >         verifyForward( Constants.ERROR_FWD );
> >         verifyForward(
> > Constants.PRODUCTSELECTION_FWD );
> > 
> >         //verifyActionErrors(new String[]
> > {"error.nodefault.implementation" } );
> >         //verifyActionErrors(new String[] {
> > "error.noaction.specified"} );
> > 
> >         //NavigationBean navigationBean =
> > (NavigationBean)getSession().getAttribute(
> > "navigationBean" );
> >         //assertTrue( "NavigationBean is null",
> > navigationBean == null);
> >         verifyNoActionErrors();
> > 
> >     // JUnitDoclet end method productSelection
> >   }
> > 
> > 
> > 
> > 
> > 
> > And I get zero errors at all...
> > 
> 
=== message truncated === 


	
	
		
_______________________________________________________
Yahoo! Acesso Grátis - navegue de graça com conexão de qualidade! 
http://br.acesso.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Help with Cactus StrutsTestCase

Posted by Leandro Melo <lt...@yahoo.com.br>.
Doesn`t know the answer, where can i find a good
tutorial do test struts applications?
Is it true that for good testing the actions must
delegate their work to POJOs ??



 --- Mick.Knutson@wellsfargo.com escreveu: 
> I am trying to write test cases for my Struts app,
> but can't seem to figure it out.
> I have used the examples, but I don't seem to get
> the correct outcome when I run them.
> 
> I am using LookupDispatchAction's exclusively. 
> 
> So here is the method I am testing:
> ==========================
>     public void productSelectionAction(
> ActionMapping mapping
>                                         , ActionForm
> form
>                                         ,
> HttpServletRequest request
>                                         ,
> HttpServletResponse response ) {
>         log.info( "Process CreditApplicationActions
> productSelectionAction(...)" );
> 
>         NavigationBean navigationBean = (
> NavigationBean )request.getSession().getAttribute(
> "navigationBean" );
>         if( navigationBean == null ) {
>             navigationBean = new NavigationBean();
>         }
> 
>         if( Constants.TRUE.equals(
> request.getParameter( Constants.BUS_LINE_SELECTED )
> ) ) {
>             navigationBean.setHasBusinessLine( true
> );
>         } else {
>             request.getSession().setAttribute(
> "businessLineForm", null );
>             navigationBean.setHasBusinessLine( false
> );
>         }
> 
>         if( Constants.TRUE.equals(
> request.getParameter( Constants.BUS_CARD_SELECTED )
> ) ) {
>             navigationBean.setHasBusinessCard( true
> );
>         } else {
>             request.getSession().setAttribute(
> "businessCardForm", null );
>             navigationBean.setHasBusinessCard( false
> );
>         }
> 
>         if( Constants.TRUE.equals(
> request.getParameter(
> Constants.BUS_SEC_CARD_SELECTED ) ) ) {
>             navigationBean.setHasSecuredCard( true
> );
>         } else {
>             request.getSession().setAttribute(
> "securedCardForm", null );
>             navigationBean.setHasSecuredCard( false
> );
>         }
> 
>         if( Constants.TRUE.equals(
> request.getParameter(
> Constants.EQUIP_EXPRESS_SELECTED ) ) ) {
>             navigationBean.setHasEquipExpress( true
> );
>         } else {
>             request.getSession().setAttribute(
> "equipExpressForm", null );
>             navigationBean.setHasEquipExpress( false
> );
>         }
> 
>         request.getSession().setAttribute(
> "navigationBean", navigationBean );
>     };
> 
> 
> 
> 
> Here is the action in the struts-config.xml:
> ===============================
>         <!-- Product selection action -->
>         <action path="/productSelection"
>                 input=".productSelection"
>                 name="productSelectionForm"
>                 parameter="action"
>                 scope="session"               
>                
>
type="com.wf.bd.ice.creditapplication.CreditApplicationActions"
> 
>                 validate="true">
>             <forward name="error"
> path=".productSelection" redirect="true" />
>             <forward name="continue"
> path=".business" redirect="true" />
>             <forward name="productSelection"
> path=".productSelection" redirect="true" />
>             <forward name="business"
> path=".business" redirect="true" />
>             <forward name="firstOwner"
> path=".firstOwner" redirect="true" />
>             <forward name="secondOwner"
> path=".secondOwner" redirect="true" />
>             <forward name="businessLine"
> path=".businessLine" redirect="true" />
>             <forward name="businessCard"
> path=".businessCard" redirect="true" />
>             <forward name="securedCard"
> path=".securedCard" redirect="true" />
>             <forward name="equipExpress"
> path=".equipExpress" redirect="true" />
>             <forward name="noSecondOwner"
> path=".noSecondOwner" redirect="true" />
>             <forward name="noBusinessLine"
> path=".noBusinessLine" redirect="true" />
>             <forward name="noBusinessCard"
> path=".noBusinessCard" redirect="true" />
>             <forward name="noSecuredCard"
> path=".noSecuredCard" redirect="true" />
>             <forward name="noEquipExpress"
> path=".noEquipExpress" redirect="true" />
>             <forward name="conclude"
> path=".acceptanceAgreement" redirect="true" />
>         </action>
> 
> 
> 
> 
> 
> Here is the test method:
> ==================
>   public void testProductSelection() throws
> Exception {
>     // JUnitDoclet begin method productSelection
> 
>         setRequestPathInfo( "/productSelection" );
> 
>         addRequestParameter( "action", "nextPage" );
> 
>         addRequestParameter( "businessLineSelected",
> "true" );
>         addRequestParameter( "businessCardSelected",
> "true" );
>         addRequestParameter(
> "businessSecuredCardSelected", "true" );
>         addRequestParameter(
> "equipmentExpressSelected", "true" );
> 
>         actionPerform();
> 
>         verifyForward( Constants.ERROR_FWD );
>         verifyForward(
> Constants.PRODUCTSELECTION_FWD );
> 
>         //verifyActionErrors(new String[]
> {"error.nodefault.implementation" } );
>         //verifyActionErrors(new String[] {
> "error.noaction.specified"} );
> 
>         //NavigationBean navigationBean =
> (NavigationBean)getSession().getAttribute(
> "navigationBean" );
>         //assertTrue( "NavigationBean is null",
> navigationBean == null);
>         verifyNoActionErrors();
> 
>     // JUnitDoclet end method productSelection
>   }
> 
> 
> 
> 
> 
> And I get zero errors at all...
> 
> 
> 
> 
> ---
> > Thanks...
> > Mick Knutson
> > 
> > 525 Market Street, SF, CA  94103
> > (415) 222-1020
> > Mick.Knutson@WellsFargo.com
> > MAC A0103-223
> ---
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
>  


	
	
		
_______________________________________________________
Yahoo! Acesso Grátis - navegue de graça com conexão de qualidade! 
http://br.acesso.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org