use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WebXmlRenderingPerformance_Test method testRenderingScalingWithInterceptorChain.
@Test
public void testRenderingScalingWithInterceptorChain() throws Exception {
final RenderContext renderContext = new WebXmlRenderContext(new PrintWriter(new NullWriter()));
final AllComponents component1 = new AllComponents();
makeAllInputsMandatory(component1);
component1.setLocked(true);
final UIContext uic1 = createUIContext();
final UIContext uicChain = createUIContext();
sendRequest(component1, uic1);
Runnable runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uic1);
for (int i = 0; i < NUM_REPETITIONS; i++) {
// Just paint component
component1.preparePaint(new MockRequest());
component1.paint(renderContext);
}
}
};
// JIT warm-up
runnable.run();
long renderTime1 = time(runnable) / NUM_REPETITIONS;
runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uicChain);
for (int i = 0; i < NUM_REPETITIONS; i++) {
// Paint with the interceptor chain
WebUtilities.renderWithTransformToHTML(component1);
}
}
};
// JIT warm-up
runnable.run();
long renderTimeChain = time(runnable) / NUM_REPETITIONS;
LOG.info("Render Component time: " + (renderTime1 / 1000000.0) + "ms");
LOG.info("Render Component/Chain time: " + (renderTimeChain / 1000000.0) + "ms");
Assert.assertTrue("Render with Chain time scaling should not be more than 3x.", renderTimeChain < renderTime1 * 3);
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WebXmlRenderingPerformance_Test method testRenderingScaling.
@Test
public void testRenderingScaling() throws Exception {
final RenderContext renderContext = new WebXmlRenderContext(new PrintWriter(new NullWriter()));
final AllComponents component1 = new AllComponents();
final UIContext uic1 = createUIContext();
sendRequest(component1, uic1);
final AllComponents component10 = new AllComponents(10);
final UIContext uic10 = createUIContext();
sendRequest(component10, uic10);
Runnable runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uic1);
for (int i = 0; i < NUM_REPETITIONS; i++) {
component1.paint(renderContext);
}
}
};
// JIT warm-up
runnable.run();
long renderTime1 = time(runnable) / NUM_REPETITIONS;
runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uic10);
for (int i = 0; i < NUM_REPETITIONS; i++) {
component10.paint(renderContext);
}
}
};
// JIT warm-up
runnable.run();
long renderTime10 = time(runnable) / NUM_REPETITIONS;
LOG.info("Render 1x time: " + (renderTime1 / 1000000.0) + "ms");
LOG.info("Render 10x time: " + (renderTime10 / 1000000.0) + "ms");
Assert.assertTrue("Render time scaling should be O(n)", renderTime10 < renderTime1 * 12);
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WApplicationRenderer_Test method testRenderedFormatWithHiddenFields.
@Test
public void testRenderedFormatWithHiddenFields() throws XpathException, IOException, SAXException {
MockWEnvironment environment = new MockWEnvironment();
environment.setPostPath("WApplicationRendererTest.postPath");
WApplication application = new WApplication();
UIContext uic = createUIContext();
uic.setEnvironment(environment);
uic.setUI(application);
setActiveContext(uic);
WLabel label = new WLabel("dummy");
application.add(label);
Map<String, String> hiddenParameters = new HashMap<>();
hiddenParameters.put("keyA", "valueA");
hiddenParameters.put("keyB", "valueB");
environment.setHiddenParameters(hiddenParameters);
assertSchemaMatch(application);
assertXpathEvaluatesTo(label.getText(), "normalize-space(//ui:application/ui:label)", application);
assertXpathEvaluatesTo("valueA", "//ui:application/ui:param[@name='keyA']/@value", application);
assertXpathEvaluatesTo("valueB", "//ui:application/ui:param[@name='keyB']/@value", application);
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WApplicationRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
WApplication application = new WApplication();
MockWEnvironment environment = new MockWEnvironment();
UIContext uic = createUIContext();
uic.setEnvironment(environment);
setActiveContext(uic);
// Test with no unsavedChanges
assertSchemaMatch(application);
assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application);
assertXpathEvaluatesTo("", "//ui:application/@unsavedChanges", application);
// Test with unsavedChanges
application.setUnsavedChanges(true);
assertSchemaMatch(application);
assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application);
assertXpathEvaluatesTo("true", "//ui:application/@unsavedChanges", application);
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WApplicationRenderer_Test method testDoPaintWithChildren.
@Test
public void testDoPaintWithChildren() throws IOException, SAXException, XpathException {
WApplication application = new WApplication();
WText text = new WText("test text");
WButton button = new WButton("button");
application.add(text);
application.add(button);
MockWEnvironment environment = new MockWEnvironment();
UIContext uic = createUIContext();
uic.setEnvironment(environment);
setActiveContext(uic);
application.setUnsavedChanges(true);
// Check Schema
assertSchemaMatch(application);
assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application);
assertXpathEvaluatesTo("true", "//ui:application/@unsavedChanges", application);
// Check Children
assertXpathEvaluatesTo("test text", "normalize-space(//ui:application/text()[1])", application);
assertXpathEvaluatesTo("1", "count(//ui:application/html:button)", application);
}
Aggregations