use of com.github.bordertech.wcomponents.DefaultWComponent in project wcomponents by BorderTech.
the class WPanelRenderer_Test method testRenderedLazyModePanel.
@Test
public void testRenderedLazyModePanel() throws IOException, SAXException, XpathException {
String content = "TEST CONTENT";
WPanel panel = new WPanel();
panel.setMode(PanelMode.LAZY);
panel.add(new WText(content));
// Content NOT Hidden
assertSchemaMatch(panel);
// If not hidden, then the panel's content should be rendered
assertXpathEvaluatesTo("", "//ui:panel/@type", panel);
assertXpathEvaluatesTo("", "//ui:panel/@hidden", panel);
assertXpathEvaluatesTo("lazy", "//ui:panel/@mode", panel);
assertXpathEvaluatesTo(content, "//ui:panel/ui:content", panel);
// Content Hidden
// Create User Context with UI component
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
setFlag(panel, ComponentModel.HIDE_FLAG, true);
assertSchemaMatch(panel);
// If hidden, then the panel's content should NOT be rendered
assertXpathEvaluatesTo("", "//ui:panel/@type", panel);
assertXpathEvaluatesTo("true", "//ui:panel/@hidden", panel);
assertXpathEvaluatesTo("lazy", "//ui:panel/@mode", panel);
assertXpathEvaluatesTo("", "//ui:panel/ui:content", panel);
}
use of com.github.bordertech.wcomponents.DefaultWComponent in project wcomponents by BorderTech.
the class WSectionRenderer_Test method testRenderedLazyMode.
@Test
public void testRenderedLazyMode() throws IOException, SAXException, XpathException {
WSection section = new WSection(SECTION_HEADING);
section.setMode(SectionMode.LAZY);
section.getContent().add(new WText(SECTION_CONTENT));
// Content NOT Hidden
assertSchemaMatch(section);
// If not hidden, then the section's content should be rendered
assertXpathEvaluatesTo("", "//ui:section/@type", section);
assertXpathEvaluatesTo("", "//ui:section/@hidden", section);
assertXpathEvaluatesTo("lazy", "//ui:section/@mode", section);
assertXpathEvaluatesTo(SECTION_CONTENT, "normalize-space(//ui:section/ui:panel)", section);
// Content Hidden
// Create User Context with UI component
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
setFlag(section, ComponentModel.HIDE_FLAG, true);
assertSchemaMatch(section);
// If hidden, then the section's content should NOT be rendered
assertXpathEvaluatesTo("", "//ui:section/@type", section);
assertXpathEvaluatesTo("true", "//ui:section/@hidden", section);
assertXpathEvaluatesTo("lazy", "//ui:section/@mode", section);
assertXpathEvaluatesTo("", "normalize-space(//ui:section/ui:panel)", section);
}
use of com.github.bordertech.wcomponents.DefaultWComponent in project wcomponents by BorderTech.
the class WFigureRenderer_Test method testRenderedLazyMode.
@Test
public void testRenderedLazyMode() throws IOException, SAXException, XpathException {
WFigure figure = new WFigure(new WText(FIGURE_CONTENT), FIGURE_HEADING);
figure.setMode(FigureMode.LAZY);
// Content NOT Hidden
assertSchemaMatch(figure);
// If not hidden, then the figure's content should be rendered
assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure);
assertXpathEvaluatesTo("lazy", "//ui:figure/@mode", figure);
assertXpathEvaluatesTo(FIGURE_CONTENT, "//ui:figure/ui:content", figure);
// Content Hidden
// Create User Context with UI component
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
setFlag(figure, ComponentModel.HIDE_FLAG, true);
assertSchemaMatch(figure);
// If hidden, then the figure's content should NOT be rendered
assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
assertXpathEvaluatesTo("true", "//ui:figure/@hidden", figure);
assertXpathEvaluatesTo("lazy", "//ui:figure/@mode", figure);
assertXpathEvaluatesTo("", "//ui:figure/ui:content", figure);
}
use of com.github.bordertech.wcomponents.DefaultWComponent in project wcomponents by BorderTech.
the class DataListInterceptor_Test method testInterecptorWithNullOption.
@Test
public void testInterecptorWithNullOption() throws XpathException, SAXException, IOException {
String tableKey = TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE_WITH_NULL_OPTION;
// Create interceptor
DataListInterceptor interceptor = new DataListInterceptor();
interceptor.attachUI(new DefaultWComponent());
// Action phase
MockRequest request = new MockRequest();
request.setParameter(WServlet.DATA_LIST_PARAM_NAME, tableKey);
interceptor.serviceRequest(request);
// Render phase
MockResponse response = new MockResponse();
interceptor.attachResponse(response);
interceptor.paint(new WebXmlRenderContext(new PrintWriter(response.getWriter())));
String xml = response.getWriterOutput();
// Ensure that the data matches the test table.
List<TestLookupTable.TableEntry> table = (List<TestLookupTable.TableEntry>) Factory.newInstance(LookupTable.class).getTable(tableKey);
assertXpathEvaluatesTo(String.valueOf(table.size()), "count(/ui:datalist/ui:option)", xml);
for (int i = 0; i < table.size(); i++) {
if (table.get(i) == null) {
assertXpathEvaluatesTo("", "/ui:datalist/ui:option[" + (i + 1) + "]/@value", xml);
assertXpathEvaluatesTo("", "/ui:datalist/ui:option[" + (i + 1) + "]/text()", xml);
assertXpathEvaluatesTo("true", "/ui:datalist/ui:option[" + (i + 1) + "]/@isNull", xml);
} else {
assertXpathEvaluatesTo(table.get(i).getCode(), "/ui:datalist/ui:option[" + (i + 1) + "]/@value", xml);
assertXpathEvaluatesTo(table.get(i).getDesc(), "/ui:datalist/ui:option[" + (i + 1) + "]/text()", xml);
assertXpathNotExists("/ui:datalist/ui:option[" + (i + 1) + "]/@isNull", xml);
}
}
}
use of com.github.bordertech.wcomponents.DefaultWComponent in project wcomponents by BorderTech.
the class UIRegistryAmicableImpl_Test method testRegisterFail.
/**
* Test register - exception on register with key already in use.
*/
@Test
public void testRegisterFail() {
final String key = "test123";
WComponent component = new DefaultWComponent();
UIRegistryAmicableImpl reg = new UIRegistryAmicableImpl();
reg.register(key, component);
try {
reg.register(key, component);
Assert.fail("attempted registration with key already used should have thrown an exception");
} catch (SystemException e) {
String expectedMessage = "Cannot re-register a component. Key = " + key;
Assert.assertEquals("exceptions hould have contained message expected", expectedMessage, e.getMessage());
}
}
Aggregations