[richfaces-svn-commits] JBoss Rich Faces SVN: r311 - trunk/richfaces/togglePanel/src/test/java/org/richfaces/component.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Fri Apr 6 11:21:18 EDT 2007
Author: d.bulahov
Date: 2007-04-06 11:21:18 -0400 (Fri, 06 Apr 2007)
New Revision: 311
Added:
trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelComponentTest.java
Removed:
trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelTest.java
Log:
Unit tests development
Added: trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelComponentTest.java
===================================================================
--- trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelComponentTest.java (rev 0)
+++ trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelComponentTest.java 2007-04-06 15:21:18 UTC (rev 311)
@@ -0,0 +1,184 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+package org.richfaces.component;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.commons.lang.StringUtils;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.component.html.HtmlForm;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Unit test for Datascroller component.
+ */
+public class TogglePanelComponentTest extends AbstractAjax4JsfTestCase {
+ private static Set javaScripts = new HashSet();
+
+ static {
+ javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript");
+ javaScripts.add("prototype.js");
+ javaScripts.add("scripts/togglePanel.js");
+ }
+
+ private UITogglePanel togglePanel;
+ private UIToggleControl toggleControl;
+ private UIComponent form;
+ private UIOutput a;
+ private UIOutput b;
+ private UIOutput c;
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public TogglePanelComponentTest(String testName) {
+ super(testName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+
+ a = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);
+ a.setId("a_output");
+ a.setValue("a");
+
+ b = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);
+ b.setId("b_output");
+ b.setValue("b");
+
+ c = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);
+ c.setId("c_output");
+ c.setValue("c");
+
+
+ form = new HtmlForm();
+ form.setId("form");
+ facesContext.getViewRoot().getChildren().add(form);
+
+ togglePanel = (UITogglePanel)application.createComponent("org.richfaces.TogglePanel");
+ togglePanel.setId("TogglePanel");
+ togglePanel.getFacets().put("a", a);
+ togglePanel.getFacets().put("b", b);
+ togglePanel.getFacets().put("c", c);
+ togglePanel.setStateOrder("a,b,c");
+ togglePanel.setInitialState("a");
+
+ form.getChildren().add(togglePanel);
+
+ toggleControl = (UIToggleControl)application.createComponent("org.richfaces.ToggleControl");
+ toggleControl.setId("ToggleControl");
+ toggleControl.setFor(togglePanel.getId());
+ toggleControl.setFor(togglePanel.getId());
+ form.getChildren().add(toggleControl);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ togglePanel = null;
+ toggleControl = null;
+ form = null;
+ }
+
+ /**
+ * Test component rendering
+ *
+ * @throws Exception
+ */
+ public void testRender() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ //System.out.println(page.asXml());
+
+ HtmlElement div = page.getHtmlElementById(togglePanel.getClientId(facesContext));
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+
+ HtmlElement div_control = page.getHtmlElementById(toggleControl.getClientId(facesContext));
+ String classAttr = div_control.getAttributeValue("class");
+ assertTrue(classAttr.contains("dr-tglctrl"));
+ assertTrue(classAttr.contains("rich-tglctrl"));
+ }
+
+ /**
+ * Test style rendering
+ *
+ * @throws Exception
+ */
+ public void testRenderStyle() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List links = page.getDocumentElement().getHtmlElementsByTagName("link");
+
+ assertEquals(1, links.size());
+ HtmlElement link = (HtmlElement) links.get(0);
+ assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/toggleControl.xcss"));
+ }
+
+ /**
+ * Test script rendering
+ *
+ * @throws Exception
+ */
+ public void testRenderScript() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List scripts = page.getDocumentElement().getHtmlElementsByTagName("script");
+
+ for (Iterator it = scripts.iterator(); it.hasNext();) {
+ HtmlScript item = (HtmlScript) it.next();
+ String srcAttr = item.getSrcAttribute();
+
+ if (StringUtils.isNotBlank(srcAttr)) {
+ boolean found = false;
+ for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();) {
+ String src = (String) srcIt.next();
+
+ found = srcAttr.contains(src);
+ if (found) {
+ break;
+ }
+ }
+
+ assertTrue(found);
+ }
+ }
+ }
+}
+
+
+
+
Deleted: trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelTest.java
===================================================================
--- trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelTest.java 2007-04-06 14:50:38 UTC (rev 310)
+++ trunk/richfaces/togglePanel/src/test/java/org/richfaces/component/TogglePanelTest.java 2007-04-06 15:21:18 UTC (rev 311)
@@ -1,53 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.component;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import javax.faces.component.UIComponent;
-
-/**
- * Unit test for simple Component.
- */
-public class TogglePanelTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public TogglePanelTest( String testName )
- {
- super( testName );
- }
-
-
- /**
- * Rigourous Test :-)
- */
- public void testComponent()
- {
- assertTrue( true );
- }
-}
More information about the richfaces-svn-commits
mailing list