hi,

Prior to opening a page I call an action in order to store in request collection of value beans. Although I know how to test situation when everything goes OK I do not know how to test the oposite especially when Hibernate is being used.

My action in struts-config.xml is as follow:
      <action
         parameter="method"
         path="/goToAddCode"
         type="com.delphi.struts.action.CodeAction"
         validate="false">
         <forward name="success" path=".addCode" />
      </action>
the value of parameter is goToAdd (this invokes goToAdd action). The action is simply:

public ActionForward goToAdd(ActionMapping mapping,ActionForm form,
  HttpServletRequest request,HttpServletResponse response) {

  CodeKindDAO ckdao=new CodeKindDAO();
  List codekinds=ckdao.findAll();

  if(codekinds.isEmpty()){
   ActionMessages messages=new ActionMessages();
   if(codekinds.isEmpty())
    messages.add("error",new  ActionMessage("error.codekinds.missing"));
   saveMessages(request,messages);
   return mapping.findForward("failure");
  }

  request.setAttribute("codekinds",codekinds);

 return mapping.findForward(IConstants.SUCCESS);
}

The test for success is like that:
  setRequestPathInfo("/goToAddCode");
  addRequestParameter("method","goToAdd");

  actionPerform();

  verifyForward("success");
  assertTrue(!((List)request.getAttribute("codekinds")).isEmpty());

As I wrote I've a problem to test situation when there is an error. I suppose the solution is to change the way I provide datas for testing. At this moment I just call function from appropriate DAO object which in turn use hibernate API.
How to write action tests with hibernate?

Rgs.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to