Search in sources :

Example 6 with UIContext

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

the class DevToolkit_Test method setUp.

@Before
public void setUp() {
    UIContext uic = new UIContextImpl();
    uic.setUI(new WText("dummy"));
    UIContextHolder.pushContext(uic);
    Config.getInstance().setProperty(ConfigurationProperties.DEVELOPER_TOOKIT, "true");
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) WText(com.github.bordertech.wcomponents.WText) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) Before(org.junit.Before)

Example 7 with UIContext

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

the class LookupTableHelper_Test method testRegisterList.

@Test
public void testRegisterList() {
    final String key = "LookupTableHelper_Test.testRegisterList.key";
    UIContext uic = createUIContext();
    UIContextHolder.pushContext(uic);
    MockHttpSession session = new MockHttpSession();
    ServletRequest request = new ServletRequest(new MockHttpServletRequest(session));
    LookupTableHelper.registerList(key, request);
    // Use a new request to ensure that it was stored as a session attribute
    request = new ServletRequest(new MockHttpServletRequest(session));
    Assert.assertSame("Incorrect context returned", uic, LookupTableHelper.getContext(key, request));
}
Also used : ServletRequest(com.github.bordertech.wcomponents.servlet.ServletRequest) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) UIContext(com.github.bordertech.wcomponents.UIContext) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) Test(org.junit.Test)

Example 8 with UIContext

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

the class TreeUtil_Test method testGetRoot.

@Test
public void testGetRoot() {
    UIContext uic = UIContextHolder.getCurrent();
    Assert.assertSame("Incorrect root node returned for root", root, TreeUtil.getRoot(uic, root));
    Assert.assertSame("Incorrect root node returned for containerChild", root, TreeUtil.getRoot(uic, containerChild));
    Assert.assertSame("Incorrect root node returned for simpleChild", root, TreeUtil.getRoot(uic, simpleChild));
    Assert.assertSame("Incorrect root node returned for repeaterChild", root, TreeUtil.getRoot(uic, repeaterChild));
    Assert.assertSame("Incorrect root node returned for grandChild", root, TreeUtil.getRoot(uic, grandChild));
    UIContext row2Context = repeaterChild.getRowContext("2");
    Assert.assertSame("Incorrect root node returned for repeatedComponent row 2", root, TreeUtil.getRoot(row2Context, repeatedComponent));
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 9 with UIContext

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

the class TreeUtil_Test method testCollateVisibles.

@Test
public void testCollateVisibles() {
    // Simple case - everything visible.
    List<ComponentWithContext> visibles = TreeUtil.collateVisibles(root);
    UIContext uic = UIContextHolder.getCurrent();
    Assert.assertEquals("Incorrect number of visible components", 10, visibles.size());
    Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
    Assert.assertTrue("List should contain containerChild", isInList(visibles, containerChild, uic));
    Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
    Assert.assertTrue("List should contain repeaterChild", isInList(visibles, repeaterChild, uic));
    Assert.assertTrue("List should contain grandChild", isInList(visibles, grandChild, uic));
    Assert.assertTrue("List should contain repeatedComponent row 1", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("1")));
    Assert.assertTrue("List should contain repeatedComponent row 2", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("2")));
    Assert.assertTrue("List should contain repeatedComponent row 3", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("3")));
    Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
    Assert.assertTrue("List should contain visible card", isInList(visibles, card1, uic));
    // Make grandChild invisible - should only remove it
    grandChild.setVisible(false);
    visibles = TreeUtil.collateVisibles(root);
    Assert.assertEquals("Incorrect number of visible components", 9, visibles.size());
    Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
    Assert.assertTrue("List should contain containerChild", isInList(visibles, containerChild, uic));
    Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
    Assert.assertTrue("List should contain repeaterChild", isInList(visibles, repeaterChild, uic));
    Assert.assertTrue("List should contain repeatedComponent row 1", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("1")));
    Assert.assertTrue("List should contain repeatedComponent row 2", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("2")));
    Assert.assertTrue("List should contain repeatedComponent row 3", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("3")));
    Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
    Assert.assertTrue("List should contain visible card", isInList(visibles, card1, uic));
    grandChild.setVisible(true);
    // Make containerChild invisible - should remove it and grandChild
    containerChild.setVisible(false);
    visibles = TreeUtil.collateVisibles(root);
    Assert.assertEquals("Incorrect number of visible components", 8, visibles.size());
    Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
    Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
    Assert.assertTrue("List should contain repeaterChild", isInList(visibles, repeaterChild, uic));
    Assert.assertTrue("List should contain repeatedComponent row 1", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("1")));
    Assert.assertTrue("List should contain repeatedComponent row 2", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("2")));
    Assert.assertTrue("List should contain repeatedComponent row 3", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("3")));
    Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
    Assert.assertTrue("List should contain visible card", isInList(visibles, card1, uic));
    containerChild.setVisible(true);
    // Make repeaterChild invisible - should remove it and its 3 rows
    repeaterChild.setVisible(false);
    visibles = TreeUtil.collateVisibles(root);
    Assert.assertEquals("Incorrect number of visible components", 6, visibles.size());
    Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
    Assert.assertTrue("List should contain containerChild", isInList(visibles, containerChild, uic));
    Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
    Assert.assertTrue("List should contain grandChild", isInList(visibles, grandChild, uic));
    Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
    Assert.assertTrue("List should contain visible card", isInList(visibles, card1, uic));
    repeaterChild.setVisible(true);
    // Make 2nd row of repeater invisible
    setActiveContext(repeaterChild.getRowContext("2"));
    repeatedComponent.setVisible(false);
    setActiveContext(uic);
    visibles = TreeUtil.collateVisibles(root);
    Assert.assertEquals("Incorrect number of visible components", 9, visibles.size());
    Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
    Assert.assertTrue("List should contain containerChild", isInList(visibles, containerChild, uic));
    Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
    Assert.assertTrue("List should contain repeaterChild", isInList(visibles, repeaterChild, uic));
    Assert.assertTrue("List should contain grandChild", isInList(visibles, grandChild, uic));
    Assert.assertTrue("List should contain repeatedComponent row 1", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("1")));
    Assert.assertTrue("List should contain repeatedComponent row 3", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("3")));
    Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
    Assert.assertTrue("List should contain visible card", isInList(visibles, card1, uic));
    // Switch active cards
    cardManager.makeVisible(card2);
    visibles = TreeUtil.collateVisibles(root);
    Assert.assertEquals("Incorrect number of visible components", 9, visibles.size());
    Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
    Assert.assertTrue("List should contain containerChild", isInList(visibles, containerChild, uic));
    Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
    Assert.assertTrue("List should contain repeaterChild", isInList(visibles, repeaterChild, uic));
    Assert.assertTrue("List should contain grandChild", isInList(visibles, grandChild, uic));
    Assert.assertTrue("List should contain repeatedComponent row 1", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("1")));
    Assert.assertTrue("List should contain repeatedComponent row 3", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("3")));
    Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
    Assert.assertTrue("List should contain visible card", isInList(visibles, card2, uic));
    // Make root invisible - should be an empty list
    root.setVisible(false);
    visibles = TreeUtil.collateVisibles(root);
    Assert.assertEquals("Incorrect number of visible components", 0, visibles.size());
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext) Test(org.junit.Test)

Example 10 with UIContext

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

the class DiagnosticImpl_Test method testGetContext.

@Test
public void testGetContext() {
    final UIContext uic = new UIContextImpl();
    DiagnosticImpl diag = new DiagnosticImpl(Diagnostic.INFO, uic, new WTextField(), "dummy");
    Assert.assertSame("Incorrect UI context", uic, diag.getContext());
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WTextField(com.github.bordertech.wcomponents.WTextField) 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