You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Luiz Godoy <oc...@yahoo.com> on 2005/08/18 22:22:01 UTC

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