use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WDataTableRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WDataTable table = new WDataTable();
table.addColumn(new WTableColumn(getMaliciousContent(), WText.class));
table.addColumn(new WTableColumn(getMaliciousContent(), WText.class));
table.addColumn(new WTableColumn(getMaliciousContent(), WText.class));
table.setNoDataMessage(getMaliciousAttribute("ui:table"));
UIContext uic = createUIContext();
assertSafeContent(table);
WButton button = new WButton("dummy");
table.addAction(button);
table.addActionConstraint(button, new ActionConstraint(0, 1, false, getMaliciousAttribute("ui:action")));
assertSafeContent(table);
TableDataModel tableModel = createTableModel();
table.setDataModel(tableModel);
// clear out cached data from previous renders
uic.clearScratchMap();
assertSafeContent(table);
table.setCaption(getMaliciousAttribute("ui:table"));
assertSafeContent(table);
table.setSummary(getMaliciousAttribute("ui:table"));
assertSafeContent(table);
table.setSelectGroup(getMaliciousAttribute("ui:rowselection"));
assertSafeContent(table);
table.setActiveFilters(Arrays.asList(new String[] { getMaliciousAttribute("ui:table") }));
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WFigureRenderer_Test method testRenderedEagerMode.
@Test
public void testRenderedEagerMode() throws IOException, SAXException, XpathException {
WFigure figure = new WFigure(new WText(FIGURE_CONTENT), FIGURE_HEADING);
figure.setMode(FigureMode.EAGER);
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
// The figure's content should NOT be rendered
assertSchemaMatch(figure);
assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure);
assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure);
assertXpathEvaluatesTo("", "//ui:figure/ui:content", figure);
try {
// Figure is the AJAX Trigger, content should be rendered
AjaxOperation operation = new AjaxOperation(figure.getId(), figure.getId());
AjaxHelper.setCurrentOperationDetails(operation, null);
assertSchemaMatch(figure);
assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure);
assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure);
assertXpathEvaluatesTo(FIGURE_CONTENT, "//ui:figure/ui:content", figure);
} finally {
AjaxHelper.clearCurrentOperationDetails();
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WPanelRenderer_Test method testRenderedEagerModePanel.
@Test
public void testRenderedEagerModePanel() throws IOException, SAXException, XpathException {
String content = "TEST CONTENT";
WPanel panel = new WPanel();
panel.setMode(PanelMode.EAGER);
panel.add(new WText(content));
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
// The panel's content should NOT be rendered
assertSchemaMatch(panel);
assertXpathEvaluatesTo("", "//ui:panel/@type", panel);
assertXpathEvaluatesTo("", "//ui:panel/@hidden", panel);
assertXpathEvaluatesTo("eager", "//ui:panel/@mode", panel);
assertXpathEvaluatesTo("", "//ui:panel/ui:content", panel);
try {
// Panel is the AJAX Trigger, content should be rendered
AjaxOperation operation = new AjaxOperation(panel.getId(), panel.getId());
AjaxHelper.setCurrentOperationDetails(operation, null);
assertSchemaMatch(panel);
assertXpathEvaluatesTo("", "//ui:panel/@type", panel);
assertXpathEvaluatesTo("", "//ui:panel/@hidden", panel);
assertXpathEvaluatesTo("eager", "//ui:panel/@mode", panel);
assertXpathEvaluatesTo(content, "//ui:panel/ui:content", panel);
} finally {
AjaxHelper.clearCurrentOperationDetails();
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WSectionRenderer_Test method testRenderedEagerMode.
@Test
public void testRenderedEagerMode() throws IOException, SAXException, XpathException {
WSection section = new WSection(SECTION_HEADING);
section.setMode(SectionMode.EAGER);
section.getContent().add(new WText(SECTION_CONTENT));
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
// The section's content should NOT be rendered
assertSchemaMatch(section);
assertXpathEvaluatesTo("", "//ui:section/@type", section);
assertXpathEvaluatesTo("", "//ui:section/@hidden", section);
assertXpathEvaluatesTo("eager", "//ui:section/@mode", section);
assertXpathEvaluatesTo("", "normalize-space(//ui:section/ui:panel)", section);
try {
// Section is the AJAX Trigger, content should be rendered
AjaxOperation operation = new AjaxOperation(section.getId(), section.getId());
AjaxHelper.setCurrentOperationDetails(operation, null);
assertSchemaMatch(section);
assertXpathEvaluatesTo("", "//ui:section/@type", section);
assertXpathEvaluatesTo("", "//ui:section/@hidden", section);
assertXpathEvaluatesTo("eager", "//ui:section/@mode", section);
assertXpathEvaluatesTo(SECTION_CONTENT, "normalize-space(//ui:section/ui:panel)", section);
} finally {
AjaxHelper.clearCurrentOperationDetails();
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class AbstractContainerHelper method cycleUIContext.
/**
* Call this method to simulate what would happen if the UIContext was serialized due to clustering of servers.
*/
protected void cycleUIContext() {
boolean cycleIt = ConfigurationProperties.getDeveloperClusterEmulation();
if (cycleIt) {
UIContext uic = getUIContext();
if (uic instanceof UIContextWrap) {
LOG.info("Cycling the UIContext to simulate clustering");
((UIContextWrap) uic).cycle();
}
}
}
Aggregations