Search in sources :

Example 11 with DefaultWComponent

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);
}
Also used : WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) WPanel(com.github.bordertech.wcomponents.WPanel) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 12 with DefaultWComponent

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);
}
Also used : WSection(com.github.bordertech.wcomponents.WSection) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 13 with DefaultWComponent

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);
}
Also used : WFigure(com.github.bordertech.wcomponents.WFigure) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 14 with DefaultWComponent

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);
        }
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) TestLookupTable(com.github.bordertech.wcomponents.TestLookupTable) List(java.util.List) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 15 with DefaultWComponent

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());
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Aggregations

DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)19 Test (org.junit.Test)19 WComponent (com.github.bordertech.wcomponents.WComponent)8 UIContext (com.github.bordertech.wcomponents.UIContext)7 WText (com.github.bordertech.wcomponents.WText)6 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)4 TestLookupTable (com.github.bordertech.wcomponents.TestLookupTable)2 WFigure (com.github.bordertech.wcomponents.WFigure)2 WPanel (com.github.bordertech.wcomponents.WPanel)2 WSection (com.github.bordertech.wcomponents.WSection)2 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)2 SystemException (com.github.bordertech.wcomponents.util.SystemException)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)2 PrintWriter (java.io.PrintWriter)2 List (java.util.List)2 Action (com.github.bordertech.wcomponents.Action)1 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)1 WInternalLink (com.github.bordertech.wcomponents.WInternalLink)1 WSuggestions (com.github.bordertech.wcomponents.WSuggestions)1