public void testSimpleRenderWithDeferredRunnable()
{
MockControl writerc = newControl(IMarkupWriter.class);
IMarkupWriter writer = (IMarkupWriter) writerc.getMock();
NestedMarkupWriter nested = newNestedWriter();
MockControl cyclec = newControl(IRequestCycle.class);
IRequestCycle cycle = (IRequestCycle) cyclec.getMock();
MockControl enginec = newControl(IEngine.class);
IEngine engine = (IEngine) enginec.getMock();
MockControl delegatec = newControl(IValidationDelegate.class);
IValidationDelegate delegate = (IValidationDelegate) delegatec.getMock();
MockForm form = new MockForm(delegate);
cycle.isRewound(form);
cyclec.setReturnValue(false);
cycle.getEngine();
cyclec.setReturnValue(engine);
engine.getClassResolver();
enginec.setReturnValue(getClassResolver());
MockControl supportc = newControl(PageRenderSupport.class);
PageRenderSupport support = (PageRenderSupport) supportc.getMock();
trainGetPageRenderSupport(cyclec, 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);
MockControl linkc = newControl(ILink.class);
ILink link = (ILink) linkc.getMock();
IRender render = (IRender) newMock(IRender.class);
support.addExternalScript(new ClasspathResource(getClassResolver(),
"/org/apache/tapestry/form/Form.js"));
support
.addInitializationScript("var myform_events = new FormEventManager(document.myform);");
link.getParameterNames();
linkc.setReturnValue(new String[]
{ "service" });
link.getParameterValues("service");
linkc.setReturnValue(new String[]
{ "fred" });
writer.getNestedWriter();
writerc.setReturnValue(nested);
link.getURL(null, false);
linkc.setReturnValue("/app");
writer.begin("form");
writer.attribute("method", "post");
writer.attribute("action", "/app");
writer.attribute("name", "myform");
render.render(writer, cycle);
writer.println();
trainHidden(writer, "formids", "");
trainHidden(writer, "service", "fred");
trainHidden(writer, "submitmode", "");
// 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(delegatec, delegate, null);