use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class SerializationPerformance_Test method sendRequest.
/**
* Invokes WComponent request processing, so that this test case can more closely match a production scenario.
*
* @param comp the component to invoke request processing on.
* @param uic the user context to use.
*/
private void sendRequest(final WComponent comp, final UIContext uic) {
PrintWriter writer = new PrintWriter(new NullWriter());
uic.setEnvironment(new WServlet.WServletEnvironment("", "http://localhost", ""));
uic.setUI(comp);
InterceptorComponent root = ServletUtil.createInterceptorChain(new MockHttpServletRequest());
root.attachUI(comp);
Response response = new MockResponse();
root.attachResponse(response);
setActiveContext(uic);
MockRequest request = new MockRequest();
try {
root.serviceRequest(request);
root.preparePaint(request);
root.paint(new WebXmlRenderContext(writer));
} finally {
resetContext();
}
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class WCardManager_Test method testRequestHandling.
@Test
public void testRequestHandling() {
WCardManager manager = new WCardManager();
MockContainer cardOne = new MockContainer();
MockContainer cardTwo = new MockContainer();
manager.add(cardOne);
manager.add(cardTwo);
manager.setLocked(true);
Assert.assertEquals("Detector initialisation incorrect", 0, cardOne.getHandleRequestCount());
Assert.assertEquals("Detector initialisation incorrect", 0, cardOne.getValidateCount());
Assert.assertEquals("Detector initialisation incorrect", 0, cardOne.getPreparePaintCount());
Assert.assertEquals("Detector initialisation incorrect", 0, cardOne.getPaintCount());
Assert.assertEquals("Detector initialisation incorrect", 0, cardTwo.getHandleRequestCount());
Assert.assertEquals("Detector initialisation incorrect", 0, cardTwo.getValidateCount());
Assert.assertEquals("Detector initialisation incorrect", 0, cardTwo.getPreparePaintCount());
Assert.assertEquals("Detector initialisation incorrect", 0, cardTwo.getPaintCount());
MockRequest request = new MockRequest();
setActiveContext(createUIContext());
PrintWriter writer = new XmlStringBuilder(new StringWriter());
List<Diagnostic> diags = new ArrayList<>();
manager.serviceRequest(request);
Assert.assertEquals("Card One should be visible and therefore called", 1, cardOne.getHandleRequestCount());
Assert.assertEquals("Card Two should be invisible and therefore not called", 0, cardTwo.getHandleRequestCount());
cardOne.reset();
manager.makeVisible(cardTwo);
manager.serviceRequest(request);
Assert.assertEquals("Card One should be invisible and therefore not called", 0, cardOne.getHandleRequestCount());
Assert.assertEquals("Card Two should be visible and therefore called", 1, cardTwo.getHandleRequestCount());
cardTwo.reset();
manager.validateComponent(diags);
manager.preparePaint(request);
manager.paint(new WebXmlRenderContext(writer));
Assert.assertEquals("Card Two should be visible and therefore called", 1, cardTwo.getValidateCount());
Assert.assertEquals("Card Two should be visible and therefore called", 1, cardTwo.getPreparePaintCount());
Assert.assertEquals("Card Two should be visible and therefore called", 1, cardTwo.getPaintCount());
Assert.assertEquals("Card One should be invisible and therefore not called", 0, cardOne.getValidateCount());
Assert.assertEquals("Card One should be invisible and therefore not called", 0, cardOne.getPreparePaintCount());
Assert.assertEquals("Card One should be invisible and therefore not called", 0, cardOne.getPaintCount());
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class WebXmlRenderingPerformance_Test method sendRequest.
/**
* Invokes WComponent request processing, so that this test case can more closely match a production scenario.
*
* @param comp the component to invoke request processing on.
* @param uic the user context to use.
*/
private void sendRequest(final WComponent comp, final UIContext uic) {
PrintWriter writer = new PrintWriter(new NullWriter());
uic.setEnvironment(new WServlet.WServletEnvironment("", "http://localhost", ""));
uic.setUI(comp);
InterceptorComponent root = ServletUtil.createInterceptorChain(new MockHttpServletRequest());
root.attachUI(comp);
Response response = new MockResponse();
root.attachResponse(response);
setActiveContext(uic);
MockRequest request = new MockRequest();
try {
root.serviceRequest(request);
root.preparePaint(request);
root.paint(new WebXmlRenderContext(writer));
} finally {
resetContext();
}
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class WebXmlRenderingPerformance_Test method testRenderingPerformance.
@Test
public void testRenderingPerformance() throws Exception {
final AllComponents component = new AllComponents();
final UIContext uic = createUIContext();
sendRequest(component, uic);
// Render and store the XML to compare against
setActiveContext(uic);
StringWriter tempStringWriter = new StringWriter();
PrintWriter tempPrintWriter = new PrintWriter(tempStringWriter);
component.paint(new WebXmlRenderContext(tempPrintWriter));
tempPrintWriter.close();
resetContext();
// Run the test writing raw bytes to a writer - no computation necessary
final byte[] xml = tempStringWriter.toString().getBytes("UTF-8");
final CountingNullPrintWriter nullWriter = new CountingNullPrintWriter();
LOG.info("Rendered UI size: " + xml.length + " bytes");
Runnable runnable = new Runnable() {
@Override
public void run() {
for (int i = 0; i < NUM_REPETITIONS; i++) {
for (int j = 0; j < xml.length; j++) {
nullWriter.write(xml[j]);
}
}
}
};
// JIT warm-up
runnable.run();
nullWriter.resetCount();
long rawTime = time(runnable) / NUM_REPETITIONS;
Assert.assertEquals("Incorrect amount of raw data written", xml.length * NUM_REPETITIONS, nullWriter.getCount());
nullWriter.resetCount();
// Run the test using WComponent rendering
runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uic);
for (int i = 0; i < NUM_REPETITIONS; i++) {
component.paint(new WebXmlRenderContext(nullWriter));
}
}
};
// JIT warm-up
runnable.run();
nullWriter.resetCount();
long renderTime = time(runnable) / NUM_REPETITIONS;
Assert.assertEquals("Incorrect amount of rendered data written", xml.length * NUM_REPETITIONS, nullWriter.getCount());
nullWriter.resetCount();
LOG.info("Raw write time: " + (rawTime / 1000000.0) + "ms");
LOG.info("WComponent render time: " + (renderTime / 1000000.0) + "ms");
Assert.assertTrue("WComponent render time should not exceed 5x raw write time", renderTime < rawTime * 5);
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class WWindow_Test method testPaint.
@Test
public void testPaint() throws SAXException, IOException {
final int width = 123;
final int height = 456;
MockRequest request = new MockRequest();
StringWriter writer = new StringWriter();
MockContainer content = new MockContainer();
WWindow window = new WWindow();
window.setContent(content);
window.setWidth(width);
window.setHeight(height);
window.setScrollable(true);
window.setLocked(true);
// Test paint when hidden
setActiveContext(createUIContext());
window.handleRequest(request);
window.paint(new WebXmlRenderContext(new PrintWriter(writer)));
Assert.assertEquals("Window should be hidden by default", "", writer.toString());
Assert.assertEquals("Content should not have been painted", 0, content.getPaintCount());
// Test paint when displaying
window.handleRequest(request);
window.display();
window.paint(new WebXmlRenderContext(new PrintWriter(writer)));
String xhtml = writer.toString();
Assert.assertTrue("Window should have emitted tag", xhtml.indexOf("<ui:popup") != -1);
Assert.assertTrue("Incorrect window width", xhtml.indexOf("width=\"" + width) != -1);
Assert.assertTrue("Incorrect window height", xhtml.indexOf("height=\"" + height) != -1);
Assert.assertTrue("Window should be resizable", xhtml.indexOf("resizable=\"true") != -1);
Assert.assertEquals("Content should not have been painted", 0, content.getPaintCount());
writer.getBuffer().setLength(0);
// Test paint when targetted
request.setParameter(WWindow.WWINDOW_REQUEST_PARAM_KEY, window.getId());
window.handleRequest(request);
window.paint(new WebXmlRenderContext(new PrintWriter(writer)));
Assert.assertEquals("Content should have been painted", 1, content.getPaintCount());
}
Aggregations