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));
}
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);
}
}
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);
}
}
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());
}
}
}
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;
}
Aggregations