struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Husted <hus...@apache.org>
Subject Re: ServletUnit with Struts
Date Sat, 25 Aug 2001 09:01:45 GMT
JEWeaver@thoughtworks.com wrote:
> The solution I am now pursuing, so far with success, is removing almost all
> of the application-specific "meat" from my Action subclasses.  I will
> delegate to a simple command class from the action.  The command class will
> take input paramaters, access the model layer to carry out the operation,
> and make available a logical forwarding name, result objects hash, and
> ActionErrors which can be accessed by the Action class following command
> execution.  All that will be left in the Action class will be Struts
> frame-worky stuff.

> The consequence is that I can unit test the command independently with
> vanilla junit, without relying on a host of mock servlet / struts objects
> or an in-container testing framework.  

+1 = The day I became a true believe in layered Web applications was the
day I realized that the only reasonable way to Unit Test a Web
applications was to separate the business logic from the Web tier, so
tools like JUnit can be used.

Ideally, an Action should be an adapter to handle the error checking and
control flow. Everything else should be delegated to other objects, with
no HTTP dependencies, that can be used in other environments, and tested
with Junit.

> The only Struts object I'm going to
> allow the commands to work with is an ActionErrors instance.  Removing that
> Struts dependency would be even nicer, in that you could then survive a
> departure from the struts framework with the vast bulk of your control
> layer logic unaffected.  Easy to get rid of the ActionErrors and just have
> the command class save the keys of the errors in a collection...

You might consider having the command class return generic error codes,
and then map those to the ActionErrors. For (quick and dirty) example:

int error = command(something); 
if (error==CommandErrors.NOT_FOUND) { 
	errors.add(ActionErrors.GLOBAL_ERROR, new
ActionError("errors.not.found"));
}


-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/about/struts/

Mime
View raw message