createDeviceLayout("Test Layout", "Master");
RuntimeDeviceLayout runtimeDeviceLayout =
RuntimeDeviceLayoutTestHelper.activate(canvasLayout);
DeviceLayoutContext deviceLayoutContext = new DeviceLayoutContext();
deviceLayoutContext.setMarinerPageContext(marinerPageContextMock);
deviceLayoutContext.setDeviceLayout(runtimeDeviceLayout);
deviceLayoutContextStack.push(deviceLayoutContext);
/*
* Pane related mock objects
*/
Pane pane = new Pane(canvasLayout);
com.volantis.mcs.protocols.PaneAttributes protocolPaneAttributes =
new com.volantis.mcs.protocols.PaneAttributes();
PaneInstanceMock paneInstance = new PaneInstanceMock(
"mockPaneInstance", expectations,
NDimensionalIndex.ZERO_DIMENSIONS);
paneInstance.expects.ignore().returns(false).any();
// optional for XDIME2.
paneInstance.expects.setStyleClass(null).any();
paneInstance.expects.getAttributes().returns(protocolPaneAttributes).any();
paneInstance.expects.getFormat().returns(pane).any();
StyleSheetConfiguration styleSheetConfig = new StyleSheetConfiguration();
volantisMock.expects.getPageHeadingMsg().returns(PAGE_HEADER_COMMENT);
volantisMock.expects.getStyleSheetConfiguration().returns(
styleSheetConfig);
volantisMock.expects.getPageTrackerFactory().returns(null).any();
/*
* Set expectations on MarinerPageContext Mock
*/
marinerPageContextMock.expects.getRequestURL(false).returns(
requestURL).any();
marinerPageContextMock.expects.getDeviceLayoutContext().does(new MethodAction() {
public Object perform(MethodActionEvent event) throws Throwable {
Object result = null;
if (!deviceLayoutContextStack.empty()) {
result = deviceLayoutContextStack.peek();
}
return result;
}
}).any();
marinerPageContextMock.fuzzy.pushDeviceLayoutContext(
mockFactory.expectsInstanceOf(DeviceLayoutContext.class))
.does(new MethodAction() {
public Object perform(MethodActionEvent event)
throws Throwable {
Object context = event.getArgument(
DeviceLayoutContext.class);
deviceLayoutContextStack.push(context);
return null;
}
}).any();
// optional for XDIME2
marinerPageContextMock.expects.setCanvasHasChildren(false).any();
marinerPageContextMock.fuzzy.getFormatInstance(
mockFactory.expectsInstanceOf(Pane.class),
NDimensionalIndex.ZERO_DIMENSIONS)
.returns(paneInstance)
.any();
InternalProjectFactory factory =
InternalProjectFactory.getInternalInstance();
// ProjectMock project = new ProjectMock("project mock", expectations);
final RuntimeProjectMock project =
new RuntimeProjectMock("projectMock", expectations);
project.expects.getPolicySource()
.returns(factory.createXMLPolicySource(null, ".")).any();
MethodAction initialiseCanvasAction = new MethodAction() {
public Object perform(MethodActionEvent event) throws Throwable {
// Optional for XDIME2.
marinerPageContextMock.expects.initialisedCanvas().returns(true).any();
return null;
}
};
marinerPageContextMock.fuzzy.initialise(Boolean.FALSE,
Boolean.FALSE,
null,
null,
mockFactory.expectsInstanceOf(CompiledStyleSheetCollection.class),
LAYOUT_NAME).does(initialiseCanvasAction);
marinerPageContextMock.expects.peekCanvasType().does(new MethodAction() {
public Object perform(MethodActionEvent event) throws Throwable {
Object result = null;
if (!canvasTypeStack.empty()) {
result = canvasTypeStack.peek();
}
return result;
}
}).any();
marinerPageContextMock.expects.popCanvasType().does(new MethodAction() {
public Object perform(MethodActionEvent event) throws Throwable {
Object result = null;
if (!canvasTypeStack.empty()) {
result = canvasTypeStack.pop();
}
return result;
}
}).any();
marinerPageContextMock.fuzzy.pushCanvasType(
mockFactory.expectsInstanceOf(String.class))
.does(new MethodAction() {
public Object perform(MethodActionEvent event)
throws Throwable {
Object context = event.getArgument(String.class);
canvasTypeStack.push(context);
return null;
}
}).any();
// Since we have pane set for XDIMECP via cdm:pane and for XDIME2 via
// mcs-container these two will be called twice as we cannot vary the
// stylesheet per test.
marinerPageContextMock.expects.pushContainerInstance(paneInstance).any();
marinerPageContextMock.expects.popContainerInstance(paneInstance).any();
marinerPageContextMock.expects.getCurrentContainerInstance().returns(paneInstance).any();
marinerPageContextMock.expects.getCurrentPane().returns(pane).any();
marinerPageContextMock.expects.updateFragmentationState();
marinerPageContextMock.expects.getProtocol().returns(protocol).any();
marinerPageContextMock.expects.getDeviceName().returns("Master");
marinerPageContextMock.expects.getDevice().returns(device).any();
// optional for XDIME1?
marinerPageContextMock.fuzzy.getFormat("pane",
mockFactory.expectsInstanceOf(FormatNamespace.class))
.returns(pane).any();
// optional for XDIME2.
marinerPageContextMock.expects.getPane("pane").returns(pane).any();
marinerPageContextMock.fuzzy.pushOutputBuffer(
mockFactory.expectsInstanceOf(DOMOutputBuffer.class))
.does(new MethodAction() {
public Object perform(MethodActionEvent event)
throws Throwable {
Object buffer = event.getArgument(OutputBuffer.class);
outputBufferStack.push(buffer);
return null;
}
}).any();
marinerPageContextMock.fuzzy.popOutputBuffer(
mockFactory.expectsInstanceOf(DOMOutputBuffer.class))
.does(new MethodAction() {
public Object perform(MethodActionEvent event)
throws Throwable {
return outputBufferStack.pop();
}
}).any();
marinerPageContextMock.expects.getCurrentOutputBuffer().does(new MethodAction() {
public Object perform(MethodActionEvent event) throws Throwable {
return outputBufferStack.peek();
}
}).any();
RuntimeDeviceTheme runtimeDeviceTheme = createRuntimeDeviceTheme();
marinerPageContextMock.expects.retrieveThemeStyleSheet(THEME_NAME).
returns(runtimeDeviceTheme.getCompiledStyleSheet());
marinerPageContextMock.expects.enteringXDIMECPElement().any();
marinerPageContextMock.expects.insideXDIMECPElement()
.returns(false).any();
marinerPageContextMock.expects.exitingXDIMECPElement().any();
marinerPageContextMock.expects.getEnclosingRegionInstance()
.returns(null).any();
marinerPageContextMock.expects.popDeviceLayoutContext()
.does(new MethodAction() {
public Object perform(MethodActionEvent methodActionEvent)
throws Throwable {
// Don't actually pop this as it prevents the markup
// from being generated at the end. NASTY.
return deviceLayoutContextStack.peek();
}
}).any();
setProtocolSpecificExpectations();
ApplicationContext applicationContext = new ApplicationContext(
requestContextMock);
applicationContext.setDevice(device);
applicationContext.setProtocol(protocol);
applicationContext.setDissectionSupported(true);
applicationContext.setFragmentationSupported(true);
applicationContext.setCanvasTagSupported(true);
applicationContext.setWMLCSupported(false);
ExpressionFactory expressionFactory = ExpressionFactory.getDefaultInstance();
ExpressionContext expressionContext =
expressionFactory.createExpressionContext(null,
NamespaceFactory.getDefaultInstance()
.createPrefixTracker());
expressionContext.setProperty(MarinerRequestContext.class,
requestContextMock, false);
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);
// Optional for XDIME2
marinerPageContextMock.expects.setBrandName(null, false).any();
marinerPageContextMock.expects.getStylingEngine().returns(
stylingEngine)
.any();
requestContextMock.expects.getApplicationContext().returns(
applicationContext)
.any();
requestContextMock.expects.getMarinerPageContext().returns(
marinerPageContextMock)
.any();
requestContextMock.expects.getEnvironmentContext()
.returns(environmentContextMock).any();
requestContextMock.expects.pushProject(project).any();
requestContextMock.expects.popProject(project).returns(project).any();
marinerPageContextMock.expects.getEnvironmentContext()
.returns(environmentContextMock).any(); // fixed(2);
environmentContextMock.fuzzy.setAttribute(
CacheScopeConstant.CACHE_SCOPE_ATTRIBUTE,
mockFactory.expectsInstanceOf(CacheScopeConstant.class));
environmentContextMock.expects.getCachingDirectives().returns(null).any();
environmentContextMock.expects.applyCachingDirectives().any();
deviceLayoutContext.initialise();
ListenerEventRegistryMock listenerEventRegistryMock =
new ListenerEventRegistryMock("listenerEventRegistry",
expectations);