use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class SimplePicker method afterPaint.
/**
* Override afterPaint in order to paint the UIContext serialization statistics if the profile button has been
* pressed.
*
* @param renderContext the renderContext to send output to.
*/
@Override
protected void afterPaint(final RenderContext renderContext) {
super.afterPaint(renderContext);
if (profileBtn.isPressed()) {
// UIC serialization stats
UicStats stats = new UicStats(UIContextHolder.getCurrent());
WComponent currentComp = this.getCurrentComponent();
if (currentComp != null) {
stats.analyseWC(currentComp);
}
if (renderContext instanceof WebXmlRenderContext) {
PrintWriter writer = ((WebXmlRenderContext) renderContext).getWriter();
writer.println("<hr />");
writer.println("<h2>Serialization Profile of UIC</h2>");
UicStatsAsHtml.write(writer, stats);
if (currentComp != null) {
writer.println("<hr />");
writer.println("<h2>ObjectProfiler - " + currentComp + "</h2>");
writer.println("<pre>");
try {
writer.println(ObjectGraphDump.dump(currentComp).toFlatSummary());
} catch (Exception e) {
LOG.error("Failed to dump component", e);
}
writer.println("</pre>");
}
}
}
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class ContextCleanupInterceptor_Test method testPaint.
@Test
public void testPaint() {
MyWLabel label = new MyWLabel();
label.setText("Hello world");
InterceptorComponent interceptor = new ContextCleanupInterceptor();
interceptor.setBackingComponent(label);
StringWriter writer = new StringWriter();
setActiveContext(createUIContext());
interceptor.paint(new WebXmlRenderContext(new PrintWriter(writer)));
// After the paint, the component should have been painted, and the context cleared up
Assert.assertTrue("tidyUpUIContextForTree was not called", label.tidiedUp);
Assert.assertTrue("Component was not painted", writer.toString().indexOf(label.getText()) != -1);
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class DataListInterceptor_Test method testInterecptor.
@Test
public void testInterecptor() throws XpathException, SAXException, IOException {
String tableKey = TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE;
// 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++) {
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);
}
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class DebugStructureInterceptor_Test method doRequest.
/**
* Does a request/response cycle for a WApplication.
*
* @return the xml output.
*/
private String doRequest() {
WApplication app = new WApplication();
app.setLocked(true);
UIContext uic = createUIContext();
uic.setUI(app);
setActiveContext(uic);
// Create interceptor
PageShellInterceptor pageInterceptor = new PageShellInterceptor();
DebugStructureInterceptor debugInterceptor = new DebugStructureInterceptor();
pageInterceptor.setBackingComponent(debugInterceptor);
pageInterceptor.attachUI(app);
// Action phase
MockRequest request = new MockRequest();
pageInterceptor.serviceRequest(request);
pageInterceptor.preparePaint(request);
// Render phase
MockResponse response = new MockResponse();
pageInterceptor.attachResponse(response);
pageInterceptor.paint(new WebXmlRenderContext(response.getWriter()));
return response.getWriterOutput();
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext 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);
}
}
Aggregations