NDimensionalIndex.ZERO_DIMENSIONS);
final AssetResolverMock assetResolverMock =
new AssetResolverMock("assetResolverMock", expectations);
final TestRendererContext rendererContext = new TestRendererContext(
assetResolverMock);
TestDeprecatedOutputLocator outputLocator
= new TestDeprecatedOutputLocator();
TestMenuModuleCustomisation customisation
= new TestMenuModuleCustomisation();
// Create a mock OutputBufferResolver that expects to be called lots of
// times with the same value.
ExpectationBuilder expectations = mockFactory.createOrderedBuilder();
final OutputBufferResolverMock resolverMock =
new OutputBufferResolverMock("resolverMock", expectations);
CompositeExpectedValue expectedArgument =
MockFactory.getDefaultInstance().expectsAnyDefined();
expectedArgument.addExpectedValue(mockFactory.expectsNull());
expectedArgument.addExpectedValue(mockFactory.expectsSame(MENU_PANE));
resolverMock.fuzzy.resolvePaneOutputBuffer(expectedArgument)
.returns(rendererContext.getBuffer()).any();
rendererContext.setOutputBufferResolver(resolverMock);
// todo Customise the menu model to use a MockMenuBufferLocatorFactory
// todo that will create a MockMenuBufferLocatory that expects to be
// todo called only for menus and returns a fixed buffer.
// Create the module.
MenuModuleRendererFactory rendererFactory
= new OpenwaveMenuModuleRendererFactory(
rendererContext, outputLocator, customisation);
MenuModule module = new OpenwaveMenuModule(
rendererContext, rendererFactory,
new DefaultMenuModule(rendererContext, rendererFactory));
MenuRendererSelector selector = module.getMenuRendererSelector();
// Create the menu.
MenuModelBuilder builder = new ConcreteMenuModelBuilder();
builder.startMenu();
// Set up style properties to use OpenWave menu renderer.
builder.setElementDetails("menu", null,
StylesBuilder.getCompleteStyles(
"mcs-menu-link-style: numeric-shortcut"));
// Target it at a specific pane.
DOMOutputBuffer buffer;
builder.setPane(MENU_PANE);
// Create the first menu item explicitly targeted at a different pane.
builder.startMenuItem();
// Set the style.
builder.setElementDetails("menuitem", null,
StylesBuilder.getInitialValueStyles());
// Set the href.
builder.setHref(new LiteralLinkAssetReference("href1.xml"));
// Set the pane.
builder.setPane(ITEM1_PANE);
// Create a plain text label.
builder.startLabel();
builder.startText();
// Set the text.
buffer = new TestDOMOutputBuffer();
buffer.writeText("item 1");
builder.setText(buffer);
builder.endText();
builder.endLabel();
builder.endMenuItem();
// Create the second menu item explicitly targeted at a different pane.
builder.startMenuItem();
// Set the style.
builder.setElementDetails("menuitem", null,
StylesBuilder.getInitialValueStyles());
// Set the href.
builder.setHref(new LiteralLinkAssetReference("href2.xml"));
// Set the pane.
builder.setPane(ITEM2_PANE);
// Create a plain text label.
builder.startLabel();
builder.startText();
// Set the text.
buffer = new TestDOMOutputBuffer();
buffer.writeText("item 2");
builder.setText(buffer);
builder.endText();
builder.endLabel();
builder.endMenuItem();
builder.endMenu();
Menu menu = builder.getCompletedMenuModel();
// Select the renderer to use for this menu.
MenuRenderer renderer = selector.selectMenuRenderer(menu);
// Make sure that it is of the appropriate type.
assertTrue("Incorrect renderer returned: " + renderer,
renderer instanceof OpenwaveMenuRenderer);
// Render the menu.
renderer.render(menu);
// Check the markup output.
String expected
= "<BLOCK style='mcs-menu-link-style: numeric-shortcut; white-space: nowrap'>"
+ "<select>"
+ "<option onpick=\"href1.xml\">item 1</option>"
+ "<option onpick=\"href2.xml\">item 2</option>"
+ "</select>"
+ "</BLOCK>";
DOMOutputBuffer outputBuffer = rendererContext.getBuffer();
String actual = styledDOMTester.render(outputBuffer.getRoot());
expected = styledDOMTester.normalize(expected);
assertEquals("Output not correct", expected, actual);