Search in sources :

Example 11 with WApplication

use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.

the class WApplicationRenderer_Test method testRendererTracking.

@Test
public void testRendererTracking() throws IOException, SAXException, XpathException {
    // No tracking
    WApplication application = new WApplication();
    assertSchemaMatch(application);
    assertXpathNotExists("//ui:application/ui:analytic", application);
    // Want to test with "tracking details set"
    Configuration originalConfig = Config.getInstance();
    Configuration config = Config.copyConfiguration(originalConfig);
    config.setProperty(ConfigurationProperties.TRACKING_CLIENT_ID, "CID");
    config.setProperty(ConfigurationProperties.TRACKING_APPLICATION_NAME, "APPL");
    config.setProperty(ConfigurationProperties.TRACKING_COOKIE_DOMAIN, "CD");
    config.setProperty(ConfigurationProperties.TRACKING_DATA_COLLECTION_DOMAIN, "DCD");
    Config.setConfiguration(config);
    try {
        assertSchemaMatch(application);
        assertXpathEvaluatesTo("CID", "//ui:application/ui:analytic/@clientId", application);
        assertXpathEvaluatesTo("APPL", "//ui:application/ui:analytic/@name", application);
        assertXpathEvaluatesTo("CD", "//ui:application/ui:analytic/@cd", application);
        assertXpathEvaluatesTo("DCD", "//ui:application/ui:analytic/@dcd", application);
    } finally {
        // Remove overrides
        Config.setConfiguration(originalConfig);
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) WApplication(com.github.bordertech.wcomponents.WApplication) Test(org.junit.Test)

Example 12 with WApplication

use of com.github.bordertech.wcomponents.WApplication 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 13 with WApplication

use of com.github.bordertech.wcomponents.WApplication 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)

Example 14 with WApplication

use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.

the class PlainLauncher method getUI.

/**
 * This method has been overridden to load a WComponent from parameters.
 *
 * @param httpServletRequest the servlet request being handled.
 * @return the top-level WComponent for this servlet.
 */
@Override
public synchronized WComponent getUI(final Object httpServletRequest) {
    String configuredUIClassName = getComponentToLaunchClassName();
    if (sharedUI == null || !Util.equals(configuredUIClassName, uiClassName)) {
        uiClassName = configuredUIClassName;
        WComponent ui = createUI();
        if (ui instanceof WApplication) {
            sharedUI = (WApplication) ui;
        } else {
            LOG.warn("Top-level component should be a WApplication." + " Creating WApplication wrapper...");
            sharedUI = new WApplication();
            ui.setLocked(false);
            sharedUI.add(ui);
            sharedUI.setLocked(true);
        }
        if (ConfigurationProperties.getLdeServerShowMemoryProfile()) {
            ProfileContainer profiler = new ProfileContainer();
            sharedUI.setLocked(false);
            sharedUI.add(profiler);
            sharedUI.setLocked(true);
        }
    }
    return sharedUI;
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WApplication(com.github.bordertech.wcomponents.WApplication) ProfileContainer(com.github.bordertech.wcomponents.monitor.ProfileContainer)

Example 15 with WApplication

use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.

the class PlainLauncher_Test method testGetUINonWApplication.

@Test
public void testGetUINonWApplication() {
    Config.getInstance().setProperty(ConfigurationProperties.LDE_PLAINLAUNCHER_COMPONENT_TO_LAUNCH, MyTestComponent.class.getName());
    PlainLauncher plain = new PlainLauncher();
    WComponent ui1 = plain.getUI(new MockHttpServletRequest());
    Assert.assertTrue("Root UI should be a WApplication", ui1 instanceof WApplication);
    ui1 = ((WApplication) ui1).getChildAt(0);
    Assert.assertTrue("UI should be an instance of MyTestComponent", ui1 instanceof MyTestComponent);
    // Call getUI again, the same instance should be returned
    WComponent ui2 = ((WApplication) plain.getUI(new MockHttpServletRequest())).getChildAt(0);
    Assert.assertSame("Should have returned the same UI instance", ui1, ui2);
}
Also used : AbstractWComponent(com.github.bordertech.wcomponents.AbstractWComponent) WComponent(com.github.bordertech.wcomponents.WComponent) WApplication(com.github.bordertech.wcomponents.WApplication) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

WApplication (com.github.bordertech.wcomponents.WApplication)28 Test (org.junit.Test)14 UIContext (com.github.bordertech.wcomponents.UIContext)13 WComponent (com.github.bordertech.wcomponents.WComponent)8 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 WButton (com.github.bordertech.wcomponents.WButton)4 WLabel (com.github.bordertech.wcomponents.WLabel)4 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)3 WText (com.github.bordertech.wcomponents.WText)3 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)3 PrintWriter (java.io.PrintWriter)3 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)2 WTextField (com.github.bordertech.wcomponents.WTextField)2 WWindow (com.github.bordertech.wcomponents.WWindow)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 Map (java.util.Map)2 Before (org.junit.Before)2 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)1 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)1 Environment (com.github.bordertech.wcomponents.Environment)1