/**
* Test the URLRewriting aspect of doFormLink.
*/
public void testDoFormLinkURLRewriting() throws Throwable {
CanvasLayout layout = new CanvasLayout();
Form form = new Form(layout);
final String formName = "form";
final String fragmentName = "formFragment";
form.setName(formName);
FormInstance formInstance = new FormInstance(
NDimensionalIndex.ZERO_DIMENSIONS);
formInstance.setFormat(form);
final PolicyReferenceResolverMock referenceResolverMock =
new PolicyReferenceResolverMock("referenceResolverMock",
expectations);
referenceResolverMock.expects.
resolveQuotedTextExpression(fragmentName).returns(null);
MarinerApplication application = new MarinerServletApplication();
MarinerConfiguration config = new MarinerConfiguration();
Volantis volantis = getVolantis();
PrivateAccessor.setField(volantis, "marinerConfig", config);
PrivateAccessor.invoke(volantis, "initializeURLRewriters",
new Class [] {MarinerApplication.class},
new Object [] { application });
final String testURL = "http://test/url";
PageURLRewriter layoutURLRewriter = new PageURLRewriter() {
public MarinerURL rewriteURL(MarinerRequestContext context,
MarinerURL url,
PageURLDetails details) {
return new MarinerURL(testURL);
}
};
PrivateAccessor.setField(volantis, "layoutURLRewriter",
layoutURLRewriter);
TestMarinerPageContext context = new TestMarinerPageContext();
context.setVolantis(volantis);
context.setRequestURL(new MarinerURL("http://a.url"));
FormDescriptor fd = new FormDescriptor();
fd.setName(formName);
final FormDataManager formDataManager = context.getFormDataManager();
String formSpecifier = formDataManager.getFormSpecifier(fd);
context.setPolicyReferenceResolver(referenceResolverMock);
context.pushDeviceLayoutContext(new DeviceLayoutContext());
PageGenerationCache pageGenerationCache = new PageGenerationCache();
pageGenerationCache.createFormFragmentationStates(form.getName());
context.setPageGenerationCache(pageGenerationCache);
protocol.setMarinerPageContext(context);
if(protocol.getPageHead()==null) {
protocol.initialisePageHead();
}