struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <davelnew...@gmail.com>
Subject Re: why the code passes Servlet container test but fails in StrutsTestCase
Date Sun, 14 Feb 2016 22:20:43 GMT
This shouldn't even compile since you're attempting to return a value.
On Feb 13, 2016 11:26 PM, "JOSE L MARTINEZ-AVIAL" <jlmagc@gmail.com> wrote:

> The method execute has void as a return type, instead of a String.
>
> 2016-02-13 2:26 GMT-05:00 小唐 <644282565@qq.com>:
>
> > Hi,
> >
> > I was trying to use StrutsTestCase to write a test for a Bean, which has
> a
> > member of String[]. The code runs perfectly in servlet container(Tomcat),
> > but fails as a mock test. In EditActionTest.java, assertNotNull("The
> action
> > is null but should not be.", action) still works fine, but String result
> =
> > actionProxy.execute() returns the result as "error" instead of "success".
> > All the related codes are listed below.
> >
> > Can anyone give me a hint?
> > Thanks in advance! Tom
> >
> > Person.java
> > public class Person{
> >    String[] models = new String[]{"Ford", "Nissan"};
> >
> >    public void setModels(String[] models){
> >       this.models = models;
> >    }
> >
> >    public String[] getModels(){
> >       return models;
> >    }
> > }
> >
> > Edit.java
> > public class EditAction extends ActionSupport{
> >    Person personBean;
> >
> >    public void execute(){
> >       return SUCCESS;
> >    }
> > }
> >
> > struts.xml
> > <struts>
> >       <action name="edit" class="EditAction" method="execute">
> >      <result name="input">/edit.jsp</result>
> >          <result name="success">/thankyou.jsp</result>
> >       </action>
> > </struts>
> >
> > edit.jsp
> > <%@ taglib prefix="s" uri="/struts-tags" %>
> > <s:form action="save" method="post">
> > <s:checkboxlist key="personBean.models" list="Ford, Nissan" />
> > <s:submit key="submit" />
> > </s:form>
> >
> > EditActionTest.java
> > public class EditActionTest extends StrutsTestCase {
> >    @Test
> >    public void testExecuteValidationPasses() throws Exception {
> >       request.setParameter("personBean.models", new String[]{"Ford",
> > "Nissan"});
> >       ActionProxy actionProxy = getActionProxy("/edit.action") ;
> >       EditAction action = (EditAction) actionProxy.getAction();
> >       assertNotNull("The action is null but should not be.", action);
> >       String result = actionProxy.execute();
> >       assertEquals("The execute method did not return " +
> > ActionSupport.SUCCESS + " but should have.", ActionSupport.SUCCESS,
> result);
> >    }
> > }
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message