Search in sources :

Example 26 with WLabel

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

the class WhitespaceFilterInterceptor_Test method testPaint.

@Test
public void testPaint() {
    final String testString = "    foo    bar    ";
    final String filteredString = " foo bar ";
    WLabel label = new WLabel(testString);
    WhitespaceFilterInterceptor interceptor = new WhitespaceFilterInterceptor();
    interceptor.attachUI(label);
    label.setLocked(true);
    setActiveContext(createUIContext());
    // Test when disabled
    Config.getInstance().setProperty(ConfigurationProperties.WHITESPACE_FILTER, "false");
    StringWriter writer = new StringWriter();
    PrintWriter printWriter = new PrintWriter(writer);
    interceptor.paint(new WebXmlRenderContext(printWriter));
    printWriter.close();
    Assert.assertTrue("Should not have filtered text when disabled", writer.toString().contains(testString));
    // Test when enabled
    Config.getInstance().setProperty(ConfigurationProperties.WHITESPACE_FILTER, "true");
    writer = new StringWriter();
    printWriter = new PrintWriter(writer);
    interceptor.paint(new WebXmlRenderContext(printWriter));
    printWriter.close();
    Assert.assertTrue("Should have filtered text when enabled", writer.toString().contains(filteredString));
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) WLabel(com.github.bordertech.wcomponents.WLabel) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 27 with WLabel

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

the class ProfileContainer_Test method testAfterPaint.

/**
 * Test afterPaint.
 */
@Test
public void testAfterPaint() {
    ProfileContainer app = new ProfileContainer();
    app.setLocked(true);
    UIContext uic = new UIContextImpl();
    uic.setUI(app);
    setActiveContext(uic);
    WButton button = new WButton("PUSH");
    app.add(button);
    WLabel label = new WLabel("HERE");
    app.add(label);
    StringWriter outStr = new StringWriter();
    PrintWriter writer = new PrintWriter(outStr);
    RenderContext renderContext = new WebXmlRenderContext(writer);
    app.afterPaint(renderContext);
    // expecting 1 root class, 3 components, class names as shown, profiler
    // class
    String profileLine0 = PROFILER_UIC_HEADER;
    String profileLine1 = PROFILER_LINE1.replaceAll("<<NUM_ROOTS>>", "1");
    String profileLine2 = PROFILER_LINE2.replaceAll("<<NUM_COMPONENTS>>", "4");
    String profileLine31 = PROFILER_LINE3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WButton");
    String profileLine32 = PROFILER_LINE3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.monitor.ProfileContainer");
    String profileLine33 = PROFILER_LINE3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WLabel");
    String profileLine4 = PROFILER_PROFILE_HEADER.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.monitor.ProfileContainer");
    String[] expectedResults = { profileLine0, profileLine1, profileLine2, profileLine31, profileLine32, profileLine33, profileLine4 };
    String result = outStr.toString();
    for (int i = 0; i < expectedResults.length; i++) {
        Assert.assertTrue("result should contain substring " + i + "  ", result.indexOf(expectedResults[i]) != -1);
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WButton(com.github.bordertech.wcomponents.WButton) WLabel(com.github.bordertech.wcomponents.WLabel) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 28 with WLabel

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

the class UicStatsAsHtml_Test method testWriter.

/**
 * Test writer.
 */
@Test
public void testWriter() {
    // Set up a mock UI to test
    WApplication app = new WApplication();
    app.setLocked(true);
    UIContext uic = new UIContextImpl();
    uic.setUI(app);
    setActiveContext(uic);
    WButton button = new WButton("PUSH");
    app.add(button);
    WLabel label = new WLabel("HERE");
    app.add(label);
    // Run the UIStats extract
    UicStats stats = new UicStats(uic);
    stats.analyseWC(app);
    StringWriter outStr = new StringWriter();
    PrintWriter writer = new PrintWriter(outStr);
    UicStatsAsHtml.write(writer, stats);
    // expecting 1 root class, 3 components, class names as shown
    String uicStatsHtml1 = UICSTATS_HTML1.replaceAll("<<NUM_ROOTS>>", "1");
    String uicStatsHtml2 = UICSTATS_HTML2.replaceAll("<<NUM_COMPONENTS>>", "4");
    String uicStatsHtml31 = UICSTATS_HTML3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WApplication");
    String uicStatsHtml32 = UICSTATS_HTML3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WButton");
    String uicStatsHtml33 = UICSTATS_HTML3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WLabel");
    String[] expectedResults = { uicStatsHtml1, uicStatsHtml2, uicStatsHtml31, uicStatsHtml32, uicStatsHtml33 };
    String result = outStr.toString();
    for (int i = 0; i < expectedResults.length; i++) {
        Assert.assertTrue("result should contain substring " + i + "  ", result.indexOf(expectedResults[i]) != -1);
    }
}
Also used : StringWriter(java.io.StringWriter) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WButton(com.github.bordertech.wcomponents.WButton) WLabel(com.github.bordertech.wcomponents.WLabel) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 29 with WLabel

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

the class UicStats_Test method testGetWCTreeStats.

/**
 * Test getWCTreeStats.
 */
@Test
public void testGetWCTreeStats() {
    stats.analyseWC(app);
    Map<WComponent, Stat> resultStats = stats.getWCTreeStats(app);
    // label
    for (Map.Entry<WComponent, Stat> entry : resultStats.entrySet()) {
        WComponent comp = entry.getKey();
        Stat stat = entry.getValue();
        if (comp instanceof WLabel) {
            Assert.assertEquals("this should be the label created", label, comp);
            Assert.assertEquals("stat should have correct label name", label.getId(), stat.getName());
        } else if (comp instanceof WButton) {
            Assert.assertEquals("this should be the button in the app", button, comp);
            Assert.assertEquals("stat should have correct button name", button.getId(), stat.getName());
        } else if (comp instanceof WApplication) {
            Assert.assertEquals("this should be the app", app, comp);
            Assert.assertEquals("stat should have correct app name", app.getId(), stat.getName());
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Stat(com.github.bordertech.wcomponents.monitor.UicStats.Stat) WApplication(com.github.bordertech.wcomponents.WApplication) WButton(com.github.bordertech.wcomponents.WButton) Map(java.util.Map) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 30 with WLabel

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

the class Disable method toString.

/**
 * {@inheritDoc}
 */
@Override
public String toString() {
    String targetName = getTarget().getClass().getSimpleName();
    WLabel label = getTarget().getLabel();
    if (label != null) {
        targetName = label.getText();
    }
    return "disable " + targetName;
}
Also used : WLabel(com.github.bordertech.wcomponents.WLabel)

Aggregations

WLabel (com.github.bordertech.wcomponents.WLabel)99 Test (org.junit.Test)57 WHeading (com.github.bordertech.wcomponents.WHeading)13 WTextField (com.github.bordertech.wcomponents.WTextField)10 WButton (com.github.bordertech.wcomponents.WButton)9 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)9 WComponent (com.github.bordertech.wcomponents.WComponent)8 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)8 WPanel (com.github.bordertech.wcomponents.WPanel)7 UIContext (com.github.bordertech.wcomponents.UIContext)6 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)6 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)5 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)5 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)5 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)5 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5 Action (com.github.bordertech.wcomponents.Action)4 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)4 WApplication (com.github.bordertech.wcomponents.WApplication)4 WContainer (com.github.bordertech.wcomponents.WContainer)4