You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Miguel Almeida <mi...@almeida.at> on 2011/09/21 17:25:44 UTC

Can Struts Junit plugin be used to test the redirect result of an action

I am using the Struts Junit plugin
(http://struts.apache.org/2.2.3.1/docs/struts-2-junit-plugin-tutorial.html ), extending the StrutsSpringTestCase for a regression test of an action in my application.

(Optional reading: 
Long story short on the problem, the action adds a record to a database
via hibernate. The result is a redirect to execute() of the same class,
whose prepare() populates a List<Record> object with all the records
available. For some reason, the prepare fires as it should, but returns
the old number of items. Only a refresh shows the page with the correct
results. For an odd reason, sleeping the thread before calling the dao's
code that retrieves the list for 1 second also makes the result to be
correctly updated.)

The action result is a redirectAction, that, well, redirects to another
action. The test doesn't call this second method, though.
Is it possible with this base test case to make it call the 2nd action?


Regards,

Miguel Almeida



Re: Can Struts Junit plugin be used to test the redirect result of an action

Posted by Carl Ballantyne <ca...@gmail.com>.
Just a thought but make sure hibernate is sending the sql to the database.
Try stepping through your code using the debugger and add relevant logging
to be sure. Call flush() if necessary.

On Sat, Sep 24, 2011 at 1:18 PM, miguel <mi...@almeida.at> wrote:

>
> On Thu, 2011-09-22 at 10:23 +0200, Maurizio Cucchiara wrote:
>
> > The reason behind is simple: no browser no redirect.
> > The redirect is sent as http header, so as long as there is no browser
> > to interpret the header there is no way to redirect.
> >
> > You might call by yourself the second action, WDYT?
> >
> > PS: FWIW I have not read the optional reading :)
> >
>
> Yeah, I tried that, but to no success: I can't replicate the error I
> wanted to (see the optional reading :P). Long story short, in my
> application, when I have a redirect result, the 2nd action doesn't
> retrieve the correct results from the database unless I pause its
> execution for a second. Weird. Very.
>
>
>
> > Maurizio Cucchiara
> >
> >
> >
> > On 21 September 2011 17:25, Miguel Almeida <mi...@almeida.at> wrote:
> > > I am using the Struts Junit plugin
> > > (
> http://struts.apache.org/2.2.3.1/docs/struts-2-junit-plugin-tutorial.html), extending the StrutsSpringTestCase for a regression test of an action in
> my application.
> > >
> > > (Optional reading:
> > > Long story short on the problem, the action adds a record to a database
> > > via hibernate. The result is a redirect to execute() of the same class,
> > > whose prepare() populates a List<Record> object with all the records
> > > available. For some reason, the prepare fires as it should, but returns
> > > the old number of items. Only a refresh shows the page with the correct
> > > results. For an odd reason, sleeping the thread before calling the
> dao's
> > > code that retrieves the list for 1 second also makes the result to be
> > > correctly updated.)
> > >
> > > The action result is a redirectAction, that, well, redirects to another
> > > action. The test doesn't call this second method, though.
> > > Is it possible with this base test case to make it call the 2nd action?
> > >
> > >
> > > Regards,
> > >
> > > Miguel Almeida
> > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
>

Re: Can Struts Junit plugin be used to test the redirect result of an action

Posted by miguel <mi...@almeida.at>.
On Thu, 2011-09-22 at 10:23 +0200, Maurizio Cucchiara wrote:

> The reason behind is simple: no browser no redirect.
> The redirect is sent as http header, so as long as there is no browser
> to interpret the header there is no way to redirect.
> 
> You might call by yourself the second action, WDYT?
> 
> PS: FWIW I have not read the optional reading :)
> 

Yeah, I tried that, but to no success: I can't replicate the error I
wanted to (see the optional reading :P). Long story short, in my
application, when I have a redirect result, the 2nd action doesn't
retrieve the correct results from the database unless I pause its
execution for a second. Weird. Very. 



> Maurizio Cucchiara
> 
> 
> 
> On 21 September 2011 17:25, Miguel Almeida <mi...@almeida.at> wrote:
> > I am using the Struts Junit plugin
> > (http://struts.apache.org/2.2.3.1/docs/struts-2-junit-plugin-tutorial.html ), extending the StrutsSpringTestCase for a regression test of an action in my application.
> >
> > (Optional reading:
> > Long story short on the problem, the action adds a record to a database
> > via hibernate. The result is a redirect to execute() of the same class,
> > whose prepare() populates a List<Record> object with all the records
> > available. For some reason, the prepare fires as it should, but returns
> > the old number of items. Only a refresh shows the page with the correct
> > results. For an odd reason, sleeping the thread before calling the dao's
> > code that retrieves the list for 1 second also makes the result to be
> > correctly updated.)
> >
> > The action result is a redirectAction, that, well, redirects to another
> > action. The test doesn't call this second method, though.
> > Is it possible with this base test case to make it call the 2nd action?
> >
> >
> > Regards,
> >
> > Miguel Almeida
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

Re: Can Struts Junit plugin be used to test the redirect result of an action

Posted by Maurizio Cucchiara <mc...@apache.org>.
The reason behind is simple: no browser no redirect.
The redirect is sent as http header, so as long as there is no browser
to interpret the header there is no way to redirect.

You might call by yourself the second action, WDYT?

PS: FWIW I have not read the optional reading :)

Maurizio Cucchiara



On 21 September 2011 17:25, Miguel Almeida <mi...@almeida.at> wrote:
> I am using the Struts Junit plugin
> (http://struts.apache.org/2.2.3.1/docs/struts-2-junit-plugin-tutorial.html ), extending the StrutsSpringTestCase for a regression test of an action in my application.
>
> (Optional reading:
> Long story short on the problem, the action adds a record to a database
> via hibernate. The result is a redirect to execute() of the same class,
> whose prepare() populates a List<Record> object with all the records
> available. For some reason, the prepare fires as it should, but returns
> the old number of items. Only a refresh shows the page with the correct
> results. For an odd reason, sleeping the thread before calling the dao's
> code that retrieves the list for 1 second also makes the result to be
> correctly updated.)
>
> The action result is a redirectAction, that, well, redirects to another
> action. The test doesn't call this second method, though.
> Is it possible with this base test case to make it call the 2nd action?
>
>
> Regards,
>
> Miguel Almeida
>
>
>

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