/* (non-Javadoc) * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp() */ public void setUp() throws Exception { super.setUp(); form = new HtmlForm(); form.setId("form"); form2 = new HtmlForm(); form2.setId("form2"); facesContext.getViewRoot().getChildren().add(form); facesContext.getViewRoot().getChildren().add(form2); stp1 = (UISimpleTogglePanel) application.createComponent("org.richfaces.SimpleTogglePanel"); stp1.setId("simpleTogglePanel1"); stp1.setOpened(true); stp1.setSwitchType(UISimpleTogglePanel.SERVER_SWITCH_TYPE); openMarker1 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE); openMarker1.setId("openMarker"); openMarker1.setValue("open"); closeMarker1 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE); closeMarker1.setId("closeMarker"); closeMarker1.setValue("close"); stp1.getFacets().put(openMarker1.getId(), openMarker1); stp1.getFacets().put(closeMarker1.getId(), closeMarker1); form.getChildren().add(stp1); stp2 = (UISimpleTogglePanel) application.createComponent("org.richfaces.SimpleTogglePanel"); stp2.setId("simpleTogglePanel2"); stp2.setOpened(false); stp2.setSwitchType(UISimpleTogglePanel.SERVER_SWITCH_TYPE); openMarker2 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE); openMarker2.setId("openMarker"); openMarker2.setValue("open"); closeMarker2 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE); closeMarker2.setId("closeMarker"); closeMarker2.setValue("close"); stp2.getFacets().put(openMarker2.getId(), openMarker2); stp2.getFacets().put(closeMarker2.getId(), closeMarker2); form2.getChildren().add(stp2); input = (UIInput) application.createComponent(UIInput.COMPONENT_TYPE); input.setValue(""); input.setId("opened"); input.getAttributes().put("onchange", "return true;"); stp1.getChildren().add(input); command = new HtmlCommandLink(); command.setId("command"); stp1.getChildren().add(command); }
/** * Test component rendering * * @throws Exception */ public void testRender() throws Exception { HtmlPage page = renderView(); assertNotNull(page); // System.out.println(page.asXml()); HtmlElement div1 = page.getHtmlElementById(stp1.getClientId(facesContext)); assertNotNull(div1); assertEquals("div", div1.getNodeName()); assertTrue(div1.getAttributeValue("class").contains("rich-stglpanel")); assertEquals("", div1.getAttributeValue("style")); HtmlDivision div2 = (HtmlDivision) page.getHtmlElementById(stp1.getClientId(facesContext) + "_header"); assertNotNull(div2); assertEquals("div", div2.getNodeName()); String classAttr2 = div2.getAttributeValue("class"); assertTrue(classAttr2.contains("rich-stglpanel-header")); HtmlElement div3 = page.getHtmlElementById(stp1.getClientId(facesContext) + "_switch_on"); assertNotNull(div3); assertEquals("div", div3.getNodeName()); HtmlElement div5 = page.getHtmlElementById(stp1.getClientId(facesContext) + "_switch_off"); assertNotNull(div5); assertEquals("div", div5.getNodeName()); HtmlElement div4 = page.getHtmlElementById(stp1.getClientId(facesContext) + "_body"); assertNotNull(div4); assertEquals("div", div4.getNodeName()); assertEquals("", div4.getAttributeValue("style")); try { page.getHtmlElementById(openMarker1.getClientId(facesContext)); assertTrue(false); } catch (Throwable t) { } HtmlElement f1 = page.getHtmlElementById(closeMarker1.getClientId(facesContext)); assertNotNull(f1); HtmlElement f2 = page.getHtmlElementById(openMarker2.getClientId(facesContext)); assertNotNull(f2); try { page.getHtmlElementById(closeMarker2.getClientId(facesContext)); assertTrue(false); } catch (Throwable t) { } }
/** * Test simpleTogglePanel switch * * @throws Exception */ public void testSwitch() throws Exception { assertTrue(stp1.isOpened()); HtmlPage page = renderView(); // System.out.println(page.asXml()); externalContext.addRequestParameterMap( form.getClientId(facesContext), form.getClientId(facesContext)); externalContext.addRequestParameterMap(stp1.getClientId(facesContext), "false"); stp1.setSwitchType(UISimpleTogglePanel.CLIENT_SWITCH_TYPE); UIViewRoot viewRoot = facesContext.getViewRoot(); viewRoot.processDecodes(facesContext); viewRoot.processValidators(facesContext); viewRoot.processUpdates(facesContext); assertFalse(stp1.isOpened()); }