On Sunday, February 17, 2002, at 09:00 pm, Stefano Mazzocchi wrote:

> Stuart Roebuck wrote:
>>
>> Well I've got got an EmailTransformer I've produced for a current 
>> project,
>>   it's not too elegant at the moment, but it works, and it has some 
>> generic
>> unit test code that folk might be interested in for testing the 
>> processing
>> of a transformer - I don't think there's much unit test code in the
>> current Cocoon codebase, infact I think I might be responsible for all of
>> it!!.
>>
>> If anyone can find the time to relocate it appropriately in the cocoon
>> class hierarchy, I have a number of bits of unit testing infrastructure
>> that might be handy to other folk:
>>
>>         Mock Classes for Avalon:
>>                 avalon.excalibur.DataSourceComponent
>>         Mock Classes for Framework:
>>                 avalon.framework.ComponentManager
>>                 avalon.framework.Configuration
>>         Mock Classes for Cocoon:
>>                 cocoon.environment.Redirector
>>                 cocoon.environment.Request
>>                 cocoon.environment.Session
>>                 cocoon.environment.Source
>>                 cocoon.environment.SourceResolver
>>
>> These provide sufficient glue to unit test quite a lot of actions,
>> generators and transformers in isolation which could also be handy for
>> some kinds of performance testing.
>>
>> Anyone interested?
>
> I'd be. Make them available somewhere and post the URL.

I've posted them at:

        <http://www.adolos.co.uk/temp/mocks_and_email_transformer.tgz>

I've put the email transformer in there because it is the only bit of 
general use that demonstrates the use of the Mock Classes.  There will be 
a number of updates to the Email Transformer this week to integrate 
facilities for constructing multi-part MIME emails with file attachments, 
based on the SendMail utility class which I have included in this archive.

Here's a clip from a unit test for another custom Form Mail action we have 
under development, it shows the mock classes in use:

>     private AbstractAction action;
>     private SessionMock session;
>     private Redirector redirector;
>     private SourceResolver sourceResolver;
>     private RequestMock request;
>     private Response response;
>     private Parameters parameters;
>     private Map objectModel;
>     private MockConnection connection;
>     private MockStatement statement;
>
>     public void setUp() {
>         this.action = new EmailFormAction();
>         this.session = new SessionMock();
>         this.redirector = new RedirectorMock();
>         this.sourceResolver = new SourceResolverMock();
>         this.request = new RequestMock();
>         this.response = new CommandLineResponse();
>         this.parameters = new Parameters();
>         this.objectModel = new HashMap();
>         this.objectModel.put(Constants.REQUEST_OBJECT, this.request);
>         this.objectModel.put(Constants.RESPONSE_OBJECT, this.response);
>     }
>
>
>     public void testEmailForm() throws Exception {
>         this.parameters.setParameter("smtphost","smtp.demon.co.uk");
>         this.parameters.setParameter("from","[EMAIL PROTECTED]");
>         this.parameters.setParameter("to","[EMAIL PROTECTED]");
>         this.parameters.setParameter("subject","Testing EmailFormAction")
> ;
>         this.parameters.setParameter("body","Default body test.");
>         this.parameters.setParameter("testing","yes");
>
>         this.request.mockSetParameter("name","Stuart Roebuck");
>         this.request.mockSetParameter("email","[EMAIL PROTECTED]"
> );
>         this.request.mockSetParameter("answer","cat");
>         this.request.mockSetParameter("answer","dog");
>         this.request.mockSetParameter("_submit","submit");
>         // This subject and body above should override the values set 
> below:
>         this.request.mockSetParameter("_email_subject", "New subject");
>         this.request.mockSetParameter("_email_body", "This comes before 
> the results");
>
>         Map map = action.act(this.redirector, this.sourceResolver, 
> this.objectModel, "src", this.parameters);
>         assertEquals("[EMAIL PROTECTED]", (String) map.get("from"));
>         assertEquals("[EMAIL PROTECTED]", (String) map.get("to"
> ));
>         assertEquals("Testing EmailFormAction", (String) map.get("subject"
> ));
>         assertEquals("Default body test.\n" +
>                      "email = [EMAIL PROTECTED]\n" +
>                      "name = Stuart Roebuck\n" +
>                      "answer = cat,dog\n",
>                      (String) map.get("body"));
>     }

If it finds a home I'll try to set aside some time to add some comments 
and send them in as patches.

Stuart.



            Public Key - 1024D/88DD65AF 2001-11-23 Stuart Roebuck (Adolos)
      Key fingerprint = 89D9 E405 F8B1 9B22 0FA2  F2C1 9E57 5AB1 88DD 65AF
-------------------------------------------------------------------------
Stuart Roebuck                                  [EMAIL PROTECTED]
Systems Architect                             Java, XML, MacOS X, XP, etc.
ADOLOS                                           <http://www.adolos.com/>


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

Reply via email to