cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Bigwood" <dbigw...@metatomix.com>
Subject Re: EmailTransformer and unit testing code
Date Mon, 18 Feb 2002 03:56:50 GMT
Email Transformer
============

We would like to donate an Email transformer to the Cocoon project.
Attached is java file SendMailTransformer.java. Perhaps this could
be used in conjunction with Stuart's code to produce a finished product
- best of both worlds.

Transformer allows email messages to be generated from a Sax stream.
Support for TO, CC, BCC, Text and HTML formats (HTML can be included
in stream or accessed from a specified URL). Messages are generated
as MIME multipart. HTML body parts can be added directly between
<mtxsm:part type="text/html"> tags, or referenced from an external
URL, with the addition of a src attribute.

The smtphost tag will to using localhost 127.0.0.1 for sending
email if not specified in the XML stream or the sitemap (see below).

Namespace set as mtxsm="http://metatomix.com/sendmail/1.0#"
We would be willing to refactor this to remove the namespace.

XML structure for Sendmail Transformer:

<?xml version="1.0"?>
<root xmlns:mtxsm="http://metatomix.com/sendmail/1.0#">
  ...
  <mtxsm:sendmail confirmation="true">
    <mtxsm:from mtxsm:addr="sender@m3t4.com"
      mtxsm:name="Customer Service"/>
 <mtxsm:to mtxsm:addr="dbigwood@m3t4.com"
   mtxsm:name="David Bigwood"/>
 <mtxsm:cc mtxsm:addr="7819999999@messaging.nextel.com"
   mtxsm:name="David Bigwood"/>
 <mtxsm:bcc mtxsm:addr="davidabigwood@yahoo.com"
   mtxsm:name="DAB"/>
 <mtxsm:subject>Email Test</mtxsm:subject>
 <mtxsm:smtphost>mail.domain.com</mtxsm:smtphost>
 <mtxsm:multipart type="alternative">
   <mtxsm:part type="text/html">
     <html>
     <body>
     <h1>Email Transformer HTML message</h1>
        <p>Standard HTML tags inside XML tag for Mime body part.</p>
        </body>
        </html>
      </mtxsm:part>
      <mtxsm:part type="text/html"
        src="http://domain.com/mtxemail/html/message1.html" />
      <mtxsm:part type="text/plain">
        This is a text message that will be passed through
  as displayed here including line breaks
      </mtxsm:part>
    </mtxsm:multipart>
  </mtxsm:sendmail>
  ...
</root>

Sitemap:

With transformer configured as alias "MTXSendMail".

<map:match pattern="sendmail/**">
  <map:generate type="file" src="mail/mail.xml"/>
  <map:transform type="MTXSendMail">
    <map:parameter name="mail.smtp.host" value="mail.domain.com"/>
    <map:parameter name="removetags" value="true"/>
  </map:transform>
  <map:serialize type="xml"/>
</map:match>

Where:

Data inside the 'mtxsm' namespace is removed from the passing stream
by setting the value of 'removetags' as true.

Success or failure of the send is notified to the stream by modifying
the <mtxsm:sendmail> tag by adding a confirmation attribute set to
true or false:

<mtxsm:sendmail confirmation="true|false" />

This is independent of the removetags setting in the sitemap.

-David Bigwood

----
David Bigwood
VP Engineering
Metatomix Inc






----- Original Message -----
From: "Stuart Roebuck" <stuartroebuck@mac.com>
To: <cocoon-dev@xml.apache.org>
Sent: Sunday, February 17, 2002 5:46 PM
Subject: Re: EmailTransformer and unit testing code


>
> 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","testing@adolos.co.uk");
> >
this.parameters.setParameter("to","stuart.roebuck@adolos.co.uk");
> >         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","stuart.roebuck@adolos.com"
> > );
> >         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("testing@adolos.co.uk", (String) map.get("from"));
> >         assertEquals("stuart.roebuck@adolos.co.uk", (String)
map.get("to"
> > ));
> >         assertEquals("Testing EmailFormAction", (String)
map.get("subject"
> > ));
> >         assertEquals("Default body test.\n" +
> >                      "email = stuart.roebuck@adolos.com\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                                  stuart.roebuck@adolos.com
> Systems Architect                             Java, XML, MacOS X, XP, etc.
> ADOLOS                                           <http://www.adolos.com/>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org
>
>

Mime
View raw message