DOMProtocol protocol = createProtocol();
// Create a basic layout object
RuntimeDeviceLayout deviceLayout = createDeviceLayout();
RuntimeTestMarinerPageContext pageContext = new RuntimeTestMarinerPageContext();
RuntimeTestMarinerRequestContext requestContext = new RuntimeTestMarinerRequestContext();
EnvironmentContext environmentContext = new RuntimeTestEnvironmentContext();
((RuntimeTestEnvironmentContext)environmentContext)
.setResponseWriter(writer);
ApplicationContext applicationContext = new ApplicationContext(
requestContext);
pageContext.setDeviceLayout(deviceLayout);
applicationContext.setDevice(device);
applicationContext.setProtocol(protocol);
applicationContext.setDissectionSupported(true);
applicationContext.setFragmentationSupported(true);
applicationContext.setCanvasTagSupported(true);
applicationContext.setWMLCSupported(false);
applicationContext.setEncodingManager(new EncodingManager());
applicationContext.setPackager(new DefaultPackager());
TestVolantis volantisBean = new TestVolantis();
RuntimeDeviceTheme runtimeDeviceTheme = createRuntimeDeviceTheme();
final VariantSelectionPolicyMock variantSelectionPolicyMock =
new VariantSelectionPolicyMock("variantSelectionPolicyMock",
expectations);
final SelectedVariantMock selectedVariantMock =
new SelectedVariantMock("selectedVariantMock", expectations);
selectedVariantMock.expects.getOldObject()
.returns(runtimeDeviceTheme).any();
final ProjectManagerMock projectManagerMock =
new ProjectManagerMock("projectManagerMock", expectations);
PolicyReferenceFactory referenceFactory =
new PolicyReferenceFactoryImpl(projectManagerMock);
variantSelectionPolicyMock.fuzzy
.retrieveBestObject(mockFactory.expectsAny(),
mockFactory.expectsAny(),
mockFactory.expectsAny())
.returns(selectedVariantMock).any();
volantisBean.setVariantSelectionPolicy(variantSelectionPolicyMock);
volantisBean.setPolicyReferenceFactory(referenceFactory);
volantisBean.setPageHeadingMsg("Test Page Heading Message");
ContextInternals.setMarinerPageContext(requestContext, pageContext);
ContextInternals.setEnvironmentContext(requestContext,
environmentContext);
ContextInternals.setApplicationContext(requestContext,
applicationContext);
MarinerURL marinerRequestURL =
new MarinerURL("http://localhost/volantis/test.jsp");
RequestHeaders requestHeaders = null;
// Get the parent request context if there is one.
MarinerRequestContext parentRequest = null;
if (parent != null) {
parentRequest = parent.getRequestContext();
}
// Initialise expression context.
ContextInternals.setEnvironmentContext(requestContext,
environmentContext);
ExpressionFactory expressionFactory = ExpressionFactory.getDefaultInstance();
ExpressionContext expressionContext =
expressionFactory.createExpressionContext(
null,
NamespaceFactory.getDefaultInstance()
.createPrefixTracker());
expressionContext.setProperty(MarinerRequestContext.class,
requestContext, false);
RuntimeProject project = new RuntimeProjectMock("runtimeProjectMock",
expectations);
volantisBean.setDefaultProject(project);
final CurrentProjectProviderMock projectProviderMock =
new CurrentProjectProviderMock("projectProviderMock",
expectations);
projectProviderMock.expects.getCurrentProject().returns(project).any();
// Add a project provider in for resolving relative policy expressions
// without a project into absolute IDs containing a project.
expressionContext.setProperty(CurrentProjectProvider.class,
projectProviderMock, false);
environmentContext.setExpressionContext(expressionContext);
// Initialise the page context.
pageContext.initialisePage(volantisBean, requestContext, parentRequest,
marinerRequestURL, requestHeaders);
pageContext.setCharsetName("UTF-8");
//deviceLayoutContext.initialise();
return pageContext;
}