/** * Basic sanity-test to ensure that the WComponent app is performing all the processing that it * should. */ @Test public void testWServletAppCorrectness() throws Exception { SimpleWServlet servlet = new SimpleWServlet(); servlet.init(new MockServletConfig()); MockHttpSession session = new MockHttpSession(); // First request sendWServletRequest(servlet, session, 0, null); // Second request WServletHelper helper = new WServletHelper( servlet, new MockHttpServletRequest(session), new MockHttpServletResponse()); UIContext uic = helper.getUIContext(); SimpleApp app = (SimpleApp) uic.getUI(); sendWServletRequest(servlet, session, 1, uic.getEnvironment().getSessionToken()); setActiveContext(uic); Assert.assertEquals("Incorrect step", 2, uic.getEnvironment().getStep()); Assert.assertEquals( "Incorrect property1 value", "p1_1", ((SimpleFormBean) app.beanContainer.getBean()).getProperty1()); Assert.assertEquals( "Incorrect property2 value", "p2_1", ((SimpleFormBean) app.beanContainer.getBean()).getProperty2()); }
/** * Retrieves the application title for the given context. This mess is required due to WWindow * essentially existing as a separate UI root. If WWindow is eventually removed, then we can just * retrieve the title from the root WApplication. * * @param uic the context to check. * @return the current application title. */ private String getApplicationTitle(final UIContext uic) { WComponent root = uic.getUI(); String title = root instanceof WApplication ? ((WApplication) root).getTitle() : null; Map<String, String> params = uic.getEnvironment().getHiddenParameters(); String target = params.get(WWindow.WWINDOW_REQUEST_PARAM_KEY); if (target != null) { ComponentWithContext targetComp = WebUtilities.getComponentById(target, true); if (targetComp != null && targetComp.getComponent() instanceof WWindow) { try { UIContextHolder.pushContext(targetComp.getContext()); title = ((WWindow) targetComp.getComponent()).getTitle(); } finally { UIContextHolder.popContext(); } } } return title == null ? "" : title; }