Search in sources :

Example 51 with UIContext

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);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter) AllComponents(com.github.bordertech.wcomponents.AllComponents) Test(org.junit.Test)

Example 52 with UIContext

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);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) UIContext(com.github.bordertech.wcomponents.UIContext) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter) AllComponents(com.github.bordertech.wcomponents.AllComponents) Test(org.junit.Test)

Example 53 with UIContext

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);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) HashMap(java.util.HashMap) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 54 with UIContext

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);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 55 with UIContext

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);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Aggregations

UIContext (com.github.bordertech.wcomponents.UIContext)114 Test (org.junit.Test)47 WComponent (com.github.bordertech.wcomponents.WComponent)18 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)15 SystemException (com.github.bordertech.wcomponents.util.SystemException)14 WApplication (com.github.bordertech.wcomponents.WApplication)13 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)11 WText (com.github.bordertech.wcomponents.WText)11 PrintWriter (java.io.PrintWriter)11 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 SeleniumWComponentsWebDriver (com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver)9 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)7 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)7 WDropdown (com.github.bordertech.wcomponents.WDropdown)7 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)7 StringWriter (java.io.StringWriter)7 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)6 Environment (com.github.bordertech.wcomponents.Environment)6 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 WButton (com.github.bordertech.wcomponents.WButton)6