Please see WicketTester which is based on MockWebApplication and all
the junit test cases in src/test which use the same principle: create
the output as a string and compare it with the expected output which
is kept in a file.

Juergen

On 4/19/06, Aaron Hiniker <[EMAIL PROTECTED]> wrote:
> I would like to render a page to a String for sending as an HTML email.
>
> I searched the list and found a possible solution using
> wicket.protocol.http.MockWebApplication.. however, upon
> implementing that solution I am having problems.  Here is the code I am
> using (with garbage stuff removed) which is called from my web application's
> Form#onSubmit().
>
>
>     public static void mail( Message msg, MailTemplate pageToMail )    //
> MailTemplate extends WebPage
>     {
>         // create a mock application
>         MockWebApplication app = new MockWebApplication(
> pageToMail.getApplication().getApplicationSettings().getContextPath()
> );
>
>         // set a null home page.. we will set the page later
>         app.setHomePage( NullHomePage.class );
>
>             // setup the request/response
>             app.setupRequestAndResponse();
>             app.processRequestCycle( pageToMail );
>
>             // get the output
>             String output = new String(
> app.getServletResponse().getBinaryContent() );
>
>             // add the template to the output
>             msg.getBodies().add( new TextBody( output ) );
>
>         Mailer.mail( msg );
>
>     }
>
>
> generates
>
> java.lang.NullPointerException
> wicket.request.compound.DefaultExceptionResponseStrategy.onRuntimeException(DefaultExceptionResponseStrategy.java:141)
> wicket.request.compound.DefaultExceptionResponseStrategy.respond(DefaultExceptionResponseStrategy.java:64)
> wicket.request.compound.AbstractCompoundRequestCycleProcessor.respond(AbstractCompoundRequestCycleProcessor.java:76)
> wicket.RequestCycle.step(RequestCycle.java:976)
> wicket.RequestCycle.steps(RequestCycle.java:1010)
> wicket.RequestCycle.request(RequestCycle.java:452)
> wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:210)
> wicket.protocol.http.WicketServlet.doPost(WicketServlet.java:251)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
> org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)



The
> mail gets sent but with empty content (no output captured)


Questions..
>

can I just generate the output of a Page *instance*? Many of my pages have
> no default constructor, so I can't set them as the Mock homePage.
is using
> MockWebApplication the best way to achieve these results?





>


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to