struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mitchell, Steven C" <Steven.Mitch...@umb.com>
Subject RE: Testing Struts With JUnit
Date Fri, 19 Aug 2005 12:29:56 GMT
Luiz,

Are you aware that there is an extension of Junit made for testing Struts?

http://strutstestcase.sourceforge.net/

-----Original Message-----
From: Luiz Godoy [mailto:octaviodegodoy@yahoo.com] 
Sent: Thursday, August 18, 2005 3:22 PM
To: Struts Users Mailing List
Subject: Testing Struts With JUnit




 

I´m trying to test the action below :

public class FamiliaDNCAction extends BasicAction {

public ActionForward unspecified(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest
request, HttpServletResponse response) throws BusinessException {
  Set msgs = new HashSet();          
  return loadPage(actionMapping,actionForm,request,response);
 }

public ActionForward loadPage(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest
request, HttpServletResponse response) throws BusinessException {
  HttpSession session=request.getSession();
  CadastroFamiliaDNC cad = new CadastroFamiliaDNC();
         FamiliaDNCForm form = (FamiliaDNCForm) actionForm;
  List dados = cad.findByCodigoDependencia(form.getCodDependencia().intValue());
  session.setAttribute("dadosdnc",dados); 
  return actionMapping.findForward("inicial");
 }

}

The parameters for the action are 

FamiliaDNC.do -- calls the class
ev --> the parameter for the method, when not set calls "unspecified" method

public class TestFamiliaDNCAction extends MockStrutsTestCase{  FamiliaDNCAction fdnca;
  public TestFamiliaDNCAction(String nomeDoTeste) {
        super(nomeDoTeste);
     }
  
  public void setUp() throws Exception {
        super.setUp();
        fdnca = new FamiliaDNCAction();
    }

  public void testLoadPage() {
          
   addRequestParameter("codDependencia","1");
   addRequestParameter("codTipoFamiliaInsumo","0");
   addRequestParameter("ev","unspecified");
        setRequestPathInfo("/corporativo/cadastro/cadFamiliaDNC");
        actionPerform();
        verifyForward("inicial");
     verifyForwardPath("/corporativo/cadastro/corp_cad_familia_dnc.jsp");
        verifyNoActionErrors();
    }

 I´m getting nullPointerException, when i try to test it. I´m not sure 
witch parameters i add to the request for example in the action form i have:

<form name="form2" method="post" action="./cadFamiliaDNC.do">
                      <input type="hidden" name="codFamiliaDNC" value="">
                      <input type="hidden" name="codTipoFamiliaInsumo">
                      <input type="hidden" name="codDependencia">
                      .....
/form>  

My question is, witch parameters do i put in the addRequestParameter("?","?"); ?

any clue ?

Thanks in advance 

regards..



Luiz Octavio Godoy 

Desenvolvimento de Sistemas

__________________________________________________
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


Mime
View raw message