}
public void testSimpleRenderWithDeferredRunnable()
{
IMarkupWriter writer = newWriter();
NestedMarkupWriter nested = newNestedWriter();
IRequestCycle cycle = newCycle();
IEngine engine = newEngine(getClassResolver());
IValidationDelegate delegate = newDelegate();
ILink link = newLink();
IRender render = newRender();
MockForm form = new MockForm(delegate);
trainIsRewound(cycle, form, false);
trainGetEngine(cycle, engine);
PageRenderSupport support = newPageRenderSupport();
trainGetPageRenderSupport(cycle, support);
replayControls();
final FormSupport fs = new FormSupportImpl(writer, cycle, form);
verifyControls();
IRender body = new IRender()
{
public void render(final IMarkupWriter pwriter, IRequestCycle pcycle)
{
fs.addDeferredRunnable(new Runnable()
{
public void run()
{
pwriter.print("DEFERRED");
}
});
}
};
form.setBody(body);
trainRegister(support);
trainGetParameterNames(link, new String[]
{ "service" });
trainGetParameterValues(link, "service", new String[]
{ "fred" });
trainGetNestedWriter(writer, nested);
trainGetURL(link, null, "/app");
writer.begin("form");
writer.attribute("method", "post");
writer.attribute("action", "/app");
writer.attribute("name", "myform");
writer.attribute("id", "myform");
render.render(writer, cycle);
writer.println();
trainDiv(writer);
trainHidden(writer, "formids", "");
trainHidden(writer, "service", "fred");
trainHidden(writer, "submitmode", "");
writer.end();
// EasyMock can't fully verify that this gets called at the right moment, nor can we truly
// prove (well, except by looking at the code), that the deferred runnables execute at the
// right time.
nested.print("DEFERRED");
nested.close();
writer.end();
trainGetFocusField(delegate, null);