Search in sources :

Example 31 with WText

use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.

the class GridLayoutRenderer_Test method testDoRender.

@Test
public void testDoRender() throws IOException, SAXException, XpathException {
    final String text1 = "GridRenderer_Test.testPaint.text1";
    final String text2 = "GridRenderer_Test.testPaint.text2";
    WPanel panel = new WPanel();
    panel.setLayout(new GridLayout(1, 2, GAP, BIG_GAP));
    assertSchemaMatch(panel);
    assertXpathEvaluatesTo("1", "//ui:panel/ui:gridlayout/@rows", panel);
    assertXpathEvaluatesTo("2", "//ui:panel/ui:gridlayout/@cols", panel);
    assertXpathEvaluatesTo(GAP.toString(), "//ui:panel/ui:gridlayout/@hgap", panel);
    assertXpathEvaluatesTo(BIG_GAP.toString(), "//ui:panel/ui:gridlayout/@vgap", panel);
    assertXpathNotExists("//ui:panel/ui:gridlayout/ui:cell", panel);
    panel.add(new WText(text1));
    panel.add(new WText(text2));
    assertXpathEvaluatesTo("2", "count(//ui:panel/ui:gridlayout/ui:cell)", panel);
    assertXpathEvaluatesTo(text1, "normalize-space(//ui:panel/ui:gridlayout/ui:cell[1])", panel);
    assertXpathEvaluatesTo(text2, "normalize-space(//ui:panel/ui:gridlayout/ui:cell[2])", panel);
}
Also used : GridLayout(com.github.bordertech.wcomponents.layout.GridLayout) WText(com.github.bordertech.wcomponents.WText) WPanel(com.github.bordertech.wcomponents.WPanel) Test(org.junit.Test)

Example 32 with WText

use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.

the class ResponseCacheInterceptor_Test method testOverrideContentCache.

@Test
public void testOverrideContentCache() {
    /**
     * Original config.
     */
    Configuration originalConfig;
    originalConfig = Config.getInstance();
    String override = "OVERRIDE CONTENT CACHE";
    try {
        // Test override cache settings
        Configuration config = Config.copyConfiguration(originalConfig);
        config.setProperty(ConfigurationProperties.RESPONSE_CACHE_SETTINGS, override);
        Config.setConfiguration(config);
        // Create interceptor
        ResponseCacheInterceptor interceptor = new ResponseCacheInterceptor(CacheType.CONTENT_CACHE);
        interceptor.setBackingComponent(new WText());
        // Mock Response
        MockResponse response = new MockResponse();
        interceptor.attachResponse(response);
        // Render phase
        interceptor.paint(new WebXmlRenderContext(response.getWriter()));
        // Check Override
        Assert.assertEquals("Cache-Control header not overriden correctly for CONTENT CACHE", override, response.getHeaders().get("Cache-Control"));
    } finally {
        // Remove overrides
        Config.setConfiguration(originalConfig);
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) Configuration(org.apache.commons.configuration.Configuration) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 33 with WText

use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.

the class ResponseCacheInterceptor_Test method testOverrideDefaultNoCache.

@Test
public void testOverrideDefaultNoCache() {
    /**
     * Original config.
     */
    Configuration originalConfig;
    originalConfig = Config.getInstance();
    String override = "OVERRIDE NO CACHE";
    try {
        // Test override cache settings
        Configuration config = Config.copyConfiguration(originalConfig);
        config.setProperty(ConfigurationProperties.RESPONSE_NO_CACHE_SETTINGS, override);
        Config.setConfiguration(config);
        // Create interceptor
        ResponseCacheInterceptor interceptor = new ResponseCacheInterceptor(CacheType.CONTENT_NO_CACHE);
        interceptor.setBackingComponent(new WText());
        // Mock Response
        MockResponse response = new MockResponse();
        interceptor.attachResponse(response);
        // Render phase
        interceptor.paint(new WebXmlRenderContext(response.getWriter()));
        // Check Override
        Assert.assertEquals("Cache-Control header not overriden correctly for NO CACHE", override, response.getHeaders().get("Cache-Control"));
    } finally {
        // Remove overrides
        Config.setConfiguration(originalConfig);
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) Configuration(org.apache.commons.configuration.Configuration) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 34 with WText

use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.

the class FlowLayoutRenderer_Test method testDoRenderWithContent.

@Test
public void testDoRenderWithContent() throws IOException, SAXException, XpathException {
    final String text1 = "FlowRenderer_Test.testPaint.text1";
    final String text2 = "FlowRenderer_Test.testPaint.text2";
    WPanel panel = new WPanel();
    panel.setLayout(new FlowLayout());
    assertSchemaMatch(panel);
    panel.add(new WText(text1));
    panel.add(new WText(text2));
    assertSchemaMatch(panel);
    assertXpathEvaluatesTo("2", "count(//ui:panel/ui:flowlayout/ui:cell)", panel);
    assertXpathEvaluatesTo(text1, "normalize-space(//ui:panel/ui:flowlayout/ui:cell[1])", panel);
    assertXpathEvaluatesTo(text2, "normalize-space(//ui:panel/ui:flowlayout/ui:cell[2])", panel);
}
Also used : FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) WText(com.github.bordertech.wcomponents.WText) WPanel(com.github.bordertech.wcomponents.WPanel) Test(org.junit.Test)

Example 35 with WText

use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.

the class WApplicationRenderer_Test method testDoPaintWithChildren.

@Test
public void testDoPaintWithChildren() throws IOException, SAXException, XpathException {
    WApplication application = new WApplication();
    WText text = new WText("test text");
    WButton button = new WButton("button");
    application.add(text);
    application.add(button);
    MockWEnvironment environment = new MockWEnvironment();
    UIContext uic = createUIContext();
    uic.setEnvironment(environment);
    setActiveContext(uic);
    application.setUnsavedChanges(true);
    // Check Schema
    assertSchemaMatch(application);
    assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application);
    assertXpathEvaluatesTo("true", "//ui:application/@unsavedChanges", application);
    // Check Children
    assertXpathEvaluatesTo("test text", "normalize-space(//ui:application/text()[1])", application);
    assertXpathEvaluatesTo("1", "count(//ui:application/html:button)", application);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Aggregations

WText (com.github.bordertech.wcomponents.WText)100 Test (org.junit.Test)63 WPanel (com.github.bordertech.wcomponents.WPanel)18 WCollapsible (com.github.bordertech.wcomponents.WCollapsible)10 WDecoratedLabel (com.github.bordertech.wcomponents.WDecoratedLabel)10 WHeading (com.github.bordertech.wcomponents.WHeading)10 UIContext (com.github.bordertech.wcomponents.UIContext)9 WTabSet (com.github.bordertech.wcomponents.WTabSet)7 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)6 WList (com.github.bordertech.wcomponents.WList)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)6 MockServletConfig (com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig)6 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)5 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)5 WImage (com.github.bordertech.wcomponents.WImage)5 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)5 WTextField (com.github.bordertech.wcomponents.WTextField)5 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)5